File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,31 @@ const LOCKS: Record<string, Agent> = {
212212
213213async 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
You can’t perform that action at this time.
0 commit comments