Yarn: Environment variable for yarn cache directory location

Created on 20 Apr 2017  路  5Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
Cache location can only be configured via the cache-folder config option.

What is the expected behavior?
Being able to configure the cache location using an environment variable.

Other prominent package managers offer this functionality:

  • Composer: COMPOSER_CACHE_DIR
  • npm: NPM_CONFIG_CACHE
  • RubyGems: GEM_SPEC_CACHE
  • bower: bower_storage__packages (unconfirmed)
  • pip: PIP_DOWNLOAD_CACHE (unconfirmed)

This is extremely useful for continuous integration - you may want jobs to use a shared cache, but each individual job may not know (or perhaps shouldn't know) where that global cache exists. Additionally, if that global cache directory changes, it's much easier to update a single environment variable in the CI system than updating the yarn commands in every individual project.

I therefore propose using an envvar like YARN_CONFIG_CACHE_FOLDER. If defined, this would take precedence over the default cache directory. (However, it would not take precedence over any cache-folder option used on the command line.)

Most helpful comment

Yes, actually Yarn converts all environment variables into
YarnRegistry.config if they have yarn_ prefix.

That is not a widely known fact, do you want to write start a doc on the website for that, @zurawiki ?

All 5 comments

Sounds like a good first bug @colinodell

Can I take take a look and try to send in a PR?

Yeah absolutely!

This feature already seems to exist. The env variable name is YARN_CACHE_FOLDER

$ YARN_CACHE_FOLDER="foo" ./bin/yarn cache dir
foo/v1

Yes, actually Yarn converts all environment variables into
YarnRegistry.config if they have yarn_ prefix.

That is not a widely known fact, do you want to write start a doc on the website for that, @zurawiki ?

@bestander never link to branches! now, what line you had in mind?

馃毀 Never link to branches, share a permalink 馃毀

Was this page helpful?
0 / 5 - 0 ratings