From 992af4e112be918f00cdafcf22a8faca89ecfeba Mon Sep 17 00:00:00 2001 From: himself65 Date: Tue, 8 Sep 2020 15:45:58 +0800 Subject: [PATCH] module: fix specifier resolution option value Fixes: https://github.com/nodejs/node/issues/35095 PR-URL: https://github.com/nodejs/node/pull/35098 Reviewed-By: Geoffrey Booth Reviewed-By: Anna Henningsen Reviewed-By: Myles Borins Reviewed-By: Rich Trott --- src/node_options.cc | 21 +++---------------- src/node_options.h | 1 - .../test-esm-specifiers-both-flags.mjs | 14 ------------- test/es-module/test-esm-specifiers.mjs | 13 ++++++++---- 4 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 test/es-module/test-esm-specifiers-both-flags.mjs diff --git a/src/node_options.cc b/src/node_options.cc index 824004631f5301..0240b2ef58ae7a 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -92,20 +92,7 @@ void EnvironmentOptions::CheckOptions(std::vector* errors) { } } - if (!es_module_specifier_resolution.empty()) { - 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.empty()) { if (experimental_specifier_resolution != "node" && experimental_specifier_resolution != "explicit") { errors->push_back( @@ -377,10 +364,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "either 'explicit' (default) or 'node'", &EnvironmentOptions::experimental_specifier_resolution, kAllowedInEnvironment); - AddOption("--es-module-specifier-resolution", - "", - &EnvironmentOptions::es_module_specifier_resolution, - kAllowedInEnvironment); + AddAlias("--es-module-specifier-resolution", + "--experimental-specifier-resolution"); AddOption("--no-deprecation", "silence deprecation warnings", &EnvironmentOptions::no_deprecation, diff --git a/src/node_options.h b/src/node_options.h index 1e7ffadf0dafbc..aa138c6970be45 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -105,7 +105,6 @@ class EnvironmentOptions : public Options { bool experimental_json_modules = false; bool experimental_modules = false; std::string experimental_specifier_resolution; - std::string es_module_specifier_resolution; bool experimental_wasm_modules = false; bool experimental_import_meta_resolve = false; std::string module_type; diff --git a/test/es-module/test-esm-specifiers-both-flags.mjs b/test/es-module/test-esm-specifiers-both-flags.mjs deleted file mode 100644 index a434684589dc07..00000000000000 --- a/test/es-module/test-esm-specifiers-both-flags.mjs +++ /dev/null @@ -1,14 +0,0 @@ -import { mustCall } from '../common/index.mjs'; -import { exec } from 'child_process'; -import assert from 'assert'; - -const expectedError = - 'cannot use --es-module-specifier-resolution ' + - 'and --experimental-specifier-resolution at the same time'; - -const flags = '--es-module-specifier-resolution=node ' + - '--experimental-specifier-resolution=node'; - -exec(`${process.execPath} ${flags}`, mustCall((error) => { - assert(error.message.includes(expectedError)); -})); diff --git a/test/es-module/test-esm-specifiers.mjs b/test/es-module/test-esm-specifiers.mjs index 5e436f21b74cc6..8451a6a703bb65 100644 --- a/test/es-module/test-esm-specifiers.mjs +++ b/test/es-module/test-esm-specifiers.mjs @@ -49,9 +49,14 @@ main().catch(mustNotCall); '../../fixtures/es-module-specifiers', item, ); - spawn(process.execPath, - ['--es-module-specifier-resolution=node', modulePath], - { stdio: 'inherit' }).on('exit', (code) => { - assert.strictEqual(code, 0); + [ + '--experimental-specifier-resolution', + '--es-module-specifier-resolution' + ].forEach((option) => { + spawn(process.execPath, + [`${option}=node`, modulePath], + { stdio: 'inherit' }).on('exit', (code) => { + assert.strictEqual(code, 0); + }); }); });