@@ -11,6 +11,7 @@ import { logCommand, logSuccess, logError, logDebug } from './logger.ts'
1111
1212const execFileAsync = promisify ( execFile )
1313export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/'
14+ const NPM_COMMAND = process . platform === 'win32' ? 'npm.cmd' : 'npm'
1415
1516function createNpmEnv ( overrides : Record < string , string > = { } ) : Record < string , string > {
1617 return {
@@ -209,7 +210,7 @@ async function execNpmInteractive(
209210 env . npm_config_browser = 'false'
210211 }
211212
212- const child = pty . spawn ( 'npm' , npmArgs , {
213+ const child = pty . spawn ( NPM_COMMAND , npmArgs , {
213214 name : 'xterm-256color' ,
214215 cols : 120 ,
215216 rows : 30 ,
@@ -331,14 +332,12 @@ async function execNpm(args: string[], options: ExecNpmOptions = {}): Promise<Np
331332 }
332333
333334 try {
334- logDebug ( 'Executing npm command:' , { command : 'npm' , args : npmArgs } )
335- // Use execFile instead of exec to avoid shell injection vulnerabilities
336- // On Windows, shell: true is required to execute .cmd files (like npm.cmd)
337- // On Unix, we keep it false for better security and performance
338- const { stdout, stderr } = await execFileAsync ( 'npm' , npmArgs , {
335+ logDebug ( 'Executing npm command:' , { command : NPM_COMMAND , args : npmArgs } )
336+ // Use execFile instead of exec to avoid shell injection vulnerabilities.
337+ // Use npm.cmd on Windows to avoid shell wrapping and DEP0190 warnings.
338+ const { stdout, stderr } = await execFileAsync ( NPM_COMMAND , npmArgs , {
339339 timeout : 60000 ,
340340 env : createNpmEnv ( ) ,
341- shell : process . platform === 'win32' ,
342341 } )
343342
344343 logDebug ( 'Command succeeded:' , { stdout, stderr } )
@@ -610,11 +609,10 @@ export async function packageInit(
610609 logCommand ( `${ displayCmd } (in temp dir for ${ name } )` )
611610
612611 try {
613- const { stdout, stderr } = await execFileAsync ( 'npm' , npmArgs , {
612+ const { stdout, stderr } = await execFileAsync ( NPM_COMMAND , npmArgs , {
614613 timeout : 60000 ,
615614 cwd : tempDir ,
616615 env : createNpmEnv ( ) ,
617- shell : process . platform === 'win32' ,
618616 } )
619617
620618 logSuccess ( `Published ${ name } @0.0.0` )
0 commit comments