From fbdbfc90dd7afeba89cc3dd5e6280ed247f8b789 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 16 Aug 2022 13:47:46 -0700 Subject: [PATCH] [Refactor] `bin/tape`: make it a bit more functional, for easier v5 backporting --- bin/tape | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/tape b/bin/tape index 84f0f0ec..f774228f 100755 --- a/bin/tape +++ b/bin/tape @@ -47,7 +47,7 @@ if (typeof opts.ignore === 'string') { var glob = require('glob'); -opts._.forEach(function (arg) { +opts._.reduce(function (result, arg) { // If glob does not match, `files` will be an empty array. Note: `glob.sync` may throw an error and crash the node process. var files = glob.sync(arg); @@ -55,9 +55,11 @@ opts._.forEach(function (arg) { throw new TypeError('unknown error: glob.sync did not return an array or throw. Please report this.'); } - files.filter(function (file) { return !matcher || !matcher.shouldIgnore(file); }).forEach(function (file) { - require(resolvePath(cwd, file)); - }); + return result.concat(files); +}, []).filter(function (file) { + return !matcher || !matcher.shouldIgnore(file); +}).forEach(function (file) { + require(resolvePath(cwd, file)); }); // vim: ft=javascript