Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spawn-wrap

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spawn-wrap - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

package.json
{
"name": "spawn-wrap",
"version": "0.1.1",
"version": "0.1.2",
"description": "Wrap all spawned Node.js child processes by adding environs and arguments ahead of the main JavaScript file argument.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -30,28 +30,4 @@ // This module should *only* be loaded as a main script

// 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 (settings.execArgv) {
var pexec = process.execArgv
var sexec = settings.execArgv
if (JSON.stringify(pexec) !== JSON.stringify(sexec)) {
var spawn = require('child_process').spawn
var node = process.execPath
var sargs = pexec.concat(sexec).concat(process.argv.slice(1))
var child = spawn(node, sargs, { stdio: 'inherit' })
child.on('close', function (code, signal) {
if (signal) {
process.kill(process.pid, signal)
} else {
process.exit(code)
}
})
return
}
}
var needExecArgv = settings.execArgv || []
var spliceArgs = [1, 1].concat(argv)
process.argv.splice.apply(process.argv, spliceArgs)
// If the user added their OWN wrapper pre-load script, then

@@ -65,2 +41,10 @@ // this will pop that off of the argv, and load the "real" main

// 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

@@ -87,3 +71,3 @@ for (var a = 2; !hasMain && a < process.argv.length; a++) {

} else {
hasMain = true
hasMain = a
a = process.argv.length

@@ -95,2 +79,12 @@ break

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) {

@@ -100,3 +94,3 @@ // we got loaded by mistake for a `node -pe script` or something.

process.execPath,
process.execArgv.concat(process.argv.slice(2)),
process.execArgv.concat(needExecArgv, process.argv.slice(2)),
{ stdio: 'inherit' }

@@ -114,13 +108,39 @@ )

var isWindows = false
var pathRe = /^PATH=/
if (process.platform === 'win32' ||
process.env.OSTYPE === 'cygwin' ||
process.env.OSTYPE === 'msys') {
pathRe = /^PATH=/i
isWindows = true
// 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)) {
var spawn = require('child_process').spawn
var node = process.execPath
var sargs = pexec.concat(needExecArgv).concat(process.argv.slice(1))
var child = spawn(node, sargs, { stdio: 'inherit' })
child.on('close', function (code, signal) {
if (signal) {
process.kill(process.pid, signal)
} else {
process.exit(code)
}
})
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) {

@@ -127,0 +147,0 @@ for (var i in process.env) {

@@ -25,3 +25,3 @@ var sw = require('../')

})
console.log('WRAP %j', argv)
console.log('WRAP %j', process.execArgv.concat(argv))
sw.runMain()

@@ -114,2 +114,20 @@ return

t.test('--harmony', function (t) {
var node = process.execPath
var child = cp.spawn(node, ['--harmony', fixture, 'xyz'])
var out = ''
child.stdout.on('data', function (c) {
out += c
})
child.on('close', function (code, signal) {
t.equal(code, 0)
t.equal(signal, null)
t.equal(out, 'WRAP ["--harmony","{{FIXTURE}}","xyz"]\n' +
'["--harmony"]\n' +
'["xyz"]\n' +
'EXIT [0,null]\n')
t.end()
})
})
t.test('unwrap', function (t) {

@@ -116,0 +134,0 @@ unwrap()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc