Skip to content

Commit

Permalink
fix negative absolute patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Oct 16, 2024
1 parent b437558 commit b8c5a9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ function processPatterns(
}

for (let pattern of patterns) {
pattern = normalizePattern(pattern, expandDirectories, cwd, properties, false);
if (pattern.startsWith('!') && pattern[1] !== '(') {
ignorePatterns.push(pattern.slice(1));
const newPattern = normalizePattern(pattern.slice(1), expandDirectories, cwd, properties, true);
ignorePatterns.push(newPattern);
} else {
matchPatterns.push(pattern);
const newPattern = normalizePattern(pattern, expandDirectories, cwd, properties, false);
matchPatterns.push(newPattern);
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,20 @@ test('negative patterns in options', async () => {
assert.deepEqual(files2.sort(), ['a/b.txt', 'b/b.txt']);
});

test('negative absolute patterns in options', async () => {
const files = await glob({
patterns: [`${cwd.replaceAll('\\', '/')}**/*.txt`, `!${cwd.replaceAll('\\', '/')}**/b.txt`],
cwd
});
assert.deepEqual(files.sort(), ['a/a.txt', 'b/a.txt']);

const files2 = await glob({
patterns: [`${cwd.replaceAll('\\', '/')}**/*.txt`, `!${cwd.replaceAll('\\', '/')}**/a.txt`],
cwd
});
assert.deepEqual(files2.sort(), ['a/b.txt', 'b/b.txt']);
});

test('sync version', () => {
const files = globSync(['a/*.txt'], { cwd });
assert.deepEqual(files.sort(), ['a/a.txt', 'a/b.txt']);
Expand Down

0 comments on commit b8c5a9c

Please sign in to comment.