Caching for node_modules based on package.json/yarn.lock?
dotansimha opened this issue · comments
Are you reporting a bug or a feature request ?
- Bug
- Feature request
Description
I was wondering if it's possible to add support for caching node_modules
according to a hash of either package.json
or yarn.lock
.
It could make the builds much faster.
Expected behavior
After each sucussful build, add a build task for caching node_modules
, and save it with a key created by a hash of package.json
or yarn.lock
.
When build starts, it should hash it again and look in the cache for a matching file, untar it, and then run yarn install
.
CircleCI has a similar solution that could be integrated with Yarn:
- Restore cache task: https://github.com/dotansimha/graphql-code-generator/blob/master/.circleci/config.yml#L8-L9
- Save cache task: https://github.com/dotansimha/graphql-code-generator/blob/master/.circleci/config.yml#L35-L38
System information
VSTS or TFS:
- VSTS
- TFS
Agent:
- Hosted
- Custom
OS:
- Windows
- Mac
- Linux
This can be achieved with the new CacheBeta
pipeline task. It works by running a cache step before the yarn install, which restores / caches the global .yarn cache. So the yarn install still runs, but much faster due to having a pre-primed cache.
https://docs.microsoft.com/en-us/azure/devops/pipelines/caching/?view=azure-devops#yarn
I haven’t had the time to go through the new caching feature. Is there anything the yarn task could do to make it easier in your opinion?
Looks pretty straightforward to me.
Not really, it just worked right out of the box for me. I added the new CacheBeta task, copied the config from the docs, tweaked it around to fit my project, and was good to go.
I guess it would have been easier if your yarn task just had a checkbox to enable and abstracted away CacheBeta :p
I am experiencing something very similar to https://stackoverflow.com/questions/64325825/yarn-module-not-found-error-in-azure-pipelines-via-cache-mechanism. Any ideas on how to troubleshoot this?