Skip to content

Commit 1c66278

Browse files
marco-ippolitoaduh95
authored andcommitted
src: add config file support
PR-URL: #57016 Backport-PR-URL: #57958 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 e62a147 commit 1c66278

33 files changed

+1438
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +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 $@
810811

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

doc/api/cli.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,69 @@ files with no extension will be treated as WebAssembly if they begin with the
941941
WebAssembly magic number (`\0asm`); otherwise they will be treated as ES module
942942
JavaScript.
943943

944+
### `--experimental-config-file`
945+
946+
<!-- YAML
947+
added: REPLACEME
948+
-->
949+
950+
> Stability: 1.0 - Early development
951+
952+
Use this flag to specify a configuration file that will be loaded and parsed
953+
before the application starts.
954+
Node.js will read the configuration file and apply the settings.
955+
The configuration file should be a JSON file
956+
with the following structure:
957+
958+
```json
959+
{
960+
"$schema": "https://nodejs.org/dist/REPLACEME/docs/node_config_json_schema.json",
961+
"experimental-transform-types": true,
962+
"import": [
963+
"amaro/transform"
964+
],
965+
"disable-warning": "ExperimentalWarning",
966+
"watch-path": "src",
967+
"watch-preserve-output": true
968+
}
969+
```
970+
971+
Only flags that are allowed in [`NODE_OPTIONS`][] are supported.
972+
No-op flags are not supported.
973+
Not all V8 flags are currently supported.
974+
975+
It is possible to use the [official JSON schema](../node_config_json_schema.json)
976+
to validate the configuration file, which may vary depending on the Node.js version.
977+
Each key in the configuration file corresponds to a flag that can be passed
978+
as a command-line argument. The value of the key is the value that would be
979+
passed to the flag.
980+
981+
For example, the configuration file above is equivalent to
982+
the following command-line arguments:
983+
984+
```bash
985+
node --experimental-transform-types --import amaro/transform --disable-warning=ExperimentalWarning --watch-path=src --watch-preserve-output
986+
```
987+
988+
The priority in configuration is as follows:
989+
990+
1. NODE\_OPTIONS and command-line options
991+
2. Configuration file
992+
3. Dotenv NODE\_OPTIONS
993+
994+
Values in the configuration file will not override the values in the environment
995+
variables and command-line options, but will override the values in the `NODE_OPTIONS`
996+
env file parsed by the `--env-file` flag.
997+
998+
If duplicate keys are present in the configuration file, only
999+
the first key will be used.
1000+
1001+
The configuration parser will throw an error if the configuration file contains
1002+
unknown keys or keys that cannot used in `NODE_OPTIONS`.
1003+
1004+
Node.js will not sanitize or perform validation on the user-provided configuration,
1005+
so **NEVER** use untrusted configuration files.
1006+
9441007
### `--experimental-eventsource`
9451008

9461009
<!-- YAML

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ Interpret as either ES modules or CommonJS modules input via --eval or STDIN, wh
168168
.js or extensionless files with no sibling or parent package.json;
169169
.js or extensionless files whose nearest parent package.json lacks a "type" field, unless under node_modules.
170170
.
171+
.It Fl -experimental-config-file
172+
Enable support for experimental config file
173+
.
171174
.It Fl -experimental-import-meta-resolve
172175
Enable experimental ES modules support for import.meta.resolve().
173176
.

0 commit comments

Comments
 (0)