-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Something to consider as a future enhancement, post-launch
It's possible to use custom servers with npm, it's just pretty annoying to handle it. The server is either set globally (via npm set registry) or every single time you run a command (via --registry flag, eg npm install --registry http://www.example.com/ test). Setting it globally only allows a single server to be selected We should be able to do better than that in Yarn.
I like the approach that NuGet takes. It has a default configuration file (%AppData%\NuGet\NuGet.Config on Windows) that only has their package source configured by default:
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>However you can easily add your own package sources to it, either by editing that file (which changes it globally) or adding a config to your project (which just changes it for that one project):
<packageSources>
<add key="ReactJS.NET Dev" value="http://reactjs.net/packages/" />
<add key="ASP.NET Core Nightly Builds" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>How this works is that when you install a package, it looks in the first source to see if it's available there. If not, it continues down the list, and only fails if none of the sources contain the requested package.
Use cases:
- In other communities, it's common to have a separate package server for nightly builds, and save the "main" package feed just for stable releases.
- Corporate users may want to have an internal server for their private packages, while continuing to use public servers for public packages
Note that this issue is specifically for allowing the usage of multiple different servers (for example, the public npm server for some packages, and a private server for others). Allowing a single different server to be set (for example, if you have a caching proxy, or something like Sinopia that's both a package server and a proxy) is covered by #606. Thanks!