Skip to content

Commit e49c93a

Browse files
feat: support bun and pnpm, update handling for detecting yarn and npm
BREAKING CHANGE: Updates yarn/npm detection logic, bumping as major to preserve existing major-pegged behavior
1 parent d284155 commit e49c93a

3 files changed

Lines changed: 91 additions & 19 deletions

File tree

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,17 @@ By default the action will look for a `.node-version` file in the root level
115115
directory. If present it will setup the node environment to use that version of
116116
node, installing the specified version if necessary.
117117

118-
This will also attempt to install the `yarn` command and make it available to
119-
future steps in the workflow. If a yarn version is not provided, right now we
120-
only support installing yarn classic (i.e. v1.x) by default.
118+
This will also detect and install the appropriate package manager based on lock
119+
files present in the repository:
120+
121+
- **npm**: Detected via `package-lock.json`
122+
- **pnpm**: Detected via `pnpm-lock.yaml`
123+
- **yarn**: Detected via `yarn.lock`
124+
- **bun**: Detected via `bun.lock`
125+
126+
If a specific version is provided via inputs, that version will be installed.
127+
Otherwise, the package manager will be installed with a sensible default version
128+
when its corresponding lock file is detected.
121129

122130
The Node.js tools are made available via
123131
[nodenv](https://github.com/nodenv/nodenv).

action.yaml

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

docs/breaking-changes/v4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Breaking Changes in v4
2+
3+
- Adds support for `bun` and `pnpm`
4+
- Updates logic for existing `npm` and `yarn` detection, and so may
5+
inadvertently change behavior. Cutting as new major as a precaution.

0 commit comments

Comments
 (0)