diff --git a/bundle-size/pm.sh b/bundle-size/pm.sh index a9466641..7c884f22 100755 --- a/bundle-size/pm.sh +++ b/bundle-size/pm.sh @@ -2,8 +2,8 @@ # Check if command argument is provided if [ "$1" = "" ]; then - echo "Please provide a command to run." - exit 1 + echo "Please provide a command to run." + exit 1 fi install_pnpm_if_not_present() { @@ -15,31 +15,38 @@ install_pnpm_if_not_present() { } # Detect the package manager +current_dir=$(pwd) +cd $(git rev-parse --show-toplevel) # Navigate to the root of the git repository if [ -f yarn.lock ]; then - pm="yarn" + pm="yarn" elif [ -f package-lock.json ]; then - pm="npm" + pm="npm" +elif [ -f pnpm-lock.yaml ]; then + install_pnpm_if_not_present + pm="pnpm" else - echo "Defaulting to pnpm for install command." - install_pnpm_if_not_present - pm="pnpm" + echo "No recognized package manager found in this project." + exit 1 fi +cd $current_dir # Navigate back to the original directory # Detect the command to run build -if [ -f yarn.lock ]; then - pmb=("yarn" "build" "--profile" "--json" "pr-stats.json") -elif [ -f package-lock.json ]; then - pmb=("npm" "run" "build" "--" "--profile" "--json" "pr-stats.json") +if [ "$pm" = "yarn" ]; then + pmb=("yarn" "build" "--profile" "--json" "pr-stats.json") +elif [ "$pm" = "npm" ]; then + pmb=("npm" "run" "build" "--" "--profile" "--json" "pr-stats.json") +elif [ "$pm" = "pnpm" ]; then + install_pnpm_if_not_present + pmb=("pnpm" "build" "--profile" "--json" "pr-stats.json") else - echo "Defaulting to pnpm for build command." - install_pnpm_if_not_present - pmb=("pnpm" "build" "--profile" "--json" "pr-stats.json") + echo "No recognized package manager found in this project." + exit 1 fi # Run the provided command with the detected package manager echo "Running '$1' with $pm..." if [ "$1" = "install" ]; then - "$pm" install + "$pm" install elif [ "$1" = "build" ]; then - "${pmb[@]}" -fi + "${pmb[@]}" +fi \ No newline at end of file