diff --git a/doc/api/cli.md b/doc/api/cli.md index 6a8b3756fe72..948a1e93b7f2 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1516,19 +1516,6 @@ passing a second `parentURL` argument for contextual resolution. Previously gated the entire `import.meta.resolve` feature. -### `--experimental-import-text` - - - -> Stability: 1.0 - Early development - -Enable experimental support for importing modules with -`with { type: 'text' }`. - ### `--experimental-inspector-network-resource` + +Disable importing modules with `with { type: 'text' }`. + ### `--no-experimental-require-module` + +> Stability: 1.2 - Release candidate -Text modules are available behind the `--experimental-import-text` flag. +Text modules can be disabled with the [`--no-experimental-import-text`][] flag. Text files can be referenced by `import`: @@ -1341,6 +1352,7 @@ resolution for ESM specifiers. [`"type"`]: packages.md#type [`--experimental-package-map`]: cli.md#--experimental-package-mappath [`--input-type`]: cli.md#--input-typetype +[`--no-experimental-import-text`]: cli.md#--no-experimental-import-text [`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data [`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export [`import()`]: #import-expressions diff --git a/doc/node.1 b/doc/node.1 index 05fc5418e474..5a711e67dc4a 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -880,10 +880,6 @@ Enable experimental \fBimport.meta.resolve()\fR parent URL support, which allows passing a second \fBparentURL\fR argument for contextual resolution. Previously gated the entire \fBimport.meta.resolve\fR feature. . -.It Fl -experimental-import-text -Enable experimental support for importing modules with -\fBwith { type: 'text' }\fR. -. .It Fl -experimental-inspector-network-resource Enable experimental support for inspector network resources. . @@ -1249,6 +1245,9 @@ This flag is only available in builds with FFI support. .It Fl -no-experimental-global-navigator Disable exposition of Navigator API on the global scope. . +.It Fl -no-experimental-import-text +Disable importing modules with \fBwith { type: 'text' }\fR. +. .It Fl -no-experimental-require-module Legacy alias for \fB--no-require-module\fR. . @@ -2318,8 +2317,6 @@ one is included in the list below. .It \fB--experimental-import-meta-resolve\fR .It -\fB--experimental-import-text\fR -.It \fB--experimental-json-modules\fR .It \fB--experimental-modules\fR @@ -2408,6 +2405,8 @@ one is included in the list below. .It \fB--no-experimental-global-navigator\fR .It +\fB--no-experimental-import-text\fR +.It \fB--no-experimental-sqlite\fR .It \fB--no-experimental-strip-types\fR diff --git a/src/node_options.cc b/src/node_options.cc index 96755e2950cf..35219e28ef13 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -869,7 +869,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "experimental support for importing source as text with import " "attributes", BOOL_FIELD(experimental_import_text), - kAllowedInEnvvar); + kAllowedInEnvvar, + true); AddOption("--experimental-import-meta-resolve", "experimental ES Module import.meta.resolve() parentURL support", BOOL_FIELD(experimental_import_meta_resolve), diff --git a/src/node_options.h b/src/node_options.h index 5a59e9eff72e..b0e3fba2314b 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -226,7 +226,7 @@ class EnvironmentOptions : public Options { DEFINE_BOOL_FIELD(experimental_quic) = EXPERIMENTALS_DEFAULT_VALUE; DEFINE_BOOL_FIELD(experimental_global_navigator) = true; DEFINE_BOOL_FIELD(experimental_global_web_crypto) = true; - DEFINE_BOOL_FIELD(experimental_import_text) = EXPERIMENTALS_DEFAULT_VALUE; + DEFINE_BOOL_FIELD(experimental_import_text) = true; DEFINE_BOOL_FIELD(experimental_import_meta_resolve) = EXPERIMENTALS_DEFAULT_VALUE; DEFINE_BOOL_FIELD(entry_is_url) = false; diff --git a/test/es-module/test-defer-import-text-module.mjs b/test/es-module/test-defer-import-text-module.mjs index e6710d72fd73..63f87534af7e 100644 --- a/test/es-module/test-defer-import-text-module.mjs +++ b/test/es-module/test-defer-import-text-module.mjs @@ -1,4 +1,4 @@ -// Flags: --js-defer-import-eval --experimental-import-text +// Flags: --js-defer-import-eval // Test that uses import.defer for a text module. Currently // defer importing of a synthetic module should be a no-op diff --git a/test/es-module/test-esm-import-attributes-errors.js b/test/es-module/test-esm-import-attributes-errors.js index 5219e8d7b81c..c8ffd9320ad5 100644 --- a/test/es-module/test-esm-import-attributes-errors.js +++ b/test/es-module/test-esm-import-attributes-errors.js @@ -26,11 +26,6 @@ async function test() { { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } ); - await assert.rejects( - import(jsModuleDataUrl, { with: { type: 'text' } }), - { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } - ); - await assert.rejects( import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } diff --git a/test/es-module/test-esm-import-attributes-errors.mjs b/test/es-module/test-esm-import-attributes-errors.mjs index d265e3591be2..1168c109fdc4 100644 --- a/test/es-module/test-esm-import-attributes-errors.mjs +++ b/test/es-module/test-esm-import-attributes-errors.mjs @@ -21,11 +21,6 @@ await assert.rejects( { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } ); -await assert.rejects( - import(jsModuleDataUrl, { with: { type: 'text' } }), - { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } -); - await assert.rejects( import(jsModuleDataUrl, { with: { type: 'json', other: 'unsupported' } }), { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } diff --git a/test/es-module/test-esm-import-attributes-validation-text.js b/test/es-module/test-esm-import-attributes-validation-text.js index 9b509a2d08e3..94984e084012 100644 --- a/test/es-module/test-esm-import-attributes-validation-text.js +++ b/test/es-module/test-esm-import-attributes-validation-text.js @@ -1,4 +1,4 @@ -// Flags: --expose-internals --experimental-import-text +// Flags: --expose-internals 'use strict'; require('../common'); diff --git a/test/es-module/test-esm-import-text-disabled.mjs b/test/es-module/test-esm-import-text-disabled.mjs index 28084f0393b0..2fa67385c645 100644 --- a/test/es-module/test-esm-import-text-disabled.mjs +++ b/test/es-module/test-esm-import-text-disabled.mjs @@ -1,3 +1,4 @@ +// Flags: --no-experimental-import-text import '../common/index.mjs'; import assert from 'assert'; @@ -10,3 +11,8 @@ await assert.rejects( import('data:text/plain,hello%20world', { with: { type: 'text' } }), { code: 'ERR_UNKNOWN_MODULE_FORMAT' }, ); + +await assert.rejects( + import('data:text/javascript,export{}', { with: { type: 'text' } }), + { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }, +); diff --git a/test/es-module/test-esm-import-text.mjs b/test/es-module/test-esm-import-text.mjs index cc3dddb26d48..647aed3b78dc 100644 --- a/test/es-module/test-esm-import-text.mjs +++ b/test/es-module/test-esm-import-text.mjs @@ -1,4 +1,3 @@ -// Flags: --experimental-import-text import '../common/index.mjs'; import assert from 'assert'; diff --git a/test/es-module/test-esm-invalid-data-urls.js b/test/es-module/test-esm-invalid-data-urls.js index 6eafe75e7d7e..765e359aff1e 100644 --- a/test/es-module/test-esm-invalid-data-urls.js +++ b/test/es-module/test-esm-invalid-data-urls.js @@ -4,15 +4,16 @@ const assert = require('assert'); (async () => { await assert.rejects(import('data:text/plain,export default0'), { - code: 'ERR_UNKNOWN_MODULE_FORMAT', + code: 'ERR_IMPORT_ATTRIBUTE_MISSING', message: - 'Unknown module format: text/plain for URL data:text/plain,' + - 'export default0', + 'Module "data:text/plain,export default0" needs an import attribute ' + + 'of "type: text"', }); await assert.rejects(import('data:text/plain;base64,'), { - code: 'ERR_UNKNOWN_MODULE_FORMAT', + code: 'ERR_IMPORT_ATTRIBUTE_MISSING', message: - 'Unknown module format: text/plain for URL data:text/plain;base64,', + 'Module "data:text/plain;base64," needs an import attribute of ' + + '"type: text"', }); await assert.rejects(import('data:text/css,.error { color: red; }'), { code: 'ERR_UNKNOWN_MODULE_FORMAT', diff --git a/test/es-module/test-esm-loader-text-format.mjs b/test/es-module/test-esm-loader-text-format.mjs index 2a35992dbcf4..0fe9c4291325 100644 --- a/test/es-module/test-esm-loader-text-format.mjs +++ b/test/es-module/test-esm-loader-text-format.mjs @@ -1,8 +1,9 @@ +// Flags: --no-experimental-import-text import '../common/index.mjs'; import assert from 'node:assert'; import { registerHooks } from 'node:module'; -// A user loader can use `text` with and without import attributes without the feature flag. +// A user loader can use `text` with and without import attributes when the feature is disabled. registerHooks({ load(url, context, nextLoad) {