This commit is contained in:
lalBi94
2023-03-05 13:23:23 +01:00
commit 7bc56c09b5
14034 changed files with 1834369 additions and 0 deletions

59
node_modules/spawn-wrap/lib/mungers/cmd.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
'use strict';
const path = require("path")
const whichOrUndefined = require("../which-or-undefined")
/**
* Intercepts Node and npm processes spawned through Windows' `cmd.exe`.
*
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
* @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
* @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
*/
function mungeCmd(workingDir, options) {
const cmdi = options.args.indexOf('/c')
if (cmdi === -1) {
return {...options}
}
const re = /^\s*("*)([^"]*?\bnode(?:\.exe|\.EXE)?)("*)( .*)?$/
const npmre = /^\s*("*)([^"]*?\b(?:npm))("*)( |$)/
const command = options.args[cmdi + 1]
if (command === undefined) {
return {...options}
}
let newArgs = [...options.args];
// Remember the original Node command to use it in the shim
let originalNode;
let m = command.match(re)
let replace
if (m) {
originalNode = m[2]
// TODO: Remove `replace`: seems unused
replace = m[1] + path.join(workingDir, 'node.cmd') + m[3] + m[4]
newArgs[cmdi + 1] = m[1] + m[2] + m[3] +
' "' + path.join(workingDir, 'node') + '"' + m[4]
} else {
// XXX probably not a good idea to rewrite to the first npm in the
// path if it's a full path to npm. And if it's not a full path to
// npm, then the dirname will not work properly!
m = command.match(npmre)
if (m === null) {
return {...options}
}
let npmPath = whichOrUndefined('npm') || 'npm'
npmPath = path.join(path.dirname(npmPath), 'node_modules', 'npm', 'bin', 'npm-cli.js')
replace = m[1] + '"' + path.join(workingDir, 'node.cmd') + '"' +
' "' + npmPath + '"' +
m[3] + m[4]
newArgs[cmdi + 1] = command.replace(npmre, replace)
}
return {...options, args: newArgs, originalNode};
}
module.exports = mungeCmd

49
node_modules/spawn-wrap/lib/mungers/env.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
'use strict';
const isWindows = require("is-windows")
const path = require("path")
const homedir = require("../homedir")
const pathRe = isWindows() ? /^PATH=/i : /^PATH=/;
/**
* Updates the environment variables to intercept `node` commands and pass down options.
*
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
* @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
* @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
*/
function mungeEnv(workingDir, options) {
let pathEnv
const envPairs = options.envPairs.map((ep) => {
if (pathRe.test(ep)) {
// `PATH` env var: prefix its value with `workingDir`
// `5` corresponds to the length of `PATH=`
pathEnv = ep.substr(5)
const k = ep.substr(0, 5)
return k + workingDir + path.delimiter + pathEnv
} else {
// Return as-is
return ep;
}
});
if (pathEnv === undefined) {
envPairs.push((isWindows() ? 'Path=' : 'PATH=') + workingDir)
}
if (options.originalNode) {
const key = path.basename(workingDir).substr('.node-spawn-wrap-'.length)
envPairs.push('SW_ORIG_' + key + '=' + options.originalNode)
}
envPairs.push('SPAWN_WRAP_SHIM_ROOT=' + homedir)
if (process.env.SPAWN_WRAP_DEBUG === '1') {
envPairs.push('SPAWN_WRAP_DEBUG=1')
}
return {...options, envPairs};
}
module.exports = mungeEnv

79
node_modules/spawn-wrap/lib/mungers/node.js generated vendored Normal file
View File

@@ -0,0 +1,79 @@
'use strict';
const path = require('path')
const {debug} = require("../debug")
const {getExeBasename} = require("../exe-type")
const whichOrUndefined = require("../which-or-undefined")
/**
* Intercepts Node spawned processes.
*
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
* @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
* @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
*/
function mungeNode(workingDir, options) {
// Remember the original Node command to use it in the shim
const originalNode = options.file
const command = getExeBasename(options.file)
// make sure it has a main script.
// otherwise, just let it through.
let a = 0
let hasMain = false
let mainIndex = 1
for (a = 1; !hasMain && a < options.args.length; a++) {
switch (options.args[a]) {
case '-p':
case '-i':
case '--interactive':
case '--eval':
case '-e':
case '-pe':
hasMain = false
a = options.args.length
continue
case '-r':
case '--require':
a += 1
continue
default:
// TODO: Double-check this part
if (options.args[a].startsWith('-')) {
continue
} else {
hasMain = true
mainIndex = a
a = options.args.length
break
}
}
}
const newArgs = [...options.args];
let newFile = options.file;
if (hasMain) {
const replace = path.join(workingDir, command)
newArgs.splice(mainIndex, 0, replace)
}
// If the file is just something like 'node' then that'll
// resolve to our shim, and so to prevent double-shimming, we need
// to resolve that here first.
// This also handles the case where there's not a main file, like
// `node -e 'program'`, where we want to avoid the shim entirely.
if (options.file === command) {
const realNode = whichOrUndefined(options.file) || process.execPath
newArgs[0] = realNode
newFile = realNode
}
debug('mungeNode after', options.file, options.args)
return {...options, file: newFile, args: newArgs, originalNode};
}
module.exports = mungeNode

32
node_modules/spawn-wrap/lib/mungers/npm.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
'use strict';
const path = require("path")
const {debug} = require("../debug")
const whichOrUndefined = require("../which-or-undefined")
/**
* Intercepts npm spawned processes.
*
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
* @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
* @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
*/
function mungeNpm(workingDir, options) {
debug('munge npm')
// XXX weird effects of replacing a specific npm with a global one
const npmPath = whichOrUndefined('npm')
if (npmPath === undefined) {
return {...options};
}
const newArgs = [...options.args]
newArgs[0] = npmPath
const file = path.join(workingDir, 'node')
newArgs.unshift(file)
return {...options, file, args: newArgs}
}
module.exports = mungeNpm

61
node_modules/spawn-wrap/lib/mungers/sh.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
'use strict';
const isWindows = require("is-windows")
const path = require("path")
const {debug} = require("../debug")
const {isNode} = require("../exe-type")
const whichOrUndefined = require("../which-or-undefined")
/**
* Intercepts Node and npm processes spawned through a Linux shell.
*
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
* @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
* @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
*/
function mungeSh(workingDir, options) {
const cmdi = options.args.indexOf('-c')
if (cmdi === -1) {
return {...options} // no -c argument
}
let c = options.args[cmdi + 1]
const re = /^\s*((?:[^\= ]*\=[^\=\s]*)*[\s]*)([^\s]+|"[^"]+"|'[^']+')( .*)?$/
const match = c.match(re)
if (match === null) {
return {...options} // not a command invocation. weird but possible
}
let command = match[2]
// strip quotes off the command
const quote = command.charAt(0)
if ((quote === '"' || quote === '\'') && command.endsWith(quote)) {
command = command.slice(1, -1)
}
const exe = path.basename(command)
let newArgs = [...options.args];
// Remember the original Node command to use it in the shim
let originalNode;
const workingNode = path.join(workingDir, 'node')
if (isNode(exe)) {
originalNode = command
c = `${match[1]}${match[2]} "${workingNode}" ${match[3]}`
newArgs[cmdi + 1] = c
} else if (exe === 'npm' && !isWindows()) {
// XXX this will exhibit weird behavior when using /path/to/npm,
// if some other npm is first in the path.
const npmPath = whichOrUndefined('npm')
if (npmPath) {
c = c.replace(re, `$1 "${workingNode}" "${npmPath}" $3`)
newArgs[cmdi + 1] = c
debug('npm munge!', c)
}
}
return {...options, args: newArgs, originalNode};
}
module.exports = mungeSh

43
node_modules/spawn-wrap/lib/mungers/shebang.js generated vendored Normal file
View File

@@ -0,0 +1,43 @@
'use strict';
const fs = require("fs")
const path = require("path")
const {isNode} = require("../exe-type")
const whichOrUndefined = require("../which-or-undefined")
/**
* Intercepts processes spawned through a script with a shebang line.
*
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
* @param options {import("../munge").InternalSpawnOptions} Original internal spawn options.
* @return {import("../munge").InternalSpawnOptions} Updated internal spawn options.
*/
function mungeShebang(workingDir, options) {
const resolved = whichOrUndefined(options.file)
if (resolved === undefined) {
return {...options}
}
const shebang = fs.readFileSync(resolved, 'utf8')
const match = shebang.match(/^#!([^\r\n]+)/)
if (!match) {
return {...options} // not a shebang script, probably a binary
}
const shebangbin = match[1].split(' ')[0]
const maybeNode = path.basename(shebangbin)
if (!isNode(maybeNode)) {
return {...options} // not a node shebang, leave untouched
}
const originalNode = shebangbin
const file = shebangbin
const args = [shebangbin, path.join(workingDir, maybeNode)]
.concat(resolved)
.concat(match[1].split(' ').slice(1))
.concat(options.args.slice(1))
return {...options, file, args, originalNode};
}
module.exports = mungeShebang