我有一個 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"
}
}