Skip to content

Commit 54b272c

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

File tree

14 files changed

+112
-22
lines changed

14 files changed

+112
-22
lines changed

β€ŽMakefileβ€Ž

Lines changed: 1 addition & 1 deletion
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β€Ž

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -911,29 +911,30 @@ added: v23.6.0
911911
912912
Enable experimental import support for `.node` addons.
913913

914-
### `--experimental-config-file`
914+
### `--experimental-config-file=path`
915915

916916
<!-- YAML
917917
added: REPLACEME
918918
-->
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 present, Node.js will look for a
923+
configuration file at the specified path.
924924
Node.js will read the configuration file and apply the settings.
925925
The configuration file should be a JSON file
926926
with the following structure:
927927

928+
> \[!NOTE]
929+
> Replace `vX.Y.Z` in the `$schema` with the version of Node.js you are using.
930+
928931
```json
929932
{
930-
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node_config_json_schema.json",
933+
"$schema": "https://nodejs.org/dist/vX.Y.Z/docs/node-config-schema.json",
931934
"nodeOptions": {
932-
"experimental-transform-types": true,
933935
"import": [
934-
"amaro/transform"
936+
"amaro/strip"
935937
],
936-
"disable-warning": "ExperimentalWarning",
937938
"watch-path": "src",
938939
"watch-preserve-output": true
939940
}
@@ -944,7 +945,7 @@ In the `nodeOptions` field, only flags that are allowed in [`NODE_OPTIONS`][] ar
944945
No-op flags are not supported.
945946
Not all V8 flags are currently supported.
946947

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

956957
```bash
957-
node --experimental-transform-types --import amaro/transform --disable-warning=ExperimentalWarning --watch-path=src --watch-preserve-output
958+
node --import amaro/strip --watch-path=src --watch-preserve-output
958959
```
959960

960961
The priority in configuration is as follows:
@@ -976,6 +977,18 @@ unknown keys or keys that cannot used in `NODE_OPTIONS`.
976977
Node.js will not sanitize or perform validation on the user-provided configuration,
977978
so **NEVER** use untrusted configuration files.
978979

980+
### `--experimental-default-config-file`
981+
982+
<!-- YAML
983+
added: REPLACEME
984+
-->
985+
986+
> Stability: 1.0 - Early development
987+
988+
If the `--experimental-default-config-file` flag is present, Node.js will look for a
989+
`node.config.json` file in the current working directory and load it as a
990+
as configuration file.
991+
979992
### `--experimental-eventsource`
980993

981994
<!-- YAML
File renamed without changes.

β€Ždoc/node.1β€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ Interpret the entry point as a URL.
167167
Enable experimental addon module support.
168168
.
169169
.It Fl -experimental-config-file
170-
Enable support for experimental config file
170+
Specifies the experimental config file path
171+
.
172+
.It Fl -experimental-default-config-file
173+
Enable support for the default experimental config file
171174
.
172175
.It Fl -experimental-import-meta-resolve
173176
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
@@ -315,7 +315,8 @@ function setupSQLite() {
315315
}
316316

317317
function initializeConfigFileSupport() {
318-
if (getOptionValue('--experimental-config-file')) {
318+
if (getOptionValue('--experimental-default-config-file') ||
319+
getOptionValue('--experimental-config-file')) {
319320
emitExperimentalWarning('--experimental-config-file');
320321
}
321322
}

β€Ž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
@@ -685,7 +685,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
685685
Implies("--env-file-if-exists", "[has_env_file_string]");
686686
AddOption("--experimental-config-file",
687687
"set config file from supplied file",
688-
&EnvironmentOptions::experimental_config_file);
688+
&EnvironmentOptions::experimental_config_file_path);
689+
AddOption("--experimental-default-config-file",
690+
"set config file from default config file",
691+
&EnvironmentOptions::experimental_default_config_file);
689692
AddOption("--test",
690693
"launch test runner on startup",
691694
&EnvironmentOptions::test_runner);

β€Žsrc/node_options.hβ€Ž

Lines changed: 2 additions & 1 deletion
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+
std::string experimental_config_file_path;
262+
bool experimental_default_config_file = false;
262263

263264
inline DebugOptions* get_debug_options() { return &debug_options_; }
264265
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)