Skip to content

@actions/tool-cache: convert to an ESM module#2274

Merged
danwkennedy merged 3 commits intomainfrom
danwkennedy/actions-tool-cache-esm
Jan 29, 2026
Merged

@actions/tool-cache: convert to an ESM module#2274
danwkennedy merged 3 commits intomainfrom
danwkennedy/actions-tool-cache-esm

Conversation

@danwkennedy
Copy link
Contributor

Description

We're upgrading all the packages in this repo to ESM modules. @actions/tool-cache can go next since all its dependencies are ESM modules.

@danwkennedy danwkennedy requested a review from a team as a code owner January 29, 2026 02:35
Copilot AI review requested due to automatic review settings January 29, 2026 02:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates @actions/tool-cache to be an ESM-only package, aligning it with other ESM-converted packages in the repo and updating its dependencies accordingly.

Changes:

  • Configure the tool-cache TypeScript build for Node-style ESM (module/moduleResolution set to node16) and update internal imports to use .js specifiers and top-level @actions/exec exports.
  • Refactor manifest.ts to pure ESM imports and introduce an _internal helper object for testability, while keeping _readLinuxVersionFile as a backwards-compatibility alias.
  • Mark the package as ESM-only in package.json, add an exports map, bump to version 4.0.0 with updated dependency versions and lockfile, update Jest config and tests to work with the new ESM shape, and document the breaking change in RELEASES.md.

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/tool-cache/tsconfig.json Sets module and moduleResolution to node16 for ESM-compatible builds while preserving existing outDir/rootDir layout.
packages/tool-cache/src/tool-cache.ts Updates internal imports to use .js specifiers and the top-level @actions/exec ESM entrypoint, keeping public API and logic unchanged.
packages/tool-cache/src/manifest.ts Converts from require-style imports to ESM imports, introduces _internal.readLinuxVersionFile for Jest mocking, and retains _readLinuxVersionFile() as a compatibility wrapper.
packages/tool-cache/package.json Declares the package as ESM-only via "type": "module", adds an exports map for types/import, bumps to 4.0.0, and updates runtime and dev dependencies to current major versions.
packages/tool-cache/package-lock.json Synchronizes lockfile with new dependency versions (including transitive dev tooling like nock and its dependencies).
packages/tool-cache/__tests__/tool-cache.test.ts Adjusts imports to reference ../src/tool-cache.js so tests run against the ESM-shaped source with Jest’s .js mapper.
packages/tool-cache/__tests__/retry-helper.test.ts Points the test to ../src/retry-helper.js to match ESM-style internal imports.
packages/tool-cache/__tests__/manifest.test.ts Switches to ESM-style imports for tool-cache/manifest and updates spies to target mm._internal.readLinuxVersionFile, keeping the OS-version resolution tests working.
packages/tool-cache/RELEASES.md Adds a 4.0.0 entry documenting that the package is now ESM-only and clarifies the require vs import() breaking change.
jest.config.js Maps @actions/tool-cache to the built lib/tool-cache.js and ensures it and its dependencies are transpiled by ts-jest, mirroring the setup used for other ESM-converted packages.
Files not reviewed (1)
  • packages/tool-cache/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

lokesh755
lokesh755 previously approved these changes Jan 29, 2026
@danwkennedy danwkennedy merged commit 9d912b1 into main Jan 29, 2026
18 of 21 checks passed
DariuszPorowski added a commit to raven-actions/actionlint that referenced this pull request Jan 30, 2026
<!-- markdownlint-disable MD041 -->
## 💌 Description

This change pins the installed version of `@actions/tool-cache` to major
version 3.

<!-- Add a more detailed description of the changes if needed. -->

The `@actions/tool-cache` package was recently converted to an ESM
module: actions/toolkit#2274. This is
incompatible with the usage of `require` in the actionlint script:


https://github.com/raven-actions/actionlint/blob/580b34edf3f0039a5691481c6081049971ecd530/action.yml#L217-L218

## 🔗 Related issue

<!-- If your PR refers to a related issue, link it here. -->

Fixes: #51

## 📚 Type of change

<!-- Mark with an `x` all the checkboxes that apply (like `[x]`) -->

- [ ] 📝 Examples / docs / tutorials
- [x] 🐛 Bug fix (non-breaking change which fixes an issue)
- [ ] 🥂 Improvement (non-breaking change which improves an existing
feature)
- [ ] ✨ New feature (non-breaking change which adds functionality)
- [ ] 💥 Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🚨 Security fix
- [x] ⬆️ Dependencies update

## ✔️ Checklist

<!-- Mark with an `x` all the checkboxes that apply (like `[x]`) -->

- [x] I've read the [`Code of
Conduct`](https://github.com/raven-actions/.workflows/blob/main/.github/CODE_OF_CONDUCT.md)
document.
- [x] I've read the
[`Contributing`](https://github.com/raven-actions/.workflows/blob/main/.github/CONTRIBUTING.md)
guide.

---------

Co-authored-by: Dariusz Porowski <3431813+DariuszPorowski@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants