NPM:使用作用域更新所有依赖项



是否有更新特定范围的所有包依赖项的快捷方式。

例如,在以下package.json是否有一种快速方法仅更新具有@example范围的包?

…
dependencies: {
alpha,
bravo,
@example/a,
@example/b,
@example/c,
@example/d,
@example/e,
@example/f,
}

我为此编写了小工具。为 Yarn 项目运行npx update-by-scope @example,为 Npm 项目运行npx update-by-scope @example npm install

我使用npm-check-updates包更新依赖项 - 只需全局安装它然后运行ncu. 默认情况下,它以"检查"模式对所有包运行,但您可以传递命令行标志,让它将每个包的最新版本写入package.json。 它支持筛选,因此您只能将更新应用于单个范围,例如ncu '/@angular/.*/'

使用纱线:

yarn upgrade --scope @example

我在项目中遇到了同样的问题angular。 我从package.jsonscript部分使用.

我将custom name(例如update-scope)设置为key,并将命令设置为value

"scripts": {
"ng": "ng",
"build": "node package-builder",
"update-scope": "npm update @example/a && npm update @example/b && ..."
}

然后使用以下命令运行custom name

npm run update-scope // `update-scope` is my custom name

最后,my scope中的所有my packages都已更新。

我希望有用。

我偶然发现了这个确切的问题,并且包 npm 检查无缝地完成了这个技巧。

键入npx npm-check -u并选择要升级的软件包,然后按回车键继续。

不幸的是,yarn upgrade在最新版本的 Yarn 中被删除了。相反,请使用yarn up '@scope/*',它将在每个 package.json 文件中以@scope/开头的每个包升级到最新版本。请参阅这些文档。这也避免了必须安装升级插件或使用不支持模式匹配的升级交互式

最新更新