Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Last active June 2, 2023 09:39
Show Gist options
  • Save Ajnasz/22838f49728b51979ac4a03494ece36a to your computer and use it in GitHub Desktop.
Save Ajnasz/22838f49728b51979ac4a03494ece36a to your computer and use it in GitHub Desktop.
pinpoint package versions in package.json, getting versions from package-lock.json
jq < package.json '.dependencies | to_entries[]|select(.value|startswith("^"))|.key' | \
xargs -I {} jq --arg v {} '.dependencies[$v]|{($v): .version}' package-lock.json | \
jq 'to_entries[]|.key+" "+.value' | \
xargs -P 1 -I {} sh -c 'key=$(echo {} | cut -f 1 -d " ");value=$(echo {} | cut -f 2 -d " ");jq --arg k $key --arg v $value ".dependencies[\$k]=\$v" package.json> package.tmp.json && mv package.tmp.json package.json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment