Cache YARN properly?

There is an existing feature request to have Yarn preinstalled, please :heart: that post as that is how the product team gauges interest and prioritizes requests.

Regarding the issue of caching the Yarn packages, adding the following snippets to your circle.yml file will resolve that:

machine:
  pre:
    - mkdir ~/.yarn-cache

and

dependencies:
  cache_directories:
    - ~/.yarn-cache

Please keep in mind that this will increase your Restore Cache step, so you may want to do a couple tests to see which is faster.

To explain, we need to create the ~/.yarn-cache directory before the dependencies, as you can not tell CircleCi to cache a directory that does not exist at the time the instruction is parsed.

5 Likes