| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7b9400c commit eb4f443
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,20 +156,6 @@ Enable experimental Source Map V3 support for stack traces. | |||
| 156 | 156 | Currently, overriding `Error.prepareStackTrace` is ignored when the | |
| 157 | 157 | `--enable-source-maps` flag is set. | |
| 158 | 158 | ||
| 159 | - ### `--es-module-specifier-resolution=mode` | ||
| 160 | - <!-- YAML | ||
| 161 | - added: v12.0.0 | ||
| 162 | - --> | ||
| 163 | - | ||
| 164 | - Sets the resolution algorithm for resolving ES module specifiers. Valid options | ||
| 165 | - are `explicit` and `node`. | ||
| 166 | - | ||
| 167 | - The default is `explicit`, which requires providing the full path to a | ||
| 168 | - module. The `node` mode will enable support for optional file extensions and | ||
| 169 | - the ability to import a directory that has an index file. | ||
| 170 | - | ||
| 171 | - Please see [customizing ESM specifier resolution][] for example usage. | ||
| 172 | - | ||
| 173 | 159 | ### `--experimental-conditional-exports` | |
| 174 | 160 | <!-- YAML | |
| 175 | 161 | added: v13.2.0 | |
@@ -223,6 +209,20 @@ added: v13.1.0 | |||
| 223 | 209 | Enable experimental support for a package using `require` or `import` to load | |
| 224 | 210 | itself. | |
| 225 | 211 | ||
| 212 | + ### `--experimental-specifier-resolution=mode` | ||
| 213 | + <!-- YAML | ||
| 214 | + added: REPLACEME | ||
| 215 | + --> | ||
| 216 | + | ||
| 217 | + Sets the resolution algorithm for resolving ES module specifiers. Valid options | ||
| 218 | + are `explicit` and `node`. | ||
| 219 | + | ||
| 220 | + The default is `explicit`, which requires providing the full path to a | ||
| 221 | + module. The `node` mode will enable support for optional file extensions and | ||
| 222 | + the ability to import a directory that has an index file. | ||
| 223 | + | ||
| 224 | + Please see [customizing ESM specifier resolution][] for example usage. | ||
| 225 | + | ||
| 226 | 226 | ### `--experimental-vm-modules` | |
| 227 | 227 | <!-- YAML | |
| 228 | 228 | added: v9.6.0 | |
@@ -1045,7 +1045,6 @@ Node.js options that are allowed are: | |||
| 1045 | 1045 | <!-- node-options-node start --> | |
| 1046 | 1046 | * `--enable-fips` | |
| 1047 | 1047 | * `--enable-source-maps` | |
| 1048 | - * `--es-module-specifier-resolution` | ||
| 1049 | 1048 | * `--experimental-conditional-exports` | |
| 1050 | 1049 | * `--experimental-json-modules` | |
| 1051 | 1050 | * `--experimental-loader` | |
@@ -1054,6 +1053,7 @@ Node.js options that are allowed are: | |||
| 1054 | 1053 | * `--experimental-repl-await` | |
| 1055 | 1054 | * `--experimental-report` | |
| 1056 | 1055 | * `--experimental-resolve-self` | |
| 1056 | + * `--experimental-specifier-resolution` | ||
| 1057 | 1057 | * `--experimental-vm-modules` | |
| 1058 | 1058 | * `--experimental-wasi-unstable-preview0` | |
| 1059 | 1059 | * `--experimental-wasm-modules` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1372,7 +1372,7 @@ the CommonJS loader. One of the behavior differences is automatic resolution | |||
| 1372 | 1372 | of file extensions and the ability to import directories that have an index | |
| 1373 | 1373 | file. | |
| 1374 | 1374 | ||
| 1375 | - The `--es-module-specifier-resolution=[mode]` flag can be used to customize | ||
| 1375 | + The `--experimental-specifier-resolution=[mode]` flag can be used to customize | ||
| 1376 | 1376 | the extension resolution algorithm. The default mode is `explicit`, which | |
| 1377 | 1377 | requires the full path to a module be provided to the loader. To enable the | |
| 1378 | 1378 | automatic extension resolution and importing from directories that include an | |
@@ -1383,7 +1383,7 @@ $ node index.mjs | |||
| 1383 | 1383 | success! | |
| 1384 | 1384 | $ node index # Failure! | |
| 1385 | 1385 | Error: Cannot find module | |
| 1386 | - $ node --es-module-specifier-resolution=node index | ||
| 1386 | + $ node --experimental-specifier-resolution=node index | ||
| 1387 | 1387 | success! | |
| 1388 | 1388 | ``` | |
| 1389 | 1389 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -110,9 +110,6 @@ Enable FIPS-compliant crypto at startup. | |||
| 110 | 110 | Requires Node.js to be built with | |
| 111 | 111 | .Sy ./configure --openssl-fips . | |
| 112 | 112 | . | |
| 113 | - .It Fl -es-module-specifier-resolution | ||
| 114 | - Select extension resolution algorithm for ES Modules; either 'explicit' (default) or 'node' | ||
| 115 | - . | ||
| 116 | 113 | .It Fl -experimental-conditional-exports | |
| 117 | 114 | Enable experimental support for "require" and "node" conditional export targets. | |
| 118 | 115 | . | |
@@ -130,6 +127,9 @@ Enable experimental top-level | |||
| 130 | 127 | .Sy await | |
| 131 | 128 | keyword support in REPL. | |
| 132 | 129 | . | |
| 130 | + .It Fl -experimental-specifier-resolution | ||
| 131 | + Select extension resolution algorithm for ES Modules; either 'explicit' (default) or 'node' | ||
| 132 | + . | ||
| 133 | 133 | .It Fl -experimental-report | |
| 134 | 134 | Enable experimental | |
| 135 | 135 | .Sy diagnostic report | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,8 +13,8 @@ const { getOptionValue } = require('internal/options'); | |||
| 13 | 13 | const preserveSymlinks = getOptionValue('--preserve-symlinks'); | |
| 14 | 14 | const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); | |
| 15 | 15 | const experimentalJsonModules = getOptionValue('--experimental-json-modules'); | |
| 16 | - const esModuleSpecifierResolution = | ||
| 17 | - getOptionValue('--es-module-specifier-resolution'); | ||
| 16 | + const experimentalSpeciferResolution = | ||
| 17 | + getOptionValue('--experimental-specifier-resolution'); | ||
| 18 | 18 | const typeFlag = getOptionValue('--input-type'); | |
| 19 | 19 | const experimentalWasmModules = getOptionValue('--experimental-wasm-modules'); | |
| 20 | 20 | const { resolve: moduleWrapResolve, | |
@@ -110,10 +110,14 @@ function resolve(specifier, parentURL) { | |||
| 110 | 110 | if (ext === '.js' || (!format && isMain)) | |
| 111 | 111 | format = getPackageType(url.href) === TYPE_MODULE ? 'module' : 'commonjs'; | |
| 112 | 112 | if (!format) { | |
| 113 | - if (esModuleSpecifierResolution === 'node') | ||
| 113 | + if (experimentalSpeciferResolution === 'node') { | ||
| 114 | + process.emitWarning( | ||
| 115 | + 'The Node.js specifier resolution in ESM is experimental.', | ||
| 116 | + 'ExperimentalWarning'); | ||
| 114 | 117 | format = legacyExtensionFormatMap[ext]; | |
| 115 | - else | ||
| 118 | + } else { | ||
| 116 | 119 | throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url)); | |
| 120 | + } | ||
| 117 | 121 | } | |
| 118 | 122 | return { url: `${url}`, format }; | |
| 119 | 123 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -789,7 +789,7 @@ inline Maybe<URL> ResolveIndex(const URL& search) { | |||
| 789 | 789 | Maybe<URL> FinalizeResolution(Environment* env, | |
| 790 | 790 | const URL& resolved, | |
| 791 | 791 | const URL& base) { | |
| 792 | - if (env->options()->es_module_specifier_resolution == "node") { | ||
| 792 | + if (env->options()->experimental_specifier_resolution == "node") { | ||
| 793 | 793 | Maybe<URL> file = ResolveExtensions<TRY_EXACT_NAME>(resolved); | |
| 794 | 794 | if (!file.IsNothing()) { | |
| 795 | 795 | return file; | |
@@ -1053,7 +1053,7 @@ Maybe<URL> PackageMainResolve(Environment* env, | |||
| 1053 | 1053 | return Just(resolved); | |
| 1054 | 1054 | } | |
| 1055 | 1055 | } | |
| 1056 | - if (env->options()->es_module_specifier_resolution == "node") { | ||
| 1056 | + if (env->options()->experimental_specifier_resolution == "node") { | ||
| 1057 | 1057 | if (pcfg.has_main == HasMain::Yes) { | |
| 1058 | 1058 | return FinalizeResolution(env, URL(pcfg.main, pjson_url), base); | |
| 1059 | 1059 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,9 +128,23 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) { | |||
| 128 | 128 | } | |
| 129 | 129 | ||
| 130 | 130 | if (!es_module_specifier_resolution.empty()) { | |
| 131 | - if (es_module_specifier_resolution != "node" && | ||
| 132 | - es_module_specifier_resolution != "explicit") { | ||
| 133 | - errors->push_back("invalid value for --es-module-specifier-resolution"); | ||
| 131 | + if (!experimental_specifier_resolution.empty()) { | ||
| 132 | + errors->push_back( | ||
| 133 | + "bad option: cannot use --es-module-specifier-resolution" | ||
| 134 | + " and --experimental-specifier-resolution at the same time"); | ||
| 135 | + } else { | ||
| 136 | + experimental_specifier_resolution = es_module_specifier_resolution; | ||
| 137 | + if (experimental_specifier_resolution != "node" && | ||
| 138 | + experimental_specifier_resolution != "explicit") { | ||
| 139 | + errors->push_back( | ||
| 140 | + "invalid value for --es-module-specifier-resolution"); | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + } else if (!experimental_specifier_resolution.empty()) { | ||
| 144 | + if (experimental_specifier_resolution != "node" && | ||
| 145 | + experimental_specifier_resolution != "explicit") { | ||
| 146 | + errors->push_back( | ||
| 147 | + "invalid value for --experimental-specifier-resolution"); | ||
| 134 | 148 | } | |
| 135 | 149 | } | |
| 136 | 150 | ||
@@ -365,9 +379,13 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 365 | 379 | "set module type for string input", | |
| 366 | 380 | &EnvironmentOptions::module_type, | |
| 367 | 381 | kAllowedInEnvironment); | |
| 368 | - AddOption("--es-module-specifier-resolution", | ||
| 382 | + AddOption("--experimental-specifier-resolution", | ||
| 369 | 383 | "Select extension resolution algorithm for es modules; " | |
| 370 | 384 | "either 'explicit' (default) or 'node'", | |
| 385 | + &EnvironmentOptions::experimental_specifier_resolution, | ||
| 386 | + kAllowedInEnvironment); | ||
| 387 | + AddOption("--es-module-specifier-resolution", | ||
| 388 | + "", | ||
| 371 | 389 | &EnvironmentOptions::es_module_specifier_resolution, | |
| 372 | 390 | kAllowedInEnvironment); | |
| 373 | 391 | AddOption("--no-deprecation", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,6 +104,7 @@ class EnvironmentOptions : public Options { | |||
| 104 | 104 | bool experimental_conditional_exports = false; | |
| 105 | 105 | bool experimental_json_modules = false; | |
| 106 | 106 | bool experimental_resolve_self = false; | |
| 107 | + std::string experimental_specifier_resolution; | ||
| 107 | 108 | std::string es_module_specifier_resolution; | |
| 108 | 109 | bool experimental_wasm_modules = false; | |
| 109 | 110 | std::string module_type; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + import { mustCall } from '../common/index.mjs'; | ||
| 2 | + import { exec } from 'child_process'; | ||
| 3 | + import assert from 'assert'; | ||
| 4 | + | ||
| 5 | + const expectedError = | ||
| 6 | + 'cannot use --es-module-specifier-resolution ' + | ||
| 7 | + 'and --experimental-specifier-resolution at the same time'; | ||
| 8 | + | ||
| 9 | + const flags = '--es-module-specifier-resolution=node ' + | ||
| 10 | + '--experimental-specifier-resolution=node'; | ||
| 11 | + | ||
| 12 | + exec(`${process.execPath} ${flags}`, { | ||
| 13 | + timeout: 300 | ||
| 14 | + }, mustCall((error) => { | ||
| 15 | + assert(error.message.includes(expectedError)); | ||
| 16 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + // Flags: --es-module-specifier-resolution=node | ||
| 2 | + import '../common/index.mjs'; | ||
| 3 | + import assert from 'assert'; | ||
| 4 | + | ||
| 5 | + // commonJS index.js | ||
| 6 | + import commonjs from '../fixtures/es-module-specifiers/package-type-commonjs'; | ||
| 7 | + // esm index.js | ||
| 8 | + import module from '../fixtures/es-module-specifiers/package-type-module'; | ||
| 9 | + // Notice the trailing slash | ||
| 10 | + import success, { explicit, implicit, implicitModule } | ||
| 11 | + from '../fixtures/es-module-specifiers/'; | ||
| 12 | + | ||
| 13 | + assert.strictEqual(commonjs, 'commonjs'); | ||
| 14 | + assert.strictEqual(module, 'module'); | ||
| 15 | + assert.strictEqual(success, 'success'); | ||
| 16 | + assert.strictEqual(explicit, 'esm'); | ||
| 17 | + assert.strictEqual(implicit, 'cjs'); | ||
| 18 | + assert.strictEqual(implicitModule, 'cjs'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // Flags: --es-module-specifier-resolution=node | ||
| 1 | + // Flags: --experimental-specifier-resolution=node | ||
| 2 | 2 | import { mustNotCall } from '../common/index.mjs'; | |
| 3 | 3 | import assert from 'assert'; | |
| 4 | 4 | import path from 'path'; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments