@@ -31,88 +31,83 @@ if command -v bun >/dev/null 2>&1; then
3131 has_bun=true
3232fi
3333
34- # Count how many are installed
34+ # Count how many NON-npm managers are installed (npm doesn't count, it's bundled with Node)
3535count=0
3636managers=()
37- if $has_npm ; then count=$(( count + 1 )) ; managers+=(" npm" ); fi
3837if $has_yarn ; then count=$(( count + 1 )) ; managers+=(" yarn" ); fi
3938if $has_pnpm ; then count=$(( count + 1 )) ; managers+=(" pnpm" ); fi
4039if $has_bun ; then count=$(( count + 1 )) ; managers+=(" bun" ); fi
4140
42- # If only one is installed, check if it's the recommended one
43- if [ " $count " -eq 1 ]; then
44- if $has_pnpm ; then
45- echo -e " ${GREEN} ✓ Only pnpm is installed - recommended configuration!${NC} "
46- echo " pnpm is fast, disk-efficient, and strictly follows package.json"
47- exit 0
48- elif $has_bun ; then
49- echo -e " ${GREEN} ✓ Only bun is installed - excellent choice!${NC} "
50- echo " bun is extremely fast and includes runtime + bundler"
51- exit 0
52- elif $has_npm ; then
53- echo -e " ${YELLOW} ℹ npm is installed (bundled with Node.js)${NC} "
54- echo " "
55- echo -e " ${BLUE} Recommendation: Consider pnpm for better performance and disk efficiency${NC} "
56- echo " "
57- echo " Why pnpm?"
58- echo " • 2x faster than npm"
59- echo " • Saves disk space with content-addressable storage"
60- echo " • Strict dependency resolution (no phantom dependencies)"
61- echo " • Drop-in replacement for npm"
62- echo " "
63- echo " Install pnpm:"
64- echo " npm install -g pnpm"
65- echo " "
66- exit 0
41+ # Check for conflicting lock files in current directory
42+ has_package_lock=false
43+ has_yarn_lock=false
44+ has_pnpm_lock=false
45+ has_bun_lock=false
46+
47+ if [ -f " package-lock.json" ]; then has_package_lock=true; fi
48+ if [ -f " yarn.lock" ]; then has_yarn_lock=true; fi
49+ if [ -f " pnpm-lock.yaml" ]; then has_pnpm_lock=true; fi
50+ if [ -f " bun.lockb" ]; then has_bun_lock=true; fi
51+
52+ lock_count=0
53+ if $has_package_lock ; then lock_count=$(( lock_count + 1 )) ; fi
54+ if $has_yarn_lock ; then lock_count=$(( lock_count + 1 )) ; fi
55+ if $has_pnpm_lock ; then lock_count=$(( lock_count + 1 )) ; fi
56+ if $has_bun_lock ; then lock_count=$(( lock_count + 1 )) ; fi
57+
58+ # If multiple lock files exist in current directory, warn about project-level conflict
59+ if [ " $lock_count " -gt 1 ]; then
60+ echo -e " ${RED} ⚠ Multiple package manager lock files detected in current directory:${NC} "
61+ if $has_package_lock ; then echo " - package-lock.json (npm)" ; fi
62+ if $has_yarn_lock ; then echo " - yarn.lock (yarn)" ; fi
63+ if $has_pnpm_lock ; then echo " - pnpm-lock.yaml (pnpm)" ; fi
64+ if $has_bun_lock ; then echo " - bun.lockb (bun)" ; fi
65+ echo " "
66+ echo -e " ${RED} Problem: This project has conflicting lock files!${NC} "
67+ echo " • Delete all but ONE lock file"
68+ echo " • Reinstall dependencies with chosen package manager"
69+ echo " • Add others to .gitignore"
70+ echo " "
71+ exit 1
72+ fi
73+
74+ # If only npm or npm + one other manager, that's fine (npm is unavoidable)
75+ if [ " $count " -eq 0 ]; then
76+ if $has_npm ; then
77+ echo -e " ${GREEN} ✓ npm installed (bundled with Node.js)${NC} "
6778 else
68- echo -e " ${GREEN} ✓ Only ${managers[0]} is installed${NC} "
69- exit 0
79+ echo -e " ${RED} ⚠ No Node.js package manager found${NC} "
80+ echo " Install Node.js to get npm"
81+ exit 1
7082 fi
83+ exit 0
7184fi
7285
73- # If multiple managers are installed, warn
86+ if [ " $count " -eq 1 ]; then
87+ # npm + one other manager is the common, recommended setup
88+ echo -e " ${GREEN} ✓ Package managers: npm (Node.js bundled) + ${managers[0]}${NC} "
89+ exit 0
90+ fi
91+
92+ # If multiple NON-npm managers installed, provide guidance (not an error, just info)
7493if [ " $count " -gt 1 ]; then
75- echo -e " ${YELLOW} ⚠ Multiple Node.js package managers detected:${NC} "
94+ echo -e " ${BLUE} ℹ Multiple Node.js package managers available:${NC} "
95+ if $has_npm ; then
96+ version=$( npm --version 2> /dev/null || echo " unknown" )
97+ echo " - npm ($version ) [bundled with Node.js]"
98+ fi
7699 for mgr in " ${managers[@]} " ; do
77100 version=" "
78101 case $mgr in
79- npm) version=$( $mgr --version 2> /dev/null || echo " unknown" ) ;;
80- yarn) version=$( $mgr --version 2> /dev/null || echo " unknown" ) ;;
81- pnpm) version=$( $mgr --version 2> /dev/null || echo " unknown" ) ;;
82- bun) version=$( $mgr --version 2> /dev/null || echo " unknown" ) ;;
102+ yarn) version=$( yarn --version 2> /dev/null || echo " unknown" ) ;;
103+ pnpm) version=$( pnpm --version 2> /dev/null || echo " unknown" ) ;;
104+ bun) version=$( bun --version 2> /dev/null || echo " unknown" ) ;;
83105 esac
84106 echo " - $mgr ($version )"
85107 done
86108 echo " "
87- echo -e " ${RED} Problems with multiple managers:${NC} "
88- echo " • Lock file conflicts (package-lock.json vs pnpm-lock.yaml vs yarn.lock)"
89- echo " • Different dependency resolution algorithms"
90- echo " • Wasted disk space from multiple caches"
91- echo " • Team confusion about which manager to use"
92- echo " "
93- echo -e " ${BLUE} Recommendation: Choose ONE package manager per project${NC} "
94- echo " "
95- echo " Recommended priority:"
96- echo " 1. pnpm - Fast, disk-efficient, strict (recommended for most projects)"
97- echo " 2. bun - Extremely fast, includes runtime (good for new projects)"
98- echo " 3. npm - Default, bundled with Node.js (keep for compatibility)"
99- echo " 4. yarn - Classic choice (consider migrating to pnpm or bun)"
109+ echo -e " ${BLUE} Tip: Use one package manager per project (check lock files)${NC} "
100110 echo " "
101- echo " Project-specific guidance:"
102- echo " • Check for existing lock files to see what your project uses"
103- echo " • Use .npmrc or package.json 'packageManager' field to enforce choice"
104- echo " • Consider 'pnpm' as default for new projects"
105- echo " "
106- echo " Note: npm comes bundled with Node.js and should typically be kept installed."
107- echo " You can use other managers alongside npm, but choose ONE for each project."
108- echo " "
109-
110- exit 1
111111fi
112112
113- # If none are installed (unlikely if Node.js is installed)
114- echo -e " ${RED} ⚠ No Node.js package manager found${NC} "
115- echo " Install Node.js to get npm, then optionally install pnpm:"
116- echo " nvm install --lts"
117- echo " npm install -g pnpm"
118- exit 1
113+ exit 0
0 commit comments