Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save richard-flosi/f0886b2a698c1620bee84615abf1597e to your computer and use it in GitHub Desktop.
Save richard-flosi/f0886b2a698c1620bee84615abf1597e to your computer and use it in GitHub Desktop.
Pin current dependencies versions
#!/bin/zsh
# For each package name
for PACKAGE in `npm pkg get dependencies | jq 'keys[]' | tr -d '"'`
do
echo "Found ${PACKAGE}" &&
# Get the current installed version
VERSION=`npm ls ${PACKAGE} --depth 0 --json | jq --arg package ${PACKAGE} '.dependencies.[$package].version' | tr -d '"'` &&
echo "Current version ${VERSION}" &&
# Update package.json to pin the current version
npm pkg set dependencies.${PACKAGE}=${VERSION} &&
echo "Pinned ${PACKAGE} to version ${VERSION}" &&
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment