From 366b38d7094b9dce498262e960364d39a752e066 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sat, 3 Oct 2020 17:36:32 +0400 Subject: [PATCH 1/3] fix: check bash path before invocation --- .travis.yml | 12 ++++++------ index.js | 20 ++++++++++++++++++-- package.json | 16 +++++++++------- test/api.js | 19 +++++++++++++++++++ 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index e67bc0c..c13488e 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 + - '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..9388cb4 100644 --- a/package.json +++ b/package.json @@ -20,24 +20,26 @@ "test": "mocha" }, "dependencies": { - "bash-path": "^1.0.1", - "component-emitter": "^1.2.1", + "bash-path": "^2.0.1", + "component-emitter": "^1.3.0", "cross-spawn": "^5.1.0", "each-parallel-async": "^1.0.0", "extend-shallow": "^2.0.1", "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", + "glob": "^7.1.6", "gulp-format-md": "^1.0.0", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "mocha": "^3.2.0" + "minimist": "^1.2.5", + "mkdirp": "^0.5.5", + "mocha": "^6.2.3", + "mock-require": "^3.0.3", + "sinon": "^9.1.0" }, "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'); + }); }); From d3533dc4c0450bb186e722131e28ee6961c28ee4 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sun, 1 Nov 2020 13:08:16 +0300 Subject: [PATCH 2/3] chore(package): up deps BREAKING CHANGE: require NodeJS >= 8 --- .travis.yml | 1 + package.json | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index c13488e..18f5186 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ language: node_js # https://github.com/nodejs/Release#end-of-life-releases node_js: + - '15' - '14' - '12' - '10' diff --git a/package.json b/package.json index 9388cb4..d440fd8 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ ], "main": "index.js", "engines": { - "node": ">=4.0" + "node": ">=8.0" }, "scripts": { "test": "mocha" @@ -22,9 +22,9 @@ "dependencies": { "bash-path": "^2.0.1", "component-emitter": "^1.3.0", - "cross-spawn": "^5.1.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.1" }, @@ -34,12 +34,12 @@ "async-array-reduce": "^1.0.0", "delete": "^1.1.0", "glob": "^7.1.6", - "gulp-format-md": "^1.0.0", + "gulp-format-md": "^2.0.0", "minimist": "^1.2.5", "mkdirp": "^0.5.5", - "mocha": "^6.2.3", + "mocha": "^7.2.0", "mock-require": "^3.0.3", - "sinon": "^9.1.0" + "sinon": "^9.2.1" }, "keywords": [ "bash", From 982b7283c8c3780b07fd10a9e3dd0af8d44e1dd8 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Fri, 11 Jun 2021 00:11:42 +0300 Subject: [PATCH 3/3] ci: add Node.js v16 to build matrix --- .travis.yml | 3 +-- package.json | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 18f5186..ae1886e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -sudo: false os: - linux - windows @@ -6,7 +5,7 @@ language: node_js # https://github.com/nodejs/Release#end-of-life-releases node_js: - - '15' + - '16' - '14' - '12' - '10' diff --git a/package.json b/package.json index d440fd8..e821678 100644 --- a/package.json +++ b/package.json @@ -33,13 +33,13 @@ "array-unique": "^0.3.2", "async-array-reduce": "^1.0.0", "delete": "^1.1.0", - "glob": "^7.1.6", + "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.1" + "sinon": "^9.2.4" }, "keywords": [ "bash",