You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/03/23 19:42:12 UTC
git commit: CB-6323 Fix superspawn's resolve function on windows (was
very broken)
Repository: cordova-cli
Updated Branches:
refs/heads/master bc4422b62 -> c0923f6cf
CB-6323 Fix superspawn's resolve function on windows (was very broken)
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/c0923f6c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/c0923f6c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/c0923f6c
Branch: refs/heads/master
Commit: c0923f6cfba938010c47915711e3102f781df154
Parents: bc4422b
Author: Andrew Grieve <ag...@chromium.org>
Authored: Sat Mar 22 08:12:16 2014 -0700
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Sat Mar 22 08:13:07 2014 -0700
----------------------------------------------------------------------
src/superspawn.js | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/c0923f6c/src/superspawn.js
----------------------------------------------------------------------
diff --git a/src/superspawn.js b/src/superspawn.js
index 7fce47e..41bdcac 100644
--- a/src/superspawn.js
+++ b/src/superspawn.js
@@ -19,20 +19,25 @@
var child_process = require('child_process');
var fs = require('fs');
+var path = require('path');
var _ = require('underscore');
var Q = require('q');
var shell = require('shelljs');
var events = require('./events');
// On Windows, spawn() for batch files requires absolute path & having the extension.
-function resolvePath(cmd) {
- if (fs.exists(cmd)) {
+function resolveWindowsExe(cmd) {
+ var winExtensions = ['.exe', '.cmd', '.bat', '.js', '.vbs'];
+ function isValidExe(c) {
+ return winExtensions.indexOf(path.extname(cmd)) !== -1 && fs.existsSync(cmd);
+ }
+ if (isValidExe(cmd)) {
return cmd;
}
cmd = shell.which(cmd) || cmd;
- if (!fs.exists(cmd)) {
- ['.cmd', '.bat', '.js'].some(function(ext) {
- if (fs.exists(cmd + ext)) {
+ if (!isValidExe(cmd)) {
+ winExtensions.some(function(ext) {
+ if (fs.existsSync(cmd + ext)) {
cmd = cmd + ext;
return true;
}
@@ -55,10 +60,10 @@ exports.spawn = function(cmd, args, opts) {
var spawnOpts = {};
var d = Q.defer();
if (process.platform.slice(0, 3) == 'win') {
- cmd = resolvePath(cmd);
+ cmd = resolveWindowsExe(cmd);
// If we couldn't find the file, likely we'll end up failing,
// but for things like "del", cmd will do the trick.
- if (!fs.exists(cmd)) {
+ if (!fs.existsSync(cmd)) {
args = [['/s', '/c', '"'+[cmd].concat(args).map(function(a){if (/^[^"].* .*[^"]/.test(a)) return '"'+a+'"'; return a;}).join(" ")+'"'].join(" ")];
cmd = 'cmd';
}