Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicated result when using globstar #231

Merged
merged 2 commits into from Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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