Skip to content

Commit f9edab1

Browse files
guybedfordtargos
authored andcommitted
esm: unflag --experimental-modules
PR-URL: #29866 Backport-PR-URL: #33055 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent d072f08 commit f9edab1

File tree

108 files changed

+201
-367
lines changed

Some content is hidden

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

108 files changed

+201
-367
lines changed

doc/api/cli.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Specify the `module` of a custom [experimental ECMAScript Module loader][].
192192
added: v8.5.0
193193
-->
194194

195-
Enable experimental ES module support and caching modules.
195+
Enable latest experimental modules features (deprecated).
196196

197197
### `--experimental-policy`
198198
<!-- YAML
@@ -376,9 +376,8 @@ Specify ICU data load path. (Overrides `NODE_ICU_DATA`.)
376376
added: v12.0.0
377377
-->
378378

379-
Used with `--experimental-modules`, this configures Node.js to interpret string
380-
input as CommonJS or as an ES module. String input is input via `--eval`,
381-
`--print`, or `STDIN`.
379+
This configures Node.js to interpret string input as CommonJS or as an ES
380+
module. String input is input via `--eval`, `--print`, or `STDIN`.
382381

383382
Valid values are `"commonjs"` and `"module"`. The default is `"commonjs"`.
384383

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

@@ -78,7 +75,7 @@ until the root of the volume is reached.
7875

7976
```sh
8077
# In same folder as above package.json
81-
node --experimental-modules my-app.js # Runs as ES module
78+
node my-app.js # Runs as ES module
8279
```
8380

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

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

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

170166
```sh
171-
node --experimental-modules --input-type=module --eval \
172-
"import { sep } from 'path'; console.log(sep);"
167+
node --input-type=module --eval "import { sep } from 'path'; console.log(sep);"
173168

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

178172
For completeness there is also `--input-type=commonjs`, for explicitly running
@@ -1004,8 +998,8 @@ The `--experimental-json-modules` flag is needed for the module
1004998
to work.
1005999

10061000
```bash
1007-
node --experimental-modules index.mjs # fails
1008-
node --experimental-modules --experimental-json-modules index.mjs # works
1001+
node index.mjs # fails
1002+
node --experimental-json-modules index.mjs # works
10091003
```
10101004

10111005
## Experimental Wasm Modules
@@ -1027,7 +1021,7 @@ console.log(M);
10271021
executed under:
10281022

10291023
```bash
1030-
node --experimental-modules --experimental-wasm-modules index.mjs
1024+
node --experimental-wasm-modules index.mjs
10311025
```
10321026

10331027
would provide the exports interface for the instantiation of `module.wasm`.
@@ -1173,7 +1167,7 @@ export async function getSource(url, context, defaultGetSource) {
11731167
#### <code>transformSource</code> hook
11741168
11751169
```console
1176-
NODE_OPTIONS='--experimental-modules --experimental-loader ./custom-loader.mjs' node x.js
1170+
NODE_OPTIONS='--experimental-loader ./custom-loader.mjs' node x.js
11771171
```
11781172
11791173
> Note: The loaders API is being redesigned. This hook may disappear or its
@@ -1733,11 +1727,11 @@ automatic extension resolution and importing from directories that include an
17331727
index file use the `node` mode.
17341728
17351729
```bash
1736-
$ node --experimental-modules index.mjs
1730+
$ node index.mjs
17371731
success!
1738-
$ node --experimental-modules index #Failure!
1732+
$ node index # Failure!
17391733
Error: Cannot find module
1740-
$ node --experimental-modules --experimental-specifier-resolution=node index
1734+
$ node --experimental-specifier-resolution=node index
17411735
success!
17421736
```
17431737

doc/api/vm.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ changes:
8585
* `importModuleDynamically` {Function} Called during evaluation of this module
8686
when `import()` is called. If this option is not specified, calls to
8787
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
88-
This option is part of the experimental API for the `--experimental-modules`
89-
flag, and should not be considered stable.
88+
This option is part of the experimental modules API, and should not be
89+
considered stable.
9090
* `specifier` {string} specifier passed to `import()`
9191
* `module` {vm.Module}
9292
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -876,8 +876,8 @@ changes:
876876
* `importModuleDynamically` {Function} Called during evaluation of this module
877877
when `import()` is called. If this option is not specified, calls to
878878
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
879-
This option is part of the experimental API for the `--experimental-modules`
880-
flag, and should not be considered stable.
879+
This option is part of the experimental modules API, and should not be
880+
considered stable.
881881
* `specifier` {string} specifier passed to `import()`
882882
* `module` {vm.Module}
883883
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -972,8 +972,8 @@ changes:
972972
* `importModuleDynamically` {Function} Called during evaluation of this module
973973
when `import()` is called. If this option is not specified, calls to
974974
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
975-
This option is part of the experimental API for the `--experimental-modules`
976-
flag, and should not be considered stable.
975+
This option is part of the experimental modules API, and should not be
976+
considered stable.
977977
* `specifier` {string} specifier passed to `import()`
978978
* `module` {vm.Module}
979979
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -1048,8 +1048,8 @@ changes:
10481048
* `importModuleDynamically` {Function} Called during evaluation of this module
10491049
when `import()` is called. If this option is not specified, calls to
10501050
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
1051-
This option is part of the experimental API for the `--experimental-modules`
1052-
flag, and should not be considered stable.
1051+
This option is part of the experimental modules API, and should not be
1052+
considered stable.
10531053
* `specifier` {string} specifier passed to `import()`
10541054
* `module` {vm.Module}
10551055
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is

doc/node.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Specify the
133133
to use as a custom module loader.
134134
.
135135
.It Fl -experimental-modules
136-
Enable experimental ES module support and caching modules.
136+
Enable experimental latest experimental modules features.
137137
.
138138
.It Fl -experimental-policy
139139
Use the specified file as a security policy.

lib/internal/bootstrap/loaders.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,21 @@ class NativeModule {
210210
}
211211

212212
// Used by user-land module loaders to compile and load builtins.
213-
compileForPublicLoader(needToSyncExports) {
213+
compileForPublicLoader() {
214214
if (!this.canBeRequiredByUsers) {
215215
// No code because this is an assertion against bugs
216216
// eslint-disable-next-line no-restricted-syntax
217217
throw new Error(`Should not compile ${this.id} for public use`);
218218
}
219219
this.compileForInternalLoader();
220-
if (needToSyncExports) {
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 ? [] : ObjectKeys(this.exports);
226-
}
227-
this.getESMFacade();
228-
this.syncExports();
220+
if (!this.exportKeys) {
221+
// When using --expose-internals, we do not want to reflect the named
222+
// exports from core modules as this can trigger unnecessary getters.
223+
const internal = this.id.startsWith('internal/');
224+
this.exportKeys = internal ? [] : ObjectKeys(this.exports);
229225
}
226+
this.getESMFacade();
227+
this.syncExports();
230228
return this.exports;
231229
}
232230

lib/internal/bootstrap/pre_execution.js

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

411-
const experimentalModules = getOptionValue('--experimental-modules');
412-
const experimentalVMModules = getOptionValue('--experimental-vm-modules');
413-
if (experimentalModules || experimentalVMModules) {
414-
if (experimentalModules) {
415-
process.emitWarning(
416-
'The ESM module loader is experimental.',
417-
'ExperimentalWarning', undefined);
418-
}
419-
const {
420-
setImportModuleDynamicallyCallback,
421-
setInitializeImportMetaObjectCallback
422-
} = internalBinding('module_wrap');
423-
const esm = require('internal/process/esm_loader');
424-
// Setup per-isolate callbacks that locate data or callbacks that we keep
425-
// track of for different ESM modules.
426-
setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject);
427-
setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback);
428-
}
411+
const {
412+
setImportModuleDynamicallyCallback,
413+
setInitializeImportMetaObjectCallback
414+
} = internalBinding('module_wrap');
415+
const esm = require('internal/process/esm_loader');
416+
// Setup per-isolate callbacks that locate data or callbacks that we keep
417+
// track of for different ESM modules.
418+
setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject);
419+
setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback);
429420
}
430421

431422
function initializeFrozenIntrinsics() {

lib/internal/main/check_syntax.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,20 @@ 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 { defaultResolve } = require('internal/modules/esm/resolve');
57-
const { defaultGetFormat } = require('internal/modules/esm/get_format');
58-
const { url } = defaultResolve(pathToFileURL(filename).toString());
59-
const { format } = defaultGetFormat(url);
60-
isModule = format === 'module';
61-
}
62-
if (isModule) {
63-
const { ModuleWrap } = internalBinding('module_wrap');
64-
new ModuleWrap(filename, undefined, source, 0, 0);
65-
return;
66-
}
50+
let isModule = false;
51+
if (filename === '[stdin]' || filename === '[eval]') {
52+
isModule = getOptionValue('--input-type') === 'module';
53+
} else {
54+
const { defaultResolve } = require('internal/modules/esm/resolve');
55+
const { defaultGetFormat } = require('internal/modules/esm/get_format');
56+
const { url } = defaultResolve(pathToFileURL(filename).toString());
57+
const { format } = defaultGetFormat(url);
58+
isModule = format === 'module';
59+
}
60+
if (isModule) {
61+
const { ModuleWrap } = internalBinding('module_wrap');
62+
new ModuleWrap(filename, undefined, source, 0, 0);
63+
return;
6764
}
6865

6966
wrapSafe(filename, source);

lib/internal/main/run_main_module.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ prepareMainThreadExecution(true);
88

99
markBootstrapComplete();
1010

11-
// Note: this loads the module through the ESM loader if
12-
// --experimental-loader is provided or --experimental-modules is on
13-
// and the module is determined to be an ES module. This hangs from the CJS
14-
// module loader because we currently allow monkey-patching of the module
15-
// loaders in the preloaded scripts through require('module').
11+
// Note: this loads the module through the ESM loader if the module is
12+
// determined to be an ES module. This hangs from the CJS module loader
13+
// because we currently allow monkey-patching of the module loaders
14+
// in the preloaded scripts through require('module').
1615
// runMain here might be monkey-patched by users in --require.
1716
// XXX: the monkey-patchability here should probably be deprecated.
1817
require('internal/modules/cjs/loader').Module.runMain(process.argv[1]);

lib/internal/modules/cjs/helpers.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const {
99
ERR_UNKNOWN_BUILTIN_MODULE
1010
} = require('internal/errors').codes;
1111
const { NativeModule } = require('internal/bootstrap/loaders');
12-
const { getOptionValue } = require('internal/options');
13-
const experimentalModules = getOptionValue('--experimental-modules');
1412

1513
const { validateString } = require('internal/validators');
1614
const path = require('path');
@@ -19,11 +17,11 @@ const { URL } = require('url');
1917

2018
const debug = require('internal/util/debuglog').debuglog('module');
2119

22-
function loadNativeModule(filename, request, experimentalModules) {
20+
function loadNativeModule(filename, request) {
2321
const mod = NativeModule.map.get(filename);
2422
if (mod) {
2523
debug('load native module %s', request);
26-
mod.compileForPublicLoader(experimentalModules);
24+
mod.compileForPublicLoader();
2725
return mod;
2826
}
2927
}
@@ -48,10 +46,7 @@ function makeRequireFunction(mod, redirects) {
4846
const href = destination.href;
4947
if (destination.protocol === 'node:') {
5048
const specifier = destination.pathname;
51-
const mod = loadNativeModule(
52-
specifier,
53-
href,
54-
experimentalModules);
49+
const mod = loadNativeModule(specifier, href);
5550
if (mod && mod.canBeRequiredByUsers) {
5651
return mod.exports;
5752
}

0 commit comments

Comments
 (0)