Commit 3bcf86d
esm: use sync loading/resolving on non-loader-hook thread
ESM resolution and loading is now always synchronous from a
non-loader-hook thread. If no asynchrnous loader hooks are
registered, the resolution/loading is entirely synchronous.
If asynchronous loader hooks are registered, these would be
synchronous on the non-loader-hook thread, and asynchronous
on the loader hook thread.
This avoids several races caused by async/sync loading sharing
the same cache. In particular, asynchronous loader hooks
now works with `require(esm)` - previously it tends to break
due to races.
In addition, when an asynchronous loader hook
returns a promise that never settles, the main thread no longer
silently exits with exit code 13, leaving the code below
any module loading calls silently ignored without being executed.
Instead, it now throws ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED
which can be caught and handled by the main thread. If the module
request comes from `import()`, the never-settling promise is
now relayed to the result returned by `import()`.
Drive-by: when annotating the error about importing undetectable
named exports from CommonJS, it now no longer reload the source
code of the CommonJS module, and instead reuses format information
cached when the module was loaded for linking.
PR-URL: #60380
Fixes: #59666
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>1 parent cd5c1ad commit 3bcf86dCopy full SHA for 3bcf86d
File tree
Expand file treeCollapse file tree
21 files changed
+466
-367
lines changedOpen diff view settings
Filter options
- doc/api
- lib/internal
- modules/esm
- test_runner/mock
- test
- es-module
- fixtures
- es-module-loaders/never-settling-resolve-step
- module-hooks
- require-esm
- module-hooks
Expand file treeCollapse file tree
21 files changed
+466
-367
lines changedOpen diff view settings
Collapse file
+7Lines changed: 7 additions & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
703 | 703 | |
704 | 704 | |
705 | 705 | |
| 706 | + |
| 707 | + |
| 708 | + |
| 709 | + |
| 710 | + |
| 711 | + |
| 712 | + |
706 | 713 | |
707 | 714 | |
708 | 715 | |
|
Collapse file
+2Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1137 | 1137 | |
1138 | 1138 | |
1139 | 1139 | |
| 1140 | + |
| 1141 | + |
1140 | 1142 | |
1141 | 1143 | |
1142 | 1144 | |
|
Collapse file
lib/internal/modules/esm/hooks.js
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/hooks.js+17-11Lines changed: 17 additions & 11 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
23 | 23 | |
24 | 24 | |
25 | 25 | |
| 26 | + |
26 | 27 | |
27 | 28 | |
28 | 29 | |
29 | 30 | |
30 | 31 | |
31 | 32 | |
32 | | - |
33 | 33 | |
34 | 34 | |
35 | | - |
36 | 35 | |
37 | 36 | |
38 | 37 | |
| ||
117 | 116 | |
118 | 117 | |
119 | 118 | |
| 119 | + |
120 | 120 | |
121 | 121 | |
122 | | - |
| 122 | + |
123 | 123 | |
124 | 124 | |
125 | 125 | |
126 | 126 | |
127 | 127 | |
128 | | - |
| 128 | + |
129 | 129 | |
130 | 130 | |
131 | 131 | |
| ||
169 | 169 | |
170 | 170 | |
171 | 171 | |
| 172 | + |
| 173 | + |
172 | 174 | |
173 | 175 | |
174 | 176 | |
| ||
350 | 352 | |
351 | 353 | |
352 | 354 | |
353 | | - |
354 | | - |
355 | | - |
356 | | - |
357 | 355 | |
358 | 356 | |
359 | 357 | |
| ||
560 | 558 | |
561 | 559 | |
562 | 560 | |
563 | | - |
| 561 | + |
| 562 | + |
| 563 | + |
| 564 | + |
564 | 565 | |
565 | 566 | |
566 | 567 | |
| ||
647 | 648 | |
648 | 649 | |
649 | 650 | |
| 651 | + |
650 | 652 | |
651 | | - |
| 653 | + |
652 | 654 | |
653 | | - |
| 655 | + |
| 656 | + |
| 657 | + |
654 | 658 | |
655 | 659 | |
656 | 660 | |
| ||
819 | 823 | |
820 | 824 | |
821 | 825 | |
| 826 | + |
| 827 | + |
822 | 828 | |
823 | 829 | |
824 | 830 | |
|
Collapse file
lib/internal/modules/esm/initialize_import_meta.js
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/initialize_import_meta.js+2-1Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
33 | 33 | |
34 | 34 | |
35 | 35 | |
36 | | - |
| 36 | + |
| 37 | + |
37 | 38 | |
38 | 39 | |
39 | 40 | |
|
0 commit comments