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

43
node_modules/spawn-wrap/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,43 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [2.0.0](https://github.com/istanbuljs/spawn-wrap/compare/v1.4.3...v2.0.0) (2019-12-20)
### ⚠ BREAKING CHANGES
* no longer feature detect spawnSync, present since Node 0.11.
* Drop support for iojs (#84)
* explicitly drops support for Node 6
### Bug Fixes
* Avoid path concatenation ([5626f2a](https://github.com/istanbuljs/spawn-wrap/commit/5626f2a))
* Handle whitespace in homedir paths ([#98](https://github.com/istanbuljs/spawn-wrap/issues/98)) ([f002ecc](https://github.com/istanbuljs/spawn-wrap/commit/f002ecc)), closes [istanbuljs/nyc#784](https://github.com/istanbuljs/nyc/issues/784)
* Make munge functions pure ([#99](https://github.com/istanbuljs/spawn-wrap/issues/99)) ([5c1293e](https://github.com/istanbuljs/spawn-wrap/commit/5c1293e))
* Remove '/.node-spawn-wrap-' from lib/homedir.js export ([5bcb288](https://github.com/istanbuljs/spawn-wrap/commit/5bcb288))
* Remove legacy `ChildProcess` resolution ([#85](https://github.com/istanbuljs/spawn-wrap/issues/85)) ([da05012](https://github.com/istanbuljs/spawn-wrap/commit/da05012))
* Remove legacy `spawnSync` feature detection ([#87](https://github.com/istanbuljs/spawn-wrap/issues/87)) ([78777aa](https://github.com/istanbuljs/spawn-wrap/commit/78777aa))
* Switch from mkdirp to make-dir ([#94](https://github.com/istanbuljs/spawn-wrap/issues/94)) ([b8dace1](https://github.com/istanbuljs/spawn-wrap/commit/b8dace1))
* Use `is-windows` package for detection ([#88](https://github.com/istanbuljs/spawn-wrap/issues/88)) ([c3e6239](https://github.com/istanbuljs/spawn-wrap/commit/c3e6239)), closes [istanbuljs/spawn-wrap#61](https://github.com/istanbuljs/spawn-wrap/issues/61)
* Use safe path functions in `setup` ([#86](https://github.com/istanbuljs/spawn-wrap/issues/86)) ([4103f72](https://github.com/istanbuljs/spawn-wrap/commit/4103f72))
### Features
* Drop support for iojs ([#84](https://github.com/istanbuljs/spawn-wrap/issues/84)) ([6e86337](https://github.com/istanbuljs/spawn-wrap/commit/6e86337))
* require Node 8 ([#80](https://github.com/istanbuljs/spawn-wrap/issues/80)) ([19543e7](https://github.com/istanbuljs/spawn-wrap/commit/19543e7))
## [2.0.0-beta.0](https://github.com/istanbuljs/spawn-wrap/compare/v1.4.3...v2.0.0-beta.0) (2019-10-07)
See 2.0.0 for notes.
### [1.4.3](https://github.com/isaacs/spawn-wrap/compare/v1.4.2...v1.4.3) (2019-08-23)
### Bug Fixes
* **win32:** handle cases where "node" is quoted ([#102](https://github.com/isaacs/spawn-wrap/issues/102)) ([aac8730](https://github.com/isaacs/spawn-wrap/commit/aac8730))

15
node_modules/spawn-wrap/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,15 @@
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

111
node_modules/spawn-wrap/README.md generated vendored Normal file
View File

@@ -0,0 +1,111 @@
# spawn-wrap
Wrap all spawned Node.js child processes by adding environs and
arguments ahead of the main JavaScript file argument.
Any child processes launched by that child process will also be
wrapped in a similar fashion.
This is a bit of a brutal hack, designed primarily to support code
coverage reporting in cases where tests or the system under test are
loaded via child processes rather than via `require()`.
It can also be handy if you want to run your own mock executable
instead of some other thing when child procs call into it.
[![Build Status](https://travis-ci.org/istanbuljs/spawn-wrap.svg)](https://travis-ci.org/istanbuljs/spawn-wrap)
## USAGE
```javascript
var wrap = require('spawn-wrap')
// wrap(wrapperArgs, environs)
var unwrap = wrap(['/path/to/my/main.js', 'foo=bar'], { FOO: 1 })
// later to undo the wrapping, you can call the returned function
unwrap()
```
In this example, the `/path/to/my/main.js` file will be used as the
"main" module, whenever any Node or io.js child process is started,
whether via a call to `spawn` or `exec`, whether node is invoked
directly as the command or as the result of a shebang `#!` lookup.
In `/path/to/my/main.js`, you can do whatever instrumentation or
environment manipulation you like. When you're done, and ready to run
the "real" main.js file (ie, the one that was spawned in the first
place), you can do this:
```javascript
// /path/to/my/main.js
// process.argv[1] === 'foo=bar'
// and process.env.FOO === '1'
// my wrapping manipulations
setupInstrumentationOrCoverageOrWhatever()
process.on('exit', function (code) {
storeCoverageInfoSynchronously()
})
// now run the instrumented and covered or whatever codes
require('spawn-wrap').runMain()
```
## ENVIRONMENT VARIABLES
Spawn-wrap responds to two environment variables, both of which are
preserved through child processes.
`SPAWN_WRAP_DEBUG=1` in the environment will make this module dump a
lot of information to stderr.
`SPAWN_WRAP_SHIM_ROOT` can be set to a path on the filesystem where
the shim files are written in a `.node-spawn-wrap-<id>` folder. By
default this is done in `$HOME`, but in some environments you may wish
to point it at some other root. (For example, if `$HOME` is mounted
as read-only in a virtual machine or container.)
## CONTRACTS and CAVEATS
The initial wrap call uses synchronous I/O. Probably you should not
be using this script in any production environments anyway.
Also, this will slow down child process execution by a lot, since
we're adding a few layers of indirection.
The contract which this library aims to uphold is:
* Wrapped processes behave identical to their unwrapped counterparts
for all intents and purposes. That means that the wrapper script
propagates all signals and exit codes.
* If you send a signal to the wrapper, the child gets the signal.
* If the child exits with a numeric status code, then the wrapper
exits with that code.
* If the child dies with a signal, then the wrapper dies with the
same signal.
* If you execute any Node child process, in any of the various ways
that such a thing can be done, it will be wrapped.
* Children of wrapped processes are also wrapped.
(Much of this made possible by
[foreground-child](http://npm.im/foreground-child).)
There are a few ways situations in which this contract cannot be
adhered to, despite best efforts:
1. In order to handle cases where `node` is invoked in a shell script,
the `PATH` environment variable is modified such that the the shim
will be run before the "real" node. However, since Windows does
not allow executing shebang scripts like regular programs, a
`node.cmd` file is required.
2. Signal propagation through `dash` doesn't always work. So, if you
use `child_process.exec()` on systems where `/bin/sh` is actually
`dash`, then the process may exit with a status code > 128 rather
than indicating that it received a signal.
3. `cmd.exe` is even stranger with how it propagates and interprets
unix signals. If you want your programs to be portable, then
probably you wanna not rely on signals too much.
4. It *is* possible to escape the wrapping, if you spawn a bash
script, and that script modifies the `PATH`, and then calls a
specific `node` binary explicitly.

165
node_modules/spawn-wrap/index.js generated vendored Normal file
View File

@@ -0,0 +1,165 @@
'use strict';
module.exports = wrap
wrap.runMain = runMain
const Module = require('module')
const fs = require('fs')
const cp = require('child_process')
const ChildProcess = cp.ChildProcess
const assert = require('assert')
const crypto = require('crypto')
const IS_WINDOWS = require('is-windows')()
const makeDir = require('make-dir')
const rimraf = require('rimraf')
const path = require('path')
const signalExit = require('signal-exit')
const {IS_DEBUG, debug} = require("./lib/debug")
const munge = require("./lib/munge")
const homedir = require("./lib/homedir")
const shebang = process.platform === 'os390' ?
'#!/bin/env ' : '#!'
const shim = shebang + process.execPath + '\n' +
fs.readFileSync(path.join(__dirname, 'shim.js'))
function wrap(argv, env, workingDir) {
const spawnSyncBinding = process.binding('spawn_sync')
// if we're passed in the working dir, then it means that setup
// was already done, so no need.
const doSetup = !workingDir
if (doSetup) {
workingDir = setup(argv, env)
}
const spawn = ChildProcess.prototype.spawn
const spawnSync = spawnSyncBinding.spawn
function unwrap() {
if (doSetup && !IS_DEBUG) {
rimraf.sync(workingDir)
}
ChildProcess.prototype.spawn = spawn
spawnSyncBinding.spawn = spawnSync
}
spawnSyncBinding.spawn = wrappedSpawnFunction(spawnSync, workingDir)
ChildProcess.prototype.spawn = wrappedSpawnFunction(spawn, workingDir)
return unwrap
}
function wrappedSpawnFunction (fn, workingDir) {
return wrappedSpawn
function wrappedSpawn (options) {
const mungedOptions = munge(workingDir, options)
debug('WRAPPED', mungedOptions)
return fn.call(this, mungedOptions)
}
}
function setup(argv, env) {
if (argv && typeof argv === 'object' && !env && !Array.isArray(argv)) {
env = argv
argv = []
}
if (!argv && !env) {
throw new Error('at least one of "argv" and "env" required')
}
if (argv) {
assert(Array.isArray(argv), 'argv must be an array')
} else {
argv = []
}
if (env) {
assert(typeof env === 'object', 'env must be an object')
} else {
env = {}
}
debug('setup argv=%j env=%j', argv, env)
// For stuff like --use_strict or --harmony, we need to inject
// the argument *before* the wrap-main.
const execArgv = []
for (let i = 0; i < argv.length; i++) {
if (argv[i].startsWith('-')) {
execArgv.push(argv[i])
if (argv[i] === '-r' || argv[i] === '--require') {
execArgv.push(argv[++i])
}
} else {
break
}
}
if (execArgv.length) {
if (execArgv.length === argv.length) {
argv.length = 0
} else {
argv = argv.slice(execArgv.length)
}
}
const key = process.pid + '-' + crypto.randomBytes(6).toString('hex')
let workingDir = path.resolve(homedir, `.node-spawn-wrap-${key}`)
const settings = JSON.stringify({
module: __filename,
deps: {
foregroundChild: require.resolve('foreground-child'),
signalExit: require.resolve('signal-exit'),
debug: require.resolve('./lib/debug')
},
isWindows: IS_WINDOWS,
key,
workingDir,
argv,
execArgv,
env,
root: process.pid
}, null, 2) + '\n'
if (!IS_DEBUG) {
signalExit(() => rimraf.sync(workingDir))
}
makeDir.sync(workingDir)
workingDir = fs.realpathSync(workingDir)
if (IS_WINDOWS) {
const cmdShim =
'@echo off\r\n' +
'SETLOCAL\r\n' +
'CALL :find_dp0\r\n' +
'SET PATHEXT=%PATHEXT:;.JS;=;%\r\n' +
'"' + process.execPath + '" "%dp0%node" %*\r\n' +
'EXIT /b %errorlevel%\r\n'+
':find_dp0\r\n' +
'SET dp0=%~dp0\r\n' +
'EXIT /b\r\n'
fs.writeFileSync(path.join(workingDir, 'node.cmd'), cmdShim)
fs.chmodSync(path.join(workingDir, 'node.cmd'), '0755')
}
fs.writeFileSync(path.join(workingDir, 'node'), shim)
fs.chmodSync(path.join(workingDir, 'node'), '0755')
const cmdname = path.basename(process.execPath).replace(/\.exe$/i, '')
if (cmdname !== 'node') {
fs.writeFileSync(path.join(workingDir, cmdname), shim)
fs.chmodSync(path.join(workingDir, cmdname), '0755')
}
fs.writeFileSync(path.join(workingDir, 'settings.json'), settings)
return workingDir
}
function runMain () {
process.argv.splice(1, 1)
process.argv[1] = path.resolve(process.argv[1])
delete require.cache[process.argv[1]]
Module.runMain()
}

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

@@ -0,0 +1,32 @@
'use strict';
const util = require('util');
const fs = require('fs')
/**
* Boolean indicating if debug mode is enabled.
*
* @type {boolean}
*/
const IS_DEBUG = process.env.SPAWN_WRAP_DEBUG === '1'
/**
* If debug is enabled, write message to stderr.
*
* If debug is disabled, no message is written.
*/
function debug(...args) {
if (!IS_DEBUG) {
return;
}
const prefix = `SW ${process.pid}: `
const data = util.format(...args).trim()
const message = data.split('\n').map(line => `${prefix}${line}\n`).join('')
fs.writeSync(2, message)
}
module.exports = {
IS_DEBUG,
debug,
}

53
node_modules/spawn-wrap/lib/exe-type.js generated vendored Normal file
View File

@@ -0,0 +1,53 @@
'use strict';
const isWindows = require("is-windows")
const path = require("path")
function isCmd(file) {
const comspec = path.basename(process.env.comspec || '').replace(/\.exe$/i, '')
return isWindows() && (file === comspec || /^cmd(?:\.exe)?$/i.test(file))
}
function isNode(file) {
const cmdname = path.basename(process.execPath).replace(/\.exe$/i, '')
return file === 'node' || cmdname === file
}
function isNpm(file) {
// XXX is this even possible/necessary?
// wouldn't npm just be detected as a node shebang?
return file === 'npm' && !isWindows()
}
function isSh(file) {
return ['dash', 'sh', 'bash', 'zsh'].includes(file)
}
/**
* Returns the basename of the executable.
*
* On Windows, strips the `.exe` extension (if any) and normalizes the name to
* lowercase.
*
* @param exePath {string} Path of the executable as passed to spawned processes:
* either command or a path to a file.
* @return {string} Basename of the executable.
*/
function getExeBasename(exePath) {
const baseName = path.basename(exePath);
if (isWindows()) {
// Stripping `.exe` seems to be enough for our usage. We may eventually
// want to handle all executable extensions (such as `.bat` or `.cmd`).
return baseName.replace(/\.exe$/i, "").toLowerCase();
} else {
return baseName;
}
}
module.exports = {
isCmd,
isNode,
isNpm,
isSh,
getExeBasename,
}

5
node_modules/spawn-wrap/lib/homedir.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
'use strict'
const os = require('os')
module.exports = process.env.SPAWN_WRAP_SHIM_ROOT || os.homedir()

84
node_modules/spawn-wrap/lib/munge.js generated vendored Normal file
View File

@@ -0,0 +1,84 @@
'use strict';
const {isCmd, isNode, isNpm, isSh, getExeBasename} = require("./exe-type")
const mungeCmd = require("./mungers/cmd")
const mungeEnv = require("./mungers/env")
const mungeNode = require("./mungers/node")
const mungeNpm = require("./mungers/npm")
const mungeSh = require("./mungers/sh")
const mungeShebang = require("./mungers/shebang")
/**
* @typedef {object} InternalSpawnOptions Options for the internal spawn functions
* `childProcess.ChildProcess.prototype.spawn` and `process.binding('spawn_sync').spawn`.
* These are the options mapped by the `munge` function to intercept spawned processes and
* handle the wrapping logic.
*
* @property {string} file File to execute: either an absolute system-dependent path or a
* command name.
* @property {string[]} args Command line arguments passed to the spawn process, including argv0.
* @property {string | undefined} cwd Optional path to the current working directory passed to the
* spawned process. Default: `process.cwd()`
* @property {boolean} windowsHide Boolean controlling if the process should be spawned as
* hidden (no GUI) on Windows.
* @property {boolean} windowsVerbatimArguments Boolean controlling if Node should preprocess
* the CLI arguments on Windows.
* @property {boolean} detached Boolean controlling if the child process should keep its parent
* alive or not.
* @property {string[]} envPairs Array of serialized environment variable key/value pairs. The
* variables serialized as `key + "=" + value`.
* @property {import("child_process").StdioOptions} stdio Stdio options, with the same semantics
* as the `stdio` parameter from the public API.
* @property {number | undefined} uid User id for the spawn process, same as the `uid` parameter
* from the public API.
* @property {number | undefined} gid Group id for the spawn process, same as the `gid` parameter
* from the public API.
*
* @property {string | undefined} originalNode Custom property only used by `spawn-wrap`. It is
* used to remember the original Node executable that was intended to be spawned by the user.
*/
/**
* Returns updated internal spawn options to redirect the process through the shim and wrapper.
*
* This works on the options passed to `childProcess.ChildProcess.prototype.spawn` and
* `process.binding('spawn_sync').spawn`.
*
* This function works by trying to identify the spawn process and map the options accordingly.
* `spawn-wrap` recognizes most shells, Windows `cmd.exe`, Node and npm invocations; when spawn
* either directly or through a script with a shebang line.
* It also unconditionally updates the environment variables so bare `node` commands execute
* the shim script instead of Node's binary.
*
* @param workingDir {string} Absolute system-dependent path to the directory containing the shim files.
* @param options {InternalSpawnOptions} Original internal spawn options.
* @return {InternalSpawnOptions} Updated internal spawn options.
*/
function munge(workingDir, options) {
const basename = getExeBasename(options.file);
// XXX: dry this
if (isSh(basename)) {
options = mungeSh(workingDir, options)
} else if (isCmd(basename)) {
options = mungeCmd(workingDir, options)
} else if (isNode(basename)) {
options = mungeNode(workingDir, options)
} else if (isNpm(basename)) {
// XXX unnecessary? on non-windows, npm is just another shebang
options = mungeNpm(workingDir, options)
} else {
options = mungeShebang(workingDir, options)
}
// now the options are munged into shape.
// whether we changed something or not, we still update the PATH
// so that if a script somewhere calls `node foo`, it gets our
// wrapper instead.
options = mungeEnv(workingDir, options)
return options
}
module.exports = munge

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

12
node_modules/spawn-wrap/lib/which-or-undefined.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
'use strict';
const which = require("which")
function whichOrUndefined(executable) {
try {
return which.sync(executable)
} catch (error) {
}
}
module.exports = whichOrUndefined

View File

@@ -0,0 +1,66 @@
/// <reference types="node"/>
import * as fs from 'fs';
declare namespace makeDir {
interface Options {
/**
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
@default 0o777
*/
readonly mode?: number;
/**
Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
@default require('fs')
*/
readonly fs?: typeof fs;
}
}
declare const makeDir: {
/**
Make a directory and its parents if needed - Think `mkdir -p`.
@param path - Directory to create.
@returns The path to the created directory.
@example
```
import makeDir = require('make-dir');
(async () => {
const path = await makeDir('unicorn/rainbow/cake');
console.log(path);
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
// Multiple directories:
const paths = await Promise.all([
makeDir('unicorn/rainbow'),
makeDir('foo/bar')
]);
console.log(paths);
// [
// '/Users/sindresorhus/fun/unicorn/rainbow',
// '/Users/sindresorhus/fun/foo/bar'
// ]
})();
```
*/
(path: string, options?: makeDir.Options): Promise<string>;
/**
Synchronously make a directory and its parents if needed - Think `mkdir -p`.
@param path - Directory to create.
@returns The path to the created directory.
*/
sync(path: string, options?: makeDir.Options): string;
};
export = makeDir;

156
node_modules/spawn-wrap/node_modules/make-dir/index.js generated vendored Normal file
View File

@@ -0,0 +1,156 @@
'use strict';
const fs = require('fs');
const path = require('path');
const {promisify} = require('util');
const semver = require('semver');
const useNativeRecursiveOption = semver.satisfies(process.version, '>=10.12.0');
// https://github.com/nodejs/node/issues/8987
// https://github.com/libuv/libuv/pull/1088
const checkPath = pth => {
if (process.platform === 'win32') {
const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ''));
if (pathHasInvalidWinCharacters) {
const error = new Error(`Path contains invalid characters: ${pth}`);
error.code = 'EINVAL';
throw error;
}
}
};
const processOptions = options => {
// https://github.com/sindresorhus/make-dir/issues/18
const defaults = {
mode: 0o777,
fs
};
return {
...defaults,
...options
};
};
const permissionError = pth => {
// This replicates the exception of `fs.mkdir` with native the
// `recusive` option when run on an invalid drive under Windows.
const error = new Error(`operation not permitted, mkdir '${pth}'`);
error.code = 'EPERM';
error.errno = -4048;
error.path = pth;
error.syscall = 'mkdir';
return error;
};
const makeDir = async (input, options) => {
checkPath(input);
options = processOptions(options);
const mkdir = promisify(options.fs.mkdir);
const stat = promisify(options.fs.stat);
if (useNativeRecursiveOption && options.fs.mkdir === fs.mkdir) {
const pth = path.resolve(input);
await mkdir(pth, {
mode: options.mode,
recursive: true
});
return pth;
}
const make = async pth => {
try {
await mkdir(pth, options.mode);
return pth;
} catch (error) {
if (error.code === 'EPERM') {
throw error;
}
if (error.code === 'ENOENT') {
if (path.dirname(pth) === pth) {
throw permissionError(pth);
}
if (error.message.includes('null bytes')) {
throw error;
}
await make(path.dirname(pth));
return make(pth);
}
try {
const stats = await stat(pth);
if (!stats.isDirectory()) {
throw new Error('The path is not a directory');
}
} catch (_) {
throw error;
}
return pth;
}
};
return make(path.resolve(input));
};
module.exports = makeDir;
module.exports.sync = (input, options) => {
checkPath(input);
options = processOptions(options);
if (useNativeRecursiveOption && options.fs.mkdirSync === fs.mkdirSync) {
const pth = path.resolve(input);
fs.mkdirSync(pth, {
mode: options.mode,
recursive: true
});
return pth;
}
const make = pth => {
try {
options.fs.mkdirSync(pth, options.mode);
} catch (error) {
if (error.code === 'EPERM') {
throw error;
}
if (error.code === 'ENOENT') {
if (path.dirname(pth) === pth) {
throw permissionError(pth);
}
if (error.message.includes('null bytes')) {
throw error;
}
make(path.dirname(pth));
return make(pth);
}
try {
if (!options.fs.statSync(pth).isDirectory()) {
throw new Error('The path is not a directory');
}
} catch (_) {
throw error;
}
}
return pth;
};
return make(path.resolve(input));
};

View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,59 @@
{
"name": "make-dir",
"version": "3.1.0",
"description": "Make a directory and its parents if needed - Think `mkdir -p`",
"license": "MIT",
"repository": "sindresorhus/make-dir",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && nyc ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"mkdir",
"mkdirp",
"make",
"directories",
"dir",
"dirs",
"folders",
"directory",
"folder",
"path",
"parent",
"parents",
"intermediate",
"recursively",
"recursive",
"create",
"fs",
"filesystem",
"file-system"
],
"dependencies": {
"semver": "^6.0.0"
},
"devDependencies": {
"@types/graceful-fs": "^4.1.3",
"@types/node": "^13.7.1",
"ava": "^1.4.0",
"codecov": "^3.2.0",
"graceful-fs": "^4.1.15",
"nyc": "^15.0.0",
"path-type": "^4.0.0",
"tempy": "^0.2.1",
"tsd": "^0.11.0",
"xo": "^0.25.4"
}
}

125
node_modules/spawn-wrap/node_modules/make-dir/readme.md generated vendored Normal file
View File

@@ -0,0 +1,125 @@
# make-dir [![Build Status](https://travis-ci.org/sindresorhus/make-dir.svg?branch=master)](https://travis-ci.org/sindresorhus/make-dir) [![codecov](https://codecov.io/gh/sindresorhus/make-dir/branch/master/graph/badge.svg)](https://codecov.io/gh/sindresorhus/make-dir)
> Make a directory and its parents if needed - Think `mkdir -p`
## Advantages over [`mkdirp`](https://github.com/substack/node-mkdirp)
- Promise API *(Async/await ready!)*
- Fixes many `mkdirp` issues: [#96](https://github.com/substack/node-mkdirp/pull/96) [#70](https://github.com/substack/node-mkdirp/issues/70) [#66](https://github.com/substack/node-mkdirp/issues/66)
- 100% test coverage
- CI-tested on macOS, Linux, and Windows
- Actively maintained
- Doesn't bundle a CLI
- Uses the native `fs.mkdir/mkdirSync` [`recursive` option](https://nodejs.org/dist/latest/docs/api/fs.html#fs_fs_mkdir_path_options_callback) in Node.js >=10.12.0 unless [overridden](#fs)
## Install
```
$ npm install make-dir
```
## Usage
```
$ pwd
/Users/sindresorhus/fun
$ tree
.
```
```js
const makeDir = require('make-dir');
(async () => {
const path = await makeDir('unicorn/rainbow/cake');
console.log(path);
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
})();
```
```
$ tree
.
└── unicorn
└── rainbow
└── cake
```
Multiple directories:
```js
const makeDir = require('make-dir');
(async () => {
const paths = await Promise.all([
makeDir('unicorn/rainbow'),
makeDir('foo/bar')
]);
console.log(paths);
/*
[
'/Users/sindresorhus/fun/unicorn/rainbow',
'/Users/sindresorhus/fun/foo/bar'
]
*/
})();
```
## API
### makeDir(path, options?)
Returns a `Promise` for the path to the created directory.
### makeDir.sync(path, options?)
Returns the path to the created directory.
#### path
Type: `string`
Directory to create.
#### options
Type: `object`
##### mode
Type: `integer`\
Default: `0o777`
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
##### fs
Type: `object`\
Default: `require('fs')`
Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
## Related
- [make-dir-cli](https://github.com/sindresorhus/make-dir-cli) - CLI for this module
- [del](https://github.com/sindresorhus/del) - Delete files and directories
- [globby](https://github.com/sindresorhus/globby) - User-friendly glob matching
- [cpy](https://github.com/sindresorhus/cpy) - Copy files
- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line
- [move-file](https://github.com/sindresorhus/move-file) - Move a file
---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-make-dir?utm_source=npm-make-dir&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>

45
node_modules/spawn-wrap/package.json generated vendored Normal file
View File

@@ -0,0 +1,45 @@
{
"name": "spawn-wrap",
"version": "2.0.0",
"description": "Wrap all spawned Node.js child processes by adding environs and arguments ahead of the main JavaScript file argument.",
"main": "index.js",
"engines": {
"node": ">=8"
},
"dependencies": {
"foreground-child": "^2.0.0",
"is-windows": "^1.0.2",
"make-dir": "^3.0.0",
"rimraf": "^3.0.0",
"signal-exit": "^3.0.2",
"which": "^2.0.1"
},
"scripts": {
"test": "tap",
"release": "standard-version",
"clean": "rm -rf ~/.node-spawn-wrap-*"
},
"repository": {
"type": "git",
"url": "git+https://github.com/istanbuljs/spawn-wrap.git"
},
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"license": "ISC",
"bugs": {
"url": "https://github.com/istanbuljs/spawn-wrap/issues"
},
"homepage": "https://github.com/istanbuljs/spawn-wrap#readme",
"devDependencies": {
"standard-version": "^7.1.0",
"tap": "^14.10.5"
},
"files": [
"lib/",
"index.js",
"shim.js"
],
"tap": {
"coverage": false,
"timeout": 240
}
}

156
node_modules/spawn-wrap/shim.js generated vendored Normal file
View File

@@ -0,0 +1,156 @@
'use strict'
// This module should *only* be loaded as a main script
// by child processes wrapped by spawn-wrap. It sets up
// argv to include the injected argv (including the user's
// wrapper script) and any environment variables specified.
//
// If any argv were passed in (ie, if it's used to force
// a wrapper script, and not just ensure that an env is kept
// around through all the child procs), then we also set up
// a require('spawn-wrap').runMain() function that will strip
// off the injected arguments and run the main file.
// wrap in iife for babylon to handle module-level return
;(function () {
if (module !== require.main) {
throw new Error('spawn-wrap: cli wrapper invoked as non-main script')
}
const Module = require('module')
const path = require('path')
const settings = require('./settings.json')
const {debug} = require(settings.deps.debug)
debug('shim', [process.argv[0]].concat(process.execArgv, process.argv.slice(1)))
const foregroundChild = require(settings.deps.foregroundChild)
const IS_WINDOWS = settings.isWindows
const argv = settings.argv
const nargs = argv.length
const env = settings.env
const key = settings.key
const node = process.env['SW_ORIG_' + key] || process.execPath
Object.assign(process.env, env)
const needExecArgv = settings.execArgv || []
// If the user added their OWN wrapper pre-load script, then
// this will pop that off of the argv, and load the "real" main
function runMain () {
debug('runMain pre', process.argv)
process.argv.splice(1, nargs)
process.argv[1] = path.resolve(process.argv[1])
delete require.cache[process.argv[1]]
debug('runMain post', process.argv)
Module.runMain()
debug('runMain after')
}
// Argv coming in looks like:
// bin shim execArgv main argv
//
// Turn it into:
// bin settings.execArgv execArgv settings.argv main argv
//
// If we don't have a main script, then just run with the necessary
// execArgv
let hasMain = false
for (let a = 2; !hasMain && a < process.argv.length; a++) {
switch (process.argv[a]) {
case '-i':
case '--interactive':
case '--eval':
case '-e':
case '-p':
case '-pe':
hasMain = false
a = process.argv.length
continue
case '-r':
case '--require':
a += 1
continue
default:
// TODO: Double-check what's going on
if (process.argv[a].startsWith('-')) {
continue
} else {
hasMain = a
a = process.argv.length
break
}
}
}
debug('after argv parse hasMain=%j', hasMain)
if (hasMain > 2) {
// if the main file is above #2, then it means that there
// was a --exec_arg *before* it. This means that we need
// to slice everything from 2 to hasMain, and pass that
// directly to node. This also splices out the user-supplied
// execArgv from the argv.
const addExecArgv = process.argv.splice(2, hasMain - 2)
needExecArgv.push(...addExecArgv)
}
if (!hasMain) {
// we got loaded by mistake for a `node -pe script` or something.
const args = process.execArgv.concat(needExecArgv, process.argv.slice(2))
debug('no main file!', args)
foregroundChild(node, args)
return
}
// If there are execArgv, and they're not the same as how this module
// was executed, then we need to inject those. This is for stuff like
// --harmony or --use_strict that needs to be *before* the main
// module.
if (needExecArgv.length) {
const pexec = process.execArgv
if (JSON.stringify(pexec) !== JSON.stringify(needExecArgv)) {
debug('need execArgv for this', pexec, '=>', needExecArgv)
const sargs = pexec.concat(needExecArgv).concat(process.argv.slice(1))
foregroundChild(node, sargs)
return
}
}
// At this point, we've verified that we got the correct execArgv,
// and that we have a main file, and that the main file is sitting at
// argv[2]. Splice this shim off the list so it looks like the main.
process.argv.splice(1, 1, ...argv)
// Unwrap the PATH environment var so that we're not mucking
// with the environment. It'll get re-added if they spawn anything
if (IS_WINDOWS) {
for (const i in process.env) {
if (/^path$/i.test(i)) {
process.env[i] = process.env[i].replace(__dirname + ';', '')
}
}
} else {
process.env.PATH = process.env.PATH.replace(__dirname + ':', '')
}
const spawnWrap = require(settings.module)
if (nargs) {
spawnWrap.runMain = function (original) {
return function () {
spawnWrap.runMain = original
runMain()
}
}(spawnWrap.runMain)
}
spawnWrap(argv, env, __dirname)
debug('shim runMain', process.argv)
delete require.cache[process.argv[1]]
Module.runMain()
// end iife wrapper for babylon
})()