From 021fa6d22bc85f2e8f075405bcb97c6a1b87af22 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 3 Jun 2021 22:38:38 -0700 Subject: [PATCH] [Refactor] `bin/tape`: separate "preparing of files list" from "require files list" --- bin/tape | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/tape b/bin/tape index 771fd015..03f9b273 100755 --- a/bin/tape +++ b/bin/tape @@ -41,7 +41,7 @@ if (typeof opts.ignore === 'string') { var matcher = ignore.createMatcher(ignoreStr); } -opts._.forEach(function (arg) { +var files = 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); @@ -50,9 +50,13 @@ 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); +}).map(function (file) { + return resolvePath(cwd, file); }); +files.forEach(function (x) { require(x); }); + // vim: ft=javascript