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(pluginutils): add current working dirctory when pattern starts with one * #1547

Merged
merged 1 commit into from
Aug 13, 2023
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
2 changes: 1 addition & 1 deletion packages/pluginutils/src/createFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ensureArray from './utils/ensureArray';
import normalizePath from './normalizePath';

function getMatcherString(id: string, resolutionBase: string | false | null | undefined) {
if (resolutionBase === false || isAbsolute(id) || id.startsWith('*')) {
if (resolutionBase === false || isAbsolute(id) || id.startsWith('**')) {
return normalizePath(id);
}

Expand Down
20 changes: 14 additions & 6 deletions packages/pluginutils/test/createFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ test('does not add current working directory when pattern is an absolute path',
t.falsy(filter(resolve('..', 'c')));
});

test('does not add current working directory when pattern starts with character **', (t) => {
const filter = createFilter(['**/*']);

t.truthy(filter(resolve('a')));
t.truthy(filter(resolve('..', '..', 'a')));
});

test('add current working directory when pattern starts with one *', (t) => {
const filter = createFilter([`*`]);

t.truthy(filter(resolve('a')));
t.falsy(filter(resolve('..', '..', 'a')));
});

test('normalizes path when pattern is an absolute path', (t) => {
const filterPosix = createFilter([`${resolve('.')}/*`]);
const filterWin = createFilter([`${resolve('.')}\\*`]);
Expand Down Expand Up @@ -161,9 +175,3 @@ test('normalizes path when pattern has resolution base', (t) => {
t.truthy(filterPosix(resolve('test/a')));
t.truthy(filterWin(resolve('test/a')));
});

test('does not add current working directory when pattern starts with a glob', (t) => {
const filter = createFilter(['**/*']);
t.truthy(filter(resolve('a')));
t.truthy(filter(resolve('..', '..', 'a')));
});