src: swap dotenv and config file parsing order · nodejs/node@99bb02f · GitHub
Skip to content

Commit 99bb02f

Browse 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

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

doc/api/cli.md

Lines changed: 4 additions & 4 deletions

src/node.cc

Lines 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);

src/node_dotenv.cc

Lines 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

test/parallel/test-config-file.js

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)