Skip to content

Commit d9d2900

Browse files
fix(pluginutils)!: don't add cwd to absolute or patterns that start with a glob (#517)
1 parent b819a0f commit d9d2900

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/pluginutils/src/createFilter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolve, sep, posix } from 'path';
1+
import { resolve, sep, posix, isAbsolute } from 'path';
22

33
import pm from 'picomatch';
44

@@ -7,7 +7,7 @@ import { CreateFilter } from '../types';
77
import ensureArray from './utils/ensureArray';
88

99
function getMatcherString(id: string, resolutionBase: string | false | null | undefined) {
10-
if (resolutionBase === false) {
10+
if (resolutionBase === false || isAbsolute(id) || id.startsWith('*')) {
1111
return id;
1212
}
1313

packages/pluginutils/test/createFilter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,16 @@ test('handles relative paths', (t) => {
124124
t.truthy(filter(resolve('a.js')));
125125
t.falsy(filter(resolve('foo/a.js')));
126126
});
127+
128+
test('does not add current working directory when pattern is an absolute path', (t) => {
129+
const filter = createFilter([resolve('..', '..', '*')]);
130+
t.truthy(filter(resolve('..', '..', 'a')));
131+
t.truthy(filter(resolve('..', '..', 'b')));
132+
t.falsy(filter(resolve('..', 'c')));
133+
});
134+
135+
test('does not add current working directory when pattern starts with a glob', (t) => {
136+
const filter = createFilter(['**/*']);
137+
t.truthy(filter(resolve('a')));
138+
t.truthy(filter(resolve('..', '..', 'a')));
139+
});

0 commit comments

Comments
 (0)