diff --git a/.travis.yml b/.travis.yml index e67bc0c..ae1886e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ -sudo: false os: - linux - - osx + - windows language: node_js + +# https://github.com/nodejs/Release#end-of-life-releases node_js: - - node + - '16' + - '14' + - '12' + - '10' - '8' - - '7' - - '6' - - '5' - - '4' diff --git a/index.js b/index.js index c4f2463..017c081 100644 --- a/index.js +++ b/index.js @@ -186,7 +186,7 @@ glob.sync = function(pattern, options) { return (opts.nullglob || fs.existsSync(fp)) ? [pattern] : []; } - var cp = spawn.sync(bashPath, cmd(pattern, opts), opts); + var cp = spawn.sync(getBash(), cmd(pattern, opts), opts); var error = cp.stderr ? String(cp.stderr).trim() : null; if (error) { err = handleError(error, pattern, opts); @@ -264,7 +264,7 @@ function bash(pattern, options, cb) { return; } - var cp = spawn(bashPath, cmd(pattern, options), options); + var cp = spawn(getBash(), cmd(pattern, options), options); var buf = new Buffer(0); cp.stdout.on('data', function(data) { @@ -475,6 +475,22 @@ function emitMatches(str, pattern, options) { glob.emit('match', getFiles(str, pattern, options), options.cwd); } +/** + * Returns bash path if exists. + * @ignore + * @return {String} Bash bin path. + * + */ +function getBash() { + const bashBinPath = bashPath() + + if (!bashBinPath) { + throw new TypeError('`bash` not found') + } + + return bashBinPath +} + /** * Expose `glob` */ diff --git a/package.json b/package.json index d835c08..e821678 100644 --- a/package.json +++ b/package.json @@ -14,30 +14,32 @@ ], "main": "index.js", "engines": { - "node": ">=4.0" + "node": ">=8.0" }, "scripts": { "test": "mocha" }, "dependencies": { - "bash-path": "^1.0.1", - "component-emitter": "^1.2.1", - "cross-spawn": "^5.1.0", + "bash-path": "^2.0.1", + "component-emitter": "^1.3.0", + "cross-spawn": "^7.0.3", "each-parallel-async": "^1.0.0", - "extend-shallow": "^2.0.1", + "extend-shallow": "^3.0.2", "is-extglob": "^2.1.1", - "is-glob": "^4.0.0" + "is-glob": "^4.0.1" }, "devDependencies": { "arr-union": "^3.1.0", "array-unique": "^0.3.2", "async-array-reduce": "^1.0.0", "delete": "^1.1.0", - "glob": "^7.1.2", - "gulp-format-md": "^1.0.0", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "mocha": "^3.2.0" + "glob": "^7.1.7", + "gulp-format-md": "^2.0.0", + "minimist": "^1.2.5", + "mkdirp": "^0.5.5", + "mocha": "^7.2.0", + "mock-require": "^3.0.3", + "sinon": "^9.2.4" }, "keywords": [ "bash", diff --git a/test/api.js b/test/api.js index 5dfc8f6..c78ee45 100644 --- a/test/api.js +++ b/test/api.js @@ -2,6 +2,8 @@ require('mocha'); var assert = require('assert'); +var sinon = require('sinon'); +var mock = require('mock-require'); var glob = require('..'); describe('bash-glob', function() { @@ -48,4 +50,21 @@ describe('bash-glob', function() { } }); }); + + it('throws exception if `bash` not found', function() { + var bashPathSpy = sinon.spy(function () { return null; }); + mock('bash-path', bashPathSpy); + + var glob = mock.reRequire('..') + + try { + glob.sync(['*']); + + } catch (err) { + assert(err); + assert.equal(err.message, '`bash` not found'); + } + + mock.stop('bash-path'); + }); });