| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 106e5ce commit fa96f54
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 | - To be used in conjunction with `--experimental-modules`. Sets the resolution | ||
| 165 | - algorithm for resolving specifiers. Valid options 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: REPLACEME | |
@@ -222,6 +208,20 @@ added: REPLACEME | |||
| 222 | 208 | Enable experimental support for a package using `require` or `import` to load | |
| 223 | 209 | itself. | |
| 224 | 210 | ||
| 211 | + ### `--experimental-specifier-resolution=mode` | ||
| 212 | + <!-- YAML | ||
| 213 | + added: REPLACEME | ||
| 214 | + --> | ||
| 215 | + | ||
| 216 | + Sets the resolution algorithm for resolving ES module specifiers. Valid options | ||
| 217 | + are `explicit` and `node`. | ||
| 218 | + | ||
| 219 | + The default is `explicit`, which requires providing the full path to a | ||
| 220 | + module. The `node` mode will enable support for optional file extensions and | ||
| 221 | + the ability to import a directory that has an index file. | ||
| 222 | + | ||
| 223 | + Please see [customizing ESM specifier resolution][] for example usage. | ||
| 224 | + | ||
| 225 | 225 | ### `--experimental-vm-modules` | |
| 226 | 226 | <!-- YAML | |
| 227 | 227 | added: v9.6.0 | |
@@ -1082,7 +1082,6 @@ Node.js options that are allowed are: | |||
| 1082 | 1082 | <!-- node-options-node start --> | |
| 1083 | 1083 | * `--enable-fips` | |
| 1084 | 1084 | * `--enable-source-maps` | |
| 1085 | - * `--es-module-specifier-resolution` | ||
| 1086 | 1085 | * `--experimental-conditional-exports` | |
| 1087 | 1086 | * `--experimental-json-modules` | |
| 1088 | 1087 | * `--experimental-loader` | |
@@ -1091,6 +1090,7 @@ Node.js options that are allowed are: | |||
| 1091 | 1090 | * `--experimental-repl-await` | |
| 1092 | 1091 | * `--experimental-report` | |
| 1093 | 1092 | * `--experimental-resolve-self` | |
| 1093 | + * `--experimental-specifier-resolution` | ||
| 1094 | 1094 | * `--experimental-vm-modules` | |
| 1095 | 1095 | * `--experimental-wasm-modules` | |
| 1096 | 1096 | * `--force-context-aware` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1375,7 +1375,7 @@ the CommonJS loader. One of the behavior differences is automatic resolution | |||
| 1375 | 1375 | of file extensions and the ability to import directories that have an index | |
| 1376 | 1376 | file. | |
| 1377 | 1377 | ||
| 1378 | - The `--es-module-specifier-resolution=[mode]` flag can be used to customize | ||
| 1378 | + The `--experimental-specifier-resolution=[mode]` flag can be used to customize | ||
| 1379 | 1379 | the extension resolution algorithm. The default mode is `explicit`, which | |
| 1380 | 1380 | requires the full path to a module be provided to the loader. To enable the | |
| 1381 | 1381 | automatic extension resolution and importing from directories that include an | |
@@ -1386,7 +1386,7 @@ $ node --experimental-modules index.mjs | |||
| 1386 | 1386 | success! | |
| 1387 | 1387 | $ node --experimental-modules index #Failure! | |
| 1388 | 1388 | Error: Cannot find module | |
| 1389 | - $ node --experimental-modules --es-module-specifier-resolution=node index | ||
| 1389 | + $ node --experimental-modules --experimental-specifier-resolution=node index | ||
| 1390 | 1390 | success! | |
| 1391 | 1391 | ``` | |
| 1392 | 1392 | ||
| 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 | |
|---|---|---|---|
@@ -9,8 +9,8 @@ const { getOptionValue } = require('internal/options'); | |||
| 9 | 9 | const preserveSymlinks = getOptionValue('--preserve-symlinks'); | |
| 10 | 10 | const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); | |
| 11 | 11 | const experimentalJsonModules = getOptionValue('--experimental-json-modules'); | |
| 12 | - const esModuleSpecifierResolution = | ||
| 13 | - getOptionValue('--es-module-specifier-resolution'); | ||
| 12 | + const experimentalSpeciferResolution = | ||
| 13 | + getOptionValue('--experimental-specifier-resolution'); | ||
| 14 | 14 | const typeFlag = getOptionValue('--input-type'); | |
| 15 | 15 | const experimentalWasmModules = getOptionValue('--experimental-wasm-modules'); | |
| 16 | 16 | const { resolve: moduleWrapResolve, | |
@@ -108,10 +108,14 @@ function resolve(specifier, parentURL) { | |||
| 108 | 108 | if (ext === '.js' || (!format && isMain)) | |
| 109 | 109 | format = getPackageType(url.href) === TYPE_MODULE ? 'module' : 'commonjs'; | |
| 110 | 110 | if (!format) { | |
| 111 | - if (esModuleSpecifierResolution === 'node') | ||
| 111 | + if (experimentalSpeciferResolution === 'node') { | ||
| 112 | + process.emitWarning( | ||
| 113 | + 'The Node.js specifier resolution in ESM is experimental.', | ||
| 114 | + 'ExperimentalWarning'); | ||
| 112 | 115 | format = legacyExtensionFormatMap[ext]; | |
| 113 | - else | ||
| 116 | + } else { | ||
| 114 | 117 | throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url)); | |
| 118 | + } | ||
| 115 | 119 | } | |
| 116 | 120 | return { url: `${url}`, format }; | |
| 117 | 121 | } | |
| 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 | |
|---|---|---|---|
@@ -155,9 +155,27 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) { | |||
| 155 | 155 | errors->push_back("--es-module-specifier-resolution requires " | |
| 156 | 156 | "--experimental-modules be enabled"); | |
| 157 | 157 | } | |
| 158 | - if (es_module_specifier_resolution != "node" && | ||
| 159 | - es_module_specifier_resolution != "explicit") { | ||
| 160 | - errors->push_back("invalid value for --es-module-specifier-resolution"); | ||
| 158 | + if (!experimental_specifier_resolution.empty()) { | ||
| 159 | + errors->push_back( | ||
| 160 | + "bad option: cannot use --es-module-specifier-resolution" | ||
| 161 | + " and --experimental-specifier-resolution at the same time"); | ||
| 162 | + } else { | ||
| 163 | + experimental_specifier_resolution = es_module_specifier_resolution; | ||
| 164 | + if (experimental_specifier_resolution != "node" && | ||
| 165 | + experimental_specifier_resolution != "explicit") { | ||
| 166 | + errors->push_back( | ||
| 167 | + "invalid value for --es-module-specifier-resolution"); | ||
| 168 | + } | ||
| 169 | + } | ||
| 170 | + } else if (!experimental_specifier_resolution.empty()) { | ||
| 171 | + if (!experimental_modules) { | ||
| 172 | + errors->push_back("--experimental-specifier-resolution requires " | ||
| 173 | + "--experimental-modules be enabled"); | ||
| 174 | + } | ||
| 175 | + if (experimental_specifier_resolution != "node" && | ||
| 176 | + experimental_specifier_resolution != "explicit") { | ||
| 177 | + errors->push_back( | ||
| 178 | + "invalid value for --experimental-specifier-resolution"); | ||
| 161 | 179 | } | |
| 162 | 180 | } | |
| 163 | 181 | ||
@@ -408,9 +426,13 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 408 | 426 | "set module type for string input", | |
| 409 | 427 | &EnvironmentOptions::module_type, | |
| 410 | 428 | kAllowedInEnvironment); | |
| 411 | - AddOption("--es-module-specifier-resolution", | ||
| 429 | + AddOption("--experimental-specifier-resolution", | ||
| 412 | 430 | "Select extension resolution algorithm for es modules; " | |
| 413 | 431 | "either 'explicit' (default) or 'node'", | |
| 432 | + &EnvironmentOptions::experimental_specifier_resolution, | ||
| 433 | + kAllowedInEnvironment); | ||
| 434 | + AddOption("--es-module-specifier-resolution", | ||
| 435 | + "", | ||
| 414 | 436 | &EnvironmentOptions::es_module_specifier_resolution, | |
| 415 | 437 | kAllowedInEnvironment); | |
| 416 | 438 | AddOption("--no-deprecation", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,6 +105,7 @@ class EnvironmentOptions : public Options { | |||
| 105 | 105 | bool experimental_json_modules = false; | |
| 106 | 106 | bool experimental_modules = false; | |
| 107 | 107 | bool experimental_resolve_self = false; | |
| 108 | + std::string experimental_specifier_resolution; | ||
| 108 | 109 | std::string es_module_specifier_resolution; | |
| 109 | 110 | bool experimental_wasm_modules = false; | |
| 110 | 111 | std::string module_type; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + // Flags: --experimental-modules | ||
| 2 | + import { mustCall } from '../common/index.mjs'; | ||
| 3 | + import { exec } from 'child_process'; | ||
| 4 | + import assert from 'assert'; | ||
| 5 | + | ||
| 6 | + const expectedError = | ||
| 7 | + 'cannot use --es-module-specifier-resolution ' + | ||
| 8 | + 'and --experimental-specifier-resolution at the same time'; | ||
| 9 | + | ||
| 10 | + const flags = '--experimental-modules ' + | ||
| 11 | + '--es-module-specifier-resolution=node ' + | ||
| 12 | + '--experimental-specifier-resolution=node'; | ||
| 13 | + | ||
| 14 | + exec(`${process.execPath} ${flags}`, { | ||
| 15 | + timeout: 300 | ||
| 16 | + }, mustCall((error) => { | ||
| 17 | + assert(error.message.includes(expectedError)); | ||
| 18 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + // Flags: --experimental-modules --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: --experimental-modules --es-module-specifier-resolution=node | ||
| 1 | + // Flags: --experimental-modules --experimental-specifier-resolution=node | ||
| 2 | 2 | import { mustNotCall } from '../common/index.mjs'; | |
| 3 | 3 | import assert from 'assert'; | |
| 4 | 4 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments