Skip to content

Commit 662848e

Browse files
Merge pull request #3204 from pierreb-devkit/docs/config-merge-documentation
docs(config): document merge architecture and array replacement semantics
2 parents 6d8066a + aeea2f5 commit 662848e

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,42 @@ GITHUB_TOKEN=xxx npm run release:auto # Semantic release (CI)
114114

115115
## :wrench: Configuration
116116

117-
Configuration files live in `config/defaults/`. The `development.js` file is the base; other files in that folder override it.
117+
Configuration is split between a **global** file and **per-module** files, then merged at startup into a single config object.
118118

119-
Environment variables prefixed with `DEVKIT_NODE_` are merged on top. The variable path maps directly to the config object key:
119+
### File layout
120+
121+
Only `config.*.js` files participate in the merge. Other config files in module directories (e.g. policy, seed) are loaded separately by their own init logic.
122+
123+
```text
124+
config/defaults/
125+
config.development.js ← global defaults (app, db, host, port, log, seed, …)
126+
config.production.js ← production overrides
127+
config.test.js ← test overrides
128+
129+
modules/<name>/config/
130+
config.development.js ← module defaults (e.g. uploads, auth, tasks)
131+
config.<env>.js ← module env overrides (optional)
132+
```
133+
134+
### Merge order (priority ascending)
135+
136+
| Layer | Source | Example |
137+
|-------|--------|---------|
138+
| 1 | Module development defaults | `modules/*/config/config.development.js` |
139+
| 2 | Global development defaults | `config/defaults/config.development.js` |
140+
| 3 | Module env overrides | `modules/*/config/config.<env>.js` |
141+
| 4 | Global env overrides | `config/defaults/config.<env>.js` |
142+
| 5 | `DEVKIT_NODE_*` env vars | `DEVKIT_NODE_app_title='my app'` |
143+
144+
Layers 3–4 are only applied when `NODE_ENV` is not `development`.
145+
146+
### Merge semantics
147+
148+
- **Objects** are merged recursively — keys from higher layers override lower layers, unmentioned keys are preserved.
149+
- **Arrays are replaced entirely** — a higher-priority layer defining a 2-item array replaces a 4-item array from a lower layer. Items are never merged by index.
150+
- **`undefined` values** are skipped — they do not overwrite existing keys.
151+
152+
### Environment variables
120153

121154
```bash
122155
DEVKIT_NODE_app_title='my app' # sets config.app.title

0 commit comments

Comments
 (0)