UNPKG

14.4 kBMarkdownView Raw
1npm-check
2=========
3[![Build Status](https://travis-ci.org/dylang/npm-check.svg?branch=master)](https://travis-ci.org/dylang/npm-check)
4[![NPM version](https://badge.fury.io/js/npm-check.svg)](http://badge.fury.io/js/npm-check)
5[![npm](https://img.shields.io/npm/dm/npm-check.svg?maxAge=2592000)]()
6
7> Check for outdated, incorrect, and unused dependencies.
8
9<img width="796" alt="npm-check -u" src="https://cloud.githubusercontent.com/assets/51505/9569917/96947fea-4f48-11e5-9783-2d78077256f2.png">
10
11### Features
12
13* Tells you what's out of date.
14* Provides a link to the package's documentation so you can decide if you want the update.
15* Kindly informs you if a dependency is not being used in your code.
16* Works on your globally installed packages too, via `-g`.
17* **Interactive Update** for less typing and fewer typos, via `-u`.
18* Supports public and private [@scoped/packages](https://docs.npmjs.com/getting-started/scoped-packages).
19* Supports ES6-style [`import from`](http://exploringjs.com/es6/ch_modules.html) syntax.
20* Upgrades your modules using your installed version of npm, including the new `npm@3`, so dependencies go where you expect them.
21* Works with any public npm registry, [private registries](https://www.npmjs.com/enterprise), and alternate registries like [Sinopia](https://github.com/rlidwka/sinopia).
22* Does not query registries for packages with `private: true` in their package.json.
23* Emoji in a command-line app, because command-line apps can be fun too.
24* Works with `npm@2` and `npm@3`, as well as newer alternative installers like `ied` and `pnpm`.
25
26### Requirements
27* Node >= 10.9.0
28
29### On the command line
30
31This is the easiest way to use `npm-check`.
32
33### Install
34```bash
35$ npm install -g npm-check
36```
37
38### Use
39```bash
40$ npm-check
41```
42
43<img width="882" alt="npm-check" src="https://cloud.githubusercontent.com/assets/51505/9569919/99c2412a-4f48-11e5-8c65-e9b6530ee991.png">
44
45The result should look like the screenshot, or something nice when your packages are all up-to-date and in use.
46
47When updates are required it will return a non-zero response code that you can use in your CI tools.
48
49### Options
50
51```
52Usage
53 $ npm-check <path> <options>
54
55Path
56 Where to check. Defaults to current directory. Use -g for checking global modules.
57
58Options
59 -u, --update Interactive update.
60 -y, --update-all Uninteractive update. Apply all updates without prompting.
61 -g, --global Look at global modules.
62 -s, --skip-unused Skip check for unused packages.
63 -p, --production Skip devDependencies.
64 -d, --dev-only Look at devDependencies only (skip dependencies).
65 -i, --ignore Ignore dependencies based on succeeding glob.
66 -E, --save-exact Save exact version (x.y.z) instead of caret (^x.y.z) in package.json.
67 --specials List of depcheck specials to include in check for unused dependencies.
68 --no-color Force or disable color output.
69 --no-emoji Remove emoji support. No emoji in default in CI environments.
70 --debug Show debug output. Throw in a gist when creating issues on github.
71
72Examples
73 $ npm-check # See what can be updated, what isn't being used.
74 $ npm-check ../foo # Check another path.
75 $ npm-check -gu # Update globally installed modules by picking which ones to upgrade.
76```
77
78![npm-check-u](https://cloud.githubusercontent.com/assets/51505/9569912/8c600cd8-4f48-11e5-8757-9387a7a21316.gif)
79
80#### `-u, --update`
81
82Show an interactive UI for choosing which modules to update.
83
84Automatically updates versions referenced in the `package.json`.
85
86_Based on recommendations from the `npm` team, `npm-check` only updates using `npm install`, not `npm update`.
87To avoid using more than one version of `npm` in one directory, `npm-check` will automatically install updated modules
88using the version of `npm` installed globally._
89
90<img width="669" alt="npm-check -g -u" src="https://cloud.githubusercontent.com/assets/51505/9569921/9ca3aeb0-4f48-11e5-95ab-6fdb88124007.png">
91
92##### Update using [ied](https://github.com/alexanderGugel/ied) or [pnpm](https://github.com/rstacruz/pnpm)
93
94Set environment variable `NPM_CHECK_INSTALLER` to the name of the installer you wish to use.
95
96```bash
97NPM_CHECK_INSTALLER=pnpm npm-check -u
98## pnpm install --save-dev foo@version --color=always
99```
100
101You can also use this for dry-run testing:
102
103```bash
104NPM_CHECK_INSTALLER=echo npm-check -u
105```
106
107#### `-y, --update-all`
108
109Updates your dependencies like `--update`, just without any prompt. This is especially useful if you want to automate your dependency updates with `npm-check`.
110
111#### `-g, --global`
112
113Check the versions of your globally installed packages.
114
115If the value of `process.env.NODE_PATH` is set, it will override the default path of global node_modules returned by package [`global-modules`](https://www.npmjs.com/package/global-modules).
116
117_Tip: Use `npm-check -u -g` to do a safe interactive update of global modules, including npm itself._
118
119#### `-s, --skip-unused`
120
121By default `npm-check` will let you know if any of your modules are not being used by looking at `require` statements
122in your code.
123
124This option will skip that check.
125
126This is enabled by default when using `global` or `update`.
127
128#### `-p, --production`
129
130By default `npm-check` will look at packages listed as `dependencies` and `devDependencies`.
131
132This option will let it ignore outdated and unused checks for packages listed as `devDependencies`.
133
134#### `-d, --dev-only`
135
136Ignore `dependencies` and only check `devDependencies`.
137
138This option will let it ignore outdated and unused checks for packages listed as `dependencies`.
139
140#### `-i, --ignore`
141
142Ignore dependencies that match specified glob.
143
144`$ npm-check -i babel-*` will ignore all dependencies starting with 'babel-'.
145
146#### `-E, --save-exact`
147
148Install packages using `--save-exact`, meaning exact versions will be saved in package.json.
149
150Applies to both `dependencies` and `devDependencies`.
151
152#### `--specials`
153
154Check special (e.g. config) files when looking for unused dependencies.
155
156`$ npm-check --specials=bin,webpack` will look in the `scripts` section of package.json and in webpack config.
157
158See [https://github.com/depcheck/depcheck#special](https://github.com/depcheck/depcheck#special) for more information.
159
160#### `--color, --no-color`
161
162Enable or disable color support.
163
164By default `npm-check` uses colors if they are available.
165
166#### `--emoji, --no-emoji`
167
168Enable or disable emoji support. Useful for terminals that don't support them. Automatically disabled in CI servers.
169
170#### `--spinner, --no-spinner`
171
172Enable or disable the spinner. Useful for terminals that don't support them. Automatically disabled in CI servers.
173
174### API
175
176The API is here in case you want to wrap this with your CI toolset.
177
178```js
179const npmCheck = require('npm-check');
180
181npmCheck(options)
182 .then(currentState => console.log(currentState.get('packages')));
183```
184
185#### `update`
186
187* Interactive update.
188* default is `false`
189
190#### `global`
191
192* Check global modules.
193* default is `false`
194* `cwd` is automatically set with this option.
195
196#### `skipUnused`
197
198* Skip checking for unused packages.
199* default is `false`
200
201#### `ignoreDev`
202
203* Ignore `devDependencies`.
204* This is called `--production` on the command line to match `npm`.
205* default is `false`
206
207#### `devOnly`
208
209* Ignore `dependencies` and only check `devDependencies`.
210* default is `false`
211
212#### `ignore`
213
214* Ignore dependencies that match specified glob.
215* default is `[]`
216
217#### `saveExact`
218
219* Update package.json with exact version `x.y.z` instead of semver range `^x.y.z`.
220* default is `false`
221
222#### `debug`
223
224* Show debug output. Throw in a gist when creating issues on github.
225* default is `false`
226
227#### `cwd`
228
229* Override where `npm-check` checks.
230* default is `process.cwd()`
231
232#### `specials`
233
234* List of [`depcheck`](https://github.com/depcheck/depcheck) special parsers to include.
235* default is `''`
236
237#### `currentState`
238
239The result of the promise is a `currentState` object, look in [state.js](lib/state/state.js) to see how it works.
240
241You will probably want `currentState.get('packages')` to get an array of packages and the state of each of them.
242
243Each item in the array will look like the following:
244
245```js
246{
247 moduleName: 'lodash', // name of the module.
248 homepage: 'https://lodash.com/', // url to the home page.
249 regError: undefined, // error communicating with the registry
250 pkgError: undefined, // error reading the package.json
251 latest: '4.7.0', // latest according to the registry.
252 installed: '4.6.1', // version installed
253 isInstalled: true, // Is it installed?
254 notInstalled: false, // Is it installed?
255 packageWanted: '4.7.0', // Requested version from the package.json.
256 packageJson: '^4.6.1', // Version or range requested in the parent package.json.
257 devDependency: false, // Is this a devDependency?
258 usedInScripts: undefined, // Array of `scripts` in package.json that use this module.
259 mismatch: false, // Does the version installed not match the range in package.json?
260 semverValid: '4.6.1', // Is the installed version valid semver?
261 easyUpgrade: true, // Will running just `npm install` upgrade the module?
262 bump: 'minor', // What kind of bump is required to get the latest, such as patch, minor, major.
263 unused: false // Is this module used in the code?
264},
265```
266
267You will also see this if you use `--debug` on the command line.
268
269### RC File Support
270Additional options can be sent to the depcheck process. See [depcheck API](https://github.com/depcheck/depcheck#api). Create a .npmcheckrc{.json,.yml,.js} file and set the depcheck options under depcheck property.
271
272For example, to skip packages for unused check, but still want them in the outdated check (so can't use the --ignore option):
273```
274# .npmcheckrc
275
276depcheck:
277 ignoreMatches: ["replace-in-file","snyk","sonarqube-scanner"]
278
279```
280
281### Inspiration
282
283* [npm outdated](https://docs.npmjs.com/cli/v7/commands/npm-outdated) - awkward output, requires --depth=0 to be grokable.
284* [david](https://github.com/alanshaw/david) - does not work with private registries.
285* [update-notifier](https://github.com/yeoman/update-notifier) - for single modules, not everything in package.json.
286* [depcheck](https://github.com/depcheck/depcheck) - only part of the puzzle. npm-check uses depcheck.
287
288### About the Author
289
290Hi! Thanks for checking out this project! My name is **Dylan Greene**. When not overwhelmed with my two young kids I enjoy contributing
291to the open source community. I'm also a tech lead at [Opower](https://opower.com/). [![@dylang](https://img.shields.io/badge/github-dylang-green.svg)](https://github.com/dylang) [![@dylang](https://img.shields.io/badge/twitter-dylang-blue.svg)](https://twitter.com/dylang)
292
293Here's some of my other Node projects:
294
295| Name | Description | npm&nbsp;Downloads |
296|---|---|---|
297| [`grunt‑notify`](https://github.com/dylang/grunt-notify) | Automatic desktop notifications for Grunt errors and warnings. Supports OS X, Windows, Linux. | [![grunt-notify](https://img.shields.io/npm/dm/grunt-notify.svg?style=flat-square)](https://www.npmjs.org/package/grunt-notify) |
298| [`shortid`](https://github.com/dylang/shortid) | Amazingly short non-sequential url-friendly unique id generator. | [![shortid](https://img.shields.io/npm/dm/shortid.svg?style=flat-square)](https://www.npmjs.org/package/shortid) |
299| [`space‑hogs`](https://github.com/dylang/space-hogs) | Discover surprisingly large directories from the command line. | [![space-hogs](https://img.shields.io/npm/dm/space-hogs.svg?style=flat-square)](https://www.npmjs.org/package/space-hogs) |
300| [`rss`](https://github.com/dylang/node-rss) | RSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS. | [![rss](https://img.shields.io/npm/dm/rss.svg?style=flat-square)](https://www.npmjs.org/package/rss) |
301| [`grunt‑prompt`](https://github.com/dylang/grunt-prompt) | Interactive prompt for your Grunt config using console checkboxes, text input with filtering, password fields. | [![grunt-prompt](https://img.shields.io/npm/dm/grunt-prompt.svg?style=flat-square)](https://www.npmjs.org/package/grunt-prompt) |
302| [`xml`](https://github.com/dylang/node-xml) | Fast and simple xml generator. Supports attributes, CDATA, etc. Includes tests and examples. | [![xml](https://img.shields.io/npm/dm/xml.svg?style=flat-square)](https://www.npmjs.org/package/xml) |
303| [`changelog`](https://github.com/dylang/changelog) | Command line tool (and Node module) that generates a changelog in color output, markdown, or json for modules in npmjs.org's registry as well as any public github.com repo. | [![changelog](https://img.shields.io/npm/dm/changelog.svg?style=flat-square)](https://www.npmjs.org/package/changelog) |
304| [`grunt‑attention`](https://github.com/dylang/grunt-attention) | Display attention-grabbing messages in the terminal | [![grunt-attention](https://img.shields.io/npm/dm/grunt-attention.svg?style=flat-square)](https://www.npmjs.org/package/grunt-attention) |
305| [`observatory`](https://github.com/dylang/observatory) | Beautiful UI for showing tasks running on the command line. | [![observatory](https://img.shields.io/npm/dm/observatory.svg?style=flat-square)](https://www.npmjs.org/package/observatory) |
306| [`anthology`](https://github.com/dylang/anthology) | Module information and stats for any @npmjs user | [![anthology](https://img.shields.io/npm/dm/anthology.svg?style=flat-square)](https://www.npmjs.org/package/anthology) |
307| [`grunt‑cat`](https://github.com/dylang/grunt-cat) | Echo a file to the terminal. Works with text, figlets, ascii art, and full-color ansi. | [![grunt-cat](https://img.shields.io/npm/dm/grunt-cat.svg?style=flat-square)](https://www.npmjs.org/package/grunt-cat) |
308
309_This list was generated using [anthology](https://github.com/dylang/anthology)._
310
311### License
312Copyright (c) 2016 Dylan Greene, contributors.
313
314Released under the [MIT license](https://tldrlegal.com/license/mit-license).
315
316Screenshots are [CC BY-SA](https://creativecommons.org/licenses/by-sa/4.0/) (Attribution-ShareAlike).