Fix Node 24-specific deprecation warning (#1199)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 2f1012f · Browse files · 6 files·+29 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+29 added−4 removed
- tests:+10 added−0 removed
- other:+19 added−4 removed
Provenance
- Commit
1ac5b91- Tree
9babfab- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
2f1012f
6 files changed+29 added−4 removed
modified:.github/workflows/main.yml+2 added-2 removed
8 unmodified lines910111213131415161712 unmodified lines303132333434353637385 unmodified lines8 unmodified lines strategy: fail-fast: false matrix: node-version: - 23 - 24 - 18 os: - ubuntu - macos12 unmodified lines - uses: lycheeverse/lychee-action@v1 with: args: --cache --verbose --no-progress --include-fragments --exclude packagephobia --exclude /pull/ --exclude linkedin --exclude stackoverflow --exclude stackexchange --exclude github.com/nodejs/node --exclude file:///test --exclude invalid.com '*.md' 'docs/*.md' '.github/**/*.md' '*.json' '*.js' 'lib/**/*.js' 'test/**/*.js' '*.ts' 'test-d/**/*.ts' fail: true if: ${{ matrix.os == 'ubuntu' && matrix.node-version == 23 }} if: ${{ matrix.os == 'ubuntu' && matrix.node-version == 24 }} - run: npm run lint - run: npm run type - run: npm run unit - uses: codecov/codecov-action@v45 unmodified linesadded:lib/arguments/shell.js+12 added
123456789101112// When the `shell` option is set, any command argument is concatenated as a single string by Node.js:// https://github.com/nodejs/node/blob/e38ce27f3ca0a65f68a31cedd984cddb927d4002/lib/child_process.js#L614-L624// However, since Node 24, it also prints a deprecation warning.// To avoid this warning, we perform that same operation before calling `node:child_process`.// Shells only understand strings, which is why Node.js performs that concatenation.// However, we rely on users splitting command arguments as an array.// For example, this allows us to easily detect which arguments are passed.// So we do want users to pass array of arguments even with `shell: true`, but we also want to avoid any warning.export const concatenateShell = (file, commandArguments, options) => options.shell && commandArguments.length > 0 ? [[file, ...commandArguments].join(' '), [], options] : [file, commandArguments, options];
modified:lib/methods/main-async.js+2 added-1 removed
2 unmodified lines3 import {MaxBufferError} from 'get-stream';4 import {handleCommand} from '../arguments/command.js';5 import {normalizeOptions} from '../arguments/options.js';6 import {SUBPROCESS_OPTIONS} from '../arguments/fd-options.js';7+import {concatenateShell} from '../arguments/shell.js';8 import {addIpcMethods} from '../ipc/methods.js';9 import {makeError, makeSuccessResult} from '../return/result.js';10 import {handleResult} from '../return/reject.js';11 import {handleEarlyError} from '../return/early-error.js';63 unmodified lines75 76 const spawnSubprocessAsync = ({file, commandArguments, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors}) => {77 let subprocess;78 try {78- subprocess = spawn(file, commandArguments, options);79+ subprocess = spawn(...concatenateShell(file, commandArguments, options));80 } catch (error) {81 return handleEarlyError({82 error,83 command,111 unmodified linesmodified:lib/methods/main-sync.js+2 added-1 removed
1 import {spawnSync} from 'node:child_process';2 import {handleCommand} from '../arguments/command.js';3 import {normalizeOptions} from '../arguments/options.js';4+import {concatenateShell} from '../arguments/shell.js';5 import {makeError, makeEarlyError, makeSuccessResult} from '../return/result.js';6 import {handleResult} from '../return/reject.js';7 import {handleStdioSync} from '../stdio/handle-sync.js';8 import {stripNewline} from '../io/strip-newline.js';106 unmodified lines115 const runSubprocessSync = ({file, commandArguments, options, command, escapedCommand, fileDescriptors, startTime}) => {116 try {117 addInputOptionsSync(fileDescriptors, options);118 const normalizedOptions = normalizeSpawnSyncOptions(options);118- return spawnSync(file, commandArguments, normalizedOptions);119+ return spawnSync(...concatenateShell(file, commandArguments, normalizedOptions));120 } catch (error) {121 return makeEarlyError({122 error,123 command,40 unmodified linesmodified:test/helpers/fixtures-directory.js+10 added
123456789101112131415161718197 unmodified linesimport path from 'node:path';import process from 'node:process';import {fileURLToPath} from 'node:url';import logProcessErrors from 'log-process-errors';import pathKey from 'path-key';
// Make tests fail if any warning (such as a deprecation warning) is emittedlogProcessErrors({ onError(error, event) { if (event === 'warning') { throw error; } },});
export const PATH_KEY = pathKey();export const FIXTURES_DIRECTORY_URL = new URL('../fixtures/', import.meta.url);// @todo: use import.meta.dirname after dropping support for Node <20.11.0export const FIXTURES_DIRECTORY = path.resolve(fileURLToPath(FIXTURES_DIRECTORY_URL));7 unmodified linesmodified:package.json+1 added
69 unmodified lines70717273747576777827 unmodified lines69 unmodified lines "c8": "^10.1.2", "get-node": "^15.0.0", "is-in-ci": "^1.0.0", "is-running": "^2.1.0", "log-process-errors": "^12.0.1", "path-exists": "^5.0.0", "path-key": "^4.0.0", "tempfile": "^5.0.0", "tsd": "^0.31.0",27 unmodified lines