Skip to content

Commit e5a01b1

Browse files
src: set default config as node.config.json
1 parent 5f49a6b commit e5a01b1

File tree

14 files changed

+114
-22
lines changed

14 files changed

+114
-22
lines changed

β€ŽMakefileβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ doc: $(NODE_EXE) doc-only ## Build Node.js, and then build the documentation wit
807807

808808
out/doc:
809809
mkdir -p $@
810-
cp doc/node_config_json_schema.json $@
810+
cp doc/node-config-schema.json $@
811811

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

β€Ždoc/api/cli.mdβ€Ž

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -939,29 +939,30 @@ files with no extension will be treated as WebAssembly if they begin with the
939939
WebAssembly magic number (`\0asm`); otherwise they will be treated as ES module
940940
JavaScript.
941941

942-
### `--experimental-config-file`
942+
### `--experimental-config-file=config`
943943

944944
<!-- YAML
945945
added: REPLACEME
946946
-->
947947

948948
> Stability: 1.0 - Early development
949949
950-
Use this flag to specify a configuration file that will be loaded and parsed
951-
before the application starts.
950+
If present, Node.js will look for a
951+
configuration file at the specified path.
952952
Node.js will read the configuration file and apply the settings.
953953
The configuration file should be a JSON file
954954
with the following structure:
955955

956+
> \[!NOTE]
957+
> Replace `vX.Y.Z` in the `$schema` with the version of Node.js you are using.
958+
956959
```json
957960
{
958-
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node_config_json_schema.json",
961+
"$schema": "https://nodejs.org/dist/vX.Y.Z/docs/node-config-schema.json",
959962
"nodeOptions": {
960-
"experimental-transform-types": true,
961963
"import": [
962-
"amaro/transform"
964+
"amaro/strip"
963965
],
964-
"disable-warning": "ExperimentalWarning",
965966
"watch-path": "src",
966967
"watch-preserve-output": true
967968
}
@@ -972,7 +973,7 @@ In the `nodeOptions` field, only flags that are allowed in [`NODE_OPTIONS`][] ar
972973
No-op flags are not supported.
973974
Not all V8 flags are currently supported.
974975

975-
It is possible to use the [official JSON schema](../node_config_json_schema.json)
976+
It is possible to use the [official JSON schema](../node-config-schema.json)
976977
to validate the configuration file, which may vary depending on the Node.js version.
977978
Each key in the configuration file corresponds to a flag that can be passed
978979
as a command-line argument. The value of the key is the value that would be
@@ -982,7 +983,7 @@ For example, the configuration file above is equivalent to
982983
the following command-line arguments:
983984

984985
```bash
985-
node --experimental-transform-types --import amaro/transform --disable-warning=ExperimentalWarning --watch-path=src --watch-preserve-output
986+
node --import amaro/strip --watch-path=src --watch-preserve-output
986987
```
987988

988989
The priority in configuration is as follows:
@@ -1004,6 +1005,18 @@ unknown keys or keys that cannot used in `NODE_OPTIONS`.
10041005
Node.js will not sanitize or perform validation on the user-provided configuration,
10051006
so **NEVER** use untrusted configuration files.
10061007

1008+
### `--experimental-default-config-file`
1009+
1010+
<!-- YAML
1011+
added: REPLACEME
1012+
-->
1013+
1014+
> Stability: 1.0 - Early development
1015+
1016+
If the `--experimental-default-config-file` flag is present, Node.js will look for a
1017+
`node.config.json` file in the current working directory and load it as a
1018+
as configuration file.
1019+
10071020
### `--experimental-eventsource`
10081021

10091022
<!-- YAML
File renamed without changes.

β€Ždoc/node.1β€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ Interpret as either ES modules or CommonJS modules input via --eval or STDIN, wh
169169
.js or extensionless files whose nearest parent package.json lacks a "type" field, unless under node_modules.
170170
.
171171
.It Fl -experimental-config-file
172-
Enable support for experimental config file
172+
Specifies the configuration file to load.
173+
.
174+
.It Fl -experimental-default-config-file
175+
Enable support for automatically loading node.config.json.
173176
.
174177
.It Fl -experimental-import-meta-resolve
175178
Enable experimental ES modules support for import.meta.resolve().

β€Žlib/internal/process/pre_execution.jsβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ function setupSQLite() {
393393
}
394394

395395
function initializeConfigFileSupport() {
396-
if (getOptionValue('--experimental-config-file')) {
396+
if (getOptionValue('--experimental-default-config-file') ||
397+
getOptionValue('--experimental-config-file')) {
397398
emitExperimentalWarning('--experimental-config-file');
398399
}
399400
}

β€Žsrc/node_config_file.ccβ€Ž

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,32 @@ 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";
12+
constexpr std::string_view default_file =
13+
"--experimental-default-config-file";
14+
15+
bool has_default_config_file = false;
1216

1317
for (auto it = args.begin(); it != args.end(); ++it) {
14-
if (*it == flag) {
18+
if (*it == flag_path) {
1519
// Case: "--experimental-config-file foo"
1620
if (auto next = std::next(it); next != args.end()) {
1721
return *next;
1822
}
19-
} else if (it->starts_with(flag)) {
23+
} else if (it->starts_with(flag_path)) {
2024
// Case: "--experimental-config-file=foo"
21-
if (it->size() > flag.size() && (*it)[flag.size()] == '=') {
22-
return it->substr(flag.size() + 1);
25+
if (it->size() > flag_path.size() && (*it)[flag_path.size()] == '=') {
26+
return it->substr(flag_path.size() + 1);
2327
}
28+
} else if (*it == default_file || it->starts_with(default_file)) {
29+
has_default_config_file = true;
2430
}
2531
}
2632

33+
if (has_default_config_file) {
34+
return "node.config.json";
35+
}
36+
2737
return std::nullopt;
2838
}
2939

β€Žsrc/node_options.ccβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
690690
Implies("--env-file-if-exists", "[has_env_file_string]");
691691
AddOption("--experimental-config-file",
692692
"set config file from supplied file",
693-
&EnvironmentOptions::experimental_config_file);
693+
&EnvironmentOptions::experimental_config_file_path);
694+
AddOption("--experimental-default-config-file",
695+
"set config file from default config file",
696+
&EnvironmentOptions::experimental_default_config_file);
694697
AddOption("--test",
695698
"launch test runner on startup",
696699
&EnvironmentOptions::test_runner);

β€Žsrc/node_options.hβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ class EnvironmentOptions : public Options {
257257

258258
bool report_exclude_env = false;
259259
bool report_exclude_network = false;
260-
std::string experimental_config_file;
260+
std::string experimental_config_file_path;
261+
bool experimental_default_config_file = false;
261262

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

0 commit comments

Comments
Β (0)