Skip to content

Commit

Permalink
fix: handle empty & no-glob patterns correctly (terkelg#37)
Browse files Browse the repository at this point in the history
* Use `cwd` when `isGlob` is false. Fixes terkelg#36

* fix: ignore any empty "str" value

* fix: use "resolve" for cwd
  • Loading branch information
Timothy Johnson authored and lukeed committed Nov 30, 2018
1 parent a9b92be commit a649f6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ async function walk(output, prefix, lexer, opts, dirname='', level=0) {
* @returns {Array} array containing matching files
*/
module.exports = async function (str, opts={}) {
if (!str) return [];

let glob = globalyzer(str);

if (!glob.isGlob) return fs.existsSync(str) ? [str] : [];
opts.cwd = opts.cwd || '.';
if (!glob.isGlob) return fs.existsSync(resolve(opts.cwd, str)) ? [str] : [];
if (opts.flush) CACHE = {};

let matches = [];
opts.cwd = opts.cwd || '.';
const { path } = globrex(glob.glob, { filepath:true, globstar:true, extended:true });

path.globstar = path.globstar.toString();
Expand Down
8 changes: 8 additions & 0 deletions test/glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ test('glob: options.cwd', async t => {
]);
});

test('glob: options.cwd (without glob)', async t => {
t.plan(1);

let dir = join(cwd, 'one', 'child');

await isMatch(t, '../child/a.js', { cwd:dir }, [ '../child/a.js' ]);
});

test('glob: options.cwd (absolute)', async t => {
t.plan(2);

Expand Down

0 comments on commit a649f6e

Please sign in to comment.