From 85936c93cd2d874f71320585e43cb86a993b1ea5 Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 2 Jan 2025 15:05:49 +0100 Subject: [PATCH 1/2] chore: support nonpnpm monorepos --- bundle-size/pm.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bundle-size/pm.sh b/bundle-size/pm.sh index a9466641..eddfd479 100755 --- a/bundle-size/pm.sh +++ b/bundle-size/pm.sh @@ -15,25 +15,32 @@ 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" elif [ -f package-lock.json ]; then 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 +if [ "$pm" = "yarn" ]; then pmb=("yarn" "build" "--profile" "--json" "pr-stats.json") -elif [ -f package-lock.json ]; then +elif [ "$pm" = "npm" ]; then pmb=("npm" "run" "build" "--" "--profile" "--json" "pr-stats.json") -else - echo "Defaulting to pnpm for build command." +elif [ "$pm" = "pnpm" ]; then install_pnpm_if_not_present pmb=("pnpm" "build" "--profile" "--json" "pr-stats.json") +else + echo "No recognized package manager found in this project." + exit 1 fi # Run the provided command with the detected package manager From 3f543ccc7e597c2fc514636dbac3ba87485f1bed Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 2 Jan 2025 15:35:18 +0100 Subject: [PATCH 2/2] fix indentation --- bundle-size/pm.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/bundle-size/pm.sh b/bundle-size/pm.sh index eddfd479..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() { @@ -18,35 +18,35 @@ install_pnpm_if_not_present() { 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" + install_pnpm_if_not_present + pm="pnpm" else - echo "No recognized package manager found in this project." - exit 1 + 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 [ "$pm" = "yarn" ]; then - pmb=("yarn" "build" "--profile" "--json" "pr-stats.json") + pmb=("yarn" "build" "--profile" "--json" "pr-stats.json") elif [ "$pm" = "npm" ]; then - pmb=("npm" "run" "build" "--" "--profile" "--json" "pr-stats.json") + 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") + install_pnpm_if_not_present + pmb=("pnpm" "build" "--profile" "--json" "pr-stats.json") else - echo "No recognized package manager found in this project." - exit 1 + 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