yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Why isn't --prefer-offline on by default?

Open callumlocke opened this issue 7 years ago • 4 comments

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

What is the current behavior?

When you are online, you have to use the --prefer-offline flag if you want yarn to actually use your cache.

What is the expected behavior?

I feel like --prefer-offline should be the default, and --prefer-network should be for people who want to bypass their cache for some reason.

Please mention your node.js, yarn and operating system version.

Yarn 1.9.4 Node v10.10.0 macOS 10.12.6

callumlocke avatar Sep 18 '18 10:09 callumlocke

A breaking change - but I agree 💯%

We should discuss if we can improve the setup to consider modules that are not hosted on npm (for example pointing to a repository like git+https://[email protected]/myname/myrepo.git or to a github repo with username/repo. The situation occurs for automated testing when the code for an unpublished/self hosted module always needs to be up to date, but the already published npm modules will be fetched in vain as same version already is present in the offline cache.

In addition to the suggestions from @callumlocke I propose a flag to indicate that only npm modules prefer the offline cache. This would result in express being fetched from the offline cache while prettier/prettier is fetched online from Github. If the client is offline it defaults to the offline cache.

The name of this flag could be --prefer-online-not-npm but please come with inputs if you think of something better.

To summerise the full suggestion:

  • The current behaviour when adding --prefer-offline becomes default (prefer all from offline cache)
  • The current default behaviour can be achieved by adding --prefer-online (prefer all from online)
  • Setting --prefer-online-not-npm will fetch npm modules from offline cache and fetch all other modules online (defaults of offline cache if not online)

mathiasrw avatar Jan 07 '19 00:01 mathiasrw

While I'm neutral on the conversation here, I do want to note for those who find this thread that you can set your own defaults for the cli using the .yarnrc file.

So here:

yarn-offline-mirror ".yarn-local-mirror"
yarn-offline-mirror-pruning true
--install.prefer-offline true

In .yarnrc gets you a local mirror, pruning, and yarn will default to using the mirror.

pckilgore avatar Jun 06 '19 04:06 pckilgore

In .yarnrc gets you a local mirror, pruning, and yarn will default to using the mirror.

Which you can also do using the CLI commands for yarn config set ... =)

DanielRuf avatar Jun 06 '19 06:06 DanielRuf

Which is: yarn config set install.prefer-offline true

hcharley avatar Apr 05 '20 02:04 hcharley