@@ -19,35 +19,36 @@ import type {
1919} from "./validation/options" ;
2020
2121import { resolveBrowserslistConfigFile } from "./resolve-targets" ;
22+ import type { PluginAPI , PresetAPI } from "./helpers/config-api" ;
2223
2324// Represents a config object and functions to lazily load the descriptors
2425// for the plugins and presets so we don't load the plugins/presets unless
2526// the options object actually ends up being applicable.
2627export type OptionsAndDescriptors = {
2728 options : ValidatedOptions ;
28- plugins : ( ) => Handler < Array < UnloadedDescriptor > > ;
29- presets : ( ) => Handler < Array < UnloadedDescriptor > > ;
29+ plugins : ( ) => Handler < Array < UnloadedDescriptor < PluginAPI > > > ;
30+ presets : ( ) => Handler < Array < UnloadedDescriptor < PresetAPI > > > ;
3031} ;
3132
3233// Represents a plugin or presets at a given location in a config object.
3334// At this point these have been resolved to a specific object or function,
3435// but have not yet been executed to call functions with options.
35- export type UnloadedDescriptor = {
36+ export interface UnloadedDescriptor < API , Options = { } | undefined | false > {
3637 name : string | undefined ;
37- value : any | Function ;
38- options : { } | undefined | false ;
38+ value : object | ( ( api : API , options : Options , dirname : string ) => unknown ) ;
39+ options : Options ;
3940 dirname : string ;
4041 alias : string ;
4142 ownPass ?: boolean ;
4243 file ?: {
4344 request : string ;
4445 resolved : string ;
4546 } ;
46- } ;
47+ }
4748
48- function isEqualDescriptor (
49- a : UnloadedDescriptor ,
50- b : UnloadedDescriptor ,
49+ function isEqualDescriptor < API > (
50+ a : UnloadedDescriptor < API > ,
51+ b : UnloadedDescriptor < API > ,
5152) : boolean {
5253 return (
5354 a . name === b . name &&
@@ -150,7 +151,7 @@ const createCachedPresetDescriptors = makeWeakCacheSync(
150151 return makeStrongCacheSync ( ( alias : string ) =>
151152 makeStrongCache ( function * (
152153 passPerPreset : boolean ,
153- ) : Handler < Array < UnloadedDescriptor > > {
154+ ) : Handler < Array < UnloadedDescriptor < PresetAPI > > > {
154155 const descriptors = yield * createPresetDescriptors (
155156 items ,
156157 dirname ,
@@ -174,7 +175,7 @@ const createCachedPluginDescriptors = makeWeakCacheSync(
174175 const dirname = cache . using ( dir => dir ) ;
175176 return makeStrongCache ( function * (
176177 alias : string ,
177- ) : Handler < Array < UnloadedDescriptor > > {
178+ ) : Handler < Array < UnloadedDescriptor < PluginAPI > > > {
178179 const descriptors = yield * createPluginDescriptors ( items , dirname , alias ) ;
179180 return descriptors . map (
180181 // Items are cached using the overall plugin array identity when
@@ -197,9 +198,9 @@ const DEFAULT_OPTIONS = {};
197198 * cache, or else returns the input descriptor and adds it to the cache for
198199 * next time.
199200 */
200- function loadCachedDescriptor (
201- cache : WeakMap < { } | Function , WeakMap < { } , Array < UnloadedDescriptor > > > ,
202- desc : UnloadedDescriptor ,
201+ function loadCachedDescriptor < API > (
202+ cache : WeakMap < { } | Function , WeakMap < { } , Array < UnloadedDescriptor < API > > > > ,
203+ desc : UnloadedDescriptor < API > ,
203204) {
204205 const { value, options = DEFAULT_OPTIONS } = desc ;
205206 if ( options === false ) return desc ;
@@ -235,7 +236,7 @@ function* createPresetDescriptors(
235236 dirname : string ,
236237 alias : string ,
237238 passPerPreset : boolean ,
238- ) : Handler < Array < UnloadedDescriptor > > {
239+ ) : Handler < Array < UnloadedDescriptor < PresetAPI > > > {
239240 return yield * createDescriptors (
240241 "preset" ,
241242 items ,
@@ -249,17 +250,17 @@ function* createPluginDescriptors(
249250 items : PluginList ,
250251 dirname : string ,
251252 alias : string ,
252- ) : Handler < Array < UnloadedDescriptor > > {
253+ ) : Handler < Array < UnloadedDescriptor < PluginAPI > > > {
253254 return yield * createDescriptors ( "plugin" , items , dirname , alias ) ;
254255}
255256
256- function * createDescriptors (
257+ function * createDescriptors < API > (
257258 type : "plugin" | "preset" ,
258259 items : PluginList ,
259260 dirname : string ,
260261 alias : string ,
261262 ownPass ?: boolean ,
262- ) : Handler < Array < UnloadedDescriptor > > {
263+ ) : Handler < Array < UnloadedDescriptor < API > > > {
263264 const descriptors = yield * gensync . all (
264265 items . map ( ( item , index ) =>
265266 createDescriptor ( item , dirname , {
@@ -278,7 +279,7 @@ function* createDescriptors(
278279/**
279280 * Given a plugin/preset item, resolve it into a standard format.
280281 */
281- export function * createDescriptor (
282+ export function * createDescriptor < API > (
282283 pair : PluginItem ,
283284 dirname : string ,
284285 {
@@ -290,7 +291,7 @@ export function* createDescriptor(
290291 alias : string ;
291292 ownPass ?: boolean ;
292293 } ,
293- ) : Handler < UnloadedDescriptor > {
294+ ) : Handler < UnloadedDescriptor < API > > {
294295 const desc = getItemDescriptor ( pair ) ;
295296 if ( desc ) {
296297 return desc ;
@@ -365,7 +366,7 @@ export function* createDescriptor(
365366 } ;
366367}
367368
368- function assertNoDuplicates ( items : Array < UnloadedDescriptor > ) : void {
369+ function assertNoDuplicates < API > ( items : Array < UnloadedDescriptor < API > > ) : void {
369370 const map = new Map ( ) ;
370371
371372 for ( const item of items ) {
0 commit comments