MCPcopy
hub / github.com/rollup/plugins / getMatcherString

Function getMatcherString

packages/pluginutils/src/createFilter.ts:10–24  ·  view source on GitHub ↗
(id: string, resolutionBase: string | false | null | undefined)

Source from the content-addressed store, hash-verified

8import normalizePath from './normalizePath';
9
10function getMatcherString(id: string, resolutionBase: string | false | null | undefined) {
11 if (resolutionBase === false || isAbsolute(id) || id.startsWith('**')) {
12 return normalizePath(id);
13 }
14
15 // resolve('') is valid and will default to process.cwd()
16 const basePath = normalizePath(resolve(resolutionBase || ''))
17 // escape all possible (posix + win) path characters that might interfere with regex
18 .replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
19 // Note that we use posix.join because:
20 // 1. the basePath has been normalized to use /
21 // 2. the incoming glob (id) matcher, also uses /
22 // otherwise Node will force backslash (\) on windows
23 return posix.join(basePath, normalizePath(id));
24}
25
26const createFilter: CreateFilter = function createFilter(include?, exclude?, options?) {
27 const resolutionBase = options && options.resolve;

Callers 1

getMatcherFunction · 0.85

Calls 2

normalizePathFunction · 0.70
resolveFunction · 0.50

Tested by

no test coverage detected