types.d.ts
15.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
/*
* This file was automatically generated.
* DO NOT MODIFY BY HAND.
* Run `yarn special-lint-fix` to update
*/
import { Dirent } from "fs";
import { AsyncSeriesBailHook, AsyncSeriesHook, SyncHook } from "tapable";
type Alias = string | false | string[];
declare interface AliasOption {
alias: Alias;
name: string;
onlyModule?: boolean;
}
type AliasOptionNewRequest = string | false | string[];
declare interface AliasOptions {
[index: string]: AliasOptionNewRequest;
}
declare interface BaseResolveRequest {
path: string | false;
context?: object;
descriptionFilePath?: string;
descriptionFileRoot?: string;
descriptionFileData?: JsonObject;
relativePath?: string;
ignoreSymlinks?: boolean;
fullySpecified?: boolean;
__innerRequest?: string;
__innerRequest_request?: string;
__innerRequest_relativePath?: string;
}
declare class CachedInputFileSystem {
constructor(fileSystem: any, duration: number);
fileSystem: any;
lstat?: {
(arg0: string, arg1: FileSystemCallback<FileSystemStats>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
lstatSync?: (arg0: string, arg1?: object) => FileSystemStats;
stat: {
(arg0: string, arg1: FileSystemCallback<FileSystemStats>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
statSync: (arg0: string, arg1?: object) => FileSystemStats;
readdir: (
arg0: string,
arg1?:
| null
| ((
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | Dirent[]
) => void)
| ReaddirOptions
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
| "base64url"
| "latin1"
| "binary"
| "hex"
| "buffer",
arg2?: (
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | Dirent[]
) => void
) => void;
readdirSync: (
arg0: string,
arg1?: object
) => (string | Buffer)[] | FileSystemDirent[];
readFile: {
(arg0: string, arg1: FileSystemCallback<string | Buffer>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
readFileSync: (arg0: string, arg1?: object) => string | Buffer;
readJson?: {
(arg0: string, arg1: FileSystemCallback<object>): void;
(arg0: string, arg1: object, arg2: FileSystemCallback<object>): void;
};
readJsonSync?: (arg0: string, arg1?: object) => object;
readlink: {
(arg0: string, arg1: FileSystemCallback<string | Buffer>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
readlinkSync: (arg0: string, arg1?: object) => string | Buffer;
purge(what?: string | Set<string> | string[]): void;
}
declare class CloneBasenamePlugin {
constructor(
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>,
target:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>
);
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
target:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
apply(resolver: Resolver): void;
}
type ErrorWithDetail = Error & { details?: string };
declare interface ExtensionAliasOption {
alias: string | string[];
extension: string;
}
declare interface ExtensionAliasOptions {
[index: string]: string | string[];
}
declare interface FileSystem {
readFile: {
(arg0: string, arg1: FileSystemCallback<string | Buffer>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
readdir: (
arg0: string,
arg1?:
| null
| ((
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | Dirent[]
) => void)
| ReaddirOptions
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
| "base64url"
| "latin1"
| "binary"
| "hex"
| "buffer",
arg2?: (
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | Dirent[]
) => void
) => void;
readJson?: {
(arg0: string, arg1: FileSystemCallback<object>): void;
(arg0: string, arg1: object, arg2: FileSystemCallback<object>): void;
};
readlink: {
(arg0: string, arg1: FileSystemCallback<string | Buffer>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
lstat?: {
(arg0: string, arg1: FileSystemCallback<FileSystemStats>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
stat: {
(arg0: string, arg1: FileSystemCallback<FileSystemStats>): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<string | Buffer>
): void;
};
}
declare interface FileSystemCallback<T> {
(err?: null | (PossibleFileSystemError & Error), result?: T): any;
}
declare interface FileSystemDirent {
name: string | Buffer;
isDirectory: () => boolean;
isFile: () => boolean;
}
declare interface FileSystemStats {
isDirectory: () => boolean;
isFile: () => boolean;
}
declare interface Iterator<T, Z> {
(
item: T,
callback: (err?: null | Error, result?: null | Z) => void,
i: number
): void;
}
type JsonObject = { [index: string]: JsonValue } & {
[index: string]:
| undefined
| null
| string
| number
| boolean
| JsonObject
| JsonValue[];
};
type JsonValue = null | string | number | boolean | JsonObject | JsonValue[];
declare interface KnownHooks {
resolveStep: SyncHook<
[
AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>,
ResolveRequest
]
>;
noResolve: SyncHook<[ResolveRequest, Error]>;
resolve: AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>;
}
declare class LogInfoPlugin {
constructor(
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>
);
source:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
apply(resolver: Resolver): void;
}
declare interface ParsedIdentifier {
request: string;
query: string;
fragment: string;
directory: boolean;
module: boolean;
file: boolean;
internal: boolean;
}
type Plugin =
| { apply: (arg0: Resolver) => void }
| ((this: Resolver, arg1: Resolver) => void);
declare interface PnpApiImpl {
resolveToUnqualified: (arg0: string, arg1: string, arg2: object) => string;
}
declare interface PossibleFileSystemError {
code?: string;
errno?: number;
path?: string;
syscall?: string;
}
declare interface ReaddirOptions {
encoding?:
| null
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
| "base64url"
| "latin1"
| "binary"
| "hex"
| "buffer";
withFileTypes?: boolean;
}
/**
* Resolve context
*/
declare interface ResolveContext {
contextDependencies?: WriteOnlySet<string>;
/**
* files that was found on file system
*/
fileDependencies?: WriteOnlySet<string>;
/**
* dependencies that was not found on file system
*/
missingDependencies?: WriteOnlySet<string>;
/**
* set of hooks' calls. For instance, `resolve → parsedResolve → describedResolve`,
*/
stack?: Set<string>;
/**
* log function
*/
log?: (arg0: string) => void;
/**
* yield result, if provided plugins can return several results
*/
yield?: (arg0: ResolveRequest) => void;
}
declare interface ResolveFunction {
(context: object, path: string, request: string): string | false;
(path: string, request: string): string | false;
}
declare interface ResolveFunctionAsync {
(
context: object,
path: string,
request: string,
resolveContext: ResolveContext,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
(
context: object,
path: string,
request: string,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
(
path: string,
request: string,
resolveContext: ResolveContext,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
(
path: string,
request: string,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
}
declare interface ResolveOptions {
alias: AliasOption[];
fallback: AliasOption[];
aliasFields: Set<string | string[]>;
extensionAlias: ExtensionAliasOption[];
cachePredicate: (arg0: ResolveRequest) => boolean;
cacheWithContext: boolean;
/**
* A list of exports field condition names.
*/
conditionNames: Set<string>;
descriptionFiles: string[];
enforceExtension: boolean;
exportsFields: Set<string | string[]>;
importsFields: Set<string | string[]>;
extensions: Set<string>;
fileSystem: FileSystem;
unsafeCache: false | object;
symlinks: boolean;
resolver?: Resolver;
modules: (string | string[])[];
mainFields: { name: string[]; forceRelative: boolean }[];
mainFiles: Set<string>;
plugins: Plugin[];
pnpApi: null | PnpApiImpl;
roots: Set<string>;
fullySpecified: boolean;
resolveToContext: boolean;
restrictions: Set<string | RegExp>;
preferRelative: boolean;
preferAbsolute: boolean;
}
type ResolveOptionsOptionalFS = Omit<UserResolveOptions, "fileSystem"> &
Partial<Pick<UserResolveOptions, "fileSystem">>;
type ResolveRequest = BaseResolveRequest & Partial<ParsedIdentifier>;
declare abstract class Resolver {
fileSystem: FileSystem;
options: ResolveOptions;
hooks: KnownHooks;
ensureHook(
name:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>
): AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
getHook(
name:
| string
| AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>
): AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>;
resolveSync(context: object, path: string, request: string): string | false;
resolve(
context: object,
path: string,
request: string,
resolveContext: ResolveContext,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
doResolve(
hook: AsyncSeriesBailHook<
[ResolveRequest, ResolveContext],
null | ResolveRequest
>,
request: ResolveRequest,
message: null | string,
resolveContext: ResolveContext,
callback: (err?: null | Error, result?: ResolveRequest) => void
): void;
parse(identifier: string): ParsedIdentifier;
isModule(path: string): boolean;
isPrivate(path: string): boolean;
isDirectory(path: string): boolean;
join(path: string, request: string): string;
normalize(path: string): string;
}
declare interface UserResolveOptions {
/**
* A list of module alias configurations or an object which maps key to value
*/
alias?: AliasOptions | AliasOption[];
/**
* A list of module alias configurations or an object which maps key to value, applied only after modules option
*/
fallback?: AliasOptions | AliasOption[];
/**
* An object which maps extension to extension aliases
*/
extensionAlias?: ExtensionAliasOptions;
/**
* A list of alias fields in description files
*/
aliasFields?: (string | string[])[];
/**
* A function which decides whether a request should be cached or not. An object is passed with at least `path` and `request` properties.
*/
cachePredicate?: (arg0: ResolveRequest) => boolean;
/**
* Whether or not the unsafeCache should include request context as part of the cache key.
*/
cacheWithContext?: boolean;
/**
* A list of description files to read from
*/
descriptionFiles?: string[];
/**
* A list of exports field condition names.
*/
conditionNames?: string[];
/**
* Enforce that a extension from extensions must be used
*/
enforceExtension?: boolean;
/**
* A list of exports fields in description files
*/
exportsFields?: (string | string[])[];
/**
* A list of imports fields in description files
*/
importsFields?: (string | string[])[];
/**
* A list of extensions which should be tried for files
*/
extensions?: string[];
/**
* The file system which should be used
*/
fileSystem: FileSystem;
/**
* Use this cache object to unsafely cache the successful requests
*/
unsafeCache?: boolean | object;
/**
* Resolve symlinks to their symlinked location
*/
symlinks?: boolean;
/**
* A prepared Resolver to which the plugins are attached
*/
resolver?: Resolver;
/**
* A list of directories to resolve modules from, can be absolute path or folder name
*/
modules?: string | string[];
/**
* A list of main fields in description files
*/
mainFields?: (
| string
| string[]
| { name: string | string[]; forceRelative: boolean }
)[];
/**
* A list of main files in directories
*/
mainFiles?: string[];
/**
* A list of additional resolve plugins which should be applied
*/
plugins?: Plugin[];
/**
* A PnP API that should be used - null is "never", undefined is "auto"
*/
pnpApi?: null | PnpApiImpl;
/**
* A list of root paths
*/
roots?: string[];
/**
* The request is already fully specified and no extensions or directories are resolved for it
*/
fullySpecified?: boolean;
/**
* Resolve to a context instead of a file
*/
resolveToContext?: boolean;
/**
* A list of resolve restrictions
*/
restrictions?: (string | RegExp)[];
/**
* Use only the sync constraints of the file system calls
*/
useSyncFileSystemCalls?: boolean;
/**
* Prefer to resolve module requests as relative requests before falling back to modules
*/
preferRelative?: boolean;
/**
* Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots
*/
preferAbsolute?: boolean;
}
declare interface WriteOnlySet<T> {
add: (item: T) => void;
}
declare function exports(
context: object,
path: string,
request: string,
resolveContext: ResolveContext,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
declare function exports(
context: object,
path: string,
request: string,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
declare function exports(
path: string,
request: string,
resolveContext: ResolveContext,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
declare function exports(
path: string,
request: string,
callback: (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void
): void;
declare namespace exports {
export const sync: ResolveFunction;
export function create(
options: ResolveOptionsOptionalFS
): ResolveFunctionAsync;
export namespace create {
export const sync: (options: ResolveOptionsOptionalFS) => ResolveFunction;
}
export namespace ResolverFactory {
export let createResolver: (options: UserResolveOptions) => Resolver;
}
export const forEachBail: <T, Z>(
array: T[],
iterator: Iterator<T, Z>,
callback: (err?: null | Error, result?: null | Z) => void
) => void;
export type ResolveCallback = (
err: null | ErrorWithDetail,
res?: string | false,
req?: ResolveRequest
) => void;
export {
CachedInputFileSystem,
CloneBasenamePlugin,
LogInfoPlugin,
ResolveOptionsOptionalFS,
PnpApiImpl as PnpApi,
Resolver,
FileSystem,
ResolveContext,
ResolveRequest,
Plugin,
UserResolveOptions as ResolveOptions,
ResolveFunctionAsync,
ResolveFunction
};
}
export = exports;