Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Git dependency on global npm install

Tags:

node.js

npm

Npm allows the use of a custom git URL to specify a dependency (see npm install private github repositories by dependency in package.json).

However, these dependencies are usually packed and published to npm registry, so they can be installed by name. This publish process usually includes build files, minified files, etc. that are usually not available in github.

When installing the dependencies with a custom git URL, these build, minify, etc. files might be needed, however they will not be available.

To generate these files, npm scripts could be used to run a hook in the install lifecycle. However, I could not find the proper script for this task as:

  1. Prepublish does not run in global installs. It will be deprecated in favor of prepare and prepublishOnly
  2. Prepare also run only on local installs. (EDIT: prepare also run on global installs, unlike what is said at npm scripts docs)
  3. Prepack runs before npm pack and npm publish and also when installing git dependencies (as explained in the documentation). However, it was not triggered when trying this script in a global install (node LTS version: v6.11.0, npm version (from node LTS): 3.10.10).
  4. Preinstall and Install are not recomended in the best practices:

Don't use install. Use a .gyp file for compilation, and prepublish for anything else. You should almost never have to explicitly set a preinstall or install script. If you are doing this, please consider if there is another option. The only valid use of install or preinstall scripts is for compilation which must be done on the target architecture.

  1. Postinstall will run also in local installs of the package, which is not the expected behaviour.
like image 862
atfornes Avatar asked Oct 29 '22 06:10

atfornes


1 Answers

prepare node script does the trick. However this npm script is only available from npm v5.0.0 as explained here: https://github.com/npm/npm/blob/dcc4273cadebe70f853e6d948a425978bc42e045/CHANGELOG.md#feature-summary

like image 69
atfornes Avatar answered Nov 12 '22 19:11

atfornes