Last active
August 11, 2017 17:47
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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