Skip to content

Commit ef9f6ab

Browse files
committed
feat: auto-pass --no-runtime when the runtime input is set
When the user pins a runtime via the action's `runtime` input, that runtime has already been installed and put on PATH by the time `pnpm install` runs. If the project's package.json also declares a different `devEngines.runtime` with `onFail: download`, pnpm install would fetch that second runtime and silently swap the active one — defeating the matrix/explicit pin. `--no-runtime` (pnpm v11.1.0+) tells pnpm install to skip the runtime fetch entirely. Appending it whenever the `runtime` input is set matches user intent: "I told the action which runtime I want, don't let install second-guess it." When the input is omitted (runtime fully driven by devEngines.runtime), `pnpm install` runs unmodified — the devEngines runtime is the only source of truth and install should honor it. Adds a `runtime-overrides-devengines` test that pins node@22 in the action input, declares ^20.0.0 in devEngines.runtime, and asserts node 22 is still active after install. Bumps test workflow's pnpm pin to 11.1.0 since `--no-runtime` requires it.
1 parent 7b64e33 commit ef9f6ab

4 files changed

Lines changed: 68 additions & 13 deletions

File tree

‎.github/workflows/test.yaml‎

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717
matrix:
1818
include:
1919
- os: ubuntu-latest
20-
version: '11.0.7'
20+
version: '11.1.0'
2121
- os: macos-latest
22-
version: '11.0.7'
22+
version: '11.1.0'
2323
- os: windows-latest
24-
version: '11.0.7'
24+
version: '11.1.0'
2525

2626
steps:
2727
- uses: actions/checkout@v6
@@ -73,7 +73,7 @@ jobs:
7373
- id: pnpm
7474
uses: ./
7575
with:
76-
version: '11.0.7'
76+
version: '11.1.0'
7777
runtime: node@${{ matrix.major }}
7878

7979
- name: 'Test: node binary on PATH'
@@ -114,7 +114,7 @@ jobs:
114114
- uses: actions/checkout@v6
115115
- uses: ./
116116
with:
117-
version: '11.0.7'
117+
version: '11.1.0'
118118
runtime: bun@latest
119119
- name: 'Test: bun on PATH'
120120
run: |
@@ -130,7 +130,7 @@ jobs:
130130
- uses: actions/checkout@v6
131131
- uses: ./
132132
with:
133-
version: '11.0.7'
133+
version: '11.1.0'
134134
runtime: deno@2
135135
- name: 'Test: deno on PATH'
136136
run: |
@@ -155,7 +155,7 @@ jobs:
155155
rm -f pnpm-lock.yaml
156156
cat > package.json <<'EOF'
157157
{
158-
"packageManager": "pnpm@11.0.7",
158+
"packageManager": "pnpm@11.1.0",
159159
"devEngines": {
160160
"runtime": { "name": "node", "version": "^22.0.0", "onFail": "download" }
161161
},
@@ -197,6 +197,53 @@ jobs:
197197
fi
198198
shell: bash
199199

200+
runtime-overrides-devengines:
201+
# Explicit `runtime` input conflicts with `devEngines.runtime` in
202+
# package.json. The action should install the explicit version AND pass
203+
# `--no-runtime` to pnpm install so the devEngines runtime doesn't shadow
204+
# the matrix one. Requires pnpm >= 11.1.0.
205+
name: 'Explicit runtime overrides devEngines.runtime'
206+
runs-on: ubuntu-latest
207+
steps:
208+
- uses: actions/checkout@v6
209+
210+
- name: Set up package.json with conflicting devEngines.runtime
211+
run: |
212+
rm -f pnpm-lock.yaml
213+
cat > package.json <<'EOF'
214+
{
215+
"packageManager": "pnpm@11.1.0",
216+
"devEngines": {
217+
"runtime": { "name": "node", "version": "^20.0.0", "onFail": "download" }
218+
},
219+
"dependencies": {
220+
"is-odd": "3.0.1"
221+
}
222+
}
223+
EOF
224+
shell: bash
225+
226+
- id: pnpm
227+
uses: ./
228+
with:
229+
runtime: node@22
230+
231+
- name: 'Test: node 22 stays active after pnpm install'
232+
run: |
233+
set -e
234+
actual="$(node --version)"
235+
echo "node --version: ${actual}"
236+
case "${actual}" in
237+
v22.*) ;;
238+
*) echo "Expected node v22.x after install (--no-runtime should have suppressed the devEngines runtime fetch), got ${actual}"; exit 1 ;;
239+
esac
240+
# pnpm install should still have run.
241+
if [ ! -d node_modules/is-odd ]; then
242+
echo "Expected pnpm install to have populated node_modules/is-odd"
243+
exit 1
244+
fi
245+
shell: bash
246+
200247
runtime-version-fallback:
201248
# `runtime: node` without an `@<version>` suffix should fall back to the
202249
# version declared in devEngines.runtime.
@@ -210,7 +257,7 @@ jobs:
210257
rm -f pnpm-lock.yaml
211258
cat > package.json <<'EOF'
212259
{
213-
"packageManager": "pnpm@11.0.7",
260+
"packageManager": "pnpm@11.1.0",
214261
"devEngines": {
215262
"runtime": { "name": "node", "version": "^20.0.0", "onFail": "download" }
216263
}
@@ -246,7 +293,7 @@ jobs:
246293
- id: pnpm
247294
uses: ./
248295
with:
249-
version: '11.0.7'
296+
version: '11.1.0'
250297

251298
- name: 'Test: pnpm works, runtime outputs are empty'
252299
env:

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
1. The action installs `@pnpm/exe` (a Node.js-bundled standalone build of pnpm) into `dest`, then self-updates to the requested pnpm version.
9696
2. `PNPM_HOME` is exported and `$PNPM_HOME/bin` is added to `PATH`.
9797
3. The action runs `pnpm runtime set <name> <version> -g`, which downloads the requested runtime into `$PNPM_HOME/bin` — making `node`, `bun`, or `deno` available to later workflow steps.
98-
4. If a `package.json` exists in the workspace, the action runs `pnpm install`.
98+
4. If a `package.json` exists in the workspace, the action runs `pnpm install`. When the `runtime` input is set, `--no-runtime` is appended so the just-installed runtime isn't shadowed by a different version declared in `devEngines.runtime`. This flag requires pnpm ≥ 11.1.0.
9999

100100
## License
101101

‎dist/index.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/pnpm-install/index.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ export function runPnpmInstall(inputs: Inputs) {
2020
return
2121
}
2222

23-
startGroup('Running pnpm install...')
24-
const { error, status } = spawnSync('pnpm', ['install'], {
23+
// When the user pinned a runtime explicitly via the `runtime` input, we've
24+
// already installed it via `pnpm runtime set` above. Pass `--no-runtime`
25+
// to `pnpm install` so the matrix/explicit node isn't shadowed by a
26+
// different version from `devEngines.runtime` on the same install.
27+
// Requires pnpm >= 11.1.0 (the version that introduced `--no-runtime`).
28+
const args = ['install']
29+
if (inputs.runtime) args.push('--no-runtime')
30+
31+
startGroup(`Running pnpm ${args.join(' ')}...`)
32+
const { error, status } = spawnSync('pnpm', args, {
2533
stdio: 'inherit',
2634
cwd: GITHUB_WORKSPACE,
2735
shell: true,

0 commit comments

Comments
 (0)