Skip to content

Commit

Permalink
module: unflag esm json modules
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Jan 29, 2022
1 parent d86dcaa commit e116204
Show file tree
Hide file tree
Showing 21 changed files with 35 additions and 88 deletions.
3 changes: 0 additions & 3 deletions doc/node.1
Expand Up @@ -142,9 +142,6 @@ Enable Source Map V3 support for stack traces.
.It Fl -experimental-import-meta-resolve
Enable experimental ES modules support for import.meta.resolve().
.
.It Fl -experimental-json-modules
Enable experimental JSON interop support for the ES Module loader.
.
.It Fl -experimental-loader Ns = Ns Ar module
Specify the
.Ar module
Expand Down
11 changes: 4 additions & 7 deletions lib/internal/modules/esm/get_format.js
Expand Up @@ -8,7 +8,6 @@ const {
const { extname } = require('path');
const { getOptionValue } = require('internal/options');

const experimentalJsonModules = getOptionValue('--experimental-json-modules');
const experimentalSpecifierResolution =
getOptionValue('--experimental-specifier-resolution');
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
Expand All @@ -20,7 +19,8 @@ const extensionFormatMap = {
'__proto__': null,
'.cjs': 'commonjs',
'.js': 'module',
'.mjs': 'module'
'.json': 'json',
'.mjs': 'module',
};

const legacyExtensionFormatMap = {
Expand All @@ -29,17 +29,14 @@ const legacyExtensionFormatMap = {
'.js': 'commonjs',
'.json': 'commonjs',
'.mjs': 'module',
'.node': 'commonjs'
'.node': 'commonjs',
};

let experimentalSpecifierResolutionWarned = false;

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

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

const protocolHandlers = ObjectAssign(ObjectCreate(null), {
'data:'(parsed) {
const { 1: mime } = RegExpPrototypeExec(
Expand All @@ -49,7 +46,7 @@ const protocolHandlers = ObjectAssign(ObjectCreate(null), {
const format = ({
'__proto__': null,
'text/javascript': 'module',
'application/json': experimentalJsonModules ? 'json' : null,
'application/json': 'json',
'application/wasm': experimentalWasmModules ? 'wasm' : null
})[mime] || null;

Expand Down
1 change: 0 additions & 1 deletion lib/internal/modules/esm/translators.js
Expand Up @@ -259,7 +259,6 @@ translators.set('builtin', async function builtinStrategy(url) {

// Strategy for loading a JSON file
translators.set('json', async function jsonStrategy(url, source) {
emitExperimentalWarning('Importing JSON modules');
assertBufferSource(source, true, 'load');
debug(`Loading JSONModule ${url}`);
const pathname = StringPrototypeStartsWith(url, 'file:') ?
Expand Down
10 changes: 2 additions & 8 deletions src/node_options.cc
Expand Up @@ -315,19 +315,13 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
kAllowedInEnvironment);
AddOption("--experimental-abortcontroller", "",
NoOp{}, kAllowedInEnvironment);
AddOption("--experimental-json-modules",
"experimental JSON interop support for the ES Module loader",
&EnvironmentOptions::experimental_json_modules,
kAllowedInEnvironment);
AddOption("--experimental-json-modules", "", NoOp{}, kAllowedInEnvironment);
AddOption("--experimental-loader",
"use the specified module as a custom loader",
&EnvironmentOptions::userland_loader,
kAllowedInEnvironment);
AddAlias("--loader", "--experimental-loader");
AddOption("--experimental-modules",
"",
&EnvironmentOptions::experimental_modules,
kAllowedInEnvironment);
AddOption("--experimental-modules","", NoOp{}, kAllowedInEnvironment);
AddOption("--experimental-wasm-modules",
"experimental ES Module support for webassembly modules",
&EnvironmentOptions::experimental_wasm_modules,
Expand Down
2 changes: 0 additions & 2 deletions src/node_options.h
Expand Up @@ -107,8 +107,6 @@ class EnvironmentOptions : public Options {
std::vector<std::string> conditions;
std::string dns_result_order;
bool enable_source_maps = false;
bool experimental_json_modules = false;
bool experimental_modules = false;
std::string experimental_specifier_resolution;
bool experimental_wasm_modules = false;
bool experimental_import_meta_resolve = false;
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-assertionless-json-import.js
@@ -1,4 +1,4 @@
// Flags: --experimental-json-modules --experimental-loader ./test/fixtures/es-module-loaders/assertionless-json-import.mjs
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/assertionless-json-import.mjs
'use strict';
const common = require('../common');
const { strictEqual } = require('assert');
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-data-urls.js
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
'use strict';
const common = require('../common');
const assert = require('assert');
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-dynamic-import-assertion.js
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
'use strict';
const common = require('../common');
const { strictEqual } = require('assert');
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-dynamic-import-assertion.mjs
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { strictEqual } from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-import-assertion-1.mjs
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { strictEqual } from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-import-assertion-2.mjs
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { strictEqual } from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-import-assertion-3.mjs
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { strictEqual } from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-import-assertion-4.mjs
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { strictEqual } from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-import-assertion-errors.js
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
'use strict';
const common = require('../common');
const { rejects } = require('assert');
Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-import-assertion-errors.mjs
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { rejects } from 'assert';

Expand Down
1 change: 0 additions & 1 deletion test/es-module/test-esm-import-json-named-export.mjs
Expand Up @@ -5,7 +5,6 @@ import { spawn } from 'child_process';
import { execPath } from 'process';

const child = spawn(execPath, [
'--experimental-json-modules',
path('es-modules', 'import-json-named-export.mjs'),
]);

Expand Down
14 changes: 4 additions & 10 deletions test/es-module/test-esm-invalid-data-urls.js
Expand Up @@ -5,20 +5,14 @@ const assert = require('assert');
(async () => {
await assert.rejects(import('data:text/plain,export default0'), {
code: 'ERR_INVALID_MODULE_SPECIFIER',
message:
'Invalid module "data:text/plain,export default0" has an unsupported ' +
'MIME type "text/plain"',
message: 'Invalid module "data:text/plain,export default0" has an unsupported MIME type "text/plain"',
});
await assert.rejects(import('data:text/plain;base64,'), {
code: 'ERR_INVALID_MODULE_SPECIFIER',
message:
'Invalid module "data:text/plain;base64," has an unsupported ' +
'MIME type "text/plain"',
message: 'Invalid module "data:text/plain;base64," has an unsupported MIME type "text/plain"',
});
await assert.rejects(import('data:application/json,[]'), {
await assert.rejects(import('data:text/css,.error { color: red; }'), {
code: 'ERR_INVALID_MODULE_SPECIFIER',
message:
'Invalid module "data:application/json,[]" has an unsupported ' +
'MIME type "application/json"',
message: 'Invalid module "data:text/css,.error { color: red; }" has an unsupported MIME type "text/css"',
});
})().then(common.mustCall());
1 change: 0 additions & 1 deletion test/es-module/test-esm-json-cache.mjs
@@ -1,4 +1,3 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';

import { strictEqual, deepStrictEqual } from 'assert';
Expand Down
25 changes: 1 addition & 24 deletions test/es-module/test-esm-json.mjs
@@ -1,29 +1,6 @@
// Flags: --experimental-json-modules
import '../common/index.mjs';
import { path } from '../common/fixtures.mjs';
import { strictEqual, ok } from 'assert';
import { spawn } from 'child_process';
import { strictEqual } from 'assert';

import secret from '../fixtures/experimental.json' assert { type: 'json' };

strictEqual(secret.ofLife, 42);

// Test warning message
const child = spawn(process.execPath, [
'--experimental-json-modules',
path('/es-modules/json-modules.mjs'),
]);

let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => {
stderr += data;
});
child.on('close', (code, signal) => {
strictEqual(code, 0);
strictEqual(signal, null);
ok(stderr.toString().includes(
'ExperimentalWarning: Importing JSON modules is an experimental feature. ' +
'This feature could change at any time'
));
});
21 changes: 0 additions & 21 deletions test/es-module/test-esm-non-js.js

This file was deleted.

23 changes: 23 additions & 0 deletions test/es-module/test-esm-non-js.mjs
@@ -0,0 +1,23 @@
import { mustCall } from '../common/index.mjs';
import { fileURL } from '../common/fixtures.mjs';
import { match, strictEqual } from 'assert';
import { spawn } from 'child_process';
import { execPath } from 'process';

// Verify non-js extensions fail for ESM
const child = spawn(execPath, [
'--input-type=module',
'--eval',
`import ${JSON.stringify(fileURL('es-modules', 'file.unknown'))}`,
]);

let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => {
stderr += data;
});
child.on('close', mustCall((code, signal) => {
strictEqual(code, 1);
strictEqual(signal, null);
match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);
}));

0 comments on commit e116204

Please sign in to comment.