如何使用 Yarn 升级所有作用域包? [英] How do I upgrade all scoped packages with Yarn?

查看:92
本文介绍了如何使用 Yarn 升级所有作用域包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 Yarn 包管理器升级我的 package.json 的依赖项部分中的所有特定范围的包?

Is it possible to upgrade all specific scoped packages in the dependencies section of my package.json by using the Yarn package manager?

例如:

yarn upgrade @scope/* 

这将升级 yarn.lockpackage.json 文件中的所有范围包.

This will upgrade all scoped packages in yarn.lock and package.json file.

推荐答案

由于 Yarn 目前无法做到这一点,所以我编写了一个很短的 Node 脚本来完成您想要的:

Since there's no way to do this currently with Yarn, I've written a very short Node script to do what you want:

var fs = require('fs');
var child_process = require('child_process');

var filterRegex = /@angular\/.*/;

fs.readFile('./package.json', function(err, data) {
    if (err) throw err;

    var dependencies = JSON.parse(data)['dependencies'];
    Object.keys(dependencies).forEach(function(dependency) {
        if (filterRegex.test(dependency)) {
            console.log('Upgrading ' + dependency);
            child_process.execSync('yarn upgrade ' + dependency);
        } else {
            console.log('Skipping ' + dependency);
        }
    });
});

以下是其作用的简要说明:

Here's a quick explanation of what that does:

  • 从终端当前所在目录加载package.json

然后我们解析 package.json 的 JSON 并得到 "dependencies"

we then parse the JSON of the package.json and get the "dependencies" key

对于每个依赖项,我们运行指定为 filterRegex 的正则表达式(如果你需要改变这个或想要解释正则表达式的语法,我会用 RegExr.我使用 @angular 作为正则表达式的示例前缀)

for each dependency, we run the regex specified as the filterRegex (if you need to change this or want an explanation of the regex syntax, I would test with RegExr. I used @angular as an example prefix for the regex)

如果依赖匹配,我们运行yarn upgrade [DEPENDENCY]并记录它

if the dependency matches, we run yarn upgrade [DEPENDENCY] and log it

如果您对此有任何问题,请告诉我,但它应该可以解决您的问题,直到 Yarn 团队提出更好的方案.

Let me know if you have any trouble with this, but it should solve your issue until the Yarn team come up with something better.

这篇关于如何使用 Yarn 升级所有作用域包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆