File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,21 @@ test("resolveInstallInvocation prefers npm_execpath and falls back to node-adjac
7272 } ,
7373 ) ;
7474
75+ assert . deepEqual (
76+ resolveInstallInvocation ( "npm" , {
77+ env : {
78+ npm_execpath :
79+ "C:\\Users\\example\\AppData\\Roaming\\npm\\node_modules\\pnpm\\bin\\pnpm.cjs" ,
80+ } ,
81+ platform : "win32" ,
82+ nodeExecPath : "C:\\Program Files\\nodejs\\node.exe" ,
83+ } ) ,
84+ {
85+ command : "C:\\Program Files\\nodejs\\npm.cmd" ,
86+ args : [ "install" ] ,
87+ } ,
88+ ) ;
89+
7590 assert . deepEqual (
7691 resolveInstallInvocation ( "npm" , {
7792 env : { } ,
Original file line number Diff line number Diff line change @@ -149,6 +149,15 @@ function shouldStripInstallEnvKey(key: string): boolean {
149149 ) ;
150150}
151151
152+ function isNpmExecPath ( execPath : string ) : boolean {
153+ const normalized = execPath . replaceAll ( "\\" , "/" ) . toLowerCase ( ) ;
154+ return (
155+ normalized . endsWith ( "/npm-cli.js" ) ||
156+ normalized . endsWith ( "/npm-cli.mjs" ) ||
157+ / ( ^ | \/ ) n p m ( \. c m d | \. e x e ) ? $ / . test ( normalized )
158+ ) ;
159+ }
160+
152161export function createInstallEnv (
153162 parentEnv : Readonly < Record < string , string | undefined >> = process . env ,
154163) : NodeJS . ProcessEnv {
@@ -180,7 +189,7 @@ export function resolveInstallInvocation(
180189 if ( packageManager === "npm" ) {
181190 // biome-ignore lint/complexity/useLiteralKeys: process.env-compatible maps use index signatures in TS.
182191 const npmExecPath = env [ "npm_execpath" ] ;
183- if ( npmExecPath ) {
192+ if ( npmExecPath && isNpmExecPath ( npmExecPath ) ) {
184193 return { command : nodeExecPath , args : [ npmExecPath , "install" ] } ;
185194 }
186195 if ( platform === "win32" ) {
You can’t perform that action at this time.
0 commit comments