Skip to content

Commit

Permalink
Fix duplicated result when using globstar (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Feb 2, 2022
1 parent 9f53ca5 commit f9d35ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
@@ -1,4 +1,5 @@
import fs from 'node:fs';
import nodePath from 'node:path';
import merge2 from 'merge2';
import fastGlob from 'fast-glob';
import dirGlob from 'dir-glob';
Expand Down Expand Up @@ -84,8 +85,9 @@ const createFilterFunction = isIgnored => {

return fastGlobResult => {
const path = fastGlobResult.path || fastGlobResult;
const seenOrIgnored = seen.has(path) || (isIgnored && isIgnored(path));
seen.add(path);
const pathKey = nodePath.normalize(path);
const seenOrIgnored = seen.has(pathKey) || (isIgnored && isIgnored(path));
seen.add(pathKey);
return !seenOrIgnored;
};
};
Expand Down
7 changes: 7 additions & 0 deletions tests/globby.js
Expand Up @@ -116,6 +116,13 @@ test('glob - stream async iterator support', async t => {
t.deepEqual(results, ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']);
});

test('glob - duplicated patterns', async t => {
const result1 = await runGlobby(t, [`./${temporary}/**`, `./${temporary}`]);
t.deepEqual(result1, ['./tmp/a.tmp', './tmp/b.tmp', './tmp/c.tmp', './tmp/d.tmp', './tmp/e.tmp']);
const result2 = await runGlobby(t, [`./${temporary}`, `./${temporary}/**`]);
t.deepEqual(result2, ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']);
});

test.serial('cwd option', async t => {
process.chdir(temporary);
t.deepEqual(await runGlobby(t, '*.tmp', {cwd}), ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']);
Expand Down

0 comments on commit f9d35ae

Please sign in to comment.