isaacs/npm — pull request #2388 by rvagg (2012-04-21 14:02:49+00:00)
Title: --skip-installed flag for `npm install`

I don't have tests for this because I couldn't see how to work them in to the existing test structure as this is just an extra flag for `npm install`, if you'd like tests then could you point me in the right direction to get started?

`npm install [...] --skip-installed` will act a little like a plain `npm install` does on a directory with a *package.json*, that is, it'll skip any packages that already exist in the *node_modules* directory:

```
$ npm install foo bar
$ # → foo and bar installed into node_modules
$ npm install foo bar --skip-installed
$ # → nothing is done, they are already there
$ npm install foo bar baz --skip-installed
$ # → baz installed into node_modules
```

Additionally, semver matching is performed so you can do it by version, and even semver ranges (basically it's all passed to `semver.satisies, so you can do:

```
$ npm install foo@0.0.5
$ # → foo@0.0.5 installed to node_modules
$ npm install foo@0.0.5 --skip-installed
$ # → nothing happens
$ npm install foo@0.0.6 --skip-installed
$ # → foo@0.0.6 installed to node_modules
$ npm install 'foo@>=0.0.4' --skip-installed
$ # → nothing happens
$ npm install 'foo@>=0.0.10' --skip-installed
$ # → foo@* (latest) installed to node_modules
```

The main reason I want this is for use via the API in Ender so we can do `ender build pkg1 pkg2 pkg3` and have it act like a plain `npm install`, i.e. not install anything if it's already there. But it's also very handy as a command line option, particularly when installation can be slow (like down here in AU where the latency kills us).