安装 npm-check-updates

1
npm i -g npm-check-updates

检测更新

ncu 是 npm-check-updates 的缩写命令

1
ncu -u
1
2
3
4
5
6
7
8
9
10
11
12
Upgrading /Users/shitao/WebstormProjects/blog/package.json
[====================] 38/38 100%

@babel/preset-env ^7.11.0 → ^7.11.5
eslint ^7.6.0 → ^7.9.0
hexo-generator-search ^2.4.0 → ^2.4.1
hexo-renderer-marked ^3.0.0 → ^3.2.0
hexo-renderer-stylus ^1.1.0 → ^2.0.1
terser ^5.0.0 → ^5.3.2
workbox-build ^5.1.3 → ^5.1.4

Run npm install to install new versions.

更新后会自动修改 package.json 里的版本号,但是 package-lock.json 或者 yarn.lock 不会更新,需要重新 npm install 或者 yarn install。

升级 npm 包

1
npm install

查看 ncu 帮助

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
❯ ncu --help
Usage: ncu [options] [filter]

[filter] is a list or regex of package names to check (all others will be ignored).

Options:
--concurrency <n> Max number of concurrent HTTP requests to
registry. (default: 8)
--configFilePath <path> Directory of .ncurc config file (default:
directory of `packageFile`).
--configFileName <filename> Config file name (default: .ncurc.{json,yml,js})
--cwd <path> Working directory in which npm will be executed.
--dep <dep> Check one or more sections of dependencies only:
prod, dev, peer, optional, bundle
(comma-delimited).
--deprecated Include deprecated packages.
--doctor Iteratively installs upgrades and runs tests to
identify breaking upgrades. Run "ncu --doctor"
for detailed help. Add "-u" to execute.
--enginesNode Include only packages that satisfy engines.node
as specified in the package file.
-e, --errorLevel <n> Set the error level. 1: exits with error code 0
if no errors occur. 2: exits with error code 0
if no packages need updating (useful for
continuous integration). (default: 1)
-f, --filter <matches> Include only package names matching the given
string, comma-or-space-delimited list, or
/regex/.
-g, --global Check global packages instead of in the current
project.
--greatest DEPRECATED. Renamed to "--target greatest".
-i, --interactive Enable interactive prompts for each dependency;
implies -u unless one of the json options are
set,
-j, --jsonAll Output new package file instead of
human-readable message.
--jsonDeps Like `jsonAll` but only lists `dependencies`,
`devDependencies`, `optionalDependencies`, etc
of the new package data.
--jsonUpgraded Output upgraded dependencies in json.
-l, --loglevel <n> Amount to log: silent, error, minimal, warn,
info, verbose, silly. (default: "warn")
-m, --minimal Do not upgrade newer versions that are already
satisfied by the version range according to
semver.
-n, --newest DEPRECATED. Renamed to "--target newest".
-p, --packageManager <name> npm, yarn (default: "npm")
-o, --ownerChanged Check if the package owner changed between
current and upgraded version.
--packageData <string> Package file data (you can also use stdin).
--packageFile <path> Package file location (default: ./package.json).
--pre <n> Include -alpha, -beta, -rc. (default: 0; default
with --newest and --greatest: 1).
--prefix <path> Current working directory of npm.
-r, --registry <url> Third-party npm registry.
--removeRange Remove version ranges from the final package
version.
--semverLevel <value> DEPRECATED. Renamed to --target.
-s, --silent Don't output anything (--loglevel silent).
-t, --target <value> Target version to upgrade to: latest, newest,
greatest, minor, patch.
--timeout <ms> Global timeout in milliseconds. (default: no
global timeout and 30 seconds per
npm-registery-fetch).
-u, --upgrade Overwrite package file with upgraded versions
instead of just outputting to console.
-x, --reject <matches> Exclude packages matching the given string,
comma-or-space-delimited list, or /regex/.
-V, --version output the version number
-h, --help display help for command