[Pkg-javascript-commits] [node-foreground-child] 31/69: Only use cross-spawn-async for shebangs
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Aug 25 11:43:04 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-foreground-child.
commit 1d5020e5510115843a560c8d10f387835c1b7dd6
Author: isaacs <i at izs.me>
Date: Sun Jan 3 17:16:15 2016 -0800
Only use cross-spawn-async for shebangs
Spawning everything through cmd.exe breaks when the PATH environment
variable does not include the path to cmd.exe. However, it should still
work just fine, provided that the invoked executable is referenced by a
full absolute path.
---
index.js | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/index.js b/index.js
index 267eb47..30d6de9 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,20 @@
var signalExit = require('signal-exit')
var spawn = require('child_process').spawn
-if (process.platform === 'win32') {
- spawn = require('cross-spawn-async')
+var crossSpawn = require('cross-spawn-async')
+var fs = require('fs')
+
+function needsCrossSpawn (exe) {
+ if (process.platform !== 'win32') {
+ return false
+ }
+
+ var buffer = new Buffer(150)
+ try {
+ var fd = fs.openSync(exe, 'r')
+ fs.readSync(fd, buffer, 0, 150, 0)
+ } catch (e) {}
+
+ return /\#\!(.+)/i.test(buffer.toString().trim())
}
module.exports = function (program, args, cb) {
@@ -30,7 +43,8 @@ module.exports = function (program, args, cb) {
args = [].slice.call(arguments, 1, arrayIndex)
}
- var child = spawn(program, args, { stdio: 'inherit' })
+ var spawnfn = needsCrossSpawn(program) ? crossSpawn : spawn
+ var child = spawnfn(program, args, { stdio: 'inherit' })
var childExited = false
signalExit(function (code, signal) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-foreground-child.git
More information about the Pkg-javascript-commits
mailing list