Skip to content

Commit 796f3d0

Browse files
guybedfordMylesBorins
authored andcommitted
esm: unflag --experimental-modules
PR-URL: #29866 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent cc6f99d commit 796f3d0

File tree

95 files changed

+194
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+194
-331
lines changed

doc/api/cli.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ Currently, overriding `Error.prepareStackTrace` is ignored when the
161161
added: v12.0.0
162162
-->
163163

164-
To be used in conjunction with `--experimental-modules`. Sets the resolution
165-
algorithm for resolving specifiers. Valid options are `explicit` and `node`.
164+
Sets the resolution algorithm for resolving ES module specifiers. Valid options
165+
are `explicit` and `node`.
166166

167167
The default is `explicit`, which requires providing the full path to a
168168
module. The `node` mode will enable support for optional file extensions and
@@ -191,7 +191,8 @@ Enable experimental JSON support for the ES Module loader.
191191
added: v8.5.0
192192
-->
193193

194-
Enable experimental ES module support and caching modules.
194+
Enable latest experimental modules features (currently
195+
`--experimental-conditional-exports` and `--experimental-self-resolve`).
195196

196197
### `--experimental-policy`
197198
<!-- YAML
@@ -342,9 +343,8 @@ Specify ICU data load path. (Overrides `NODE_ICU_DATA`.)
342343
added: v12.0.0
343344
-->
344345

345-
Used with `--experimental-modules`, this configures Node.js to interpret string
346-
input as CommonJS or as an ES module. String input is input via `--eval`,
347-
`--print`, or `STDIN`.
346+
This configures Node.js to interpret string input as CommonJS or as an ES
347+
module. String input is input via `--eval`, `--print`, or `STDIN`.
348348

349349
Valid values are `"commonjs"` and `"module"`. The default is `"commonjs"`.
350350

@@ -409,7 +409,7 @@ endpoint on `http://host:port/json/list`.
409409
added: v9.0.0
410410
-->
411411

412-
Specify the `module` of a custom [experimental ECMAScript Module][] loader.
412+
Specify the `module` of a custom [experimental ECMAScript Module loader][].
413413
`module` may be either a path to a file, or an ECMAScript Module name.
414414

415415
### `--max-http-header-size=size`
@@ -1330,7 +1330,7 @@ greater than `4` (its current default value). For more information, see the
13301330
[debugger]: debugger.html
13311331
[debugging security implications]: https://nodejs.org/en/docs/guides/debugging-getting-started/#security-implications
13321332
[emit_warning]: process.html#process_process_emitwarning_warning_type_code_ctor
1333-
[experimental ECMAScript Module]: esm.html#esm_resolve_hook
1333+
[experimental ECMAScript Module loader]: esm.html#esm_resolve_hook
13341334
[libuv threadpool documentation]: http://docs.libuv.org/en/latest/threadpool.html
13351335
[remote code execution]: https://www.owasp.org/index.php/Code_Injection
13361336
[context-aware]: addons.html#addons_context_aware_addons

doc/api/esm.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ specifier resolution, and default behavior.
2727

2828
<!-- type=misc -->
2929

30-
The `--experimental-modules` flag can be used to enable support for
31-
ECMAScript modules (ES modules).
32-
33-
Once enabled, Node.js will treat the following as ES modules when passed to
34-
`node` as the initial input, or when referenced by `import` statements within
35-
ES module code:
30+
Experimental support for ECMAScript modules is enabled by default.
31+
Node.js will treat the following as ES modules when passed to `node` as the
32+
initial input, or when referenced by `import` statements within ES module code:
3633

3734
* Files ending in `.mjs`.
3835

@@ -80,7 +77,7 @@ until the root of the volume is reached.
8077

8178
```sh
8279
# In same folder as above package.json
83-
node --experimental-modules my-app.js # Runs as ES module
80+
node my-app.js # Runs as ES module
8481
```
8582

8683
If the nearest parent `package.json` lacks a `"type"` field, or contains
@@ -114,9 +111,8 @@ own `package.json` file, so each project’s dependencies have their own package
114111
scopes. A `package.json` lacking a `"type"` field is treated as if it contained
115112
`"type": "commonjs"`.
116113

117-
The package scope applies not only to initial entry points (`node
118-
--experimental-modules my-app.js`) but also to files referenced by `import`
119-
statements and `import()` expressions.
114+
The package scope applies not only to initial entry points (`node my-app.js`)
115+
but also to files referenced by `import` statements and `import()` expressions.
120116

121117
```js
122118
// my-app.js, in an ES module package scope because there is a package.json
@@ -169,11 +165,9 @@ piped to `node` via `STDIN`, will be treated as ES modules when the
169165
`--input-type=module` flag is set.
170166

171167
```sh
172-
node --experimental-modules --input-type=module --eval \
173-
"import { sep } from 'path'; console.log(sep);"
168+
node --input-type=module --eval "import { sep } from 'path'; console.log(sep);"
174169

175-
echo "import { sep } from 'path'; console.log(sep);" | \
176-
node --experimental-modules --input-type=module
170+
echo "import { sep } from 'path'; console.log(sep);" | node --input-type=module
177171
```
178172

179173
For completeness there is also `--input-type=commonjs`, for explicitly running
@@ -927,8 +921,8 @@ The `--experimental-json-modules` flag is needed for the module
927921
to work.
928922

929923
```bash
930-
node --experimental-modules index.mjs # fails
931-
node --experimental-modules --experimental-json-modules index.mjs # works
924+
node index.mjs # fails
925+
node --experimental-json-modules index.mjs # works
932926
```
933927

934928
## Experimental Wasm Modules
@@ -950,7 +944,7 @@ console.log(M);
950944
executed under:
951945

952946
```bash
953-
node --experimental-modules --experimental-wasm-modules index.mjs
947+
node --experimental-wasm-modules index.mjs
954948
```
955949

956950
would provide the exports interface for the instantiation of `module.wasm`.
@@ -1061,7 +1055,7 @@ export async function resolve(specifier,
10611055
With this loader, running:
10621056
10631057
```console
1064-
NODE_OPTIONS='--experimental-modules --experimental-loader ./custom-loader.mjs' node x.js
1058+
NODE_OPTIONS='--experimental-loader ./custom-loader.mjs' node x.js
10651059
```
10661060
10671061
would load the module `x.js` as an ES module with relative resolution support
@@ -1352,11 +1346,11 @@ automatic extension resolution and importing from directories that include an
13521346
index file use the `node` mode.
13531347
13541348
```bash
1355-
$ node --experimental-modules index.mjs
1349+
$ node index.mjs
13561350
success!
1357-
$ node --experimental-modules index #Failure!
1351+
$ node index # Failure!
13581352
Error: Cannot find module
1359-
$ node --experimental-modules --es-module-specifier-resolution=node index
1353+
$ node --es-module-specifier-resolution=node index
13601354
success!
13611355
```
13621356

doc/api/vm.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ changes:
8888
* `importModuleDynamically` {Function} Called during evaluation of this module
8989
when `import()` is called. If this option is not specified, calls to
9090
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
91-
This option is part of the experimental API for the `--experimental-modules`
92-
flag, and should not be considered stable.
91+
This option is part of the experimental modules API, and should not be
92+
considered stable.
9393
* `specifier` {string} specifier passed to `import()`
9494
* `module` {vm.Module}
9595
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -854,8 +854,8 @@ changes:
854854
* `importModuleDynamically` {Function} Called during evaluation of this module
855855
when `import()` is called. If this option is not specified, calls to
856856
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
857-
This option is part of the experimental API for the `--experimental-modules`
858-
flag, and should not be considered stable.
857+
This option is part of the experimental modules API, and should not be
858+
considered stable.
859859
* `specifier` {string} specifier passed to `import()`
860860
* `module` {vm.Module}
861861
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -951,8 +951,8 @@ changes:
951951
* `importModuleDynamically` {Function} Called during evaluation of this module
952952
when `import()` is called. If this option is not specified, calls to
953953
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
954-
This option is part of the experimental API for the `--experimental-modules`
955-
flag, and should not be considered stable.
954+
This option is part of the experimental modules API, and should not be
955+
considered stable.
956956
* `specifier` {string} specifier passed to `import()`
957957
* `module` {vm.Module}
958958
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -1028,8 +1028,8 @@ changes:
10281028
* `importModuleDynamically` {Function} Called during evaluation of this module
10291029
when `import()` is called. If this option is not specified, calls to
10301030
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
1031-
This option is part of the experimental API for the `--experimental-modules`
1032-
flag, and should not be considered stable.
1031+
This option is part of the experimental modules API, and should not be
1032+
considered stable.
10331033
* `specifier` {string} specifier passed to `import()`
10341034
* `module` {vm.Module}
10351035
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is

doc/node.1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Enable experimental support for "require" and "node" conditional export targets.
120120
Enable experimental JSON interop support for the ES Module loader.
121121
.
122122
.It Fl -experimental-modules
123-
Enable experimental ES module support and caching modules.
123+
Enable experimental latest experimental modules features.
124124
.
125125
.It Fl -experimental-resolve-self
126126
Enable experimental support for a package to load itself.
@@ -208,8 +208,7 @@ It uses the Chrome DevTools Protocol.
208208
.It Fl -experimental-loader Ns = Ns Ar module
209209
Specify the
210210
.Ar module
211-
as a custom loader, to load
212-
.Fl -experimental-modules .
211+
to use as a custom module loader.
213212
.
214213
.It Fl -max-http-header-size Ns = Ns Ar size
215214
Specify the maximum size of HTTP headers in bytes. Defaults to 8KB.

lib/internal/bootstrap/loaders.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,23 +211,21 @@ function requireWithFallbackInDeps(request) {
211211
}
212212

213213
// This is exposed for public loaders
214-
NativeModule.prototype.compileForPublicLoader = function(needToSyncExports) {
214+
NativeModule.prototype.compileForPublicLoader = function() {
215215
if (!this.canBeRequiredByUsers) {
216216
// No code because this is an assertion against bugs
217217
// eslint-disable-next-line no-restricted-syntax
218218
throw new Error(`Should not compile ${this.id} for public use`);
219219
}
220220
this.compile();
221-
if (needToSyncExports) {
222-
if (!this.exportKeys) {
223-
// When using --expose-internals, we do not want to reflect the named
224-
// exports from core modules as this can trigger unnecessary getters.
225-
const internal = this.id.startsWith('internal/');
226-
this.exportKeys = internal ? [] : Object.keys(this.exports);
227-
}
228-
this.getESMFacade();
229-
this.syncExports();
221+
if (!this.exportKeys) {
222+
// When using --expose-internals, we do not want to reflect the named
223+
// exports from core modules as this can trigger unnecessary getters.
224+
const internal = this.id.startsWith('internal/');
225+
this.exportKeys = internal ? [] : Object.keys(this.exports);
230226
}
227+
this.getESMFacade();
228+
this.syncExports();
231229
return this.exports;
232230
};
233231

lib/internal/bootstrap/pre_execution.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -401,24 +401,15 @@ function initializeESMLoader() {
401401
// Create this WeakMap in js-land because V8 has no C++ API for WeakMap.
402402
internalBinding('module_wrap').callbackMap = new SafeWeakMap();
403403

404-
const experimentalModules = getOptionValue('--experimental-modules');
405-
const experimentalVMModules = getOptionValue('--experimental-vm-modules');
406-
if (experimentalModules || experimentalVMModules) {
407-
if (experimentalModules) {
408-
process.emitWarning(
409-
'The ESM module loader is experimental.',
410-
'ExperimentalWarning', undefined);
411-
}
412-
const {
413-
setImportModuleDynamicallyCallback,
414-
setInitializeImportMetaObjectCallback
415-
} = internalBinding('module_wrap');
416-
const esm = require('internal/process/esm_loader');
417-
// Setup per-isolate callbacks that locate data or callbacks that we keep
418-
// track of for different ESM modules.
419-
setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject);
420-
setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback);
421-
}
404+
const {
405+
setImportModuleDynamicallyCallback,
406+
setInitializeImportMetaObjectCallback
407+
} = internalBinding('module_wrap');
408+
const esm = require('internal/process/esm_loader');
409+
// Setup per-isolate callbacks that locate data or callbacks that we keep
410+
// track of for different ESM modules.
411+
setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject);
412+
setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback);
422413
}
423414

424415
function initializeFrozenIntrinsics() {
@@ -460,9 +451,6 @@ function resolveMainPath(main) {
460451
}
461452

462453
function shouldUseESMLoader(mainPath) {
463-
const experimentalModules = getOptionValue('--experimental-modules');
464-
if (!experimentalModules)
465-
return false;
466454
const userLoader = getOptionValue('--experimental-loader');
467455
if (userLoader)
468456
return true;

lib/internal/main/check_syntax.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,18 @@ if (process.argv[1] && process.argv[1] !== '-') {
4747

4848
function checkSyntax(source, filename) {
4949
const { getOptionValue } = require('internal/options');
50-
const experimentalModules = getOptionValue('--experimental-modules');
51-
if (experimentalModules) {
52-
let isModule = false;
53-
if (filename === '[stdin]' || filename === '[eval]') {
54-
isModule = getOptionValue('--input-type') === 'module';
55-
} else {
56-
const resolve = require('internal/modules/esm/default_resolve');
57-
const { format } = resolve(pathToFileURL(filename).toString());
58-
isModule = format === 'module';
59-
}
60-
if (isModule) {
61-
const { ModuleWrap } = internalBinding('module_wrap');
62-
new ModuleWrap(filename, undefined, source, 0, 0);
63-
return;
64-
}
50+
let isModule = false;
51+
if (filename === '[stdin]' || filename === '[eval]') {
52+
isModule = getOptionValue('--input-type') === 'module';
53+
} else {
54+
const resolve = require('internal/modules/esm/default_resolve');
55+
const { format } = resolve(pathToFileURL(filename).toString());
56+
isModule = format === 'module';
57+
}
58+
if (isModule) {
59+
const { ModuleWrap } = internalBinding('module_wrap');
60+
new ModuleWrap(filename, undefined, source, 0, 0);
61+
return;
6562
}
6663

6764
wrapSafe(filename, source);

lib/internal/main/run_main_module.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const CJSModule = require('internal/modules/cjs/loader').Module;
1010

1111
markBootstrapComplete();
1212

13-
// Note: this loads the module through the ESM loader if
14-
// --experimental-loader is provided or --experimental-modules is on
15-
// and the module is determined to be an ES module
13+
// Note: this loads the module through the ESM loader if the module is
14+
// determined to be an ES module
1615
CJSModule.runMain(process.argv[1]);

lib/internal/modules/cjs/helpers.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const {
66
ERR_UNKNOWN_BUILTIN_MODULE
77
} = require('internal/errors').codes;
88
const { NativeModule } = require('internal/bootstrap/loaders');
9-
const { getOptionValue } = require('internal/options');
10-
const experimentalModules = getOptionValue('--experimental-modules');
119

1210
const { validateString } = require('internal/validators');
1311
const path = require('path');
@@ -16,11 +14,11 @@ const { URL } = require('url');
1614

1715
const debug = require('internal/util/debuglog').debuglog('module');
1816

19-
function loadNativeModule(filename, request, experimentalModules) {
17+
function loadNativeModule(filename, request) {
2018
const mod = NativeModule.map.get(filename);
2119
if (mod) {
2220
debug('load native module %s', request);
23-
mod.compileForPublicLoader(experimentalModules);
21+
mod.compileForPublicLoader();
2422
return mod;
2523
}
2624
}
@@ -45,10 +43,7 @@ function makeRequireFunction(mod, redirects) {
4543
const href = destination.href;
4644
if (destination.protocol === 'node:') {
4745
const specifier = destination.pathname;
48-
const mod = loadNativeModule(
49-
specifier,
50-
href,
51-
experimentalModules);
46+
const mod = loadNativeModule(specifier, href);
5247
if (mod && mod.canBeRequiredByUsers) {
5348
return mod.exports;
5449
}

0 commit comments

Comments
 (0)