nikjohn nikjohn - 1 month ago 9
Git Question

npm module install locally only if not available globally

We have a web project that has multiple

git submodules
within each other. For functional testing, we use both
PhantomJS
and
Selenium
(one for local development, the other for CI deployment and Visual Regression Testing).

Because each submodule has it's own
package.json
,
PhantomJS
and
selenium-standalone
are installed multiple times during the bootstrap process.

My question is this: Can I install these giant
npm
modules globally and somehow have my application pick up the global installation and only when this is unavailable, try and pull from cache or from the remote repo?

Something like:

if(global_install){
continue
}
else{
npm install
}

Answer

Maybe a solution can be what RedSpar0w proposed here: https://github.com/npm/npm/issues/2949#issuecomment-238703924

{
    "name": "Meh",
    "description": "Some Description",
    "scripts": {
        "preinstall": "(npm list someDependency -g && npm install otherDependency -g) || (npm list someDependency || npm install someDependency) && npm install otherDependency -g"
    }
}

checks if someDependency installed globally if so then install otherDependency globally otherwise check if someDependency installed locally if not then install someDependency locally but either way install otherDependency globally because someDependency is not installed locally

You can play with it depending on your needs.

Comments