My team uses a private npm registry. We install packages from this private registry when developing locally and when deploying to production. When deploying to staging, however, we'd like to pull from GitHub instead. I thought this would be possible using a preinstall
script which rewrites package.json to use the appropriate git+ssh:// URLs in place of the version numbers if NODE_ENV=staging.
This appears not to work, possibly because npm ignores the changes made to package.json (having already required it).
Perhaps I'm going about this in completely the wrong way. What is the recommended way of achieving this?
Installing Packages with npm from Github npm has the ability to install code from Github. If you look at the docs, you can install a package from a hosted git provider by leveraging npm to clone it with git npm install <git remote url>.
`npm install` saves any specified packages into `dependencies` by default. * `-P, --save-prod`: Package will appear in your `dependencies`. This is the default unless `-D` or `-O` are present.
As of npm5, npm will run any preparescript for bare "installs", which includes git deps. Which means the above comments around compilation and dist folders is out of date. Any package that properly sets their compilation to run on preparewill work just fine as a git dep without committing any compiled assets into git.
Even if you never publish your package, you can still get a lot of benefits of using npm if you just want to write a node program (a), and perhaps if you also want to be able to easily install it elsewhere after packing it up into a tarball (b). npm install (in package directory, no arguments):
You could try running npm-install
, which will resolve and install all of your dependencies, then npm-shrinkwrap
, which will generate the file npm-shrinkwrap.json
.
You can run your pre-install script on npm-shrinkwrap.json
and insert 'git+ssh://' URL's as needed, which already has all of the resolved dependencies you need. This should give you a shrink-wrapped package.json file which points to your github repositories.
Check out https://www.npmjs.org/doc/cli/npm-shrinkwrap.html#Building-shrinkwrapped-packages for more info on shrink-wrapping.
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