npm自动升级过期的package.json中的包

23 min read

第一步:使用npm 命令查看已经过期的安装包

npm outdated

第二步:安装npm升级插件

npm install -g npm-check-updates

第三步:查看最新的版本命令

ncu

第四步:升级低版本的npm包文件

ncu -u

到此升级工作就完成了。

➜  koa2-ts-init npm outdated
Package            Current  Wanted  Latest  Location  Depended by
baidu-aip-sdk      MISSING  4.15.8  4.15.8  -         koa2-ts-init
boom               MISSING   7.3.0   7.3.0  -         koa2-ts-init
convict            MISSING   4.4.1   6.2.2  -         koa2-ts-init
debug              MISSING   3.2.7   4.3.4  -         koa2-ts-init
koa                MISSING  2.13.4  2.13.4  -         koa2-ts-init
koa-bunyan-logger  MISSING   2.1.0   2.1.0  -         koa2-ts-init
koa-compose        MISSING   4.1.0   4.1.0  -         koa2-ts-init
koa-json           MISSING   2.0.2   2.0.2  -         koa2-ts-init
koa-router         MISSING   7.4.0  10.1.1  -         koa2-ts-init
ts-node            MISSING   4.1.0  10.7.0  -         koa2-ts-init
➜  koa2-ts-init npm outdated
Package            Current  Wanted  Latest  Location  Depended by
baidu-aip-sdk      MISSING  4.15.8  4.15.8  -         koa2-ts-init
boom               MISSING   7.3.0   7.3.0  -         koa2-ts-init
convict            MISSING   4.4.1   6.2.2  -         koa2-ts-init
debug              MISSING   3.2.7   4.3.4  -         koa2-ts-init
koa                MISSING  2.13.4  2.13.4  -         koa2-ts-init
koa-bunyan-logger  MISSING   2.1.0   2.1.0  -         koa2-ts-init
koa-compose        MISSING   4.1.0   4.1.0  -         koa2-ts-init
koa-json           MISSING   2.0.2   2.0.2  -         koa2-ts-init
koa-router         MISSING   7.4.0  10.1.1  -         koa2-ts-init
ts-node            MISSING   4.1.0  10.7.0  -         koa2-ts-init
➜  koa2-ts-init npm install -g npm-check-updates

added 268 packages in 17s

30 packages are looking for funding
  run `npm fund` for details
➜  koa2-ts-init ncu -a
error: unknown option '-a'
➜  koa2-ts-init ncu   
Checking /Users/pan/koa2-ts-init/package.json
[====================] 26/26 100%

 convict                  ^4.0.2  →   ^6.2.2     
 debug                    ^3.1.0  →   ^4.3.4     
 koa                      ^2.5.0  →  ^2.13.4     
 koa-bunyan-logger        ^2.0.0  →   ^2.1.0     
 koa-compose              ^4.0.0  →   ^4.1.0     
 koa-router               ^7.4.0  →  ^10.1.1     
 ts-node                  ^4.1.0  →  ^10.7.0     
 @types/boom              ^7.1.1  →   ^7.3.2     
 @types/bunyan            ^1.8.4  →   ^1.8.8     
 @types/convict           ^4.1.1  →   ^6.1.1     
 @types/debug            ^0.0.30  →   ^4.1.7     
 @types/jest             ^22.1.2  →  ^27.4.1     
 @types/koa              ^2.0.44  →  ^2.13.4     
 @types/koa-json         ^2.0.16  →  ^2.0.20     
 @types/koa-router       ^7.0.27  →   ^7.4.4     
 body-parser             ^1.18.2  →  ^1.20.0     
 husky              ^0.15.0-rc.8  →   ^7.0.4     
 jest                    ^22.2.2  →  ^27.5.1     
 lint-staged              ^6.1.0  →  ^12.4.0     
 nodemon                ^1.14.12  →  ^2.0.15     
 ts-jest                 ^22.0.4  →  ^27.1.4     
 typescript               ^2.7.1  →   ^4.6.3     

Run ncu -u to upgrade package.json
➜  koa2-ts-init ncu -u
Upgrading /Users/pan/koa2-ts-init/package.json
[====================] 26/26 100%

 convict                  ^4.0.2  →   ^6.2.2     
 debug                    ^3.1.0  →   ^4.3.4     
 koa                      ^2.5.0  →  ^2.13.4     
 koa-bunyan-logger        ^2.0.0  →   ^2.1.0     
 koa-compose              ^4.0.0  →   ^4.1.0     
 koa-router               ^7.4.0  →  ^10.1.1     
 ts-node                  ^4.1.0  →  ^10.7.0     
 @types/boom              ^7.1.1  →   ^7.3.2     
 @types/bunyan            ^1.8.4  →   ^1.8.8     
 @types/convict           ^4.1.1  →   ^6.1.1     
 @types/debug            ^0.0.30  →   ^4.1.7     
 @types/jest             ^22.1.2  →  ^27.4.1     
 @types/koa              ^2.0.44  →  ^2.13.4     
 @types/koa-json         ^2.0.16  →  ^2.0.20     
 @types/koa-router       ^7.0.27  →   ^7.4.4     
 body-parser             ^1.18.2  →  ^1.20.0     
 husky              ^0.15.0-rc.8  →   ^7.0.4     
 jest                    ^22.2.2  →  ^27.5.1     
 lint-staged              ^6.1.0  →  ^12.4.0     
 nodemon                ^1.14.12  →  ^2.0.15     
 ts-jest                 ^22.0.4  →  ^27.1.4     
 typescript               ^2.7.1  →   ^4.6.3     

Run npm install to install new versions.