Skip to content

Commit a235a15

Browse files
committed
fixup! module: support require()ing synchronous ESM graphs
1 parent a1b3cd4 commit a235a15

File tree

7 files changed

+29
-24
lines changed

7 files changed

+29
-24
lines changed

doc/api/cli.md

+17-13
Original file line numberDiff line numberDiff line change
@@ -879,17 +879,21 @@ added: REPLACEME
879879

880880
> Stability: 1.1 - Active Developement
881881
882-
Supports loading a synchronous ES module graph in `require()`. If the module
883-
graph is not synchronous (contains top-level await), Node.js throws an error
884-
without executing the module. If `--print-pending-tla` is passed, Node.js
885-
will evaluate the module, try to locate the top-level awaits, and print
886-
their location to help users fix them.
887-
888-
With this option alone, the module being `require()`'d should be explicitly
889-
marked as an ES module either using the `"type": "module"` field in
890-
`package.json` or the `.mjs` extension. To load implicit ES modules with
891-
automatic syntax-based module type detection, use
892-
`--experimental-require-module-with-detection`.
882+
Supports loading a synchronous ES module graph in `require()`.
883+
884+
When `--experimental-require-module` is enabled, and `require()`
885+
resolves to an ES module, if the module is fully synchronous
886+
(contains no top-level await), the `require()` call returns the
887+
module name space object. Otherwise, Node.js throws an error
888+
without executing the module. If `--experimental-print-required-tla`
889+
is passed, Node.js will evaluate the module, try to locate the
890+
top-level awaits, and print their location to help users fix them.
891+
892+
With this option alone, the module being `require()`'d should be
893+
explicitly marked as an ES module either using the `"type": "module"`
894+
field in `package.json` or the `.mjs` extension. To load implicit ES
895+
modules ending with `.js` using automatic syntax-based module type
896+
detection, use `--experimental-require-module-with-detection`.
893897

894898
### `--experimental-require-module-with-detection`
895899

@@ -1611,7 +1615,7 @@ changes:
16111615

16121616
Identical to `-e` but prints the result.
16131617

1614-
### `--print-pending-tla`
1618+
### `--experimental-print-required-tla`
16151619

16161620
<!-- YAML
16171621
added: REPLACEME
@@ -2602,7 +2606,7 @@ Node.js options that are allowed are:
26022606
* `--policy-integrity`
26032607
* `--preserve-symlinks-main`
26042608
* `--preserve-symlinks`
2605-
* `--print-pending-tla`
2609+
* `--experimental-print-required-tla`
26062610
* `--prof-process`
26072611
* `--redirect-warnings`
26082612
* `--report-compact`

doc/api/errors.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2496,8 +2496,8 @@ object.
24962496
When trying to `require()` a [ES Module][] under `--experimental-require-module`,
24972497
the module turns out to be asynchronous. That is, it contains top-level await.
24982498
To see where the top-level await is, use
2499-
`--print-pending-tla` (this would execute the modules before looking for
2500-
the top-level awaits).
2499+
`--experimental-print-required-tla` (this would execute the modules
2500+
before looking for the top-level awaits).
25012501

25022502
<a id="ERR_REQUIRE_ESM"></a>
25032503

src/module_wrap.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ void ModuleWrap::InstantiateSync(const FunctionCallbackInfo<Value>& args) {
571571
}
572572
}
573573

574-
// If --print-pending-tla is true, proceeds to evaluation even if it's
575-
// async because we want to search for the TLA and help users locate them.
576-
if (module->IsGraphAsync() && !env->options()->print_pending_tla) {
574+
// If --experimental-print-required-tla is true, proceeds to evaluation even
575+
// if it's async because we want to search for the TLA and help users locate
576+
// them.
577+
if (module->IsGraphAsync() && !env->options()->print_required_tla) {
577578
THROW_ERR_REQUIRE_ASYNC_MODULE(env);
578579
return;
579580
}
@@ -607,7 +608,7 @@ void ModuleWrap::EvaluateSync(const FunctionCallbackInfo<Value>& args) {
607608
}
608609

609610
if (module->IsGraphAsync()) {
610-
CHECK(env->options()->print_pending_tla);
611+
CHECK(env->options()->print_required_tla);
611612
auto stalled = module->GetStalledTopLevelAwaitMessage(isolate);
612613
if (stalled.size() != 0) {
613614
for (auto pair : stalled) {

src/node_errors.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ ERRORS_WITH_CODE(V)
192192
V(ERR_REQUIRE_ASYNC_MODULE, \
193193
"require() cannot be used on an ESM graph with top-level await. Use " \
194194
"import() instead. To see where the top-level await comes from, use " \
195-
"--print-pending-tla.") \
195+
"--experimental-print-required-tla.") \
196196
V(ERR_SCRIPT_EXECUTION_INTERRUPTED, \
197197
"Script execution was interrupted by `SIGINT`") \
198198
V(ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, "Failed to set PSK identity hint") \

src/node_options.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
352352
"ES module syntax, try again to evaluate them as ES modules",
353353
&EnvironmentOptions::detect_module,
354354
kAllowedInEnvvar);
355-
AddOption("--print-pending-tla",
355+
AddOption("--experimental-print-required-tla",
356356
"Print pending top-level await. If --experimental-require-module "
357357
"is true, evaluate asynchronous graphs loaded by `require()` but "
358358
"do not run the microtasks, in order to to find and print "
359359
"top-level await in the graph",
360-
&EnvironmentOptions::print_pending_tla,
360+
&EnvironmentOptions::print_required_tla,
361361
kAllowedInEnvvar);
362362
AddOption("--experimental-require-module",
363363
"Allow loading explicit ES Modules in require().",

src/node_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class EnvironmentOptions : public Options {
105105
bool abort_on_uncaught_exception = false;
106106
std::vector<std::string> conditions;
107107
bool detect_module = false;
108-
bool print_pending_tla = false;
108+
bool print_required_tla = false;
109109
bool require_module = false;
110110
bool require_module_with_detection = false;
111111
std::string dns_result_order;

test/es-module/test-require-module-tla.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ assert.throws(() => {
4545
{
4646
spawnSyncAndExit(process.execPath, [
4747
'--experimental-require-module',
48-
'--print-pending-tla',
48+
'--experimental-print-required-tla',
4949
fixtures.path('es-modules/tla/require-execution.js'),
5050
], {
5151
signal: null,

0 commit comments

Comments
 (0)