Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 but this only effects
# specific future activities, like calling 'yarn upgrade'.
# example usage: cd some_repo; ./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[@]}"
containsElement "$f" "${git[@]}"
if [ $istgz -eq 0 ]
: # echo "$f is listed as a tgz"
elif [ $isgit -eq 0 ]
: # echo "$f is listed as a git"
echo "MATCH: $f is not mentioned in yarn.lock file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment