GeezerVison is showing github.com — Enable caching by default if `packageManager` field is defined in package.json · Issue #686 · actions/setup-node
Enable caching by default if packageManager field is defined in package.json #686DescriptionDescription:
The action allows caching global packages data as per documentation in https://github.com/actions/setup-node#caching-global-packages-data
It's an amazing feature and reduces action execution time, but it has to be enabled in configuration.
Caching is not enabled in default setup. Users may not discover caching feature by default, and miss on the faster executions times enabled by caching.
The feature request is to enable caching by default if packageManager field is defined.
This can be enabled in a major version bump, say v4, to not affect existing users.
Justification:
Just want all users to get benefit of faster executions times allowed by caching without explicitly opting in, if they have set up packageManager field in their package.json
They can always explicitly opt-out by setting cache to empty string.
Are you willing to submit a PR?
Yes Reacted by sid, George Fu, Michael Young, kpietraszko, Alexander Kachkaev, Emilio Martinez, Nato Boram, Manu Chandrasekhar, Alex Kozack, Ari Becker and 16 more Reacted by Jan Kowalleck Reacted by Lex Activitytrivikr commented on Jan 31, 2023 ContributorAuthor More actions I think the implementation can be as simple as
- if (cache && isCacheFeatureAvailable()) {
+ const packageManagerFromManifest = getNameFromPackageManagerField();
+ if ((cache !== "" || packageManagerFromManifest) && isCacheFeatureAvailable()) {
const cacheDependencyPath = core.getInput('cache-dependency-path');
- await restoreCache(cache, cacheDependencyPath);
+ const packageManager = cache !== "" ? cache : packageManagerFromManifest;
+ await restoreCache(packageManager, cacheDependencyPath);
}
where getNameFromPackageManagerField returns the package manager name from packageManager field. That is:
Other package managers can be added, once they are supported MaksimZhukov commented on Feb 1, 2023 Hello @trivikr ! Thank you for the suggested idea!
We will consider adding this feature and will let you know as soon as we have any decision. Reacted by Nato Boram, Trivikram Kamat and roman zanettin Airkro commented on Sep 16, 2023 This is what I doing before this feature landed:
jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Detect package manager
shell: bash
run: node -p "'PACKAGE_MANAGER='+require('./package.json').packageManager?.split?.('@')?.[0]" >> "$GITHUB_ENV"
- name: Install pnpm
run: corepack enable pnpm
if: ${{ env.PACKAGE_MANAGER == 'pnpm' }}
# install pnpm before setup-node
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: lts
cache: ${{ env.PACKAGE_MANAGER }}trivikr commented on Mar 25, 2025 ContributorAuthor More actions Revisiting this, as devEngines has now appeared as a standard in Node.js ecosystem.
It'll be better to track devEngines.packageManager instead of (or in addition to) packageManager field.
It's implemented by [email protected] as well as [email protected]. Reacted by v-aparnajyothi-y and Guillaume Humbert v-HarithaVattikuti commented on Aug 22, 2025 Hello Everyone,
We’ve raised PR #1348 to address the above request. Please validate it against the requirement, and confirm to proceed further.
Feel free to reach out if you have any questions or need further clarification. v-priya-kinthali commented on Aug 28, 2025 Hello everyone👋,
The requested feature has now been implemented and the related PR#1348 has been merged. This update supports enabling caching when a valid package manager field is detected. To disable this automatic caching, set package-manager-cache to false.
To utilise this feature, you can use the actions/setup-node@main branch in your workflows for now, and the changes will be reflected in the upcoming releases.
We’ll be closing this issue. Please feel free to reach out if you have any further concerns or need additional assistance.
Thanks again for your suggestion and feedback! Reacted by TOMIKAWA Sotaro, Guillaume Humbert, Sʜɪᴍᴜʀᴀ Yū and Jonas Thelemann Reacted by Jonas Thelemann and Trivikram Kamat kleinfreund commented on Sep 4, 2025 Reacted by Daniel Bayley and Derek Lindahl v-priyagupta108 commented on Sep 22, 2025 Hello 👋,
We’re planning to update this feature so that caching is automatically enabled for npm, while caching will be disabled by default for other package managers (pnpm and yarn). This adjustment is being made based on recent issues with pnpm and yarn integration. For more background, please see issue #1357.
Our goal with this change is to ensure reliability and prevent failures like those reported for pnpm and yarn. If you have any concerns or suggestions, please share your feedback!
Thank you for your understanding and support. Reacted by Alexander Kachkaev MikeMcC399 commented on Sep 26, 2025 @priyagupta108
Enabling Yarn caching through actions/setup-node@v5 by default will break CI in nodejs/corepack if updated from v4 to v5. This GitHub Actions CI sets the environment variable YARN_ENABLE_GLOBAL_CACHE: false.
In a test branch https://github.com/MikeMcC399/corepack/tree/test/setup-node-v5 I simply updated from actions/setup-node@v4 to actions/setup-node@v5 and the workflow failed with:
Run actions/setup-node@v5
Attempt to resolve LTS alias from manifest...
(node:2071) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Found in cache @ /opt/hostedtoolcache/node/22.19.0/x64
Environment details
/usr/local/bin/yarn --version
1.22.22
/usr/local/bin/yarn cache dir
error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22.
Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
Error: error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22.
Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
After disabling cache in a different branch https://github.com/MikeMcC399/corepack/tree/test/setup-node-v5-no-cache with
- uses: actions/setup-node@v5
with:
node-version: lts/*
package-manager-cache: false
the workflow succeeded.
v-aparnajyothi-y commented on Sep 26, 2025 Hello Everyone, As part of PR #1374, we introduce detection support for devEngines.packageManager, enabling automatic caching for npm dependencies. This update will be included in the upcoming patch release of v5. We hope this enhancement helps streamline workflows and improve consistency across your projects.
Your feedback and suggestions are appreciated. Please take a look and share your thoughts.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|