Created
December 31, 2023 04:38
-
-
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
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
#! /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