I am kind of a newbie regarding the npm
, so please help.
Let's say that i have some modules i am working on using a git repository for each one of them and i also installed sinopia
to have a private registry. The problem is that we are 2 teams. A team in a city and the other one is at world's end. In my team i have installed the private registry to be available in the local network. The issue here is that when we push on git, the other team doesn't have a private registry of their own, and even if they did they would need to publish each version of each module in their private registry. Also another issue is that we can't ( and don't want to ) make the sinopia
server public via IP.
Now the question is: How can we configure the package.json
/ npm
to manage dependencies from both the private registry ( if the registry responds ) and the git repository also ( if the private registry doesn't respond -- aka it doesn't exist -- ).
I know that we could set up each dependency to refer to a git tag/branch/commit but we want also to use the registry if possible.
UPDATE
So basically I would need a package.json that would know that if this part fails:
"dependencies": {
"app.core": "0.1.1"
}
because the private registry is not installed or not available, it could still load the dependecy from something like this:
"dependencies": {
"app.core": "git+ssh://[email protected]:group/app-core.git#v0.1.1"
},
Also note that i would prefer something that can be pushed in the git repository so that neither one of the teams should change the package.json locally.
Hope that someone can help.
npm is configured to use the npm public registry at https://registry.npmjs.org by default.
npm install --save-dev. –save-optional or -O: When this command is used the install the that packages will be listed under the optional Dependency section of the package. json file.
The only way that i found to work for the moment is to have a package.json like this:
"scripts": {
"postinstall" : "node fallbackDependencies.js"
}
"dependencies": {
"app.core": "git+ssh://[email protected]:group/app-core.git#v0.1.1"
},
"optionalDependencies": {
"app.core": "0.1.1"
}
And in the fallbackDependencies.js
file to run a script that takes all the dependencies from the package.json which are also in the optionalDependencies
and for each of them check if there is a folder with that name in the node_modules
folder. If there is no folder then run npm install <json.dependencies[x]>
.
This is the only temporary solution that i could think of.
If someone has a better approach to this please feel free to answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With