Skip to content

Commit 2dfcd39

Browse files
committed
Add back getAgentExecPath logic thought to be redundant
1 parent 581bfe9 commit 2dfcd39

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/utils/package-environment.mts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,31 @@ const LOCKS: Record<string, Agent> = {
212212

213213
async function getAgentExecPath(agent: Agent): Promise<string> {
214214
const binName = binByAgent.get(agent)!
215+
if (binName === NPM) {
216+
// Try to use constants.npmExecPath first, but verify it exists.
217+
const npmPath = constants.npmExecPath
218+
if (existsSync(npmPath)) {
219+
return npmPath
220+
}
221+
// If npmExecPath doesn't exist, try common locations.
222+
// Check npm in the same directory as node.
223+
const nodeDir = path.dirname(process.execPath)
224+
const npmInNodeDir = path.join(nodeDir, 'npm')
225+
if (existsSync(npmInNodeDir)) {
226+
return npmInNodeDir
227+
}
228+
// Fall back to whichBin.
229+
return (await whichBin(binName, { nothrow: true })) ?? binName
230+
}
231+
if (binName === PNPM) {
232+
// Try to use constants.pnpmExecPath first, but verify it exists.
233+
const pnpmPath = constants.pnpmExecPath
234+
if (existsSync(pnpmPath)) {
235+
return pnpmPath
236+
}
237+
// Fall back to whichBin.
238+
return (await whichBin(binName, { nothrow: true })) ?? binName
239+
}
215240
return (await whichBin(binName, { nothrow: true })) ?? binName
216241
}
217242

0 commit comments

Comments
 (0)