|
4 | 4 | * {@link ModuleLoaderObj} is returned with the loaded module along with metadata that describes the loading mechanism. |
5 | 5 | */ |
6 | 6 | declare class ModuleLoader { |
7 | | - /** |
8 | | - * @template M, E |
9 | | - * |
10 | | - * Loads an ES Module via import dynamic or CommonJS via require in Node passing back an object containing info |
11 | | - * about the loading process. |
12 | | - * |
13 | | - * @param {object} options - Options object. |
14 | | - * |
15 | | - * @param {string|URL} options.modulepath - A module name, file path, or URL. |
16 | | - * |
17 | | - * @param {(M) => E} [options.resolveModule] - An optional function which resolves the import to set `instance`. |
18 | | - * |
19 | | - * @returns {Promise<ModuleLoaderObj<M, E>>} The module / instance and data about the loading process. |
20 | | - */ |
21 | | - static load<M, E>({ modulepath, resolveModule }: { |
22 | | - modulepath: string | URL; |
23 | | - resolveModule?: (M: any) => E; |
24 | | - }): Promise<ModuleLoaderObj<M, E>>; |
| 7 | + /** |
| 8 | + * @template M, E |
| 9 | + * |
| 10 | + * Loads an ES Module via import dynamic or CommonJS via require in Node passing back an object containing info |
| 11 | + * about the loading process. |
| 12 | + * |
| 13 | + * @param {object} options - Options object. |
| 14 | + * |
| 15 | + * @param {string|URL} options.modulepath - A module name, file path, or URL. |
| 16 | + * |
| 17 | + * @param {(M) => E} [options.resolveModule] - An optional function which resolves the import to set `instance`. |
| 18 | + * |
| 19 | + * @returns {Promise<ModuleLoaderObj<M, E>>} The module / instance and data about the loading process. |
| 20 | + */ |
| 21 | + static load<M, E>({ |
| 22 | + modulepath, |
| 23 | + resolveModule, |
| 24 | + }: { |
| 25 | + modulepath: string | URL; |
| 26 | + resolveModule?: (M: any) => E; |
| 27 | + }): Promise<ModuleLoaderObj<M, E>>; |
25 | 28 | } |
26 | 29 | /** |
27 | 30 | * The object passed back from `ModuleLoader.load`. |
28 | 31 | */ |
29 | 32 | type ModuleLoaderObj<M, E> = { |
30 | | - /** |
31 | | - * If available the file path on Node otherwise this will match `loadpath` in the |
32 | | - * browser. |
33 | | - */ |
34 | | - filepath: string; |
35 | | - /** |
36 | | - * Either the module itself or any particular export the `resolveModule` function |
37 | | - * selects. |
38 | | - */ |
39 | | - instance: E; |
40 | | - /** |
41 | | - * Indicates if the import was an ES Module. |
42 | | - */ |
43 | | - isESM: boolean; |
44 | | - /** |
45 | | - * A string representation of the module path being loaded. |
46 | | - */ |
47 | | - loadpath: string; |
48 | | - /** |
49 | | - * The direct module import. |
50 | | - */ |
51 | | - module: M; |
52 | | - /** |
53 | | - * The initial string or URL sent to ModuleLoader. |
54 | | - */ |
55 | | - modulepath: string | URL; |
56 | | - /** |
57 | | - * The type and how the module was loaded. |
58 | | - */ |
59 | | - type: ('import-module' | 'import-path' | 'import-url' | 'require-module' | 'require-path' | 'require-url'); |
| 33 | + /** |
| 34 | + * If available the file path on Node otherwise this will match `loadpath` in the |
| 35 | + * browser. |
| 36 | + */ |
| 37 | + filepath: string; |
| 38 | + /** |
| 39 | + * Either the module itself or any particular export the `resolveModule` function |
| 40 | + * selects. |
| 41 | + */ |
| 42 | + instance: E; |
| 43 | + /** |
| 44 | + * Indicates if the import was an ES Module. |
| 45 | + */ |
| 46 | + isESM: boolean; |
| 47 | + /** |
| 48 | + * A string representation of the module path being loaded. |
| 49 | + */ |
| 50 | + loadpath: string; |
| 51 | + /** |
| 52 | + * The direct module import. |
| 53 | + */ |
| 54 | + module: M; |
| 55 | + /** |
| 56 | + * The initial string or URL sent to ModuleLoader. |
| 57 | + */ |
| 58 | + modulepath: string | URL; |
| 59 | + /** |
| 60 | + * The type and how the module was loaded. |
| 61 | + */ |
| 62 | + type: 'import-module' | 'import-path' | 'import-url' | 'require-module' | 'require-path' | 'require-url'; |
60 | 63 | }; |
61 | 64 |
|
62 | 65 | /** |
63 | 66 | * Provides a custom error for Node to combine CJS and ESM module not found errors. |
64 | 67 | */ |
65 | 68 | declare class ModuleLoadError extends Error { |
66 | | - /** |
67 | | - * @param {object} options - Options object. |
68 | | - * |
69 | | - * @param {string} options.message - Error message. |
70 | | - * |
71 | | - * @param {string} options.code - Error code. |
72 | | - */ |
73 | | - constructor({ message, code }: { |
74 | | - message: string; |
75 | | - code: string; |
76 | | - }); |
77 | | - code: string; |
| 69 | + /** |
| 70 | + * @param {object} options - Options object. |
| 71 | + * |
| 72 | + * @param {string} options.message - Error message. |
| 73 | + * |
| 74 | + * @param {string} options.code - Error code. |
| 75 | + */ |
| 76 | + constructor({ message, code }: { message: string; code: string }); |
| 77 | + code: string; |
78 | 78 | } |
79 | 79 |
|
80 | 80 | export { ModuleLoadError, ModuleLoader, type ModuleLoaderObj }; |
0 commit comments