Skip to content

Commit e66648e

Browse files
MylesBorinstargos
authored andcommitted
esm: remove experimental status from JSON modules
The HTML spec has officially landed JSON Modules and as such I think we can move them out of the "experimental" status. They will still be behind the `--experimental-modules` flag until the entire esm implementation moves out of experimental. Refs: https://html.spec.whatwg.org/#creating-a-json-module-script PR-URL: #27752 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent f0abfa8 commit e66648e

File tree

8 files changed

+9
-46
lines changed

8 files changed

+9
-46
lines changed

doc/api/cli.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,6 @@ the ability to import a directory that has an index file.
148148

149149
Please see [customizing esm specifier resolution][] for example usage.
150150

151-
### `--experimental-json-modules`
152-
<!-- YAML
153-
added: v12.0.0
154-
-->
155-
156-
Enable experimental JSON support for the ES Module loader.
157-
158151
### `--experimental-modules`
159152
<!-- YAML
160153
added: v8.5.0

doc/api/esm.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,11 @@ fs.readFileSync = () => Buffer.from('Hello, ESM');
409409
fs.readFileSync === readFileSync;
410410
```
411411
412-
## Experimental JSON Modules
412+
## JSON Modules
413413
414-
**Note: This API is still being designed and is subject to change.**
414+
JSON modules follow the [WHATWG JSON modules specification][].
415415
416-
Currently importing JSON modules are only supported in the `commonjs` mode
417-
and are loaded using the CJS loader. [WHATWG JSON modules][] are currently
418-
being standardized, and are experimentally supported by including the
419-
additional flag `--experimental-json-modules` when running Node.js.
420-
421-
When the `--experimental-json-modules` flag is included both the
422-
`commonjs` and `module` mode will use the new experimental JSON
423-
loader. The imported JSON only exposes a `default`, there is no
416+
The imported JSON only exposes a `default`. There is no
424417
support for named exports. A cache entry is created in the CommonJS
425418
cache, to avoid duplication. The same object will be returned in
426419
CommonJS if the JSON module has already been imported from the
@@ -433,14 +426,6 @@ Assuming an `index.mjs` with
433426
import packageConfig from './package.json';
434427
```
435428
436-
The `--experimental-json-modules` flag is needed for the module
437-
to work.
438-
439-
```bash
440-
node --experimental-modules index.mjs # fails
441-
node --experimental-modules --experimental-json-modules index.mjs # works
442-
```
443-
444429
## Experimental Wasm Modules
445430
446431
Importing Web Assembly modules is supported under the
@@ -763,7 +748,7 @@ success!
763748
[CommonJS]: modules.html
764749
[ECMAScript-modules implementation]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
765750
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
766-
[WHATWG JSON modules]: https://github.com/whatwg/html/issues/4315
751+
[WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
767752
[ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration
768753
[dynamic instantiate hook]: #esm_dynamic_instantiate_hook
769754
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules

doc/node.1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ Requires Node.js to be built with
108108
.It Fl -es-module-specifier-resolution
109109
Select extension resolution algorithm for ES Modules; either 'explicit' (default) or 'node'
110110
.
111-
.It Fl -experimental-json-modules
112-
Enable experimental JSON interop support for the ES Module loader.
113-
.
114111
.It Fl -experimental-modules
115112
Enable experimental ES module support and caching modules.
116113
.

lib/internal/modules/esm/default_resolve.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const { getOptionValue } = require('internal/options');
88

99
const preserveSymlinks = getOptionValue('--preserve-symlinks');
1010
const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
11-
const experimentalJsonModules = getOptionValue('--experimental-json-modules');
1211
const typeFlag = getOptionValue('--input-type');
1312
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
1413
const { resolve: moduleWrapResolve,
@@ -29,24 +28,22 @@ const extensionFormatMap = {
2928
'__proto__': null,
3029
'.cjs': 'commonjs',
3130
'.js': 'module',
31+
'.json': 'json',
3232
'.mjs': 'module'
3333
};
3434

3535
const legacyExtensionFormatMap = {
3636
'__proto__': null,
3737
'.cjs': 'commonjs',
3838
'.js': 'commonjs',
39-
'.json': 'commonjs',
39+
'.json': 'json',
4040
'.mjs': 'module',
4141
'.node': 'commonjs'
4242
};
4343

4444
if (experimentalWasmModules)
4545
extensionFormatMap['.wasm'] = legacyExtensionFormatMap['.wasm'] = 'wasm';
4646

47-
if (experimentalJsonModules)
48-
extensionFormatMap['.json'] = legacyExtensionFormatMap['.json'] = 'json';
49-
5047
function resolve(specifier, parentURL) {
5148
if (NativeModule.canBeRequiredByUsers(specifier)) {
5249
return {

src/node_options.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
117117
}
118118
}
119119

120-
if (experimental_json_modules && !experimental_modules) {
121-
errors->push_back("--experimental-json-modules requires "
122-
"--experimental-modules be enabled");
123-
}
124-
125120
if (experimental_wasm_modules && !experimental_modules) {
126121
errors->push_back("--experimental-wasm-modules requires "
127122
"--experimental-modules be enabled");
@@ -271,10 +266,6 @@ DebugOptionsParser::DebugOptionsParser() {
271266
}
272267

273268
EnvironmentOptionsParser::EnvironmentOptionsParser() {
274-
AddOption("--experimental-json-modules",
275-
"experimental JSON interop support for the ES Module loader",
276-
&EnvironmentOptions::experimental_json_modules,
277-
kAllowedInEnvironment);
278269
AddOption("--experimental-modules",
279270
"experimental ES Module support and caching modules",
280271
&EnvironmentOptions::experimental_modules,

src/node_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class DebugOptions : public Options {
9191
class EnvironmentOptions : public Options {
9292
public:
9393
bool abort_on_uncaught_exception = false;
94-
bool experimental_json_modules = false;
9594
bool experimental_modules = false;
9695
std::string es_module_specifier_resolution;
9796
bool experimental_wasm_modules = false;

test/es-module/test-esm-json-cache.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --experimental-modules --experimental-json-modules
1+
// Flags: --experimental-modules
22
import '../common/index.mjs';
33

44
import { strictEqual, deepStrictEqual } from 'assert';

test/es-module/test-esm-json.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Flags: --experimental-modules --experimental-json-modules
1+
// Flags: --experimental-modules
2+
23
import '../common/index.mjs';
34
import { strictEqual } from 'assert';
45

0 commit comments

Comments
 (0)