Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to configure multiple registries in a single package.json

Is there any way the I can define two registries in publishConfig in package.json?

the use case is for publishing the artifact in 2 different location based on the purpose, when it is a SNAPSHOT it will use the snapshot path and for release purpose it uses the other one.

something like:

"publishConfig": {
        "snapshot-registry": "http://artifactory.test/artifactory/api/npm-snapshots"
        "release-registry": "http://artifactory.test/artifactory/api/npm-releases"
    },
like image 728
GeoCom Avatar asked Jul 01 '19 11:07

GeoCom


1 Answers

By reading the npm package json docs npm-package-json You can only override existing npm-config settings by using publishConfig, so you may not be able to add new properties.

However, you can use .npmrc to set different registry entries for scoped packages and default. In the .npmrc example bellow I have the snapshot package set for the GitHub registry and everything else may be published to the default npm registry.

@snapshot:registry=https://npm.pkg.github.com/snapshot
registry=https://registry.npmjs.org

The tricky part is which registry will the package go to. right? with the settings we have now, a simple npm publish would not work or it may just publish to the default registry. One approach I use, is login to my scoped registry with npm login --registry=https://npm.pkg.github.com --scope=snapshot, edit my package.json to match the name of my scoped package, for example @snapshot/package so it does not go to the default registry then publish.

Then, you may login to the default registry, edit accordingly and publish again there.

I hope this helps you, Its an annoying process, we may even need a "package registry manager" Don't know if one exists.

like image 74
akaizn Avatar answered Sep 22 '22 04:09

akaizn