Skip to content

Commit b4c1657

Browse files
committed
fix to work with pathnames for windows
1 parent 826c8a9 commit b4c1657

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/command-exists.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var exec = require('child_process').exec;
44
var execSync = require('child_process').execSync;
55
var fs = require('fs');
6+
var path = require('path');
67
var access = fs.access;
78
var accessSync = fs.accessSync;
89
var constants = fs.constants || fs;
@@ -105,6 +106,18 @@ var cleanInput = function(s) {
105106
return s;
106107
}
107108

109+
if (isUsingWindows) {
110+
cleanInput = function(s) {
111+
var isPathName = /[\\]/.test(s);
112+
if (isPathName) {
113+
var dirname = '"' + path.dirname(s) + '"';
114+
var basename = '"' + path.basename(s) + '"';
115+
return dirname + ':' + basename;
116+
}
117+
return '"' + s + '"';
118+
}
119+
}
120+
108121
module.exports = function commandExists(commandName, callback) {
109122
var cleanedCommandName = cleanInput(commandName);
110123
if (!callback && typeof Promise !== 'undefined') {

test/executable-script.cmd

Whitespace-only changes.

test/test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,16 @@ describe('commandExists', function(){
110110
});
111111
});
112112
}
113+
114+
if (isUsingWindows) {
115+
it('it should report true if there is an executable file with that name', function(done) {
116+
var commandToUse = 'test\\executable-script.cmd'
117+
commandExists(commandToUse)
118+
.then(function(command){
119+
expect(command).to.be(commandToUse);
120+
done();
121+
});
122+
});
123+
}
113124
});
114125
});

0 commit comments

Comments
 (0)