Skip to content

Commit f016bd6

Browse files
guybedfordtargos
authored andcommitted
esm: unflag --experimental-modules
PR-URL: #29866 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent af392a1 commit f016bd6

File tree

105 files changed

+200
-363
lines changed

Some content is hidden

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

105 files changed

+200
-363
lines changed

doc/api/cli.md

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

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

188188
### `--experimental-policy`
189189
<!-- YAML
@@ -374,9 +374,8 @@ Specify ICU data load path. (Overrides `NODE_ICU_DATA`.)
374374
added: v12.0.0
375375
-->
376376

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

381380
Valid values are `"commonjs"` and `"module"`. The default is `"commonjs"`.
382381

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`.
@@ -1154,7 +1148,7 @@ export async function getSource(url, context, defaultGetSource) {
11541148
#### <code>transformSource</code> hook
11551149

11561150
```console
1157-
NODE_OPTIONS='--experimental-modules --experimental-loader ./custom-loader.mjs' node x.js
1151+
NODE_OPTIONS='--experimental-loader ./custom-loader.mjs' node x.js
11581152
```
11591153

11601154
> Note: The loaders API is being redesigned. This hook may disappear or its
@@ -1712,11 +1706,11 @@ automatic extension resolution and importing from directories that include an
17121706
index file use the `node` mode.
17131707
17141708
```bash
1715-
$ node --experimental-modules index.mjs
1709+
$ node index.mjs
17161710
success!
1717-
$ node --experimental-modules index #Failure!
1711+
$ node index # Failure!
17181712
Error: Cannot find module
1719-
$ node --experimental-modules --experimental-specifier-resolution=node index
1713+
$ node --experimental-specifier-resolution=node index
17201714
success!
17211715
```
17221716

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
@@ -850,8 +850,8 @@ changes:
850850
* `importModuleDynamically` {Function} Called during evaluation of this module
851851
when `import()` is called. If this option is not specified, calls to
852852
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
853-
This option is part of the experimental API for the `--experimental-modules`
854-
flag, and should not be considered stable.
853+
This option is part of the experimental modules API, and should not be
854+
considered stable.
855855
* `specifier` {string} specifier passed to `import()`
856856
* `module` {vm.Module}
857857
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -946,8 +946,8 @@ changes:
946946
* `importModuleDynamically` {Function} Called during evaluation of this module
947947
when `import()` is called. If this option is not specified, calls to
948948
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
949-
This option is part of the experimental API for the `--experimental-modules`
950-
flag, and should not be considered stable.
949+
This option is part of the experimental modules API, and should not be
950+
considered stable.
951951
* `specifier` {string} specifier passed to `import()`
952952
* `module` {vm.Module}
953953
* Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is
@@ -1022,8 +1022,8 @@ changes:
10221022
* `importModuleDynamically` {Function} Called during evaluation of this module
10231023
when `import()` is called. If this option is not specified, calls to
10241024
`import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][].
1025-
This option is part of the experimental API for the `--experimental-modules`
1026-
flag, and should not be considered stable.
1025+
This option is part of the experimental modules API, and should not be
1026+
considered stable.
10271027
* `specifier` {string} specifier passed to `import()`
10281028
* `module` {vm.Module}
10291029
* 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
@@ -125,7 +125,7 @@ Specify the
125125
to use as a custom module loader.
126126
.
127127
.It Fl -experimental-modules
128-
Enable experimental ES module support and caching modules.
128+
Enable experimental latest experimental modules features.
129129
.
130130
.It Fl -experimental-policy
131131
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
@@ -404,24 +404,15 @@ function initializeESMLoader() {
404404
// Create this WeakMap in js-land because V8 has no C++ API for WeakMap.
405405
internalBinding('module_wrap').callbackMap = new SafeWeakMap();
406406

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

427418
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)