Skip to content

Commit

Permalink
fix(pluginutils)!: don't add cwd to absolute or patterns that start w…
Browse files Browse the repository at this point in the history
…ith a glob (#517)
  • Loading branch information
LarsDenBakker committed Aug 6, 2020
1 parent b819a0f commit d9d2900
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/pluginutils/src/createFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve, sep, posix } from 'path';
import { resolve, sep, posix, isAbsolute } from 'path';

import pm from 'picomatch';

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

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

Expand Down
13 changes: 13 additions & 0 deletions packages/pluginutils/test/createFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,16 @@ test('handles relative paths', (t) => {
t.truthy(filter(resolve('a.js')));
t.falsy(filter(resolve('foo/a.js')));
});

test('does not add current working directory when pattern is an absolute path', (t) => {
const filter = createFilter([resolve('..', '..', '*')]);
t.truthy(filter(resolve('..', '..', 'a')));
t.truthy(filter(resolve('..', '..', 'b')));
t.falsy(filter(resolve('..', 'c')));
});

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')));
});

0 comments on commit d9d2900

Please sign in to comment.