Skip to content

Commit

Permalink
fix(pluginutils): Escape glob characters in folder (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods authored and shellscape committed Dec 20, 2019
1 parent ad861da commit a93de9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/pluginutils/src/createFilter.ts
@@ -1,16 +1,22 @@
import { resolve, sep } from 'path';
import { resolve, join, sep } from 'path';

import mm from 'micromatch';

import { CreateFilter } from '../types';

import ensureArray from './utils/ensureArray';

const ESCAPE_IN_PATH = '()+@!'

function getMatcherString(id: string, resolutionBase: string | false | null | undefined) {
if (resolutionBase === false) {
return id;
}
return resolve(...(typeof resolutionBase === 'string' ? [resolutionBase, id] : [id]));
let basePath = typeof resolutionBase === 'string' ? resolve(resolutionBase) : process.cwd();
for (const char of ESCAPE_IN_PATH) {
basePath = basePath.replace(new RegExp(`\\${char}`, 'g'), `\\${char}`);
}
return join(basePath, id);
}

const createFilter: CreateFilter = function createFilter(include?, exclude?, options?) {
Expand Down
10 changes: 10 additions & 0 deletions packages/pluginutils/test/createFilter.ts
Expand Up @@ -4,6 +4,8 @@ import test from 'ava';

import { createFilter } from '../';

test.beforeEach(() => process.chdir(__dirname));

test('includes by default', (t) => {
const filter = createFilter();
t.truthy(filter(resolve('x')));
Expand Down Expand Up @@ -107,3 +109,11 @@ test('includes names starting with a "."', (t) => {
t.truthy(filter(resolve('.a')));
t.truthy(filter(resolve('.x/a')));
});

test.serial('includes names containing parenthesis', (t) => {
process.chdir(resolve(__dirname, 'fixtures/folder-with (parens)'));
const filter = createFilter(['*.ts+(|x)', '**/*.ts+(|x)'], ['*.d.ts', '**/*.d.ts']);
t.truthy(filter(resolve('folder (test)/src/main.tsx')));
t.truthy(filter(resolve('.x/(test)a.ts')));
t.falsy(filter(resolve('.x/(test)a.d.ts')));
});
Empty file.

0 comments on commit a93de9d

Please sign in to comment.