|
| 1 | +- Start Date: 2017-09-21 |
| 2 | +- RFC PR: |
| 3 | +- Yarn Issue: |
| 4 | + |
| 5 | +# Summary |
| 6 | + |
| 7 | +Yarn should always use the registry configured by the current user, falling back to the default registry otherwise. It should not use the registry specified in the `resolved` field of lockfile. |
| 8 | + |
| 9 | +# Motivation |
| 10 | + |
| 11 | +The default registry used by Yarn is `registry.yarnpkg.com`, but the use of alternate registries is possible through configuration or command-line flags. Using an alternate registry can be useful for a number of reasons; it can improve performance, facilitate serving private packages, and improve the reliability of build and test servers. However, many of these use cases are environment specific. These benefits cannot be realized without allowing the use of different registries in different environments. |
| 12 | + |
| 13 | +* Using a registry mirror that is closer to you can dramatically improve performance. Using a single registry mirror might work well for teams that work in the same office, but teams that span great distances will need to use different registry mirrors to see the same benefit. |
| 14 | +* Build environments can benefit from using a dedicated registry. In addition to the performance benefits, it can also protect against outages that might affect the public registries. |
| 15 | + |
| 16 | +Currently, Yarn will only use the configured registry for newly installed packages. For packages that are listed in the lockfile already, Yarn will use the registry saved in the lockfile instead, ignoring the registry configuration of the current user. This effectively prevents switching registries between environments. |
| 17 | + |
| 18 | +# Detailed design |
| 19 | + |
| 20 | +Yarn should adopt the behavior `npm` introduced with `npm@5`, which is to always use the registry configured by the current user. This change was described in [this blog post](http://blog.npmjs.org/post/161081169345/v500): |
| 21 | +>If you generated your package lock against registry A, and you switch to registry B, npm will now try to install the packages from registry B, instead of A. If you want to use different registries for different packages, use scope-specific registries (npm config set @myscope:registry=https://myownregist.ry/packages/). Different registries for different unscoped packages are not supported anymore. |
| 22 | +
|
| 23 | +Yarn already supports switching to a different registry and scoped registries. The change would be to use them in all cases rather than just for new packages. |
| 24 | + |
| 25 | +### What about the `resolved` field in the lockfile? |
| 26 | + |
| 27 | +The `resolved` field will not be used to determine which registry is used. Changes to to the `resolved` field, such as removing the registry, are outside the scope of this RFC. |
| 28 | + |
| 29 | +### How do scoped registries work? |
| 30 | + |
| 31 | +Yarn supports configuring a registry for a specific scope (e.g. `yarn config set '@foo:registry' 'https://registry.foo.com'`). If a scoped registry has been configured, then this registry shall be used for **all** packages under that scope. Using different registries within a single scope is not supported. |
| 32 | + |
| 33 | +### Can I configure a specific non-scoped package use an alternate registry? |
| 34 | + |
| 35 | +No, non-scoped packages would all use the same registry. This restriction simplifies the configuration, and keeps us in line with `npm`. |
| 36 | + |
| 37 | +### Should the `resolved` field be used as a fallback? |
| 38 | + |
| 39 | +No, the user's configured registry should be used at all times. Falling back to `resolved` could hide problems (i.e. outdated or misconfigured mirrors) and negatively affect performance. It could also leak information to third parties about which packages are being used, which might be undesirable in certain environments. |
| 40 | + |
| 41 | +# How We Teach This |
| 42 | + |
| 43 | +We should improve the documentation for configuring Yarn, with a focus on the registry and scoped registry configuration. This change should also be featured prominently and explained in the release notes, and any blog post or announcement accompanying the version this ships in. This is a significant change, but it does bring it more in line with the behavior of `npm`, which many people are familiar with. |
| 44 | + |
| 45 | +Overall, the behavior of Yarn should be easier to understand after this change. The behavior will be more transparent and controllable by the user. |
| 46 | + |
| 47 | +# Drawbacks |
| 48 | + |
| 49 | +1. This would be a breaking change. |
| 50 | +2. Alternate registries for non-scoped packages (or within scopes) would be impossible |
| 51 | +While this was never supported officially, it was possible to do by directly editing the `yarn.lock` file. With this change, that would no longer be possible. |
| 52 | + |
| 53 | +# Alternatives |
| 54 | + |
| 55 | +1. Add additional configuration for overriding registries |
| 56 | +We could preserve the existing behavior, but add additional configuration for overriding the registry. This `override-registry` would behave like `registry` configuration does in the main proposal. This would allow users to opt-in to the new behavior without making a breaking change. |
| 57 | +While this would solve the problem, it would also make the configuration more confusing and difficult to teach. |
| 58 | +2. Use the `registry` configuration only as a fallback to the `resolved` field |
| 59 | +This could allow the install to succeed in cases where the `resolved` field has a registry that is inaccessible to the current user. However it would do nothing to address the use case where an alternate registry is used for performance reasons. |
| 60 | + |
| 61 | +# Unresolved questions |
| 62 | + |
| 63 | +* What is the performance impact of not using the cached tarball URL (`resolved`)? |
0 commit comments