Commit 03c1b5e
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 #48515
Closes #48439
PR-URL: #48559
Backport-PR-URL: #50669
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>Module.register and allow nested loader import()
1 parent 63aa5d7 commit 03c1b5e
File tree
11 files changed
+265
-157
lines changed- doc/api
- lib/internal
- modules/esm
- test
- es-module
- fixtures/es-module-loaders
11 files changed
+265
-157
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1234 | 1234 | | |
1235 | 1235 | | |
1236 | 1236 | | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | 1237 | | |
1255 | 1238 | | |
1256 | 1239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1039 | 1039 | | |
1040 | 1040 | | |
1041 | 1041 | | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | 1042 | | |
1048 | 1043 | | |
1049 | 1044 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
129 | 131 | | |
130 | | - | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | | - | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
| 158 | + | |
158 | 159 | | |
159 | 160 | | |
160 | | - | |
| 161 | + | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| |||
234 | 236 | | |
235 | 237 | | |
236 | 238 | | |
237 | | - | |
238 | 239 | | |
239 | 240 | | |
240 | 241 | | |
| |||
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
260 | | - | |
| 261 | + | |
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
| |||
334 | 335 | | |
335 | 336 | | |
336 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
337 | 342 | | |
338 | 343 | | |
339 | 344 | | |
| |||
350 | 355 | | |
351 | 356 | | |
352 | 357 | | |
353 | | - | |
354 | 358 | | |
355 | 359 | | |
356 | 360 | | |
| |||
392 | 396 | | |
393 | 397 | | |
394 | 398 | | |
395 | | - | |
| 399 | + | |
396 | 400 | | |
397 | 401 | | |
398 | 402 | | |
| |||
467 | 471 | | |
468 | 472 | | |
469 | 473 | | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
470 | 484 | | |
471 | 485 | | |
472 | 486 | | |
| |||
716 | 730 | | |
717 | 731 | | |
718 | 732 | | |
719 | | - | |
| 733 | + | |
| 734 | + | |
720 | 735 | | |
721 | 736 | | |
722 | 737 | | |
723 | 738 | | |
724 | 739 | | |
725 | 740 | | |
726 | | - | |
727 | | - | |
728 | 741 | | |
729 | 742 | | |
730 | 743 | | |
731 | 744 | | |
732 | 745 | | |
733 | 746 | | |
734 | 747 | | |
735 | | - | |
| 748 | + | |
736 | 749 | | |
737 | 750 | | |
738 | 751 | | |
739 | 752 | | |
740 | 753 | | |
741 | | - | |
| 754 | + | |
| 755 | + | |
742 | 756 | | |
743 | 757 | | |
744 | 758 | | |
745 | 759 | | |
746 | 760 | | |
747 | 761 | | |
748 | 762 | | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | 763 | | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
| 764 | + | |
| 765 | + | |
759 | 766 | | |
760 | 767 | | |
761 | 768 | | |
| |||
772 | 779 | | |
773 | 780 | | |
774 | 781 | | |
775 | | - | |
| 782 | + | |
776 | 783 | | |
777 | 784 | | |
778 | | - | |
| 785 | + | |
779 | 786 | | |
780 | 787 | | |
781 | 788 | | |
782 | 789 | | |
783 | 790 | | |
784 | 791 | | |
785 | | - | |
786 | 792 | | |
787 | 793 | | |
788 | 794 | | |
| |||
| 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