From 272828d16d26f49383f64886472783b5a84de4fd Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Tue, 27 Aug 2024 13:46:11 +0200 Subject: [PATCH] src: add config file support --- doc/api/cli.md | 40 +++++++ doc/node.1 | 3 + doc/node_config_json_schema.json | 10 ++ lib/internal/process/pre_execution.js | 8 ++ node.gyp | 2 + src/node.cc | 21 ++++ src/node_options.cc | 3 + src/node_options.h | 1 + src/node_rc.cc | 97 +++++++++++++++++ src/node_rc.h | 35 ++++++ .../dotenv/node-options-no-tranform.env | 1 + test/fixtures/rc/empty-object.json | 4 + test/fixtures/rc/empty.json | 1 + test/fixtures/rc/override-property.json | 4 + test/fixtures/rc/transform-types.json | 3 + test/parallel/test-config_rc.js | 101 ++++++++++++++++++ 16 files changed, 334 insertions(+) create mode 100644 doc/node_config_json_schema.json create mode 100644 src/node_rc.cc create mode 100644 src/node_rc.h create mode 100644 test/fixtures/dotenv/node-options-no-tranform.env create mode 100644 test/fixtures/rc/empty-object.json create mode 100644 test/fixtures/rc/empty.json create mode 100644 test/fixtures/rc/override-property.json create mode 100644 test/fixtures/rc/transform-types.json create mode 100644 test/parallel/test-config_rc.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 9c5af91ae13f915..d3839e4b923b510 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -911,6 +911,46 @@ added: v23.6.0 Enable experimental import support for `.node` addons. +### `--experimental-config-file` + + + +> Stability: 1.0 - Early development + +Use this flag to specify a configuration file that will be loaded and parsed +before the application starts. +Node.js will read the configuration file and apply the settings. +The configuration file should be a JSON file +with the following structure: + +```json +{ + "experimental_transform_types": true +} +``` + +The priority in configuration is as follows: + +* NODE\_OPTIONS and command-line options +* Config file +* Dotenv NODE\_OPTIONS + +If multiple keys are present in the configuration file, +the last one will override the previous ones. +Unknown keys will be ignored. + +It possible to use the official json schema to validate the configuration file, +which may vary depending on the Node.js version. + +```json +{ + "$schema": "https://nodejs.org/dist/REPLACEME/node_config_json_schema.json", + "experimental_transform_types": true +} +``` + ### `--experimental-eventsource`