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 274c18a

Browse filesBrowse files
marco-ippolitotargos
authored andcommitted
src: set default config as node.config.json
PR-URL: #57171 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 5a21fa4 commit 274c18a
Copy full SHA for 274c18a

File tree

Expand file treeCollapse file tree

14 files changed

+114
-22
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

14 files changed

+114
-22
lines changed
Open diff view settings
Collapse file

‎Makefile‎

Copy file name to clipboardExpand all lines: Makefile
+1-1Lines 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.
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+22-9Lines changed: 22 additions & 9 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -919,29 +919,30 @@ flows within the application. As such, it is presently recommended to be sure
919919
your application behaviour is unaffected by this change before using it in
920920
production.
921921

922-
### `--experimental-config-file`
922+
### `--experimental-config-file=config`
923923

924924
<!-- YAML
925925
added: REPLACEME
926926
-->
927927

928928
> Stability: 1.0 - Early development
929929
930-
Use this flag to specify a configuration file that will be loaded and parsed
931-
before the application starts.
930+
If present, Node.js will look for a
931+
configuration file at the specified path.
932932
Node.js will read the configuration file and apply the settings.
933933
The configuration file should be a JSON file
934934
with the following structure:
935935

936+
> \[!NOTE]
937+
> Replace `vX.Y.Z` in the `$schema` with the version of Node.js you are using.
938+
936939
```json
937940
{
938-
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node_config_json_schema.json",
941+
"$schema": "https://nodejs.org/dist/vX.Y.Z/docs/node-config-schema.json",
939942
"nodeOptions": {
940-
"experimental-transform-types": true,
941943
"import": [
942-
"amaro/transform"
944+
"amaro/strip"
943945
],
944-
"disable-warning": "ExperimentalWarning",
945946
"watch-path": "src",
946947
"watch-preserve-output": true
947948
}
@@ -952,7 +953,7 @@ In the `nodeOptions` field, only flags that are allowed in [`NODE_OPTIONS`][] ar
952953
No-op flags are not supported.
953954
Not all V8 flags are currently supported.
954955

955-
It is possible to use the [official JSON schema](../node_config_json_schema.json)
956+
It is possible to use the [official JSON schema](../node-config-schema.json)
956957
to validate the configuration file, which may vary depending on the Node.js version.
957958
Each key in the configuration file corresponds to a flag that can be passed
958959
as a command-line argument. The value of the key is the value that would be
@@ -962,7 +963,7 @@ For example, the configuration file above is equivalent to
962963
the following command-line arguments:
963964

964965
```bash
965-
node --experimental-transform-types --import amaro/transform --disable-warning=ExperimentalWarning --watch-path=src --watch-preserve-output
966+
node --import amaro/strip --watch-path=src --watch-preserve-output
966967
```
967968

968969
The priority in configuration is as follows:
@@ -984,6 +985,18 @@ unknown keys or keys that cannot used in `NODE_OPTIONS`.
984985
Node.js will not sanitize or perform validation on the user-provided configuration,
985986
so **NEVER** use untrusted configuration files.
986987

988+
### `--experimental-default-config-file`
989+
990+
<!-- YAML
991+
added: REPLACEME
992+
-->
993+
994+
> Stability: 1.0 - Early development
995+
996+
If the `--experimental-default-config-file` flag is present, Node.js will look for a
997+
`node.config.json` file in the current working directory and load it as a
998+
as configuration file.
999+
9871000
### `--experimental-eventsource`
9881001

9891002
<!-- YAML
Collapse file

‎doc/node.1‎

Copy file name to clipboardExpand all lines: doc/node.1
+4-1Lines 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 configuration file to load.
171+
.
172+
.It Fl -experimental-default-config-file
173+
Enable support for automatically loading node.config.json.
171174
.
172175
.It Fl -experimental-import-meta-resolve
173176
Enable experimental ES modules support for import.meta.resolve().
Collapse file

‎lib/internal/process/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js
+2-1Lines 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
}
Collapse file

‎src/node_config_file.cc‎

Copy file name to clipboardExpand all lines: src/node_config_file.cc
+15-5Lines 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

Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+4-1Lines 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);
Collapse file

‎src/node_options.h‎

Copy file name to clipboardExpand all lines: src/node_options.h
+2-1Lines 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_; }
Collapse file
+5Lines 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+
}
Collapse file
+5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.