@@ -8,10 +8,10 @@ import { join } from 'node:path'
88import * as v from 'valibot'
99import { PackageNameSchema , UsernameSchema , OrgNameSchema , ScopeTeamSchema } from './schemas.ts'
1010import { logCommand , logSuccess , logError , logDebug } from './logger.ts'
11+ import { resolveNpmProcessCommand } from './npm-process.ts'
1112
1213const execFileAsync = promisify ( execFile )
1314export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/'
14- const NPM_COMMAND = process . platform === 'win32' ? 'npm.cmd' : 'npm'
1515
1616function createNpmEnv ( overrides : Record < string , string > = { } ) : Record < string , string > {
1717 return {
@@ -210,7 +210,7 @@ async function execNpmInteractive(
210210 env . npm_config_browser = 'false'
211211 }
212212
213- const child = pty . spawn ( NPM_COMMAND , npmArgs , {
213+ const child = pty . spawn ( 'npm' , npmArgs , {
214214 name : 'xterm-256color' ,
215215 cols : 120 ,
216216 rows : 30 ,
@@ -332,10 +332,9 @@ async function execNpm(args: string[], options: ExecNpmOptions = {}): Promise<Np
332332 }
333333
334334 try {
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 , {
335+ logDebug ( 'Executing npm command:' , { command : 'npm' , args : npmArgs } )
336+ const { command, args : processArgs } = resolveNpmProcessCommand ( npmArgs )
337+ const { stdout, stderr } = await execFileAsync ( command , processArgs , {
339338 timeout : 60000 ,
340339 env : createNpmEnv ( ) ,
341340 } )
@@ -609,7 +608,8 @@ export async function packageInit(
609608 logCommand ( `${ displayCmd } (in temp dir for ${ name } )` )
610609
611610 try {
612- const { stdout, stderr } = await execFileAsync ( NPM_COMMAND , npmArgs , {
611+ const { command, args : processArgs } = resolveNpmProcessCommand ( npmArgs )
612+ const { stdout, stderr } = await execFileAsync ( command , processArgs , {
613613 timeout : 60000 ,
614614 cwd : tempDir ,
615615 env : createNpmEnv ( ) ,
0 commit comments