Skip to content

Instantly share code, notes, and snippets.

@sumanchapai
Created December 31, 2023 04:38
Show Gist options
  • Save sumanchapai/1005fc218a4b115a97a764a89eab4f98 to your computer and use it in GitHub Desktop.
Save sumanchapai/1005fc218a4b115a97a764a89eab4f98 to your computer and use it in GitHub Desktop.
Find unused dependencies in the src directory (check for the presence of package name). Reads candidates from stdin or the file provided
#! /bin/bash
# Array of packages that must be kept although unused
must_keep_packages=('react-dom')
# Function to handle checking/printing if a package is unused and removable
function handle_package() {
local package=$1
# Skip this package is an important, must-keep package.
# Otherwise add it to the unused packages list
if [[ ${must_keep_packages[@]} =~ $package ]]
then
: # No op
else
echo $package
fi
}
# Driver loop
# Inspect unused packages
while read line
do
grep $line -r src/ > /dev/null || handle_package $line
done < "${1:-/dev/stdin}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment