mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-06 11:24:00 +00:00
fix(setup): stop Node's DEP0190 warning when npm runs on Windows (#1057)
Windows runs npm.cmd through a shell, and passing an argument array with `shell: true` is deprecated in Node 24 (DEP0190). Every `npm run doctor` and every Pinokio install on Windows printed the warning. npmProcessSpec now takes the npm arguments and, on Windows, joins them into the command string; the arguments are fixed subcommands (`--version`, `ci`). Unix behavior is unchanged.
This commit is contained in:
1 parent
ec7823daad
commit
3c3ea269a9
4 files changed
+31
-12
No files matched your search
@@ -0,0 +1,4 @@
|
|||||||
|
- On Windows, `npm run doctor` and the Pinokio install no longer print Node's
|
||||||
|
DEP0190 warning ("Passing args to a child process with shell option true can
|
||||||
|
lead to security vulnerabilities"): npm.cmd's fixed subcommand is now part of
|
||||||
|
the shell command string instead of an argument array (quanticsoul4772, #1057).
|
||||||
@@ -24,8 +24,8 @@ export function runChecked(command, args, { shell = false } = {}) {
|
|||||||
export function installPinokioDependencies() {
|
export function installPinokioDependencies() {
|
||||||
applyPinokioEnvironment();
|
applyPinokioEnvironment();
|
||||||
rmSync(READY_FILE, { force: true });
|
rmSync(READY_FILE, { force: true });
|
||||||
const npm = npmProcessSpec();
|
const npm = npmProcessSpec(['ci']);
|
||||||
runChecked(npm.command, ['ci'], { shell: npm.shell });
|
runChecked(npm.command, npm.args, { shell: npm.shell });
|
||||||
|
|
||||||
// Pinokio starts Vite directly and loads only its ENVIRONMENT file plus the
|
// Pinokio starts Vite directly and loads only its ENVIRONMENT file plus the
|
||||||
// normal dotenv ladder. Unlike dev-fresh.sh, it does not import macOS
|
// normal dotenv ladder. Unlike dev-fresh.sh, it does not import macOS
|
||||||
|
|||||||
@@ -76,10 +76,15 @@ export function hasRequiredDependencies(rootDir = ROOT) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the npm command and spawn mode required by the target platform. */
|
/**
|
||||||
export function npmProcessSpec(platform = process.platform) {
|
* Return the npm command, arguments and spawn mode for the target platform.
|
||||||
const windows = platform === 'win32';
|
* Windows must run npm.cmd through a shell, and Node 24 deprecates passing an
|
||||||
return { command: windows ? 'npm.cmd' : 'npm', shell: windows };
|
* argument array with `shell: true` (DEP0190), so there the arguments, which
|
||||||
|
* are fixed npm subcommands, join the command string.
|
||||||
|
*/
|
||||||
|
export function npmProcessSpec(args, platform = process.platform) {
|
||||||
|
if (platform !== 'win32') return { command: 'npm', args, shell: false };
|
||||||
|
return { command: ['npm.cmd', ...args].join(' '), args: [], shell: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Read one key from Vite's dotenv file ladder without depending on Vite. */
|
/** Read one key from Vite's dotenv file ladder without depending on Vite. */
|
||||||
@@ -190,8 +195,8 @@ export function buildCapabilitySummary(
|
|||||||
|
|
||||||
export function inspectSetup({ includeKeychain = true, authoritativeEnvironment = false, rootDir = ROOT } = {}) {
|
export function inspectSetup({ includeKeychain = true, authoritativeEnvironment = false, rootDir = ROOT } = {}) {
|
||||||
const node = classifyNodeVersion();
|
const node = classifyNodeVersion();
|
||||||
const npm = npmProcessSpec();
|
const npm = npmProcessSpec(['--version']);
|
||||||
const npmResult = spawnSync(npm.command, ['--version'], {
|
const npmResult = spawnSync(npm.command, npm.args, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
shell: npm.shell,
|
shell: npm.shell,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -69,12 +69,22 @@ test('placeholder values are never counted as configured credentials', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('doctor selects a Windows-safe npm process without changing Unix behavior', () => {
|
test('doctor selects a Windows-safe npm process without changing Unix behavior', () => {
|
||||||
assert.deepEqual(npmProcessSpec('win32'), {
|
// Windows passes no argument array with shell: true (Node DEP0190).
|
||||||
command: 'npm.cmd',
|
assert.deepEqual(npmProcessSpec(['ci'], 'win32'), {
|
||||||
|
command: 'npm.cmd ci',
|
||||||
|
args: [],
|
||||||
shell: true,
|
shell: true,
|
||||||
});
|
});
|
||||||
assert.deepEqual(npmProcessSpec('darwin'), { command: 'npm', shell: false });
|
assert.deepEqual(npmProcessSpec(['--version'], 'darwin'), {
|
||||||
assert.deepEqual(npmProcessSpec('linux'), { command: 'npm', shell: false });
|
command: 'npm',
|
||||||
|
args: ['--version'],
|
||||||
|
shell: false,
|
||||||
|
});
|
||||||
|
assert.deepEqual(npmProcessSpec(['ci'], 'linux'), {
|
||||||
|
command: 'npm',
|
||||||
|
args: ['ci'],
|
||||||
|
shell: false,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('doctor recognizes every OpenSky OAuth keychain alias used by dev-fresh', () => {
|
test('doctor recognizes every OpenSky OAuth keychain alias used by dev-fresh', () => {
|
||||||
|
|||||||
Reference in new issue
Block a user