我想从npm shrinkwrap json文件中删除所有解析。这将导致在其他机器上运行NPM install时出现问题。
"cssstyle": {
"version": "0.2.37",
"from": "cssstyle@>=0.2.29 <0.3.0",
"resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-0.2.37.tgz"
},
"dashdash": {
"version": "1.14.0",
"from": "dashdash@>=1.12.0 <2.0.0",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.0.tgz",
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"from": "assert-plus@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz"
}
}
},
"debug": {
"version": "2.2.0",
"from": "debug@>=2.2.0 <3.0.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz"
}
如何从所有文件中删除解析后的密钥
我使用的是模式:
jq 'del(.resolved)' file.json
在我看来,解决这类问题最简单的方法是使用walk/1
:
walk(if type == "object" and has("resolved") then del(.resolved) else . end)
如果您的jq没有walk/1
(它在jq 1.5发布后才作为内置包含),那么只需在上面一行之前添加它的定义(在web上很容易获得),或者可能将它包含在~/中。金桥文件。