Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save richard-flosi/824f22833405a2ee140e09798c5c3e81 to your computer and use it in GitHub Desktop.
Save richard-flosi/824f22833405a2ee140e09798c5c3e81 to your computer and use it in GitHub Desktop.
Pin current devDependencies versions
#!/bin/zsh
# For each package name
for PACKAGE in `npm pkg get devDependencies | 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 devDependencies.${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