geeklearningio / gl-vsts-tasks-yarn

Yarn Package Manager Visual Studio Team Services Build and Release Management extensions
MIT License
52 stars 18 forks source link

Caching for node_modules based on package.json/yarn.lock? #67

Closed dotansimha closed 2 years ago

dotansimha commented 5 years ago

Are you reporting a bug or a 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:

System information

VSTS or TFS:

Agent:

OS:

elwynelwyn commented 4 years ago

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

sandorfr commented 4 years ago

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.

elwynelwyn commented 4 years ago

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

walkerrandolphsmith commented 3 years ago

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?