From d9d2900469ade11eb59aecc3cd282b9cbc7af8f3 Mon Sep 17 00:00:00 2001 From: Lars den Bakker Date: Thu, 6 Aug 2020 16:59:58 +0200 Subject: [PATCH] fix(pluginutils)!: don't add cwd to absolute or patterns that start with a glob (#517) --- packages/pluginutils/src/createFilter.ts | 4 ++-- packages/pluginutils/test/createFilter.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/pluginutils/src/createFilter.ts b/packages/pluginutils/src/createFilter.ts index 16882d0e9..09ca831d2 100755 --- a/packages/pluginutils/src/createFilter.ts +++ b/packages/pluginutils/src/createFilter.ts @@ -1,4 +1,4 @@ -import { resolve, sep, posix } from 'path'; +import { resolve, sep, posix, isAbsolute } from 'path'; import pm from 'picomatch'; @@ -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; } diff --git a/packages/pluginutils/test/createFilter.ts b/packages/pluginutils/test/createFilter.ts index ffa3bc76b..7a68ca999 100755 --- a/packages/pluginutils/test/createFilter.ts +++ b/packages/pluginutils/test/createFilter.ts @@ -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'))); +});