@@ -33,23 +33,29 @@ export type PresetConversionContext = {
3333type StringOrRegExp = string | RegExp
3434type Matcher = ( value : string ) => boolean
3535
36- function compilePattern ( pattern : StringOrRegExp ) : Matcher {
36+ function compilePattern ( pattern : StringOrRegExp , isPath : boolean ) : Matcher {
3737 if ( pattern instanceof RegExp ) {
3838 return ( value ) => pattern . test ( value )
3939 }
40- return picomatch ( pattern )
40+ if ( isPath ) {
41+ return picomatch ( pattern )
42+ }
43+ return ( value ) => value . includes ( pattern )
4144}
4245
43- function compilePatterns ( patterns : StringOrRegExp [ ] ) : Matcher {
44- const matchers = patterns . map ( compilePattern )
46+ function compilePatterns ( patterns : StringOrRegExp [ ] , isPath : boolean ) : Matcher {
47+ const matchers = patterns . map ( ( p ) => compilePattern ( p , isPath ) )
4548 return ( value ) => matchers . some ( ( m ) => m ( value ) )
4649}
4750
4851/**
4952 * Pre-compile a GeneralHookFilter into a single matcher function.
5053 * Returns undefined when the filter matches everything.
5154 */
52- function compileGeneralHookFilter ( filter : GeneralHookFilter | undefined ) : Matcher | undefined {
55+ function compileGeneralHookFilter (
56+ filter : GeneralHookFilter | undefined ,
57+ isPath : boolean ,
58+ ) : Matcher | undefined {
5359 if ( filter == null ) return undefined
5460
5561 let include : StringOrRegExp [ ] | undefined
@@ -64,8 +70,8 @@ function compileGeneralHookFilter(filter: GeneralHookFilter | undefined): Matche
6470 exclude = filter . exclude != null ? arrayify ( filter . exclude ) : undefined
6571 }
6672
67- const includeMatcher = include ? compilePatterns ( include ) : undefined
68- const excludeMatcher = exclude ? compilePatterns ( exclude ) : undefined
73+ const includeMatcher = include ? compilePatterns ( include , isPath ) : undefined
74+ const excludeMatcher = exclude ? compilePatterns ( exclude , isPath ) : undefined
6975
7076 if ( includeMatcher && excludeMatcher ) {
7177 return ( value ) => ! excludeMatcher ( value ) && includeMatcher ( value )
@@ -95,9 +101,9 @@ export function compilePresetFilter(
95101 filter : RolldownBabelPreset [ 'rolldown' ] [ 'filter' ] ,
96102) : CompiledPresetFilter | undefined {
97103 if ( ! filter ) return undefined
98- const matchId = compileGeneralHookFilter ( filter . id )
104+ const matchId = compileGeneralHookFilter ( filter . id , true )
99105 const matchModuleType = compileModuleTypeFilter ( filter . moduleType )
100- const matchCode = compileGeneralHookFilter ( filter . code )
106+ const matchCode = compileGeneralHookFilter ( filter . code , false )
101107 if ( ! matchId && ! matchModuleType && ! matchCode ) return undefined
102108 return ( ctx ) =>
103109 ( ! matchId || matchId ( ctx . id ) ) &&
0 commit comments