diff --git a/.travis.yml b/.travis.yml index 587bd3e..896e270 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,9 @@ language: node_js +sudo: false +node_js: + - "0.10" + - "0.12" + - "4" + - "5" +before_install: + - npm i -g npm diff --git a/package.json b/package.json index c31f8f5..23c4913 100644 --- a/package.json +++ b/package.json @@ -17,26 +17,27 @@ "license": "MIT", "main": "./tasks/buster.js", "engines": { - "node": ">= 0.8.0" + "node": ">= 4" }, "scripts": { "start": "grunt --force default watch", "test": "grunt" }, "devDependencies": { - "buster": ">=0.7.6", - "grunt": "~0.4.1", - "grunt-cli": "~0.1.8", - "grunt-contrib-jshint": "~0.10.0", - "grunt-contrib-watch": "~0.4.0" + "buster": "0.7.x", + "grunt": "0.4.x", + "grunt-cli": "0.1.x", + "grunt-contrib-jshint": "0.11.x", + "grunt-contrib-watch": "0.6.x" }, "dependencies": { - "when": "~2.0.0", - "resolve-bin": "~0.3.0" + "resolve-bin": "0.3.x", + "when": "3.x", + "which": "1.x" }, "peerDependencies": { - "buster": ">=0.7.x", - "grunt": "~0.4.0" + "buster": ">=0.7.6", + "grunt": ">=0.4.0" }, "keywords": [ "gruntplugin", diff --git a/tasks/buster/cmd.js b/tasks/buster/cmd.js index 26004a0..f3888d5 100644 --- a/tasks/buster/cmd.js +++ b/tasks/buster/cmd.js @@ -2,10 +2,21 @@ var cp = require('child_process'); var grunt = require('grunt'); var when = require('when'); var resolveBin = require('resolve-bin'); +var which = require('which'); + +var findExecutable = function (moduleName, cmd, cb) { + resolveBin(moduleName, {executable:cmd}, function (error, path) { + if (error) { // failed to find in [global/local] node_modules - fallback to PATH + which(cmd, cb); + } else { + cb(null, path); + } + }); +}; exports.run = function (moduleName, cmd, args, callback) { callback = callback || function () {}; - resolveBin(moduleName, { executable: cmd }, function (error, path) { + findExecutable(moduleName, cmd, function (error, path) { if (error) { callback(error); } else { @@ -103,7 +114,7 @@ exports.runPhantomjs = function (args) { exports.run('phantomjs', 'phantomjs', args, function (error, phantomProcess) { if (error) { grunt.log.error( - 'PhantomJS not found. Run `npm install phantomjs` to install.'); + 'PhantomJS not found. Run `npm install [-g] phantomjs` to install.'); deferred.reject(); } else { phantomProcess.stdout.on('data', function (data) { diff --git a/test/cmd-test.js b/test/cmd-test.js index 826b74f..3bea073 100644 --- a/test/cmd-test.js +++ b/test/cmd-test.js @@ -26,10 +26,20 @@ buster.testCase('Cmd', { }); }, + 'calls callback with results when a global binary found': function (done) { + var spawnStub = this.spawnStub; + cmd.run('node', 'node', [ 1, 2, 3 ], function (err) { + assert.isNull(err); + // node is the only executable I can trust to be in actual PATH - I just dont' know that path, but there should definitely be no error + assert.calledOnce(spawnStub); + done(); + }); + }, + 'calls callback with error when resolve-bin fails': function (done) { cmd.run('no-such-module', 'no-such-file', [], function (err, actualHandle) { refute.isNull(err); - assert.match(err.message, 'cannot find'); + assert.match(err.message, 'not found'); refute(actualHandle); done(); });