@@ -27,7 +27,7 @@ const defaultGlobParams: [PicomatchOptions] = [{dot: true}];
2727
2828export class Builder <
2929 TReturnType extends Output = PathsOutput ,
30- TGlobFunction extends GlobFunction = typeof picomatch
30+ TGlobFunction = typeof picomatch
3131> {
3232 private readonly globCache : Record < string , Matcher > = { } ;
3333 private options : Options < TGlobFunction > = {
@@ -36,9 +36,11 @@ export class Builder<
3636 pathSeparator : sep ,
3737 filters : [ ] ,
3838 } ;
39+ private globFunction ?: TGlobFunction ;
3940
4041 constructor ( options ?: Partial < Options < TGlobFunction > > ) {
4142 this . options = { ...this . options , ...options } ;
43+ this . globFunction = this . options . globFunction ;
4244 }
4345
4446 group ( ) : Builder < GroupOutput , TGlobFunction > {
@@ -127,6 +129,12 @@ export class Builder<
127129 return new APIBuilder < TReturnType > ( root || "." , this . options ) ;
128130 }
129131
132+ withGlobFunction < TFunc > ( fn : TFunc ) {
133+ // cast this since we don't have the new type params yet
134+ this . globFunction = fn as unknown as TGlobFunction ;
135+ return this as unknown as Builder < TReturnType , TFunc > ;
136+ }
137+
130138 /**
131139 * @deprecated Pass options using the constructor instead:
132140 * ```ts
@@ -141,7 +149,7 @@ export class Builder<
141149 }
142150
143151 glob ( ...patterns : string [ ] ) {
144- if ( this . options . globFunction ) {
152+ if ( this . globFunction ) {
145153 return this . globWithOptions ( patterns ) ;
146154 }
147155 return this . globWithOptions (
@@ -153,11 +161,11 @@ export class Builder<
153161 globWithOptions ( patterns : string [ ] ) : Builder < TReturnType , TGlobFunction > ;
154162 globWithOptions ( patterns : string [ ] , ...options : GlobParams < TGlobFunction > ) : Builder < TReturnType , TGlobFunction > ;
155163 globWithOptions ( patterns : string [ ] , ...options : GlobParams < TGlobFunction > | [ ] ) {
156- const globFn = this . options . globFunction || ( pm as TGlobFunction | null ) ;
164+ const globFn = ( this . globFunction || pm ) as GlobFunction | null ;
157165 /* c8 ignore next 5 */
158166 if ( ! globFn ) {
159167 throw new Error (
160- ` Please install picomatch: "npm i picomatch" to use glob matching.`
168+ ' Please specify a glob function to use glob matching.'
161169 ) ;
162170 }
163171
0 commit comments