Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install from GitHub in specific environment

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?

like image 221
davidchambers Avatar asked Mar 27 '14 22:03

davidchambers


People also ask

How do I install a package from GitHub to NPM?

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>.

What does NPM install-p mean?

`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.

Does NPM run Git Deps?

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.

Should I use NPM If I never publish my package?

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):


1 Answers

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.

like image 196
Stankalank Avatar answered Sep 20 '22 14:09

Stankalank