Skip to content

Commit 73ca633

Browse files
committed
fix: Add fallback for npm exec path detection
When constants.npmExecPath from the published registry doesn't exist or isn't executable, fall back to using whichBin to find npm. This fixes CI failures where the published version's npm-exec-path module might not correctly detect npm in certain environments.
1 parent 2d5522b commit 73ca633

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/utils/package-environment.mts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,13 @@ const LOCKS: Record<string, Agent> = {
208208
async function getAgentExecPath(agent: Agent): Promise<string> {
209209
const binName = binByAgent.get(agent)!
210210
if (binName === NPM) {
211-
return constants.npmExecPath
211+
// Try to use constants.npmExecPath first, but verify it exists.
212+
const npmPath = constants.npmExecPath
213+
if (existsSync(npmPath)) {
214+
return npmPath
215+
}
216+
// If npmExecPath doesn't exist, fall back to whichBin.
217+
return (await whichBin(binName, { nothrow: true })) ?? binName
212218
}
213219
return (await whichBin(binName, { nothrow: true })) ?? binName
214220
}

0 commit comments

Comments
 (0)