Skip to content

Commit f0e653d

Browse files
marco-ippolitonodejs-github-bot
authored andcommitted
src: add config file support
PR-URL: #57016 Refs: #53787 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Tierney Cyren <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Paolo Insogna <[email protected]>
1 parent 5ab7c4c commit f0e653d

33 files changed

+1438
-1
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -809,6 +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 $@
812813

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

doc/api/cli.md

+63
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,69 @@ added: v23.6.0
911911
912912
Enable experimental import support for `.node` addons.
913913

914+
### `--experimental-config-file`
915+
916+
<!-- YAML
917+
added: REPLACEME
918+
-->
919+
920+
> Stability: 1.0 - Early development
921+
922+
Use this flag to specify a configuration file that will be loaded and parsed
923+
before the application starts.
924+
Node.js will read the configuration file and apply the settings.
925+
The configuration file should be a JSON file
926+
with the following structure:
927+
928+
```json
929+
{
930+
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node_config_json_schema.json",
931+
"experimental-transform-types": true,
932+
"import": [
933+
"amaro/transform"
934+
],
935+
"disable-warning": "ExperimentalWarning",
936+
"watch-path": "src",
937+
"watch-preserve-output": true
938+
}
939+
```
940+
941+
Only flags that are allowed in [`NODE_OPTIONS`][] are supported.
942+
No-op flags are not supported.
943+
Not all V8 flags are currently supported.
944+
945+
It is possible to use the [official JSON schema](../node_config_json_schema.json)
946+
to validate the configuration file, which may vary depending on the Node.js version.
947+
Each key in the configuration file corresponds to a flag that can be passed
948+
as a command-line argument. The value of the key is the value that would be
949+
passed to the flag.
950+
951+
For example, the configuration file above is equivalent to
952+
the following command-line arguments:
953+
954+
```bash
955+
node --experimental-transform-types --import amaro/transform --disable-warning=ExperimentalWarning --watch-path=src --watch-preserve-output
956+
```
957+
958+
The priority in configuration is as follows:
959+
960+
1. NODE\_OPTIONS and command-line options
961+
2. Configuration file
962+
3. Dotenv NODE\_OPTIONS
963+
964+
Values in the configuration file will not override the values in the environment
965+
variables and command-line options, but will override the values in the `NODE_OPTIONS`
966+
env file parsed by the `--env-file` flag.
967+
968+
If duplicate keys are present in the configuration file, only
969+
the first key will be used.
970+
971+
The configuration parser will throw an error if the configuration file contains
972+
unknown keys or keys that cannot used in `NODE_OPTIONS`.
973+
974+
Node.js will not sanitize or perform validation on the user-provided configuration,
975+
so **NEVER** use untrusted configuration files.
976+
914977
### `--experimental-eventsource`
915978

916979
<!-- YAML

doc/node.1

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ Interpret the entry point as a URL.
166166
.It Fl -experimental-addon-modules
167167
Enable experimental addon module support.
168168
.
169+
.It Fl -experimental-config-file
170+
Enable support for experimental config file
171+
.
169172
.It Fl -experimental-import-meta-resolve
170173
Enable experimental ES modules support for import.meta.resolve().
171174
.

0 commit comments

Comments
 (0)