Clarify caching of npm / Yarn / pnpm dependencies
See original GitHub issueI was excited to see the blog post GitHub Actions: Setup-node now supports dependency caching. However, it’s not clear to me what this caching actually means. From the README:
<div type='discussions-op-text'>README.md
Caching yarn dependencies:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'yarn'
- run: yarn install
- run: yarn test
Yarn caching handles both yarn versions: 1 or 2.
</div>Caching can mean many things when it comes to Yarn 2, for example, these questions come to mind:
- Is the
node_modules
folder cached? - When Yarn runs in the PnP mode, is
.yarn/cache
cached instead? - Or is it the local cache of downloaded tarballs (
~/.cache/yarn
) that is cached? - How is the caching done? Is it a local filesystem that is re-attached for future runs of the job or is the “slow” approach of @actions/cache that just uploads / downloads files to some S3-like blob storage? (I think we tested it and it wasn’t even faster than downloading dependencies from registry.npmjs.com over and over.)
Some clarifications would be appreciated 🙏.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:9 (4 by maintainers)
Top Results From Across the Web
JavaScript package managers compared: npm, Yarn, or pnpm?
The main problem the creators of pnpm had with npm and Yarn was the redundant storage of dependencies that were used across projects....
Read more >YARN vs NPM (vs pnpm) in 2019: comparison and verdict
NPM can manage packages that are local dependencies of a particular project, as well as globally-installed JavaScript tools. When used as a ...
Read more >Cache NPM dependencies on Jenkins pipeline - Stack Overflow
Each project has a cache for npm packages, which are zipped they are zipped in a file containing the node_modules folder. These zip...
Read more >Alternative Package Managers For Node.js - Maestral Solutions
Yarn can give you a speed-up and offline installation (in some cases), while pnpm will save additional disc space and is useful for...
Read more >Why you should prefer using pnpm over npm and yarn? | refine
A package manager is responsible for installing, updating, and removing software packages and dependencies. NPM has been widely used as the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@borekb makes sense to me. Let me think how we can improve readme
@dominikg , since we cache “global cache” instead “node_modules”, Node.js version doesn’t matter and cache is identical. This way we cache only “download” step for packages and not “install” step. It is how actions/cache recommends.
The caching results of “post-install” scripts is not recommended because they can have side affects (change anything on machine outside of “node_modules” folder) or produce different results based on VM state (Image version on VM is updated every week and if result of some scripts depend on machine state, build can be broken after machine update)
Hello @akd-io. You’re right. It does not cache node_modules directory. Action uses
npm config get cache
to get global cache directory where all dependencies are cached. I think we can accept this pull request because as it was mentioned not everyone can have committed package-lock.json.Hello @sandstrom. As I checked, the default branch cache is available to other branches in setup-node. Could you please create the separate issue and provide repro steps. I can suppose that on branches you change lock files, that’s why action can’t get previous primary key.
For now I’m closing the issue. If you have any other question feel free to ping me in the thread or create separate issue.