command-exists
Advanced tools
Comparing version 1.2.7 to 1.2.8
@@ -6,2 +6,3 @@ 'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var access = fs.access; | ||
@@ -65,2 +66,6 @@ var accessSync = fs.accessSync; | ||
var commandExistsWindows = function(commandName, cleanedCommandName, callback) { | ||
if (/[\x00-\x1f<>:"\|\?\*]/.test(commandName)) { | ||
callback(null, false); | ||
return; | ||
} | ||
var child = exec('where ' + cleanedCommandName, | ||
@@ -93,2 +98,5 @@ function (error) { | ||
var commandExistsWindowsSync = function(commandName, cleanedCommandName, callback) { | ||
if (/[\x00-\x1f<>:"\|\?\*]/.test(commandName)) { | ||
return false; | ||
} | ||
try { | ||
@@ -111,2 +119,14 @@ var stdout = execSync('where ' + cleanedCommandName, {stdio: []}); | ||
if (isUsingWindows) { | ||
cleanInput = function(s) { | ||
var isPathName = /[\\]/.test(s); | ||
if (isPathName) { | ||
var dirname = '"' + path.dirname(s) + '"'; | ||
var basename = '"' + path.basename(s) + '"'; | ||
return dirname + ':' + basename; | ||
} | ||
return '"' + s + '"'; | ||
} | ||
} | ||
module.exports = function commandExists(commandName, callback) { | ||
@@ -113,0 +133,0 @@ var cleanedCommandName = cleanInput(commandName); |
{ | ||
"name": "command-exists", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"description": "check whether a command line command exists in the current environment", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,2 +57,6 @@ command-exists | ||
### v1.2.7 | ||
Removes unnecessary printed output on windows. | ||
### v1.2.6 | ||
@@ -59,0 +63,0 @@ |
@@ -113,3 +113,19 @@ 'use strict'; | ||
} | ||
if (isUsingWindows) { | ||
it('it should report true if there is an executable file with that name', function(done) { | ||
var commandToUse = 'test\\executable-script.cmd' | ||
commandExists(commandToUse) | ||
.then(function(command){ | ||
expect(command).to.be(commandToUse); | ||
done(); | ||
}); | ||
}); | ||
it('it should report false if there is a double quotation mark in the file path', function() { | ||
var commandToUse = 'test\\"executable-script.cmd' | ||
expect(commandExists.sync(commandToUse)).to.be(false); | ||
}); | ||
} | ||
}); | ||
}); |
12494
251
84