Commit ca4f765
committed
esm: unflag
Major functional changes:
- Allow `import()` to work within loaders that require other loaders,
- Unflag the use of `Module.register`.
A new interface `Customizations` has been created in order to unify
`ModuleLoader` (previously `DefaultModuleLoader`), `Hooks` and
`CustomizedModuleLoader` all of which now implement it:
```ts
interface LoadResult {
format: ModuleFormat;
source: ModuleSource;
}
interface ResolveResult {
format: string;
url: URL['href'];
}
interface Customizations {
allowImportMetaResolve: boolean;
load(url: string, context: object): Promise<LoadResult>
resolve(
originalSpecifier:
string, parentURL: string,
importAssertions: Record<string, string>
): Promise<ResolveResult>
resolveSync(
originalSpecifier:
string, parentURL: string,
importAssertions: Record<string, string>
) ResolveResult;
register(specifier: string, parentUrl: string): any;
forceLoadHooks(): void;
importMetaInitialize(meta, context, loader): void;
}
```
The `ModuleLoader` class now has `setCustomizations` which takes an
object of this shape and delegates its responsibilities to this object
if present.
Note that two properties `allowImportMetaResolve` and `resolveSync`
exist now as a mechanism for `import.meta.resolve` – since `Hooks`
does not implement `resolveSync` other loaders cannot use
`import.meta.resolve`; `allowImportMetaResolve` is a way of checking
for that case instead of invoking `resolveSync` and erroring.
Fixes nodejs#48515
Closes nodejs#48439Module.register and allow nested loader import()
1 parent 77ea173 commit ca4f765
11 files changed
Lines changed: 268 additions & 157 deletions
File tree
- doc/api
- lib/internal
- modules/esm
- test
- es-module
- fixtures/es-module-loaders
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1233 | 1233 | | |
1234 | 1234 | | |
1235 | 1235 | | |
1236 | | - | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | 1236 | | |
1254 | 1237 | | |
1255 | 1238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1036 | 1036 | | |
1037 | 1037 | | |
1038 | 1038 | | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | 1039 | | |
1045 | 1040 | | |
1046 | 1041 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
| 70 | + | |
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
| |||
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
85 | | - | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| |||
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| 126 | + | |
| 127 | + | |
124 | 128 | | |
125 | 129 | | |
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
130 | 134 | | |
131 | | - | |
132 | 135 | | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
137 | | - | |
138 | 140 | | |
139 | 141 | | |
140 | 142 | | |
| |||
152 | 154 | | |
153 | 155 | | |
154 | 156 | | |
155 | | - | |
| 157 | + | |
156 | 158 | | |
157 | 159 | | |
158 | | - | |
| 160 | + | |
| 161 | + | |
159 | 162 | | |
160 | 163 | | |
161 | | - | |
| 164 | + | |
| 165 | + | |
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
| |||
235 | 239 | | |
236 | 240 | | |
237 | 241 | | |
238 | | - | |
239 | 242 | | |
240 | 243 | | |
241 | 244 | | |
| |||
258 | 261 | | |
259 | 262 | | |
260 | 263 | | |
261 | | - | |
| 264 | + | |
262 | 265 | | |
263 | 266 | | |
264 | 267 | | |
| |||
335 | 338 | | |
336 | 339 | | |
337 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
338 | 345 | | |
339 | 346 | | |
340 | 347 | | |
| |||
351 | 358 | | |
352 | 359 | | |
353 | 360 | | |
354 | | - | |
355 | 361 | | |
356 | 362 | | |
357 | 363 | | |
| |||
393 | 399 | | |
394 | 400 | | |
395 | 401 | | |
396 | | - | |
| 402 | + | |
397 | 403 | | |
398 | 404 | | |
399 | 405 | | |
| |||
468 | 474 | | |
469 | 475 | | |
470 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
471 | 487 | | |
472 | 488 | | |
473 | 489 | | |
| |||
717 | 733 | | |
718 | 734 | | |
719 | 735 | | |
720 | | - | |
| 736 | + | |
| 737 | + | |
721 | 738 | | |
722 | 739 | | |
723 | 740 | | |
724 | 741 | | |
725 | 742 | | |
726 | 743 | | |
727 | | - | |
728 | | - | |
729 | 744 | | |
730 | 745 | | |
731 | 746 | | |
732 | 747 | | |
733 | 748 | | |
734 | 749 | | |
735 | 750 | | |
736 | | - | |
| 751 | + | |
737 | 752 | | |
738 | 753 | | |
739 | 754 | | |
740 | 755 | | |
741 | 756 | | |
742 | | - | |
| 757 | + | |
| 758 | + | |
743 | 759 | | |
744 | 760 | | |
745 | 761 | | |
746 | 762 | | |
747 | 763 | | |
748 | 764 | | |
749 | 765 | | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | 766 | | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
| 767 | + | |
| 768 | + | |
760 | 769 | | |
761 | 770 | | |
762 | 771 | | |
| |||
773 | 782 | | |
774 | 783 | | |
775 | 784 | | |
776 | | - | |
| 785 | + | |
777 | 786 | | |
778 | 787 | | |
779 | | - | |
| 788 | + | |
780 | 789 | | |
781 | 790 | | |
782 | 791 | | |
783 | 792 | | |
784 | 793 | | |
785 | 794 | | |
786 | | - | |
787 | 795 | | |
788 | 796 | | |
789 | 797 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments