From ee953d813be1fb19930e0e64196c0aa33699b133 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Wed, 27 Nov 2019 01:54:23 -0500 Subject: esm: make specifier flag clearly experimental `--es-module-specifier-resolution` is the only flagged portion of the ESM implementation that does not have the word experimental in the flag name. This commit changes the flag to: `--experimental-specifier-resolution` `--es-module-specifier-resolution` remains as an alias for backwards compatibility but it is no longer documented. PR-URL: https://github.com/nodejs/node/pull/30678 Reviewed-By: Jan Krems Reviewed-By: Guy Bedford --- src/module_wrap.cc | 4 ++-- src/node_options.cc | 26 ++++++++++++++++++++++---- src/node_options.h | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 5745cce9e0..3c3d568329 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -789,7 +789,7 @@ inline Maybe ResolveIndex(const URL& search) { Maybe FinalizeResolution(Environment* env, const URL& resolved, const URL& base) { - if (env->options()->es_module_specifier_resolution == "node") { + if (env->options()->experimental_specifier_resolution == "node") { Maybe file = ResolveExtensions(resolved); if (!file.IsNothing()) { return file; @@ -1053,7 +1053,7 @@ Maybe PackageMainResolve(Environment* env, return Just(resolved); } } - if (env->options()->es_module_specifier_resolution == "node") { + if (env->options()->experimental_specifier_resolution == "node") { if (pcfg.has_main == HasMain::Yes) { return FinalizeResolution(env, URL(pcfg.main, pjson_url), base); } else { diff --git a/src/node_options.cc b/src/node_options.cc index 498bedd1e5..abf26fb781 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -128,9 +128,23 @@ void EnvironmentOptions::CheckOptions(std::vector* errors) { } if (!es_module_specifier_resolution.empty()) { - if (es_module_specifier_resolution != "node" && - es_module_specifier_resolution != "explicit") { - errors->push_back("invalid value for --es-module-specifier-resolution"); + if (!experimental_specifier_resolution.empty()) { + errors->push_back( + "bad option: cannot use --es-module-specifier-resolution" + " and --experimental-specifier-resolution at the same time"); + } else { + experimental_specifier_resolution = es_module_specifier_resolution; + if (experimental_specifier_resolution != "node" && + experimental_specifier_resolution != "explicit") { + errors->push_back( + "invalid value for --es-module-specifier-resolution"); + } + } + } else if (!experimental_specifier_resolution.empty()) { + if (experimental_specifier_resolution != "node" && + experimental_specifier_resolution != "explicit") { + errors->push_back( + "invalid value for --experimental-specifier-resolution"); } } @@ -365,9 +379,13 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "set module type for string input", &EnvironmentOptions::module_type, kAllowedInEnvironment); - AddOption("--es-module-specifier-resolution", + AddOption("--experimental-specifier-resolution", "Select extension resolution algorithm for es modules; " "either 'explicit' (default) or 'node'", + &EnvironmentOptions::experimental_specifier_resolution, + kAllowedInEnvironment); + AddOption("--es-module-specifier-resolution", + "", &EnvironmentOptions::es_module_specifier_resolution, kAllowedInEnvironment); AddOption("--no-deprecation", diff --git a/src/node_options.h b/src/node_options.h index fea912da44..c4cb5dc04f 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -104,6 +104,7 @@ class EnvironmentOptions : public Options { bool experimental_conditional_exports = false; bool experimental_json_modules = false; bool experimental_resolve_self = false; + std::string experimental_specifier_resolution; std::string es_module_specifier_resolution; bool experimental_wasm_modules = false; std::string module_type; -- cgit v1.2.3