@@ -10,9 +10,18 @@ inputs:
1010 node :
1111 description : " Node.js version (e.g. 18)"
1212 required : false
13+ npm :
14+ description : " NPM version (e.g. 11.7.0)"
15+ required : false
16+ pnpm :
17+ description : " PNPM version (e.g. 9.9.0)"
18+ required : false
1319 yarn :
1420 description : " Yarn version (e.g. 1.22.22)"
1521 required : false
22+ bun :
23+ description : " Bun version (e.g. 1.3.5)"
24+ required : false
1625 go :
1726 description : " Go version (e.g. 1.22)"
1827 required : false
@@ -74,35 +83,85 @@ runs:
7483 with :
7584 node-version : ${{ steps.detect-node.outputs.VERSION }}
7685
77- # Detects if yarn is being used as package manager
78- # This step enables conditional execution of the setup action,
79- # either when a version is explicitly provided or when a `yarn.lock` file exists.
80- # Right now, we only support installing yarn v1.x if the version is not explicitly provided.
81- - id : detect-yarn
86+ # Detect which package manager to use based on lock files or explicit inputs.
87+ # Priority order: npm > pnpm > yarn > bun > default to yarn v1
88+ - id : detect-package-manager
8289 shell : bash
8390 env :
91+ NPM_INPUT : ${{ inputs.npm }}
92+ PNPM_INPUT : ${{ inputs.pnpm }}
8493 YARN_INPUT : ${{ inputs.yarn }}
94+ BUN_INPUT : ${{ inputs.bun }}
8595 run : |
86- if [ -n "$YARN_INPUT" ]; then
96+ # Check for explicit version inputs first
97+ if [ -n "$NPM_INPUT" ]; then
98+ echo "PACKAGE_MANAGER=npm" >> $GITHUB_OUTPUT
99+ echo "VERSION=$NPM_INPUT" >> $GITHUB_OUTPUT
100+ elif [ -n "$PNPM_INPUT" ]; then
101+ echo "PACKAGE_MANAGER=pnpm" >> $GITHUB_OUTPUT
102+ echo "VERSION=$PNPM_INPUT" >> $GITHUB_OUTPUT
103+ elif [ -n "$YARN_INPUT" ]; then
104+ echo "PACKAGE_MANAGER=yarn" >> $GITHUB_OUTPUT
87105 echo "VERSION=$YARN_INPUT" >> $GITHUB_OUTPUT
106+ elif [ -n "$BUN_INPUT" ]; then
107+ echo "PACKAGE_MANAGER=bun" >> $GITHUB_OUTPUT
108+ echo "VERSION=$BUN_INPUT" >> $GITHUB_OUTPUT
109+ # Check for lock files
110+ elif [ -f package-lock.json ]; then
111+ echo "PACKAGE_MANAGER=npm" >> $GITHUB_OUTPUT
112+ echo "VERSION=" >> $GITHUB_OUTPUT
113+ elif [ -f pnpm-lock.yaml ]; then
114+ echo "PACKAGE_MANAGER=pnpm" >> $GITHUB_OUTPUT
115+ echo "VERSION=" >> $GITHUB_OUTPUT
88116 elif [ -f yarn.lock ]; then
89- echo "LOCK_FILE=yarn.lock" >> $GITHUB_OUTPUT
117+ echo "PACKAGE_MANAGER=yarn" >> $GITHUB_OUTPUT
118+ echo "VERSION=" >> $GITHUB_OUTPUT
119+ elif [ -f bun.lock ] || [ -f bun.lockb ]; then
120+ echo "PACKAGE_MANAGER=bun" >> $GITHUB_OUTPUT
121+ echo "VERSION=" >> $GITHUB_OUTPUT
122+ # Default to yarn v1 if no package manager is detected
90123 else
124+ echo "PACKAGE_MANAGER=yarn" >> $GITHUB_OUTPUT
91125 echo "VERSION=" >> $GITHUB_OUTPUT
92- echo "LOCK_FILE=" >> $GITHUB_OUTPUT
93126 fi
94127
95- - name : Setup Yarn
128+ - name : Setup Package Manager
96129 shell : bash
97130 env :
98- YARN_VERSION : ${{ steps.detect-yarn.outputs.VERSION }}
99- YARN_LOCK_FILE : ${{ steps.detect-yarn.outputs.LOCK_FILE }}
131+ PACKAGE_MANAGER :
132+ ${{ steps.detect-package-manager.outputs.PACKAGE_MANAGER }}
133+ VERSION : ${{ steps.detect-package-manager.outputs.VERSION }}
100134 run : |
101- if [ -n "$YARN_VERSION" ]; then
102- npm install -g yarn@$YARN_VERSION
103- elif [ -n "$YARN_LOCK_FILE" ]; then
104- npm install -g yarn
105- fi
135+ case "$PACKAGE_MANAGER" in
136+ npm)
137+ if [ -n "$VERSION" ]; then
138+ npm install -g npm@$VERSION
139+ else
140+ npm install -g npm@latest
141+ fi
142+ ;;
143+ pnpm)
144+ if [ -n "$VERSION" ]; then
145+ npm install -g pnpm@$VERSION
146+ else
147+ npm install -g pnpm
148+ fi
149+ ;;
150+ yarn)
151+ if [ -n "$VERSION" ]; then
152+ npm install -g yarn@$VERSION
153+ else
154+ npm install -g yarn
155+ fi
156+ ;;
157+ bun)
158+ if [ -n "$VERSION" ]; then
159+ npm install -g bun@$VERSION
160+ else
161+ npm install -g bun
162+ fi
163+ ;;
164+ esac
106165
107166 # Detect version for Go from input or common version files.
108167 # This step enables conditional execution of the setup action,
0 commit comments