Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 99bb02f

Browse filesBrowse files
marco-ippolitoaduh95
authored andcommitted
src: swap dotenv and config file parsing order
Signed-off-by: Marco Ippolito <marcoippolito54@gmail.com> PR-URL: #63035 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 7cd2066 commit 99bb02f
Copy full SHA for 99bb02f

4 files changed

+14-11Lines changed: 14 additions & 11 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1020,12 +1020,12 @@ node --import amaro/strip --watch-path=src --watch-preserve-output --test-isolat
10201020
The priority in configuration is as follows:
10211021

10221022
1. NODE\_OPTIONS and command-line options
1023-
2. Configuration file
1024-
3. Dotenv NODE\_OPTIONS
1023+
2. Dotenv NODE\_OPTIONS
1024+
3. Configuration file
10251025

10261026
Values in the configuration file will not override the values in the environment
1027-
variables and command-line options, but will override the values in the `NODE_OPTIONS`
1028-
env file parsed by the `--env-file` flag.
1027+
variables, command-line options, or the `NODE_OPTIONS` env file parsed by the
1028+
`--env-file` flag.
10291029

10301030
Keys cannot be duplicated within the same or different namespaces.
10311031

Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ static ExitCode InitializeNodeWithArgsInternal(
879879
HandleEnvOptions(per_process::cli_options->per_isolate->per_env);
880880

881881
std::string node_options;
882+
std::string node_options_from_dotenv;
882883
auto env_files = node::Dotenv::GetDataFromArgs(*argv);
883884

884885
if (!env_files.empty()) {
@@ -905,7 +906,8 @@ static ExitCode InitializeNodeWithArgsInternal(
905906
}
906907
}
907908

908-
per_process::dotenv_file.AssignNodeOptionsIfAvailable(&node_options);
909+
per_process::dotenv_file.AssignNodeOptionsIfAvailable(
910+
&node_options_from_dotenv);
909911
}
910912

911913
std::string node_options_from_config;
@@ -935,9 +937,10 @@ static ExitCode InitializeNodeWithArgsInternal(
935937
errors->emplace_back("The number of NODE_OPTIONS doesn't match "
936938
"the number of flags in the config file");
937939
}
938-
node_options += node_options_from_config;
939940
}
940941

942+
node_options = node_options_from_config + node_options_from_dotenv;
943+
941944
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
942945
bool should_parse_node_options =
943946
!(flags & ProcessInitializationFlags::kDisableNodeOptionsEnv);
Collapse file

‎src/node_dotenv.cc‎

Copy file name to clipboardExpand all lines: src/node_dotenv.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) const {
345345
auto match = store_.find("NODE_OPTIONS");
346346

347347
if (match != store_.end()) {
348-
*node_options = match->second;
348+
*node_options = " " + match->second;
349349
}
350350
}
351351

Collapse file

‎test/parallel/test-config-file.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-config-file.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ test('should throw an error when a flag is declared twice', async () => {
9292
assert.strictEqual(result.code, 9);
9393
});
9494

95-
test('should override env-file', onlyWithAmaroAndNodeOptions, async () => {
95+
test('should not override env-file', onlyWithAmaroAndNodeOptions, async () => {
9696
const result = await spawnPromisified(process.execPath, [
9797
'--no-warnings',
9898
'--experimental-config-file',
9999
fixtures.path('rc/transform-types.json'),
100100
'--env-file', fixtures.path('dotenv/node-options-no-tranform.env'),
101101
fixtures.path('typescript/ts/transformation/test-enum.ts'),
102102
]);
103-
assert.strictEqual(result.stderr, '');
104-
assert.match(result.stdout, /Hello, TypeScript!/);
105-
assert.strictEqual(result.code, 0);
103+
assert.match(result.stderr, /SyntaxError/);
104+
assert.strictEqual(result.stdout, '');
105+
assert.strictEqual(result.code, 1);
106106
});
107107

108108
test('should not override NODE_OPTIONS', onlyWithAmaro, async () => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.