-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathloader.d.ts
596 lines (596 loc) · 21.6 KB
/
loader.d.ts
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
declare const _amdLoaderGlobal: typeof globalThis;
declare var module: {
exports: any;
};
declare var process: {
platform: string;
type: string;
mainModule: string;
arch: string;
argv: string[];
versions: {
node: string;
electron: string;
};
};
declare var require: {
nodeRequire(module: string): any;
};
declare var global: object;
declare const _commonjsGlobal: object;
declare namespace AMDLoader {
const global: any;
class Environment {
private _detected;
private _isWindows;
private _isNode;
private _isElectronRenderer;
private _isWebWorker;
private _isElectronNodeIntegrationWebWorker;
get isWindows(): boolean;
get isNode(): boolean;
get isElectronRenderer(): boolean;
get isWebWorker(): boolean;
get isElectronNodeIntegrationWebWorker(): boolean;
constructor();
private _detect;
private static _isWindows;
}
}
declare namespace AMDLoader {
const enum LoaderEventType {
LoaderAvailable = 1,
BeginLoadingScript = 10,
EndLoadingScriptOK = 11,
EndLoadingScriptError = 12,
BeginInvokeFactory = 21,
EndInvokeFactory = 22,
NodeBeginEvaluatingScript = 31,
NodeEndEvaluatingScript = 32,
NodeBeginNativeRequire = 33,
NodeEndNativeRequire = 34,
CachedDataFound = 60,
CachedDataMissed = 61,
CachedDataRejected = 62,
CachedDataCreated = 63
}
class LoaderEvent {
type: LoaderEventType;
timestamp: number;
detail: string;
constructor(type: LoaderEventType, detail: string, timestamp: number);
}
interface ILoaderEventRecorder {
record(type: LoaderEventType, detail: string): void;
getEvents(): LoaderEvent[];
}
class LoaderEventRecorder implements ILoaderEventRecorder {
private _events;
constructor(loaderAvailableTimestamp: number);
record(type: LoaderEventType, detail: string): void;
getEvents(): LoaderEvent[];
}
class NullLoaderEventRecorder implements ILoaderEventRecorder {
static INSTANCE: NullLoaderEventRecorder;
record(type: LoaderEventType, detail: string): void;
getEvents(): LoaderEvent[];
}
}
declare namespace AMDLoader {
class Utilities {
/**
* This method does not take care of / vs \
*/
static fileUriToFilePath(isWindows: boolean, uri: string): string;
static startsWith(haystack: string, needle: string): boolean;
static endsWith(haystack: string, needle: string): boolean;
static containsQueryString(url: string): boolean;
/**
* Does `url` start with http:// or https:// or file:// or / ?
*/
static isAbsolutePath(url: string): boolean;
static forEachProperty(obj: any, callback: (key: string, value: any) => void): void;
static isEmpty(obj: any): boolean;
static recursiveClone(obj: any): any;
private static NEXT_ANONYMOUS_ID;
static generateAnonymousModule(): string;
static isAnonymousModule(id: string): boolean;
private static PERFORMANCE_NOW_PROBED;
private static HAS_PERFORMANCE_NOW;
static getHighPerformanceTimestamp(): number;
}
}
declare namespace AMDLoader {
interface AnnotatedLoadingError extends Error {
phase: 'loading';
moduleId: string;
neededBy: string[];
}
interface AnnotatedFactoryError extends Error {
phase: 'factory';
moduleId: string;
neededBy: string[];
}
interface AnnotatedValidationError extends Error {
phase: 'configuration';
}
type AnnotatedError = AnnotatedLoadingError | AnnotatedFactoryError | AnnotatedValidationError;
function ensureError<T extends Error>(err: any): T;
/**
* The signature for the loader's AMD "define" function.
*/
interface IDefineFunc {
(id: 'string', dependencies: string[], callback: any): void;
(id: 'string', callback: any): void;
(dependencies: string[], callback: any): void;
(callback: any): void;
amd: {
jQuery: boolean;
};
}
/**
* The signature for the loader's AMD "require" function.
*/
interface IRequireFunc {
(module: string): any;
(config: any): void;
(modules: string[], callback: Function): void;
(modules: string[], callback: Function, errorback: (err: any) => void): void;
config(params: IConfigurationOptions, shouldOverwrite?: boolean): void;
getConfig(): IConfigurationOptions;
/**
* Non standard extension to reset completely the loader state. This is used for running amdjs tests
*/
reset(): void;
/**
* Non standard extension to fetch loader state for building purposes.
*/
getBuildInfo(): IBuildModuleInfo[] | null;
/**
* Non standard extension to fetch loader events
*/
getStats(): LoaderEvent[];
/**
* The define function
*/
define(id: 'string', dependencies: string[], callback: any): void;
define(id: 'string', callback: any): void;
define(dependencies: string[], callback: any): void;
define(callback: any): void;
moduleManager?: ModuleManager;
}
interface IModuleConfiguration {
[key: string]: any;
}
interface INodeRequire {
(nodeModule: string): any;
main: {
filename: string;
};
}
interface INodeCachedDataConfiguration {
/**
* Directory path in which cached is stored.
*/
path: string;
/**
* Seed when generating names of cache files.
*/
seed?: string;
/**
* Optional delay for filesystem write/delete operations
*/
writeDelay?: number;
}
interface IConfigurationOptions {
/**
* Allow module ids to end with .js
*/
allowJsExtension?: boolean;
/**
* The prefix that will be aplied to all modules when they are resolved to a location
*/
baseUrl?: string;
/**
* Redirect rules for modules. The redirect rules will affect the module ids themselves
*/
paths?: {
[path: string]: any;
};
/**
* Per-module configuration
*/
config?: {
[moduleId: string]: IModuleConfiguration;
};
/**
* Catch errors when invoking the module factories
*/
catchError?: boolean;
/**
* Record statistics
*/
recordStats?: boolean;
/**
* The suffix that will be aplied to all modules when they are resolved to a location
*/
urlArgs?: string;
/**
* Callback that will be called when errors are encountered
*/
onError?: (err: AnnotatedError) => void;
/**
* The loader will issue warnings when duplicate modules are encountered.
* This list will inhibit those warnings if duplicate modules are expected.
*/
ignoreDuplicateModules?: string[];
/**
* Flag to indicate if current execution is as part of a build. Used by plugins
*/
isBuild?: boolean;
/**
* Normally, during a build, no module factories are invoked. This can be used
* to forcefully execute a module's factory.
*/
buildForceInvokeFactory?: {
[moduleId: string]: boolean;
};
/**
* Content Security Policy nonce value used to load child scripts.
*/
cspNonce?: string;
/**
* If running inside an electron renderer, prefer using <script> tags to load code.
* Defaults to false.
*/
preferScriptTags?: boolean;
/**
* A trusted types policy which will be used to create TrustedScriptURL-values.
* https://w3c.github.io/webappsec-trusted-types/dist/spec/#introduction.
*/
trustedTypesPolicy?: {
createScriptURL(value: string): string & object;
createScript(_: string, value: string): string;
};
/**
* A regex to help determine if a module is an AMD module or a node module.
* If defined, then all amd modules in the system must match this regular expression.
*/
amdModulesPattern?: RegExp;
/**
* The main entry point node's require
*/
nodeRequire?: INodeRequire;
/**
* An optional transformation applied to the source before it is loaded in node's vm
*/
nodeInstrumenter?: (source: string, vmScriptSrc: string) => string;
/**
* Support v8 cached data (http://v8project.blogspot.co.uk/2015/07/code-caching.html)
*/
nodeCachedData?: INodeCachedDataConfiguration;
}
interface IValidatedConfigurationOptions extends IConfigurationOptions {
allowJsExtension: boolean;
baseUrl: string;
paths: {
[path: string]: any;
};
config: {
[moduleId: string]: IModuleConfiguration;
};
catchError: boolean;
recordStats: boolean;
urlArgs: string;
onError: (err: AnnotatedError) => void;
ignoreDuplicateModules: string[];
isBuild: boolean;
cspNonce: string;
preferScriptTags: boolean;
}
class ConfigurationOptionsUtil {
/**
* Ensure configuration options make sense
*/
private static validateConfigurationOptions;
static mergeConfigurationOptions(overwrite?: IConfigurationOptions | null, base?: IConfigurationOptions | null): IValidatedConfigurationOptions;
}
class Configuration {
private readonly _env;
private options;
/**
* Generated from the `ignoreDuplicateModules` configuration option.
*/
private ignoreDuplicateModulesMap;
/**
* Generated from the `paths` configuration option. These are sorted with the longest `from` first.
*/
private sortedPathsRules;
constructor(env: Environment, options?: IConfigurationOptions);
private _createIgnoreDuplicateModulesMap;
private _createSortedPathsRules;
/**
* Clone current configuration and overwrite options selectively.
* @param options The selective options to overwrite with.
* @result A new configuration
*/
cloneAndMerge(options?: IConfigurationOptions): Configuration;
/**
* Get current options bag. Useful for passing it forward to plugins.
*/
getOptionsLiteral(): IValidatedConfigurationOptions;
private _applyPaths;
private _addUrlArgsToUrl;
private _addUrlArgsIfNecessaryToUrl;
private _addUrlArgsIfNecessaryToUrls;
/**
* Transform a module id to a location. Appends .js to module ids
*/
moduleIdToPaths(moduleIdOrPath: string): string[];
/**
* Transform a module id or url to a location.
*/
requireToUrl(url: string): string;
/**
* Flag to indicate if current execution is as part of a build.
*/
isBuild(): boolean;
shouldInvokeFactory(strModuleId: string): boolean;
/**
* Test if module `moduleId` is expected to be defined multiple times
*/
isDuplicateMessageIgnoredFor(moduleId: string): boolean;
/**
* Get the configuration settings for the provided module id
*/
getConfigForModule(moduleId: string): IModuleConfiguration | undefined;
/**
* Should errors be caught when executing module factories?
*/
shouldCatchError(): boolean;
/**
* Should statistics be recorded?
*/
shouldRecordStats(): boolean;
/**
* Forward an error to the error handler.
*/
onError(err: AnnotatedError): void;
}
}
declare namespace AMDLoader {
interface IModuleManager {
getGlobalAMDDefineFunc(): IDefineFunc;
getGlobalAMDRequireFunc(): IRequireFunc;
getConfig(): Configuration;
enqueueDefineAnonymousModule(dependencies: string[], callback: any): void;
getRecorder(): ILoaderEventRecorder;
}
interface IScriptLoader {
load(moduleManager: IModuleManager, scriptPath: string, loadCallback: () => void, errorCallback: (err: any) => void): void;
}
function ensureRecordedNodeRequire(recorder: ILoaderEventRecorder, _nodeRequire: (nodeModule: string) => any): (nodeModule: string) => any;
function createScriptLoader(env: Environment): IScriptLoader;
}
declare namespace AMDLoader {
interface ILoaderPlugin {
load: (pluginParam: string, parentRequire: IRelativeRequire, loadCallback: IPluginLoadCallback, options: IConfigurationOptions) => void;
}
interface IDefineCall {
stack: string | null;
dependencies: string[];
callback: any;
}
interface IRelativeRequire {
(dependencies: string[], callback: Function, errorback?: (error: Error) => void): void;
(dependency: string): any;
toUrl(id: string): string;
getStats(): LoaderEvent[];
hasDependencyCycle(): boolean;
getChecksums(): {
[scriptSrc: string]: string;
};
config(params: IConfigurationOptions, shouldOverwrite?: boolean): void;
}
interface IPluginLoadCallback {
(value: any): void;
error(err: any): void;
}
interface IPluginWriteCallback {
(contents: string): void;
getEntryPoint(): string;
asModule(moduleId: string, contents: string): void;
}
interface IPluginWriteFileCallback {
(filename: string, contents: string): void;
getEntryPoint(): string;
asModule(moduleId: string, contents: string): void;
}
class ModuleIdResolver {
static ROOT: ModuleIdResolver;
private fromModulePath;
constructor(fromModuleId: string);
/**
* Normalize 'a/../name' to 'name', etc.
*/
static _normalizeModuleId(moduleId: string): string;
/**
* Resolve relative module ids
*/
resolveModule(moduleId: string): string;
}
class Module {
readonly id: ModuleId;
readonly strId: string;
readonly dependencies: Dependency[] | null;
private readonly _callback;
private readonly _errorback;
readonly moduleIdResolver: ModuleIdResolver | null;
exports: any;
error: AnnotatedError | null;
exportsPassedIn: boolean;
unresolvedDependenciesCount: number;
private _isComplete;
constructor(id: ModuleId, strId: string, dependencies: Dependency[], callback: any, errorback: ((err: AnnotatedError) => void) | null | undefined, moduleIdResolver: ModuleIdResolver | null);
private static _safeInvokeFunction;
private static _invokeFactory;
complete(recorder: ILoaderEventRecorder, config: Configuration, dependenciesValues: any[], inversedependenciesProvider: (moduleId: number) => string[]): void;
/**
* One of the direct dependencies or a transitive dependency has failed to load.
*/
onDependencyError(err: AnnotatedError): boolean;
/**
* Is the current module complete?
*/
isComplete(): boolean;
}
interface IPosition {
line: number;
col: number;
}
interface IBuildModuleInfo {
id: string;
path: string | null;
defineLocation: IPosition | null;
dependencies: string[];
shim: string | null;
exports: any;
}
const enum ModuleId {
EXPORTS = 0,
MODULE = 1,
REQUIRE = 2
}
class RegularDependency {
static EXPORTS: RegularDependency;
static MODULE: RegularDependency;
static REQUIRE: RegularDependency;
readonly id: ModuleId;
constructor(id: ModuleId);
}
class PluginDependency {
readonly id: ModuleId;
readonly pluginId: ModuleId;
readonly pluginParam: string;
constructor(id: ModuleId, pluginId: ModuleId, pluginParam: string);
}
type Dependency = RegularDependency | PluginDependency;
class ModuleManager {
private readonly _env;
private readonly _scriptLoader;
private readonly _loaderAvailableTimestamp;
private readonly _defineFunc;
private readonly _requireFunc;
private _moduleIdProvider;
private _config;
private _hasDependencyCycle;
/**
* map of module id => module.
* If a module is found in _modules, its code has been loaded, but
* not necessary all its dependencies have been resolved
*/
private _modules2;
/**
* Set of module ids => true
* If a module is found in _knownModules, a call has been made
* to the scriptLoader to load its code or a call will be made
* This is mainly used as a flag to not try loading the same module twice
*/
private _knownModules2;
/**
* map of module id => array [module id]
*/
private _inverseDependencies2;
/**
* Hash map of module id => array [ { moduleId, pluginParam } ]
*/
private _inversePluginDependencies2;
/**
* current annonymous received define call, but not yet processed
*/
private _currentAnonymousDefineCall;
private _recorder;
private _buildInfoPath;
private _buildInfoDefineStack;
private _buildInfoDependencies;
constructor(env: Environment, scriptLoader: IScriptLoader, defineFunc: IDefineFunc, requireFunc: IRequireFunc | null, loaderAvailableTimestamp?: number);
reset(): ModuleManager;
getGlobalAMDDefineFunc(): IDefineFunc;
getGlobalAMDRequireFunc(): IRequireFunc;
private static _findRelevantLocationInStack;
getBuildInfo(): IBuildModuleInfo[] | null;
getRecorder(): ILoaderEventRecorder;
getLoaderEvents(): LoaderEvent[];
/**
* Defines an anonymous module (without an id). Its name will be resolved as we receive a callback from the scriptLoader.
* @param dependencies @see defineModule
* @param callback @see defineModule
*/
enqueueDefineAnonymousModule(dependencies: string[], callback: any): void;
/**
* Creates a module and stores it in _modules. The manager will immediately begin resolving its dependencies.
* @param strModuleId An unique and absolute id of the module. This must not collide with another module's id
* @param dependencies An array with the dependencies of the module. Special keys are: "require", "exports" and "module"
* @param callback if callback is a function, it will be called with the resolved dependencies. if callback is an object, it will be considered as the exports of the module.
*/
defineModule(strModuleId: string, dependencies: string[], callback: any, errorback: ((err: AnnotatedError) => void) | null | undefined, stack: string | null, moduleIdResolver?: ModuleIdResolver): void;
private _normalizeDependency;
private _normalizeDependencies;
private _relativeRequire;
/**
* Require synchronously a module by its absolute id. If the module is not loaded, an exception will be thrown.
* @param id The unique and absolute id of the required module
* @return The exports of module 'id'
*/
synchronousRequire(_strModuleId: string, moduleIdResolver?: ModuleIdResolver): any;
configure(params: IConfigurationOptions, shouldOverwrite: boolean): void;
getConfig(): Configuration;
/**
* Callback from the scriptLoader when a module has been loaded.
* This means its code is available and has been executed.
*/
private _onLoad;
private _createLoadError;
/**
* Callback from the scriptLoader when a module hasn't been loaded.
* This means that the script was not found (e.g. 404) or there was an error in the script.
*/
private _onLoadError;
/**
* Walks (recursively) the dependencies of 'from' in search of 'to'.
* Returns true if there is such a path or false otherwise.
* @param from Module id to start at
* @param to Module id to look for
*/
private _hasDependencyPath;
/**
* Walks (recursively) the dependencies of 'from' in search of 'to'.
* Returns cycle as array.
* @param from Module id to start at
* @param to Module id to look for
*/
private _findCyclePath;
/**
* Create the local 'require' that is passed into modules
*/
private _createRequire;
private _loadModule;
/**
* Resolve a plugin dependency with the plugin loaded & complete
* @param module The module that has this dependency
* @param pluginDependency The semi-normalized dependency that appears in the module. e.g. 'vs/css!./mycssfile'. Only the plugin part (before !) is normalized
* @param plugin The plugin (what the plugin exports)
*/
private _loadPluginDependency;
/**
* Examine the dependencies of module 'module' and resolve them as needed.
*/
private _resolve;
private _onModuleComplete;
}
}
declare var doNotInitLoader: any;
declare var define: any;
declare namespace AMDLoader {
function init(): void;
}