-
Notifications
You must be signed in to change notification settings - Fork 18
fix: avoid deprecated shell spawning for pnpm commands #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zkochan
merged 2 commits into
pnpm:main
from
sebdanielsson:copilot/fix-deprecation-warning
Sep 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' | ||
| import { createRequire } from 'node:module' | ||
| import path from 'node:path' | ||
| import { after, beforeEach, test } from 'node:test' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { build } from 'esbuild' | ||
|
|
||
| const { outputFiles } = await build({ | ||
| stdin: { | ||
| contents: ` | ||
| export { getInputs } from './inputs/index.ts' | ||
| export { runPnpmInstall } from './pnpm-install/index.ts' | ||
| export { pruneStore } from './pnpm-store-prune/index.ts' | ||
| `, | ||
| resolveDir: fileURLToPath(new URL('.', import.meta.url)), | ||
| }, | ||
| bundle: true, | ||
| platform: 'node', | ||
| format: 'cjs', | ||
| write: false, | ||
| }) | ||
| const bundledModule = { exports: {} } | ||
| new Function('require', 'module', 'exports', outputFiles[0].text)( | ||
| createRequire(import.meta.url), bundledModule, bundledModule.exports, | ||
| ) | ||
| const { getInputs, runPnpmInstall, pruneStore } = bundledModule.exports | ||
|
|
||
| const root = mkdtempSync(path.join(process.cwd(), '.pnpm-commands-test-')) | ||
| const dest = path.join(root, 'pnpm home & tools') | ||
| const project = path.join(root, 'project') | ||
| const record = path.join(root, 'command.json') | ||
| mkdirSync(path.join(dest, 'bin'), { recursive: true }) | ||
| mkdirSync(project) | ||
| writeFileSync(path.join(project, 'package.json'), '{}') | ||
| writeFileSync(path.join(project, 'pnpm-lock.yaml'), '') | ||
|
|
||
| // A native executable named pnpm proves direct spawning works even when the | ||
| // destination contains spaces or shell metacharacters. Node consumes the | ||
| // fixture named "install" as its script, then passes through the install flags. | ||
| copyFileSync(process.execPath, path.join(dest, process.platform === 'win32' ? 'pnpm.exe' : 'pnpm')) | ||
| const recorder = ` | ||
| const fs = require('node:fs') | ||
| setTimeout(() => { | ||
| fs.writeFileSync(process.env.PNPM_TEST_RECORD, JSON.stringify({ | ||
| args: process.argv.slice(2), cwd: process.cwd(), executable: process.execPath, | ||
| })) | ||
| process.exitCode = Number(process.env.PNPM_TEST_EXIT_CODE || 0) | ||
| }, 25) | ||
| ` | ||
| writeFileSync(path.join(project, 'install'), recorder) | ||
| const shimScript = path.join(dest, 'record.cjs') | ||
| writeFileSync(shimScript, recorder) | ||
| const quoteShell = value => `'${value.replaceAll("'", "'\\''")}'` | ||
| const shim = process.platform === 'win32' | ||
| ? `@"${process.execPath}" "${shimScript}" %*\r\n` | ||
| : `#!/bin/sh\nexec ${quoteShell(process.execPath)} ${quoteShell(shimScript)} "$@"\n` | ||
| writeFileSync(path.join(dest, 'bin', process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'), shim, { mode: 0o755 }) | ||
| after(() => rmSync(root, { recursive: true, force: true })) | ||
|
|
||
| beforeEach(t => { | ||
| const previousEnv = { ...process.env } | ||
| const previousExitCode = process.exitCode | ||
| t.after(() => { | ||
| for (const name of Object.keys(process.env)) { | ||
| if (!(name in previousEnv)) delete process.env[name] | ||
| } | ||
| Object.assign(process.env, previousEnv) | ||
| process.exitCode = previousExitCode | ||
| }) | ||
| Object.assign(process.env, { | ||
| GITHUB_WORKSPACE: root, | ||
| INPUT_DEST: path.relative(process.cwd(), dest), | ||
| INPUT_CACHE: 'true', | ||
| INPUT_INSTALL: 'true', | ||
| 'INPUT_REQUIRE-LOCKFILE': 'true', | ||
| 'INPUT_WORKING-DIRECTORY': 'project', | ||
| 'INPUT_PACKAGE-JSON-FILE': '', | ||
| 'INPUT_NODE-VERSION-FILE': '', | ||
| INPUT_RUNTIME: '', | ||
| PNPM_TEST_RECORD: record, | ||
| PNPM_TEST_EXIT_CODE: '0', | ||
| }) | ||
| // Simulate the PATH prepared by setup, with self-update's shim first. | ||
| const pathKey = Object.keys(process.env).find(key => key.toUpperCase() === 'PATH') ?? 'PATH' | ||
| process.env[pathKey] = [path.join(dest, 'bin'), dest, process.env[pathKey]].join(path.delimiter) | ||
| rmSync(record, { force: true }) | ||
| }) | ||
|
|
||
| test('install uses the native binary with a relative dest and a separate project directory', () => { | ||
| const inputs = getInputs() | ||
| assert.equal(inputs.dest, dest) | ||
| runPnpmInstall(inputs, true) | ||
| const actual = JSON.parse(readFileSync(record, 'utf8')) | ||
| assert.deepEqual(actual.args, ['--frozen-lockfile', '--no-runtime']) | ||
| assert.equal(actual.cwd, project) | ||
| assert.equal(path.dirname(actual.executable), dest) | ||
| }) | ||
|
|
||
| test('pruning awaits the self-updated shim ahead of the original executable on PATH', async () => { | ||
| await pruneStore(getInputs()) | ||
| assert.deepEqual(JSON.parse(readFileSync(record, 'utf8')).args, ['store', 'prune']) | ||
| }) | ||
|
|
||
| test('pruning is skipped when caching is disabled', async () => { | ||
| await pruneStore({ ...getInputs(), cache: false }) | ||
| assert.throws(() => readFileSync(record), { code: 'ENOENT' }) | ||
| }) | ||
|
|
||
| test('pruning failure warns without failing the action', async t => { | ||
| process.env.PNPM_TEST_EXIT_CODE = '7' | ||
| const output = [] | ||
| const write = process.stdout.write.bind(process.stdout) | ||
| t.mock.method(process.stdout, 'write', (chunk, ...args) => { | ||
| output.push(String(chunk)) | ||
| return write(chunk, ...args) | ||
| }) | ||
| const previousExitCode = process.exitCode | ||
| await pruneStore(getInputs()) | ||
| assert.match(output.join(''), /::warning::.*exit code 7/) | ||
| assert.equal(process.exitCode, previousExitCode) | ||
| assert.deepEqual(JSON.parse(readFileSync(record, 'utf8')).args, ['store', 'prune']) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment restates how the native executable fixture and its arguments work instead of letting the test structure express that intent. The same pattern appears in the PATH setup at line 84 and in
src/pnpm-store-prune/index.tsat lines 13–15. This violates the repository directive that comments must not narrate code, so the narration must be removed or the surrounding names and structure made self-explanatory before merging.Context Used: Comments and docs in code are suspicious. Is test coverage not sufficient the reason why a comment was added? Comments should not replace tests. Comments should also not narrate code. Is the code hard to understand? Then it should be refactored to ma... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!