So, after some digging through the NPM source code, it turns out there is a way to do this.
My solution is below:
registry=https://registry.npmjs.org/
@test-scope:registry=http://nexus:8081/nexus/content/repositories/npm-test/
//nexus:8081/nexus/content/repositories/npm-test/:username=admin
//nexus:8081/nexus/content/repositories/npm-test/:_password=YWRtaW4xMjM=
email=…
Explanation:
The scope @test-scope
specifies that packages with the scope should be published to a different registry than the default registry=
when executing the npm publish
command.
The two lines starting with //nexus:8081/...
are used to specify the credentials to the scoped repository for both username
and _password
where _password
is the base64 encoded password component from the previously used _auth
credentials.
Using this approach, only scoped packages will be published and installed from the private registry and all other packages will be installed from the default registry.
Edit:
Additional to this, the password can be specified as an environment variable so that it is not stored in plaintext in the file.
For example:
registry=https://registry.npmjs.org/
@test-scope:registry=http://nexus:8081/nexus/content/repositories/npm-test/
//nexus:8081/nexus/content/repositories/npm-test/:username=admin
//nexus:8081/nexus/content/repositories/npm-test/:_password=${BASE64_PASSWORD}
email=…
Also, when using Nexus, the email=
line must be specified.
npm-private
registry andnpm-open
registry individually. – Akkadnpm-open
, justnpm-private
at this stage, although it would be interesting to know how they can both have auth. (I do realise the example has an_auth
key) – Theola