| 1 |
'use strict'; |
| 2 |
|
| 3 |
const path = require("path") |
| 4 |
const {debug} = require("../debug") |
| 5 |
const whichOrUndefined = require("../which-or-undefined") |
| 6 |
|
| 7 |
/** |
| 8 |
* Intercepts npm spawned processes. |
| 9 |
* |
| 10 |
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files. |
| 11 |
* @param options {import("../munge").InternalSpawnOptions} Original internal spawn options. |
| 12 |
* @return {import("../munge").InternalSpawnOptions} Updated internal spawn options. |
| 13 |
*/ |
| 14 |
function mungeNpm(workingDir, options) { |
| 15 |
debug('munge npm') |
| 16 |
// XXX weird effects of replacing a specific npm with a global one |
| 17 |
const npmPath = whichOrUndefined('npm') |
| 18 |
|
| 19 |
if (npmPath === undefined) { |
| 20 |
return {...options}; |
| 21 |
} |
| 22 |
|
| 23 |
const newArgs = [...options.args] |
| 24 |
|
| 25 |
newArgs[0] = npmPath |
| 26 |
const file = path.join(workingDir, 'node') |
| 27 |
newArgs.unshift(file) |
| 28 |
|
| 29 |
return {...options, file, args: newArgs} |
| 30 |
} |
| 31 |
|
| 32 |
module.exports = mungeNpm |