Skip to content

Commit

Permalink
fixup: support both flags and give proper warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesBorins committed Nov 27, 2019
1 parent 60a9dcb commit db9f3ec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
20 changes: 19 additions & 1 deletion src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,20 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
}
}

if (!experimental_specifier_resolution.empty()) {
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 != "node" &&
experimental_specifier_resolution != "explicit") {
errors->push_back(
Expand Down Expand Up @@ -367,6 +380,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"either 'explicit' (default) or 'node'",
&EnvironmentOptions::experimental_specifier_resolution,
kAllowedInEnvironment);
AddOption("--es-module-specifier-resolution",
"Select extension resolution algorithm for es modules; "
"either 'explicit' (default) or 'node'",
&EnvironmentOptions::es_module_specifier_resolution,
kAllowedInEnvironment);
AddOption("--no-deprecation",
"silence deprecation warnings",
&EnvironmentOptions::no_deprecation,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class EnvironmentOptions : public Options {
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;
std::string experimental_policy;
Expand Down
28 changes: 10 additions & 18 deletions test/es-module/test-esm-specifiers-both-flags.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import '../common/index.mjs';
import { mustCall } from '../common/index.mjs';
import { exec } from 'child_process';
import { ok, strictEqual } from 'assert';
import assert from 'assert';

const expectedMessage = [
'Command failed: node --es-module-specifier-resolution=node',
' --experimental-specifier-resolution=node\n',
'node: bad option: cannot use --es-module-specifier-resolution',
'and --experimental-specifier-resolution at the same time'
].join(' ');
const expectedError =
'node: bad option: cannot use --es-module-specifier-resolution ' +
'and --experimental-specifier-resolution at the same time';

function handleError(error, stdout, stderr) {
ok(error);
strictEqual(error.message, expectedMessage);
}

const flags = [
'--es-module-specifier-resolution=node',
'--experimental-specifier-resolution=node'
].join(' ');
const flags = '--es-module-specifier-resolution=node ' +
'--experimental-specifier-resolution=node';

exec(`${process.execPath} ${flags}`, {
timeout: 300
}, handleError);
}, mustCall((error) => {
assert(error.message.includes(expectedError));
}));

0 comments on commit db9f3ec

Please sign in to comment.