diff options
Diffstat (limited to 'node_modules/spawn-wrap')
-rw-r--r-- | node_modules/spawn-wrap/LICENSE | 15 | ||||
-rw-r--r-- | node_modules/spawn-wrap/README.md | 111 | ||||
-rw-r--r-- | node_modules/spawn-wrap/index.js | 447 | ||||
-rw-r--r-- | node_modules/spawn-wrap/lib/is-windows.js | 5 | ||||
l--------- | node_modules/spawn-wrap/node_modules/.bin/mkdirp | 1 | ||||
l--------- | node_modules/spawn-wrap/node_modules/.bin/rimraf | 1 | ||||
l--------- | node_modules/spawn-wrap/node_modules/.bin/which | 1 | ||||
-rw-r--r-- | node_modules/spawn-wrap/package.json | 39 | ||||
-rw-r--r-- | node_modules/spawn-wrap/shim.js | 180 |
9 files changed, 0 insertions, 800 deletions
diff --git a/node_modules/spawn-wrap/LICENSE b/node_modules/spawn-wrap/LICENSE deleted file mode 100644 index 19129e315..000000000 --- a/node_modules/spawn-wrap/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -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. diff --git a/node_modules/spawn-wrap/README.md b/node_modules/spawn-wrap/README.md deleted file mode 100644 index 428df37e5..000000000 --- a/node_modules/spawn-wrap/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# 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. - -[](https://travis-ci.org/tapjs/spawn-wrap) [](https://ci.appveyor.com/project/isaacs/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. diff --git a/node_modules/spawn-wrap/index.js b/node_modules/spawn-wrap/index.js deleted file mode 100644 index 30a2d32e7..000000000 --- a/node_modules/spawn-wrap/index.js +++ /dev/null @@ -1,447 +0,0 @@ -module.exports = wrap -wrap.runMain = runMain - -var Module = require('module') -var fs = require('fs') -var cp = require('child_process') -var ChildProcess = cp.ChildProcess -var assert = require('assert') -var crypto = require('crypto') -var mkdirp = require('mkdirp') -var rimraf = require('rimraf') -var path = require('path') -var signalExit = require('signal-exit') -var home = process.env.SPAWN_WRAP_SHIM_ROOT || require('os-homedir')() -var homedir = home + '/.node-spawn-wrap-' -var which = require('which') -var util = require('util') - -var doDebug = process.env.SPAWN_WRAP_DEBUG === '1' -var debug = doDebug ? function () { - var message = util.format.apply(util, arguments).trim() - var pref = 'SW ' + process.pid + ': ' - message = pref + message.split('\n').join('\n' + pref) - process.stderr.write(message + '\n') -} : function () {} - -var shebang = process.platform === 'os390' ? - '#!/bin/env ' : '#!' - -var shim = shebang + process.execPath + '\n' + - fs.readFileSync(__dirname + '/shim.js') - -var isWindows = require('./lib/is-windows')() - -var pathRe = /^PATH=/ -if (isWindows) pathRe = /^PATH=/i - -var colon = isWindows ? ';' : ':' - -function wrap (argv, env, workingDir) { - if (!ChildProcess) { - var child = cp.spawn(process.execPath, []) - ChildProcess = child.constructor - if (process.platform === 'os390') - child.kill('SIGABRT') - else - child.kill('SIGKILL') - } - - // spawn_sync available since Node v0.11 - var spawnSyncBinding, spawnSync - try { - spawnSyncBinding = process.binding('spawn_sync') - } catch (e) {} - - // if we're passed in the working dir, then it means that setup - // was already done, so no need. - var doSetup = !workingDir - if (doSetup) { - workingDir = setup(argv, env) - } - var spawn = ChildProcess.prototype.spawn - if (spawnSyncBinding) { - spawnSync = spawnSyncBinding.spawn - } - - function unwrap () { - if (doSetup && !doDebug) { - rimraf.sync(workingDir) - } - ChildProcess.prototype.spawn = spawn - if (spawnSyncBinding) { - spawnSyncBinding.spawn = spawnSync - } - } - - if (spawnSyncBinding) { - spawnSyncBinding.spawn = wrappedSpawnFunction(spawnSync, workingDir) - } - ChildProcess.prototype.spawn = wrappedSpawnFunction(spawn, workingDir) - - return unwrap -} - -function wrappedSpawnFunction (fn, workingDir) { - return wrappedSpawn - - function wrappedSpawn (options) { - munge(workingDir, options) - debug('WRAPPED', options) - return fn.call(this, options) - } -} - -function isSh (file) { - return file === 'dash' || - file === 'sh' || - file === 'bash' || - file === 'zsh' -} - -function mungeSh (workingDir, options) { - var cmdi = options.args.indexOf('-c') - if (cmdi === -1) - return // no -c argument - - var c = options.args[cmdi + 1] - var re = /^\s*((?:[^\= ]*\=[^\=\s]*)*[\s]*)([^\s]+|"[^"]+"|'[^']+')( .*)?$/ - var match = c.match(re) - if (!match) - return // not a command invocation. weird but possible - - var command = match[2] - // strip quotes off the command - var quote = command.charAt(0) - if ((quote === '"' || quote === '\'') && quote === command.slice(-1)) { - command = command.slice(1, -1) - } - var exe = path.basename(command) - - if (isNode(exe)) { - options.originalNode = command - c = match[1] + match[2] + ' "' + workingDir + '/node" ' + match[3] - options.args[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. - var npmPath = whichOrUndefined('npm') - - if (npmPath) { - c = c.replace(re, '$1 "' + workingDir + '/node" "' + npmPath + '" $3') - options.args[cmdi + 1] = c - debug('npm munge!', c) - } - } -} - -function isCmd (file) { - var comspec = path.basename(process.env.comspec || '').replace(/\.exe$/i, '') - return isWindows && (file === comspec || /^cmd(\.exe|\.EXE)?$/.test(file)) -} - -function mungeCmd (workingDir, options) { - var cmdi = options.args.indexOf('/c') - if (cmdi === -1) - return - - var re = /^\s*("*)([^"]*?\b(?:node|iojs)(?:\.exe|\.EXE)?)("*)( .*)?$/ - var npmre = /^\s*("*)([^"]*?\b(?:npm))("*)( |$)/ - var path_ = require('path') - if (path_.win32) - path_ = path_.win32 - - var command = options.args[cmdi + 1] - if (!command) - return - - var m = command.match(re) - var replace - if (m) { - options.originalNode = m[2] - replace = m[1] + workingDir + '/node.cmd' + m[3] + m[4] - options.args[cmdi + 1] = m[1] + m[2] + m[3] + - ' "' + 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) - return - - var npmPath = whichOrUndefined('npm') || 'npm' - npmPath = path_.dirname(npmPath) + '\\node_modules\\npm\\bin\\npm-cli.js' - replace = m[1] + workingDir + '/node.cmd' + - ' "' + npmPath + '"' + - m[3] + m[4] - options.args[cmdi + 1] = command.replace(npmre, replace) - } -} - -function isNode (file) { - var cmdname = path.basename(process.execPath).replace(/\.exe$/i, '') - return file === 'node' || file === 'iojs' || cmdname === file -} - -function mungeNode (workingDir, options) { - options.originalNode = options.file - var command = path.basename(options.file).replace(/\.exe$/i, '') - // make sure it has a main script. - // otherwise, just let it through. - var a = 0 - var hasMain = false - var mainIndex = 1 - for (var 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: - if (options.args[a].match(/^-/)) { - continue - } else { - hasMain = true - mainIndex = a - a = options.args.length - break - } - } - } - - if (hasMain) { - var replace = workingDir + '/' + command - options.args.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 === options.basename) { - var realNode = whichOrUndefined(options.file) || process.execPath - options.file = options.args[0] = realNode - } - - debug('mungeNode after', options.file, options.args) -} - -function mungeShebang (workingDir, options) { - try { - var resolved = which.sync(options.file) - } catch (er) { - // nothing to do if we can't resolve - // Most likely: file doesn't exist or is not executable. - // Let exec pass through, probably will fail, oh well. - return - } - - var shebang = fs.readFileSync(resolved, 'utf8') - var match = shebang.match(/^#!([^\r\n]+)/) - if (!match) - return // not a shebang script, probably a binary - - var shebangbin = match[1].split(' ')[0] - var maybeNode = path.basename(shebangbin) - if (!isNode(maybeNode)) - return // not a node shebang, leave untouched - - options.originalNode = shebangbin - options.basename = maybeNode - options.file = shebangbin - options.args = [shebangbin, workingDir + '/' + maybeNode] - .concat(resolved) - .concat(match[1].split(' ').slice(1)) - .concat(options.args.slice(1)) -} - -function mungeEnv (workingDir, options) { - var pathEnv - for (var i = 0; i < options.envPairs.length; i++) { - var ep = options.envPairs[i] - if (ep.match(pathRe)) { - pathEnv = ep.substr(5) - var k = ep.substr(0, 5) - options.envPairs[i] = k + workingDir + colon + pathEnv - } - } - if (!pathEnv) { - options.envPairs.push((isWindows ? 'Path=' : 'PATH=') + workingDir) - } - if (options.originalNode) { - var key = path.basename(workingDir).substr('.node-spawn-wrap-'.length) - options.envPairs.push('SW_ORIG_' + key + '=' + options.originalNode) - } - - options.envPairs.push('SPAWN_WRAP_SHIM_ROOT=' + homedir) - - if (process.env.SPAWN_WRAP_DEBUG === '1') - options.envPairs.push('SPAWN_WRAP_DEBUG=1') -} - -function isnpm (file) { - // XXX is this even possible/necessary? - // wouldn't npm just be detected as a node shebang? - return file === 'npm' && !isWindows -} - -function mungenpm (workingDir, options) { - debug('munge npm') - // XXX weird effects of replacing a specific npm with a global one - var npmPath = whichOrUndefined('npm') - - if (npmPath) { - options.args[0] = npmPath - - options.file = workingDir + '/node' - options.args.unshift(workingDir + '/node') - } -} - -function munge (workingDir, options) { - options.basename = path.basename(options.file).replace(/\.exe$/i, '') - - // XXX: dry this - if (isSh(options.basename)) { - mungeSh(workingDir, options) - } else if (isCmd(options.basename)) { - mungeCmd(workingDir, options) - } else if (isNode(options.basename)) { - mungeNode(workingDir, options) - } else if (isnpm(options.basename)) { - // XXX unnecessary? on non-windows, npm is just another shebang - mungenpm(workingDir, options) - } else { - 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. - - mungeEnv(workingDir, options) -} - -function whichOrUndefined (executable) { - var path - try { - path = which.sync(executable) - } catch (er) {} - return path -} - -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 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. - var execArgv = [] - for (var i = 0; i < argv.length; i++) { - if (argv[i].match(/^-/)) { - 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) - } - } - - var key = process.pid + '-' + crypto.randomBytes(6).toString('hex') - var workingDir = homedir + key - - var settings = JSON.stringify({ - module: __filename, - deps: { - foregroundChild: require.resolve('foreground-child'), - signalExit: require.resolve('signal-exit'), - }, - key: key, - workingDir: workingDir, - argv: argv, - execArgv: execArgv, - env: env, - root: process.pid - }, null, 2) + '\n' - - signalExit(function () { - if (!doDebug) - rimraf.sync(workingDir) - }) - - mkdirp.sync(workingDir) - workingDir = fs.realpathSync(workingDir) - if (isWindows) { - var cmdShim = - '@echo off\r\n' + - 'SETLOCAL\r\n' + - 'SET PATHEXT=%PATHEXT:;.JS;=;%\r\n' + - '"' + process.execPath + '"' + ' "%~dp0\\.\\node" %*\r\n' - - fs.writeFileSync(workingDir + '/node.cmd', cmdShim) - fs.chmodSync(workingDir + '/node.cmd', '0755') - fs.writeFileSync(workingDir + '/iojs.cmd', cmdShim) - fs.chmodSync(workingDir + '/iojs.cmd', '0755') - } - fs.writeFileSync(workingDir + '/node', shim) - fs.chmodSync(workingDir + '/node', '0755') - fs.writeFileSync(workingDir + '/iojs', shim) - fs.chmodSync(workingDir + '/iojs', '0755') - var cmdname = path.basename(process.execPath).replace(/\.exe$/i, '') - if (cmdname !== 'iojs' && cmdname !== 'node') { - fs.writeFileSync(workingDir + '/' + cmdname, shim) - fs.chmodSync(workingDir + '/' + cmdname, '0755') - } - fs.writeFileSync(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() -} diff --git a/node_modules/spawn-wrap/lib/is-windows.js b/node_modules/spawn-wrap/lib/is-windows.js deleted file mode 100644 index 278abb3a0..000000000 --- a/node_modules/spawn-wrap/lib/is-windows.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = function () { - return process.platform === 'win32' || - process.env.OSTYPE === 'cygwin' || - process.env.OSTYPE === 'msys' -} diff --git a/node_modules/spawn-wrap/node_modules/.bin/mkdirp b/node_modules/spawn-wrap/node_modules/.bin/mkdirp deleted file mode 120000 index 91a5f623f..000000000 --- a/node_modules/spawn-wrap/node_modules/.bin/mkdirp +++ /dev/null @@ -1 +0,0 @@ -../../../mkdirp/bin/cmd.js
\ No newline at end of file diff --git a/node_modules/spawn-wrap/node_modules/.bin/rimraf b/node_modules/spawn-wrap/node_modules/.bin/rimraf deleted file mode 120000 index 632d6da23..000000000 --- a/node_modules/spawn-wrap/node_modules/.bin/rimraf +++ /dev/null @@ -1 +0,0 @@ -../../../rimraf/bin.js
\ No newline at end of file diff --git a/node_modules/spawn-wrap/node_modules/.bin/which b/node_modules/spawn-wrap/node_modules/.bin/which deleted file mode 120000 index 091d52ad6..000000000 --- a/node_modules/spawn-wrap/node_modules/.bin/which +++ /dev/null @@ -1 +0,0 @@ -../../../which/bin/which
\ No newline at end of file diff --git a/node_modules/spawn-wrap/package.json b/node_modules/spawn-wrap/package.json deleted file mode 100644 index 48c210054..000000000 --- a/node_modules/spawn-wrap/package.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "spawn-wrap", - "version": "1.4.2", - "description": "Wrap all spawned Node.js child processes by adding environs and arguments ahead of the main JavaScript file argument.", - "main": "index.js", - "dependencies": { - "foreground-child": "^1.5.6", - "mkdirp": "^0.5.0", - "os-homedir": "^1.0.1", - "rimraf": "^2.6.2", - "signal-exit": "^3.0.2", - "which": "^1.3.0" - }, - "scripts": { - "test": "tap --timeout=240 test/*.js", - "preversion": "npm test", - "postversion": "npm publish", - "postpublish": "git push origin --all; git push origin --tags", - "clean": "rm -rf ~/.node-spawn-wrap-*" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/isaacs/spawn-wrap.git" - }, - "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)", - "license": "ISC", - "bugs": { - "url": "https://github.com/isaacs/spawn-wrap/issues" - }, - "homepage": "https://github.com/isaacs/spawn-wrap#readme", - "devDependencies": { - "tap": "^10.7.3" - }, - "files": [ - "index.js", - "shim.js", - "lib/is-windows.js" - ] -} diff --git a/node_modules/spawn-wrap/shim.js b/node_modules/spawn-wrap/shim.js deleted file mode 100644 index dda6b2ae2..000000000 --- a/node_modules/spawn-wrap/shim.js +++ /dev/null @@ -1,180 +0,0 @@ -'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') -} - -var util -var doDebug = process.env.SPAWN_WRAP_DEBUG === '1' -var fs -function debug () { - if (!doDebug) - return - - if (!fs) { - fs = require('fs') - util = require('util') - } - - var message = util.format.apply(util, arguments).trim() - var pref = 'SW ' + process.pid + ': ' - message = pref + message.split('\n').join('\n' + pref) - fs.writeSync(2, message + '\n') -} - -debug('shim', [process.argv[0]].concat(process.execArgv, process.argv.slice(1))) - -var Module = require('module') -var assert = require('assert') -var path = require('path') - -var settings = require('./settings.json') -var foregroundChild = require(settings.deps.foregroundChild) -var argv = settings.argv -var nargs = argv.length -var env = settings.env -var key = settings.key -var node = process.env['SW_ORIG_' + key] || process.execPath - -for (var k in env) { - process.env[k] = env[k] -} - -var 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 -var hasMain = false -for (var 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: - if (process.argv[a].match(/^-/)) { - 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. - var addExecArgv = process.argv.splice(2, hasMain - 2) - needExecArgv.push.apply(needExecArgv, addExecArgv) -} - -if (!hasMain) { - // we got loaded by mistake for a `node -pe script` or something. - var 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) { - var pexec = process.execArgv - if (JSON.stringify(pexec) !== JSON.stringify(needExecArgv)) { - debug('need execArgv for this', pexec, '=>', needExecArgv) - var spawn = require('child_process').spawn - var 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. -var spliceArgs = [1, 1].concat(argv) -process.argv.splice.apply(process.argv, spliceArgs) - -// Unwrap the PATH environment var so that we're not mucking -// with the environment. It'll get re-added if they spawn anything -var isWindows = ( - process.platform === 'win32' || - process.env.OSTYPE === 'cygwin' || - process.env.OSTYPE === 'msys' -) - -if (isWindows) { - for (var i in process.env) { - if (i.match(/^path$/i)) { - process.env[i] = process.env[i].replace(__dirname + ';', '') - } - } -} else { - process.env.PATH = process.env.PATH.replace(__dirname + ':', '') -} - -var 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 -})() |