This repository is deprecated.
npm-dependency-carrier is a command line tool to carry npm dependencies between various npm registries that may or may not have internet connection.
First globally install application
npm install -g @obss/npm-dependency-carrier
After installation, you can run it with ndc
command.
ndc --help
is useful too.
We have been working in an airgapped environment to develop various js applications. During our development efforts, we saw that it is really hard to have consistent development and build environment, mainly because of npm dependencies.
We tried various techniques to move dependencies between airgapped envs and internet, but all approaches had their shortcommings. In order to fix this, we build this tool to carry differences between registries, with respect to a package.json
file.
npm-dependency-carrier
is a tool to carry dependencies between npm registries. In order to do this, it uses npm
command line commands, pacote
and libnpmpublish
library to make sure that the carrying of packages is as smooth as possible.
ndc
needs an installable project to start with. This makes sure that we can rely on npm
to resolve depenencies, so we will not add another variable to whole processes. Let’s investigate steps.
-
ndc index
: This command is used to create initial lock file, calledndc-lock.json
to find out dependencies that will be used as basis for difference calculation between registries. -
ndc compare -r [private npm group registry]
: This command is used to calculate differences between current lock file, and your target registry. If you are using multiple registries that are connected with a group registry, use group registries address here to make sure that you have a correct comparison. -
ndc fetch -r [private npm group registry]
: This command is used to download npm packages from soruce registry (npm registry) and tars them inndc-carry.tgz
. This step uses urls fromndc-lock.json
to gather packages. -
ndc publish -r [private npm registry]
: This command is used to publish downloaded packages to your registry. Here for-r
, use your target private registry, not group one. This publish stage is two phased. First phase is to uselibnpmpublish
to publish packages. This is used to override regisry settings that is defined inpackage.json
for projects. However, this step might fail because of inter-dependencies, and this step ignores prepublish and postpublish scripts. So to make sure, this step also runsnpm publish --registry=[private npm registry]
on your local for packages that failed duringlibnpmpublish
phase. -
ndc relock -r [private npm group registry]
: This command is used to fix package-lock.json files. After previous steps, your checksums will fail, so this step will usendc-lock.json
to fetch checksum of relevant package and update its checksum. You can deletepackage-lock.json
too, since now all depenencies are carried, and it is safe to have npm recalculate dependency tree, but it is recomended to run this command and make sure everythig is safe for all team. This step will also createold-package-lock.json
file that contains previous package lock file.
This is a step by step explanation of the process. This example assumes that you have access to 2 machines, one with internet and one without. This example assumes that you run npm login
for intranet machine, and have global .npmrc
file with relevant settings.
- On an internet machine run
git clone https://github.com/obss/.npm-dependency-carrier.git
and go to project folder. - On the same machine install project
npm install
. - On the same machine run
ndc index
. - Copy project folder to air gapped machine.
- On airgapped machine, run
node ndc.js compare -r [private npm group registry]
in project folder. - Move
ndc-lock.json
from airgapped machine to internet machine project directory. - On internet machine, run
ndc fetch -r [private npm group registry]
in project folder. - Copy
ndc-lock.json
andndc-carry.tgz
to airgapped machine project folder. - On airgapped machine, run
node ndc.js publish -r [private npm registry]
in project folder to publish all packages. - On airgapped machine, run
npm install
in project folder. - On airgapped machine, run
npm publish
. - On airgapped machine, run
npm install -g @obss/npm-dependency-carrier