[Pkg-javascript-commits] [node-foreground-child] 34/69: Better testing for when cross-spawn-async needed

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 f51a62146ee46d63fda3c6df8dcd787a487978d2
Author: isaacs <i at izs.me>
Date:   Thu Jan 21 14:58:43 2016 -0800

    Better testing for when cross-spawn-async needed
    
    Fix https://github.com/tapjs/foreground-child/issues/5
---
 index.js     | 19 ++++++++++++++++++-
 package.json |  5 +++--
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 30d6de9..508b86e 100644
--- a/index.js
+++ b/index.js
@@ -2,17 +2,34 @@ var signalExit = require('signal-exit')
 var spawn = require('child_process').spawn
 var crossSpawn = require('cross-spawn-async')
 var fs = require('fs')
+var which = require('which')
 
 function needsCrossSpawn (exe) {
   if (process.platform !== 'win32') {
     return false
   }
 
+  try {
+    exe = which.sync(exe)
+  } catch (er) {
+    // failure to find the file?  cmd probably needed.
+    return true
+  }
+
+  if (/\.(com|cmd|bat)$/i.test(exe)) {
+    // need cmd.exe to run command and batch files
+    return true
+  }
+
   var buffer = new Buffer(150)
   try {
     var fd = fs.openSync(exe, 'r')
     fs.readSync(fd, buffer, 0, 150, 0)
-  } catch (e) {}
+  } catch (e) {
+    // If it's not an actual file, probably it needs cmd.exe.
+    // also, would be unsafe to test arbitrary memory on next line!
+    return true
+  }
 
   return /\#\!(.+)/i.test(buffer.toString().trim())
 }
diff --git a/package.json b/package.json
index 95c9cba..450b28a 100644
--- a/package.json
+++ b/package.json
@@ -8,10 +8,11 @@
   },
   "dependencies": {
     "cross-spawn-async": "^2.1.1",
-    "signal-exit": "^2.0.0"
+    "signal-exit": "^2.0.0",
+    "which": "^1.2.1"
   },
   "devDependencies": {
-    "tap": "^4.0.0"
+    "tap": "^5.1.1"
   },
   "scripts": {
     "test": "tap --coverage test/*.js"

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