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

升级package.json中的包

作者头像
周星星9527
发布于 2021-09-30 02:50:51
发布于 2021-09-30 02:50:51
1.6K10
代码可运行
举报
运行总次数: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 删除。

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

评论
登录后参与评论
1 条评论
热度
最新
电信202到此一游
电信202到此一游
回复回复点赞举报
推荐阅读
编辑精选文章
换一批
ef和mysql使用(二)--让mysql支持EntityFramework.Extended实现批量更新和删除
我们都知道Entity Framework 中不能同时更新多条记录,但是一个老外写的扩展库可以实现此功能EntityFramework.Extended,但是如何是mysql数据库要怎么实现呢
yaphetsfang
2020/07/30
1.4K0
EntityFramework的多种记录日志方式,记录错误并分析执行时间过长原因(系列4)
本文通过介绍Entity Framework的日志记录功能,讲解了在.NET中如何实现数据库操作记录的解决方案。通过使用Entity Framework的上下文、数据库日志和IDbCommandInterceptor接口,开发者可以记录数据库操作,包括查询、更新和删除等,并获取操作的时间、SQL语句、参数等信息。同时,文章还提供了数据库日志记录的具体实现代码和示例,帮助读者更好地理解实现过程。通过本文的学习,读者可以掌握如何在.NET中实现对数据库操作的记录和跟踪,提高数据库应用的稳定性和可维护性。
GuZhenYin
2018/01/04
8750
EntityFramework的多种记录日志方式,记录错误并分析执行时间过长原因(系列4)
EF Core3.0+ 通过拦截器实现读写分离与SQL日志记录
一晃又大半年没更新技术博客..唉,去年一年发生了太多事情..博主真的 一言难尽..
GuZhenYin
2021/03/18
1.1K0
EF Core3.0+ 通过拦截器实现读写分离与SQL日志记录
Entity Framework 小知识(二)
接下来使用 DbConfigurationType 属性在上下文类中设置基于代码的配置类:
喵叔
2020/09/08
5880
Mysql 该如何 Entity Framework 数据库迁移 和 如何更好的支持EF.Extended
问题 1.在使用EntityFramework访问Mysql的时候,使用迁移来生成数据库或者更新数据库时候会遇到一些问题 2.EntityFramework.Extended对Mysql的支持不是很完全,其中修改是无法直接使用的需要做一些处理 3.EntityFramework.Extended如何跟EntityFramework其他的操作在一个事物里面(针对网友zengfanlin 问题) 解决方案 1.首先解决第一个问题 准备条件:用Nuget下载Mysql.Data.Entity(可以将依赖连同下载)
逸鹏
2018/04/11
1.8K0
Mysql 该如何 Entity Framework 数据库迁移 和 如何更好的支持EF.Extended
Entity Framework 简单查询
第一步还是先建立一个控制台的应用程序,然后通过Nuget添加Entity Framework。那么同时会给packages.config和App.config添加相应的配置。
aehyok
2018/09/11
8850
Entity Framework 简单查询
Entity Framework 自动生成CodeFirst代码
在前面的文章中我们提到Entity Framework的“Code First”模式也同样可以基于现有数据库进行开发。今天就让我们一起看一下使用Entity Framework Power Tools如何基于现有数据库生成数据类和数据库上下等。
aehyok
2018/09/11
8670
Entity Framework 自动生成CodeFirst代码
.NET:Entity Framework 笔记
有二年没关注EF,今天无意试了下发现跟主流的Hibernate等ORM框架越来越接近了,先看下Entity类的定义: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace EFSample.Model { [Table("T_ORDER")]
菩提树下的杨过
2018/01/19
1.1K0
.NET EF Core(Entity Framework Core)
1、Entity Framework Core(EF Core)是微软官方的ORM框架。优点:功能强大、官方支持、生产效率高、力求屏蔽底层数据库差异;缺点:复杂、上手门槛高、不熟悉EFCore的话可能会进坑。 2、Dapper。优点:简单,N分钟即可上手,行为可预期性强;缺点:生产效率低,需要处理底层数据库差异。 3、EF Core是 模型驱动 (Model-Driven)的开发思想,Dapper是 数据库驱动(DataBase-Driven)的开发思想的。没有优劣,只有比较。 4、性能: Dapper等≠性能高;EF Core≠性能差。 5、EF Core是官方推荐、推进的框架,尽量屏蔽底层数据库差异,.NET开发者必须熟悉,根据的项目情况再决定用哪个。
鱼找水需要时间
2024/03/23
1K0
.NET EF Core(Entity Framework Core)
Entity Framework——配置文件设置
可以使用配置文件或代码(EF6起)配置EF框架。 一、使用配置文件 安装Entity Framework自动生成的配置 当使用VS的NuGet自动安装Entity Framework(本文使用6.2.
甜橙很酸
2018/03/30
1.5K0
ADO.NET Entity Framework CodeFirst 如何输出日志(EF 5.0)
ADO.NET Entity Framework CodeFirst 如何输出日志(EF4.3) 用的EFProviderWrappers ,这个组件好久没有更新了,对于SQL执行日志的解决方案的需求
张善友
2018/01/29
6160
ADO.NET Entity Framework CodeFirst 如何输出日志(EF 5.0)
Entity Framework CodeFirst尝试
Code First模式我们称之为“代码优先”模式,是从EF4.1开始新建加入的功能。使用Code First模式进行EF开发时开发人员只需要编写对应的数据类(其实就是领域模型的实现过程),然后自动生成数据库。这样设计的好处在于我们可以针对概念模型进行所有数据操作而不必关系数据的存储关系,使我们可以更加自然的采用面向对象的方式进行面向数据的应用程序开发。
aehyok
2018/09/11
7130
Entity Framework CodeFirst尝试
Entity Framework——读写分离
1 实现 CustomDbContext扩展了DbContext,其构造函数带有形式参nameOrConnectionString,可以在使用CustomDbContext时指定数据库连接字符串。 DbContextFactory包含两个属性MasterDbContext和SlaveDbContext,MasterDbContext为主库上下文,SlaveDbContext为从库上下文。DbContextFactory还包含了一个方法:UpdateSlaves用于实现对SlaveDbContext的更新,因
甜橙很酸
2018/03/08
1.1K0
【源码解读(一)】EFCORE源码解读之创建DBContext查询拦截
    在网上很少看到有关于系统讲解EFCore源码的,可能大概也许是因为EFCore的源码总体是没有asp.net web的源码流程清晰,正如群友所说,EFCore的源码大致看起来有点凌乱,与其说凌乱,不如说是没有一个好的方向;然后昨天在群里有一个朋友再说,EfCore的拦截器如何注入Web的服务,以及EfCore如何自定义查询,我就看了一下EfCore的源码,在此之前我针对asp.net web 做了一个源码解读,有兴趣的朋友可以看前面的文章,也给别人说过啥时候讲解一下efcore的源码,刚好借助这么一个机会,讲一讲EfCore的源码,本篇文章作为一个开端,会呈现一下几点
陈显达
2023/10/16
1.1K0
【源码解读(一)】EFCORE源码解读之创建DBContext查询拦截
Entity Framework——常见报错总结
1 实体属性配置为IsRequired()对更新的影响 抛出异常类型DbEntityValidationException 表结构: 实体: public class User {
甜橙很酸
2018/03/08
8180
Entity Framework——常见报错总结
Entity Framework 小知识(三)
在单服务器上运行的站点,为了防止出现脏读现象,我们一般使用Lock语句关键字,但是如果在分布式站点上使用Lock语句关键字是不起作用的,因为程序锁住了服务器1数据库实例,但服务器2并不知道服务器1已被锁住,这样依然会出现脏读现象。这时我们就用到了EF的乐观并发。
喵叔
2020/09/08
3000
entity framework数据库映射(ORM)
Sql Server安装:EntityFramework Mysql安装:MySql.Data.Entity
sofu456
2022/05/06
1.1K0
entity framework数据库映射(ORM)
浅析Entity Framework Core中的并发处理
本文讲述如何使用Entity Framework Core来实现一个乐观并发控制,并介绍在.NET Core中使用DbContext进行数据库操作时的一些常见问题和解决方案。
GuZhenYin
2018/01/04
2.9K0
浅析Entity Framework Core中的并发处理
asp.net mvc entityframework sql server 迁移至 mysql方法以及遇到的问题
我原来的项目是asp.net mvc5 + entityframework 6.4 for sql server(localdb,sql server),现在需要把数据库切换成mysql,理论上entityframework是可以完全做到无缝切换,毕竟ORM的设计就是为了兼容不同的底层数据库。
阿新
2020/05/12
1.4K0
Entity Framework——并发策略
使用EF框架遇到并发时,一般采取乐观并发控制。 1支持并发检验 为支持并发检验,需要对实体进行额外的设置。默认情况下是不支持并发检验的。有以下两种方式: 方式名称 说明 时间戳注解/行版本 使用TimestampAttribute特性,实体的属性必须是byte数组类型 非时间戳注解 使用ConcurrencyCheckAttribute Fluent API 使用StringPropertyConfiguration.IsConcurrencyT
甜橙很酸
2018/04/17
1.2K0
推荐阅读
相关推荐
ef和mysql使用(二)--让mysql支持EntityFramework.Extended实现批量更新和删除
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验