GeezerVison is showing github.com — src: support multiple versions in node.config.json · nodejs/node@0c6040b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/cli.md +38Lines changed: 38 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1041,6 +1041,44 @@ The configuration file supports namespace-specific options: |
1041 | 1041 |
|
1042 | 1042 | * Namespace fields like `test`, `watch`, and `permission` contain configuration specific to that subsystem. |
1043 | 1043 |
|
| 1044 | +The configuration file can target a specific Node.js major version with |
| 1045 | +`nodeVersion`: |
| 1046 | + |
| 1047 | +```json |
| 1048 | +{ |
| 1049 | + "nodeVersion": 25, |
| 1050 | + "nodeOptions": { |
| 1051 | + "watch-path": "src" |
| 1052 | + } |
| 1053 | +} |
| 1054 | +``` |
| 1055 | + |
| 1056 | +To keep multiple version-specific configurations in the same file, use the |
| 1057 | +`configs` array. Node.js will use the first entry whose `nodeVersion` matches |
| 1058 | +the current Node.js major version: |
| 1059 | + |
| 1060 | +```json |
| 1061 | +{ |
| 1062 | + "$schema": "https://nodejs.org/dist/latest-v26.x/docs/node-config-schema.json", |
| 1063 | + "configs": [ |
| 1064 | + { |
| 1065 | + "nodeVersion": 25, |
| 1066 | + "config": { |
| 1067 | + "$schema": "https://nodejs.org/dist/latest-v25.x/docs/node-config-schema.json", |
| 1068 | + "nodeOptions": { |
| 1069 | + "watch-path": "src" |
| 1070 | + } |
| 1071 | + } |
| 1072 | + } |
| 1073 | + ] |
| 1074 | +} |
| 1075 | +``` |
| 1076 | + |
| 1077 | +When `configs` is used, the top level may only contain `$schema` and |
| 1078 | +`configs`. Each `configs` item must define an integer `nodeVersion` and an |
| 1079 | +object `config`. A single top-level config does not require `nodeVersion`, but |
| 1080 | +if present it must match the current Node.js major version. |
| 1081 | + |
1044 | 1082 | When a namespace is present in the |
1045 | 1083 | configuration file, Node.js automatically enables the corresponding flag |
1046 | 1084 | (e.g., `--test`, `--watch`, `--permission`). This allows you to configure |
|