Skip to content

Instantly share code, notes, and snippets.

@johanbove
Created January 31, 2023 15: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 johanbove/d495229272fb55feb0b3c81cfde92551 to your computer and use it in GitHub Desktop.
Save johanbove/d495229272fb55feb0b3c81cfde92551 to your computer and use it in GitHub Desktop.
This script will attempt to add packages to npm cache after they returned with the ECONN error
#!/bin/bash
echo "This script will attempt to add packages that return ECONN on the first try automatically."
logLevel="info"
echo "Setting config to loglevel: $logLevel"
npm config set loglevel=$logLevel
parse () {
echo "Starting npm ci..."
npm ci --legacy-peer-deps 2>&1 |
while read -r line; do
echo "Reading line: $line"
logLineWithErr=$(echo $line | grep -E -o '(http.+\.tgz)')
echo "logLineWithErr: ${#logLineWithErr}"
if [ ! -z "$logLineWithErr" -a "$logLineWithErr" != " " ]; then
echo "FOUND TGZ URL: $logLineWithErr"
url=$(echo $logLineWithErr | grep -E -o '(\/\/.*\.tgz)')
echo "url: ${#url}"
if [ ! -z "$url" -a "$url" != " " ]; then
echo "RETRY! Should do an npm cache add for: $url"
$(npm cache add https:$url)
# Start over
echo "STARTING OVER..."
parse
fi
fi
done
}
run () {
parse
}
run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment