前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >升级package.json中的包

升级package.json中的包

作者头像
周星星9527
发布于 2021-09-30 02:50:51
发布于 2021-09-30 02:50:51
1.6K00
代码可运行
举报
运行总次数:0
代码可运行

原文:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
https://github.com/raineorshine/npm-check-updates

npm-check-updates upgrades your package.json dependencies to the latest versions, ignoring specified versions.

  • maintains existing semantic versioning policies, i.e. "express": "^4.0.0" to "express": "^5.0.0".
  • only modifies package.json file. Run npm install to update your installed packages and package-lock.json.
  • Red = major upgrade (and all major version zero)
  • Cyan = minor upgrade
  • Green = patch upgrade

You may also want to consider npm-check. Similar purpose, different features.

Installation

Install globally:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
npm install -g npm-check-updates

Or run with npx:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
npx npm-check-updates

Usage

Show any new dependencies for the project in the current directory:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$ ncu
Checking package.json
[====================] 5/5 100%

 express           4.12.x  →   4.13.x
 multer            ^0.1.8^1.0.1
 react-bootstrap  ^0.22.6^0.24.0
 react-a11y        ^0.1.1^0.2.6
 webpack          ~1.9.10~1.10.5

Run ncu -u to upgrade package.json

Upgrade a project's package file:

Make sure your package file is in version control and all changes have been committed. This will overwrite your package file.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$ ncu -u
Upgrading package.json
[====================] 1/1 100%

 express           4.12.x  →   4.13.x

Run npm install to install new versions.

$ npm install      # update installed packages and package-lock.json

Check global packages:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
ncu -g

Filter packages using the --filter option or adding additional cli arguments. You can exclude specific packages with the --reject option or prefixing a filter with !. Supports strings, wildcards, globs, comma-or-space-delimited lists, and regular expressions:

代码语言:javascript
代码运行次数:0
运行
复制
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# upgrade only mocha
ncu mocha
ncu -f mocha
ncu --filter mocha

# upgrade packages that start with "react-"
ncu react-*
ncu "/^react-.*$/"

# upgrade everything except nodemon
ncu \!nodemon
ncu -x nodemon
ncu --reject nodemon

# upgrade only chalk, mocha, and react
ncu chalk mocha react
ncu chalk, mocha, react
ncu -f "chalk mocha react"

# upgrade packages that do not start with "react-".
ncu \!react-*
ncu '/^(?!react-).*$/' # mac/linux
ncu "/^(?!react-).*$/" # windows

How dependency updates are determined

  • Direct dependencies are updated to the latest stable version:
    • 2.0.12.2.0
    • 1.21.3
    • 0.1.01.0.1
  • Range operators are preserved and the version is updated:
    • ^1.2.0^2.0.0
    • 1.x2.x
    • >0.2.0>0.3.0
  • "Less than" is replaced with a wildcard:
    • <2.0.0^3.0.0
    • 1.0.0 < 2.0.0^3.0.0
  • "Any version" is preserved:
    • **
  • Prerelease and deprecated versions are ignored by default.
    • Use --pre to include prerelease versions (e.g. alpha, beta, build1235)
    • Use --deprecated to include deprecated versions
  • With --target minor, only update patch and minor:
    • 0.1.00.2.1
  • With --target patch, only update patch:
    • 0.1.00.1.2

Options

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
--color                      Force color in terminal
--concurrency <n>            Max number of concurrent HTTP requests to
                             registry. (default: 8)
--configFileName <filename>  Config file name (default: .ncurc.{json,yml,js})
--configFilePath <path>      Directory of .ncurc config file (default:
                             directory of `packageFile`).
--cwd <path>                 Working directory in which npm will be executed.
--deep                       Run recursively in current working directory.
                             Alias of (--packageFile '**/package.json').
--dep <value>                Check one or more sections of dependencies only:
                             dev, optional, peer, prod, 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, wildcard, glob, comma-or-space-delimited
                             list, or /regex/.
--filterVersion <matches>    Filter on package version using
                             comma-or-space-delimited list, or /regex/.
--format <value>             Enable additional output data, string or
                             comma-delimited list: ownerChanged, repo.
                             ownerChanged: shows if the package owner changed
                             between versions. repo: infers and displays
                             links to source code repository. (default: [])
-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")
--mergeConfig                Merges nested configs with the root config file
                             for --deep or --packageFile options (default:
                             false)').
-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".
-o, --ownerChanged           DEPRECATED. Renamed to "--format ownerChanged".
--packageData <value>        Package file data (you can also use stdin).
--packageFile <path|glob>    Package file(s) location (default:
                             ./package.json).
-p, --packageManager <name>  npm, yarn (default: "npm")
--peer                       Check peer dependencies of installed packages
                             and filter updates to compatible versions. Run
                             "ncu --help --peer" for details.
--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.
-x, --reject <matches>       Exclude packages matching the given string,
                             wildcard, glob, comma-or-space-delimited list,
                             or /regex/.
--rejectVersion <matches>    Exclude package.json versions using
                             comma-or-space-delimited list, or /regex/.
--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. Run "ncu --help
                             --target" for details.` (default: "latest")
--timeout <ms>               Global timeout in milliseconds. (default: no
                             global timeout and 30 seconds per
                             npm-registry-fetch).
-u, --upgrade                Overwrite package file with upgraded versions
                             instead of just outputting to console.
-V, --version                output the version number
-h, --help                   display help for command

Doctor Mode

Usage: ncu --doctor [-u] [options]

Iteratively installs upgrades and runs tests to identify breaking upgrades. Add -u to execute (modifies your package file, lock file, and node_modules).

To be more precise:

  1. Runs npm install and npm test to ensure tests are currently passing.
  2. Runs ncu -u to optimistically upgrade all dependencies.
  3. If tests pass, hurray!
  4. If tests fail, restores package file and lock file.
  5. For each dependency, install upgrade and run tests.
  6. When the breaking upgrade is found, saves partially upgraded package.json (not including the breaking upgrade) and exits.

Example:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$ ncu --doctor -u
npm install
npm run test
ncu -u
npm install
npm run test
Failing tests found:
/projects/myproject/test.js:13
  throw new Error('Test failed!')
  ^
Now let's identify the culprit, shall we?
Restoring package.json
Restoring package-lock.json
npm install
npm install --no-save react@16.0.0
npm run test
  ✓ react 15.0.016.0.0
npm install --no-save react-redux@7.0.0
npm run test
  ✗ react-redux 6.0.07.0.0
Saving partially upgraded package.json

Configuration Files

Use a .ncurc.{json,yml,js} file to specify configuration information. You can specify file name and path using --configFileName and --configFilePath command line options.

For example, .ncurc.json:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
{
  "upgrade": true,
  "filter": "express",
  "reject": [
    "@types/estree",
    "ts-node"
  ]
}

Module/Programmatic Usage

npm-check-updates can be required as a module:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
const ncu = require('npm-check-updates')

(async () => {

  const upgraded = await ncu.run({
    // Pass any cli option
    packageFile: '../package.json',
    upgrade: true,
    // Defaults:
    // jsonUpgraded: true,
    // silent: true,
  }))

  console.log(upgraded) // { "mypackage": "^2.0.0", ... }

})()

Known Issues

  • If ncu prints output that does not seem related to this package, it may be conflicting with another executable such as ncu-weather-cli or Nvidia CUDA. Try using the long name instead: npm-check-updates.
  • Windows: If npm-check-updates hangs, try setting the package file explicitly: ncu --packageFile package.json. You can run ncu --loglevel verbose to confirm that it was incorrectly waiting for stdin. See #136.

Problems?

File an issue. Please search existing issues first.

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-09-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 传输过程数值模拟学习笔记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
[译] 如何更新 package.json 中的依赖项
原文:https://medium.com/better-programming/how-to-upgrade-dependencies-in-package-json-e5546804187f
江米小枣
2020/06/15
5.7K0
一天一夜,山月写完了这份高效组织 npm script 最佳实践
众所周知,一个 Javasript 项目的脚本类工具,可以使用 package.json 中的 scripts 字段来组织,简单来说,这就是 npm script。
前端劝退师
2021/04/07
2.2K0
一天一夜,山月写完了这份高效组织 npm script 最佳实践
npm和Nodejs的安装与插件更新
Npm 与 Nodejs 的安装 (Ubuntu 18.04) 安装 $ sudo apt-get update #更新软件源 $ sudo apt-get install nodejs #安装Nodejs $ #sudo apt-get install nodejs-legacy #旧版系统可尝试此命令 $ sudo apt-get install npm #安装Npm 安装模块 n (用于 np
用户1316967
2022/01/18
1.5K0
npm和Nodejs的安装与插件更新
将做好的前端组件制作成npm包发布
这个问题是我们使用了淘宝镜像的问题,使用的是淘宝源cnpm,登陆到的是cnpm,我们把它切换成npm就好了。
colezhou
2019/11/24
2.7K0
Evil Package
那如果我们安装packages是恶意的怎么办呢,我们根据手册编写如下恶意setup.py
Jumbo
2018/12/05
5400
关于npm 包更新工具npm-check-updates 使用详解
首先说一下包版本的控制 假设 package.json 的包版本如下 "dependencies": { "vue": "^2.5.0", "vuex": "~3.1.0", "vue-router": "3.5.3", "react": "15.4.x", "typescript": "3.x.x", "react-dom": "*.*.*", "react-draggable": "x.x", "classnames": "x", "pinia": "*" } 执行
用户10106350
2022/10/28
1.5K0
关于npm 包更新工具npm-check-updates 使用详解
npm脚本和package.json
  在创建node.js项目如一个vue项目,或一个react项目时,项目都会生成一个描述文件package.json 。
tandaxia
2019/12/31
1.9K0
npm
为了帮助依赖于您的代码的开发人员,我们建议从以下位置开始您的软件包版本1.0.0并按如下所示递增。
贺贺V5
2021/09/07
1.5K0
npm 更新package.json中依赖包版本
NPM可以使用npm-check-updates库更新版本 1、安装: cnpm install -g npm-check-updates 2、使用: ncu --timeout=10000000 -u 指定--timeout参数防止超时 更新全部到最新版本: cnpm install 为了防止版本冲突,可以先讲node_modules删掉
JadePeng
2020/05/29
1.7K0
npm安装某个依赖到最新版本(敢于依赖)
  一键升级所有依赖的插件为 npm-check-updates需要执行以下步骤:
全栈程序员站长
2022/07/28
2.4K0
npm安装某个依赖到最新版本(敢于依赖)
package.json 配置完全解读
package.json 是前端每个项目都有的 json 文件,位于项目的根目录。许多脚手架在搭建项目时也会自动帮我们自动初始化好 package.json。
Leecason
2022/12/16
3.1K0
package.json 配置完全解读
你真的了解package.json吗?
然后,在写这系列文章时,发现有些操作需要用到package.json中的属性。然后,有些属性看起来人畜无害,但是用起来却需要查很多的资料。所以,就想着。写一篇或者两篇关于package.json的文章。
前端柒八九
2024/02/17
3790
你真的了解package.json吗?
你真的了解package.json吗?
大家好,我是柒八九。一个专注于前端开发技术/Rust及AI应用知识分享的Coder。
用户6256742
2024/05/18
2400
你真的了解package.json吗?
package.json——从vue的package.json来详细说明package.json内容
Vue2.7.14源码阅读的补充内容,~c package.json c~ 文件是项目的清单。 它可以做很多完全互不相关的事情。 例如,它是用于工具的配置中心。 它也是 npm 和 yarn 存储所有已安装软件包的名称和版本的地方;
思索
2024/08/15
2260
npm依赖包升级
上一篇文章介绍了vue-cli和create-vue两款vue脚手架,现在官方已经推荐使用creat-vue进行项目的构建,知道cli是基于webpack构建的,每次都需要全部打包构建,而vite就不需要,所以vite速度是更快的。
希里安
2023/10/30
6820
npm依赖包升级
package.json 知多少?
在 Node.js 中,模块是一个库或框架,也是一个 Node.js 项目。Node.js 项目遵循模块化的架构,当我们创建了一个 Node.js 项目,意味着创建了一个模块,这个模块必须有一个描述文件,即 package.json。它是我们最常见的配置文件,但是它里面的配置你真的有详细了解过吗?配置一个合理的 package.json 文件直接决定着我们项目的质量,本章就带大家了解下 package.json 的各项详细配置。
ConardLi
2019/12/02
1.9K0
npm 与 package.json 快速入门
张拭心 shixinzhang
2018/01/05
2.1K0
npm 与 package.json 快速入门
深入学习 package.json 这个基础文件
允许不修改[major, minor, patch]元组中最左边的非零元素的更改 。换句话说,这允许版本1.0.0及以上版本的补丁和次要更新,版本的补丁更新0.X >=0.1.0,以及版本的不更新0.0.X。
前端达人
2021/07/16
1.3K0
Meteor 1.3 正式发布啦!ES 2015模块,应用测试,移动提升等新特性
Meteor 1.3 正式发布啦,可以通过命令 `meteor update --release 1.3` 升级老项目。Meteor 1.3 包含了诸多新特性,这里先放出英文发布文档,之后我们会提供中文版的详解! Announcing Meteor 1.3 - ES2015 Modules, App Testing, Mobile Improvements and More Today we’re excited to announce Meteor 1.3, the latest release of
时见疏星
2018/06/01
4580
package.json文件知多少?
Version: 当前项目的版本,需要满足以下约定 x.x.x - major.minor.patches
用户7365393
2021/09/26
5810
相关推荐
[译] 如何更新 package.json 中的依赖项
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验