Skip to content

Commit

Permalink
[New] bin/tape: include the exact arg when there are no glob result…
Browse files Browse the repository at this point in the history
…s; use require.resolve on `--require` files
  • Loading branch information
ljharb committed Aug 16, 2022
1 parent f6f39a2 commit e23ec12
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions bin/tape
Expand Up @@ -33,6 +33,7 @@ opts.require.forEach(function (module) {
});

var resolvePath = require('path').resolve;
var requireResolve = require.resolve;

var matcher;
if (typeof opts.ignore === 'string') {
Expand All @@ -50,19 +51,22 @@ if (typeof opts.ignore === 'string') {
var glob = require('glob');

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 globFiles = glob.sync(arg);
if (glob.hasMagic(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 globFiles = glob.sync(arg);

if (!Array.isArray(globFiles)) {
throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.');
}
if (!Array.isArray(globFiles)) {
throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.');
}

return result.concat(globFiles);
return result.concat(globFiles);
}
return result.concat(arg);
}, []).filter(function (file) {
return !matcher || !matcher.shouldIgnore(file);
}).map(function (file) {
return resolvePath(cwd, file);
return requireResolve(resolvePath(cwd, file));
});

var hasImport = require('has-dynamic-import');
Expand Down

0 comments on commit e23ec12

Please sign in to comment.