@geek/spawn
Advanced tools
Comparing version 0.0.1-beta.5 to 0.0.1-beta.6
{ | ||
"name": "@geek/spawn", | ||
"version": "0.0.1-beta.5", | ||
"version": "0.0.1-beta.6", | ||
"description": "a cross-platform spawn replacement with promises", | ||
@@ -37,3 +37,6 @@ "keywords": [], | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"chalk": "^1.1.3", | ||
"debug": "^2.2.0" | ||
} | ||
} |
41
spawn.js
'use strict'; | ||
var _ = require("lodash"); | ||
var child_process = require('child_process'); | ||
var path = require("path"); | ||
const _ = require("lodash"); | ||
const child_process = require('child_process'); | ||
const path = require("path"); | ||
const chalk = require("chalk"); | ||
const module_name = path.parse(module.id).name; | ||
const SEPARATOR = process.platform === "win32" ? ";" : ":"; | ||
var env = Object.assign({}, process.env); | ||
var SEPARATOR = process.platform === "win32" ? ";" : ":"; | ||
env.PATH = path.resolve(path.join(__dirname, "/node_modules/.bin")) + SEPARATOR + env.PATH; | ||
// debug logger | ||
var logger = (func_name) => { | ||
var prefix = func_name ? `[${module_name}.${func_name}] ` : `[${module_name}`; | ||
return _.wrap(require('debug')('geek-spawn'), (func, msg) => func(chalk.blue(`[${module_name}.execute] `) + msg)); | ||
} | ||
let debug = logger(); | ||
exports.spawnSync = function(cmd, args, opts) { | ||
let debug = logger('spawnSync'); | ||
opts = opts || {}; | ||
@@ -16,3 +25,3 @@ opts.stdio = 'inherit'; | ||
if (process.platform === 'win32') { | ||
if(process.platform === 'win32') { | ||
args = ['/c', cmd].concat(args); | ||
@@ -26,12 +35,13 @@ cmd = process.env.comspec; | ||
exports.spawn = function(cmd, args, opts) { | ||
var successfulExitCodes = (opts && opts.successfulExitCodes) || [0]; | ||
let debug = logger('spawn'); | ||
return new Promise(function(resolve, reject) { | ||
opts = opts || {}; | ||
opts.successfulExitCodes = opts.successfulExitCodes || [0]; | ||
opts.stdio = 'inherit'; | ||
opts.env = env; | ||
_.defaults(opts, { | ||
successfulExitCodes: [0], | ||
stdio: 'inherit', | ||
env: env | ||
}) | ||
if (process.platform === 'win32') { | ||
if(process.platform === 'win32') { | ||
args = ['/c', cmd].concat(args); | ||
@@ -41,2 +51,3 @@ cmd = process.env.comspec; | ||
debug("Spawning in " + opts.cwd + ": " + cmd + " " + args.join(" ")); | ||
var child = child_process.spawn(cmd, args, opts); | ||
@@ -46,6 +57,6 @@ | ||
if (!_.includes(opts.successfulExitCodes, code)) { | ||
if(!_.includes(opts.successfulExitCodes, code)) { | ||
var err = { | ||
code: code, | ||
message: "'" + cmd + " " + _.join(args," ") + "' failed with code " + code, | ||
message: "'" + cmd + " " + _.join(args, " ") + "' failed with code " + code, | ||
childProcess: child, | ||
@@ -67,3 +78,3 @@ toString() { | ||
child.on('error', (err) => { | ||
child.on('error', err => { | ||
reject(err); | ||
@@ -70,0 +81,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4701
62
1
2
+ Addedchalk@^1.1.3
+ Addeddebug@^2.2.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)