Skip to content

Instantly share code, notes, and snippets.

@coltenkrauter
Created March 28, 2025 03:00
Show Gist options
  • Save coltenkrauter/fbd6cbddcadd425ba3ffd4f69a9324d5 to your computer and use it in GitHub Desktop.
Save coltenkrauter/fbd6cbddcadd425ba3ffd4f69a9324d5 to your computer and use it in GitHub Desktop.
Simple shell script to find and uninstall unused npm dependencies using depcheck, with user prompt and uninstall count. Compatible with bash and zsh.
#!/usr/bin/env bash
deps=$(npx --yes depcheck --json | jq -r '.dependencies[], .devDependencies[]')
if [ -z "$deps" ]; then
echo '✅ No unused dependencies found'
else
echo '🧹 Unused dependencies:'
echo "$deps"
echo -n 'Remove these? (y/N) '
read confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
count=$(echo "$deps" | wc -l)
echo "$deps" | xargs npm uninstall
echo "✅ Uninstalled $count package(s)"
else
echo '❌ Skipped'
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment