Skip to content

Commit db9f3ec

Browse files
committedNov 27, 2019
fixup: support both flags and give proper warnings
1 parent 60a9dcb commit db9f3ec

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed
 

‎src/node_options.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,20 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
127127
}
128128
}
129129

130-
if (!experimental_specifier_resolution.empty()) {
130+
if (!es_module_specifier_resolution.empty()) {
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()) {
131144
if (experimental_specifier_resolution != "node" &&
132145
experimental_specifier_resolution != "explicit") {
133146
errors->push_back(
@@ -367,6 +380,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
367380
"either 'explicit' (default) or 'node'",
368381
&EnvironmentOptions::experimental_specifier_resolution,
369382
kAllowedInEnvironment);
383+
AddOption("--es-module-specifier-resolution",
384+
"Select extension resolution algorithm for es modules; "
385+
"either 'explicit' (default) or 'node'",
386+
&EnvironmentOptions::es_module_specifier_resolution,
387+
kAllowedInEnvironment);
370388
AddOption("--no-deprecation",
371389
"silence deprecation warnings",
372390
&EnvironmentOptions::no_deprecation,

‎src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class EnvironmentOptions : public Options {
105105
bool experimental_json_modules = false;
106106
bool experimental_resolve_self = false;
107107
std::string experimental_specifier_resolution;
108+
std::string es_module_specifier_resolution;
108109
bool experimental_wasm_modules = false;
109110
std::string module_type;
110111
std::string experimental_policy;
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
import '../common/index.mjs';
1+
import { mustCall } from '../common/index.mjs';
22
import { exec } from 'child_process';
3-
import { ok, strictEqual } from 'assert';
3+
import assert from 'assert';
44

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

12-
function handleError(error, stdout, stderr) {
13-
ok(error);
14-
strictEqual(error.message, expectedMessage);
15-
}
16-
17-
const flags = [
18-
'--es-module-specifier-resolution=node',
19-
'--experimental-specifier-resolution=node'
20-
].join(' ');
9+
const flags = '--es-module-specifier-resolution=node ' +
10+
'--experimental-specifier-resolution=node';
2111

2212
exec(`${process.execPath} ${flags}`, {
2313
timeout: 300
24-
}, handleError);
14+
}, mustCall((error) => {
15+
assert(error.message.includes(expectedError));
16+
}));

0 commit comments

Comments
 (0)