MCPcopy
hub / github.com/vitejs/vite / patternToIdFilter

Function patternToIdFilter

packages/vite/src/node/plugins/pluginFilter.ts:36–55  ·  view source on GitHub ↗
(
  pattern: string | RegExp,
  cwd: string,
)

Source from the content-addressed store, hash-verified

34}
35
36function patternToIdFilter(
37 pattern: string | RegExp,
38 cwd: string,
39): PluginFilter {
40 if (pattern instanceof RegExp) {
41 return (id: string) => {
42 const normalizedId = slash(id)
43 const result = pattern.test(normalizedId)
44 pattern.lastIndex = 0
45 return result
46 }
47 }
48
49 const glob = getMatcherString(pattern, cwd)
50 const matcher = picomatch(glob, { dot: true })
51 return (id: string) => {
52 const normalizedId = slash(id)
53 return matcher(normalizedId)
54 }
55}
56
57function patternToCodeFilter(pattern: string | RegExp): PluginFilter {
58 if (pattern instanceof RegExp) {

Callers 1

createIdFilterFunction · 0.85

Calls 2

slashFunction · 0.90
getMatcherStringFunction · 0.85

Tested by

no test coverage detected