Skip to content

Commit c0373f2

Browse files
src: set default config as node.config.json
1 parent 044d69a commit c0373f2

13 files changed

+141
-45
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ doc: $(NODE_EXE) doc-only ## Build Node.js, and then build the documentation wit
809809

810810
out/doc:
811811
mkdir -p $@
812-
cp doc/node_config_json_schema.json $@
812+
cp doc/node-config-schema.json $@
813813

814814
# If it's a source tarball, doc/api already contains the generated docs.
815815
# Just copy everything under doc/api over.

doc/api/cli.md

+28-8
Original file line numberDiff line numberDiff line change
@@ -919,21 +919,24 @@ added: REPLACEME
919919

920920
> Stability: 1.0 - Early development
921921
922-
Use this flag to specify a configuration file that will be loaded and parsed
923-
before the application starts.
922+
If the `--experimental-config-file` flag is present, Node.js will look for a
923+
`node.config.json` file in the current working directory and load it as a
924+
as configuration file.
925+
926+
If [`--experimental-config-file-path`][] is present, Node.js will look for a
927+
configuration file at the specified path.
928+
924929
Node.js will read the configuration file and apply the settings.
925930
The configuration file should be a JSON file
926931
with the following structure:
927932

928933
```json
929934
{
930-
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node_config_json_schema.json",
935+
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node-config-schema.json",
931936
"nodeOptions": {
932-
"experimental-transform-types": true,
933937
"import": [
934-
"amaro/transform"
938+
"amaro/strip"
935939
],
936-
"disable-warning": "ExperimentalWarning",
937940
"watch-path": "src",
938941
"watch-preserve-output": true
939942
}
@@ -944,7 +947,7 @@ In the `nodeOptions` field, only flags that are allowed in [`NODE_OPTIONS`][] ar
944947
No-op flags are not supported.
945948
Not all V8 flags are currently supported.
946949

947-
It is possible to use the [official JSON schema](../node_config_json_schema.json)
950+
It is possible to use the [official JSON schema](../node-config-schema.json)
948951
to validate the configuration file, which may vary depending on the Node.js version.
949952
Each key in the configuration file corresponds to a flag that can be passed
950953
as a command-line argument. The value of the key is the value that would be
@@ -954,7 +957,7 @@ For example, the configuration file above is equivalent to
954957
the following command-line arguments:
955958

956959
```bash
957-
node --experimental-transform-types --import amaro/transform --disable-warning=ExperimentalWarning --watch-path=src --watch-preserve-output
960+
node --import amaro/strip --watch-path=src --watch-preserve-output
958961
```
959962

960963
The priority in configuration is as follows:
@@ -976,6 +979,22 @@ unknown keys or keys that cannot used in `NODE_OPTIONS`.
976979
Node.js will not sanitize or perform validation on the user-provided configuration,
977980
so **NEVER** use untrusted configuration files.
978981

982+
### `--experimental-config-file-path`
983+
984+
<!-- YAML
985+
added: REPLACEME
986+
-->
987+
988+
> Stability: 1.0 - Early development
989+
990+
Use this flag to specify the path to the configuration file that will be loaded
991+
and parsed before the application starts.
992+
Example:
993+
994+
```bash
995+
node --experimental-config-file-path=/path/to/config.json index.js
996+
```
997+
979998
### `--experimental-eventsource`
980999

9811000
<!-- YAML
@@ -3833,6 +3852,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
38333852
[`--env-file-if-exists`]: #--env-file-if-existsconfig
38343853
[`--env-file`]: #--env-fileconfig
38353854
[`--experimental-addon-modules`]: #--experimental-addon-modules
3855+
[`--experimental-config-file-path`]: #--experimental-config-file-path
38363856
[`--experimental-sea-config`]: single-executable-applications.md#generating-single-executable-preparation-blobs
38373857
[`--experimental-wasm-modules`]: #--experimental-wasm-modules
38383858
[`--heap-prof-dir`]: #--heap-prof-dir
File renamed without changes.

doc/node.1

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ Enable experimental addon module support.
169169
.It Fl -experimental-config-file
170170
Enable support for experimental config file
171171
.
172+
.It Fl -experimental-config-file-path
173+
Specifies the experimental config file path
174+
.
172175
.It Fl -experimental-import-meta-resolve
173176
Enable experimental ES modules support for import.meta.resolve().
174177
.

src/node_config_file.cc

+16-7
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,31 @@ namespace node {
88

99
std::optional<std::string_view> ConfigReader::GetDataFromArgs(
1010
const std::vector<std::string>& args) {
11-
constexpr std::string_view flag = "--experimental-config-file";
11+
constexpr std::string_view flag_path = "--experimental-config-file-path";
12+
constexpr std::string_view flag_file = "--experimental-config-file";
13+
14+
bool has_experimental_config_file = false;
1215

1316
for (auto it = args.begin(); it != args.end(); ++it) {
14-
if (*it == flag) {
15-
// Case: "--experimental-config-file foo"
17+
if (*it == flag_path) {
18+
// Case: "--experimental-config-file-path foo"
1619
if (auto next = std::next(it); next != args.end()) {
1720
return *next;
1821
}
19-
} else if (it->starts_with(flag)) {
20-
// Case: "--experimental-config-file=foo"
21-
if (it->size() > flag.size() && (*it)[flag.size()] == '=') {
22-
return it->substr(flag.size() + 1);
22+
} else if (it->starts_with(flag_path)) {
23+
// Case: "--experimental-config-file-path=foo"
24+
if (it->size() > flag_path.size() && (*it)[flag_path.size()] == '=') {
25+
return it->substr(flag_path.size() + 1);
2326
}
27+
} else if (*it == flag_file || it->starts_with(flag_file)) {
28+
has_experimental_config_file = true;
2429
}
2530
}
2631

32+
if (has_experimental_config_file) {
33+
return "node.config.json";
34+
}
35+
2736
return std::nullopt;
2837
}
2938

src/node_options.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
684684
&EnvironmentOptions::optional_env_file);
685685
Implies("--env-file-if-exists", "[has_env_file_string]");
686686
AddOption("--experimental-config-file",
687-
"set config file from supplied file",
687+
"set config file from node.config.json file",
688688
&EnvironmentOptions::experimental_config_file);
689+
AddOption("--experimental-config-file-path",
690+
"set config file from supplied file",
691+
&EnvironmentOptions::experimental_config_file_path);
692+
Implies("--experimental-config-file-path", "--experimental-config-file");
689693
AddOption("--test",
690694
"launch test runner on startup",
691695
&EnvironmentOptions::test_runner);

src/node_options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ class EnvironmentOptions : public Options {
258258

259259
bool report_exclude_env = false;
260260
bool report_exclude_network = false;
261-
std::string experimental_config_file;
261+
bool experimental_config_file = false;
262+
std::string experimental_config_file_path;
262263

263264
inline DebugOptions* get_debug_options() { return &debug_options_; }
264265
inline const DebugOptions& debug_options() const { return debug_options_; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"max-http-header-size": 10
4+
}
5+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"max-http-header-size": 20
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"max-http-header-size": 10
4+
}
5+
}

0 commit comments

Comments
 (0)