我有一个 package.json 文件,如下所示:
{
"name": "service",
"version": "1.0.0",
"private": true,
"description": "my service",
"license": "none",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@mycompany/mypackage": "1.1.1"
}
}
我想将 @mycompany/mypackage 版本更新为“1.2.1”。我发现类似的文章这和这建议jq。
当我运行 jq 命令时jq -r '"dependencies.@mycompany/mypackage" |= "1.2.1"' package.json
,出现此错误:jq: error (at temp.json:13): Invalid path expression with result "dependencies.@mycompany/m...
据我所知,我使用时的路径是正确的jq玩。
有人有什么建议吗?
答案1
你已经很接近了。您确实需要引用该@mycompany/mypackage
键,因为 和@
都是/
特殊字符,但您必须单独引用它,而不是作为整个过滤器的一部分。您还需要一个前导.
来查询根对象。这应该有效:
$ jq -r '.dependencies."@mycompany/mypackage" |= "1.2.1"' package.json
{
"name": "service",
"version": "1.0.0",
"private": true,
"description": "my service",
"license": "none",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@mycompany/mypackage": "1.2.1"
}
}