Files
puter/tools/npmSpawn.mjs
T
Rasad RegmiandDaniel Salazar 83de67cca9 fix(tools): spawn npm.cmd through a shell on Windows (#3923)
* fix(tools): spawn npm.cmd through a shell on Windows

* fix(tools): join the npm command line on Windows to avoid DEP0190

Passing args alongside shell: true warns on Node 24. Test the spawn
tuple as data and run a real npm spawn instead of mocking child_process.

---------

Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
2026-09-23 18:54:43 -07:00

22 lines
769 B
JavaScript

// Shared helper for spawning npm from the repo's tools/ scripts.
//
// On Windows `npm` resolves to the `npm.cmd` batch shim, which Node refuses
// to spawn without a shell (`spawn EINVAL`). Node also warns when args are
// passed alongside `shell: true` (DEP0190), so the command line is joined
// here; args must be plain words that need no quoting.
import { spawn } from 'node:child_process';
/** `[command, args, options]` for `spawn`. */
export const npmSpawnArgs = (
args,
options = {},
platform = process.platform,
) =>
platform === 'win32'
? [['npm.cmd', ...args].join(' '), [], { ...options, shell: true }]
: ['npm', args, options];
export const spawnNpm = (args, options = {}) =>
spawn(...npmSpawnArgs(args, options));