Skip to content

Commit

Permalink
esm: remove experimental status from JSON modules
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MylesBorins committed May 22, 2019
1 parent 6f55c53 commit ec8776d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 46 deletions.
7 changes: 0 additions & 7 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ the ability to import a directory that has an index file.

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

### `--experimental-json-modules`
<!-- YAML
added: v12.0.0
-->

Enable experimental JSON support for the ES Module loader.

### `--experimental-modules`
<!-- YAML
added: v8.5.0
Expand Down
23 changes: 4 additions & 19 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,11 @@ fs.readFileSync = () => Buffer.from('Hello, ESM');
fs.readFileSync === readFileSync;
```
## Experimental JSON Modules
## JSON Modules
**Note: This API is still being designed and is subject to change.**
JSON modules follow the [WHATWG JSON modules specification][].
Currently importing JSON modules are only supported in the `commonjs` mode
and are loaded using the CJS loader. [WHATWG JSON modules][] are currently
being standardized, and are experimentally supported by including the
additional flag `--experimental-json-modules` when running Node.js.
When the `--experimental-json-modules` flag is included both the
`commonjs` and `module` mode will use the new experimental JSON
loader. The imported JSON only exposes a `default`, there is no
The imported JSON only exposes a `default`. There is no
support for named exports. A cache entry is created in the CommonJS
cache, to avoid duplication. The same object will be returned in
CommonJS if the JSON module has already been imported from the
Expand All @@ -433,14 +426,6 @@ Assuming an `index.mjs` with
import packageConfig from './package.json';
```
The `--experimental-json-modules` flag is needed for the module
to work.
```bash
node --experimental-modules index.mjs # fails
node --experimental-modules --experimental-json-modules index.mjs # works
```
## Experimental Wasm Modules
Importing Web Assembly modules is supported under the
Expand Down Expand Up @@ -763,7 +748,7 @@ success!
[CommonJS]: modules.html
[ECMAScript-modules implementation]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
[WHATWG JSON modules]: https://github.com/whatwg/html/issues/4315
[WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
[ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration
[dynamic instantiate hook]: #esm_dynamic_instantiate_hook
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
3 changes: 0 additions & 3 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ Requires Node.js to be built with
.It Fl -es-module-specifier-resolution
Select extension resolution algorithm for ES Modules; either 'explicit' (default) or 'node'
.
.It Fl -experimental-json-modules
Enable experimental JSON interop support for the ES Module loader.
.
.It Fl -experimental-modules
Enable experimental ES module support and caching modules.
.
Expand Down
7 changes: 2 additions & 5 deletions lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { getOptionValue } = require('internal/options');

const preserveSymlinks = getOptionValue('--preserve-symlinks');
const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
const experimentalJsonModules = getOptionValue('--experimental-json-modules');
const typeFlag = getOptionValue('--input-type');
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
const { resolve: moduleWrapResolve,
Expand All @@ -29,24 +28,22 @@ const extensionFormatMap = {
'__proto__': null,
'.cjs': 'commonjs',
'.js': 'module',
'.json': 'json',
'.mjs': 'module'
};

const legacyExtensionFormatMap = {
'__proto__': null,
'.cjs': 'commonjs',
'.js': 'commonjs',
'.json': 'commonjs',
'.json': 'json',
'.mjs': 'module',
'.node': 'commonjs'
};

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

if (experimentalJsonModules)
extensionFormatMap['.json'] = legacyExtensionFormatMap['.json'] = 'json';

function resolve(specifier, parentURL) {
if (NativeModule.canBeRequiredByUsers(specifier)) {
return {
Expand Down
9 changes: 0 additions & 9 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
}
}

if (experimental_json_modules && !experimental_modules) {
errors->push_back("--experimental-json-modules requires "
"--experimental-modules be enabled");
}

if (experimental_wasm_modules && !experimental_modules) {
errors->push_back("--experimental-wasm-modules requires "
"--experimental-modules be enabled");
Expand Down Expand Up @@ -271,10 +266,6 @@ DebugOptionsParser::DebugOptionsParser() {
}

EnvironmentOptionsParser::EnvironmentOptionsParser() {
AddOption("--experimental-json-modules",
"experimental JSON interop support for the ES Module loader",
&EnvironmentOptions::experimental_json_modules,
kAllowedInEnvironment);
AddOption("--experimental-modules",
"experimental ES Module support and caching modules",
&EnvironmentOptions::experimental_modules,
Expand Down
1 change: 0 additions & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class DebugOptions : public Options {
class EnvironmentOptions : public Options {
public:
bool abort_on_uncaught_exception = false;
bool experimental_json_modules = false;
bool experimental_modules = false;
std::string es_module_specifier_resolution;
bool experimental_wasm_modules = false;
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-json-cache.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --experimental-json-modules
// Flags: --experimental-modules
import '../common/index.mjs';

import { strictEqual, deepStrictEqual } from 'assert';
Expand Down
3 changes: 2 additions & 1 deletion test/es-module/test-esm-json.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Flags: --experimental-modules --experimental-json-modules
// Flags: --experimental-modules

import '../common/index.mjs';
import { strictEqual } from 'assert';

Expand Down

0 comments on commit ec8776d

Please sign in to comment.