Skip to content

Instantly share code, notes, and snippets.

@eddiesholl
Last active August 11, 2017 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiesholl/7fb6ae4b61de162ab269adbd3e79322f to your computer and use it in GitHub Desktop.
Save eddiesholl/7fb6ae4b61de162ab269adbd3e79322f to your computer and use it in GitHub Desktop.
Find package files stored in yarn offline mirror that are no longer referenced/resolved in yarn.lock file
# There is no way right now to find packages included in an offline mirror folder that are
# not actually referenced by the current yarn.lock file. This script will compare the files
# in your offline mirror folder and find any that are not in the current set resolved by yarn.
# The closest is https://yarnpkg.com/en/docs/prune-offline-mirror but this only effects
# specific future activities, like calling 'yarn upgrade'.
# example usage: cd some_repo; clean_yarn_mirror.sh ./npm_offline_cache
echo "Scanning files in $1..."
tgz=($(grep -ho -e 'resolved .*\.tgz' yarn.lock | cut -d" " -f2))
git=($(grep -ho -e 'resolved .*\.git-.*#' yarn.lock | cut -d" " -f2 | sed 's/#//'))
files=$(ls $1)
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
for f in $files; do
containsElement "$f" "${tgz[@]}"
istgz=$?
containsElement "$f" "${git[@]}"
isgit=$?
if [ $istgz -eq 0 ]
then
: # echo "$f is listed as a tgz"
elif [ $isgit -eq 0 ]
then
: # echo "$f is listed as a git"
else
echo "MATCH: $f is not mentioned in yarn.lock file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment