@meltstudio/config-loader 3.7.0 → 3.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,37 @@ yarn add @meltstudio/config-loader
|
|
|
68
68
|
|
|
69
69
|
Requires Node.js >= 20.
|
|
70
70
|
|
|
71
|
+
## Watch Mode
|
|
72
|
+
|
|
73
|
+
Automatically reload config when files change. Watchers use `.unref()` so they don't prevent the process from exiting.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const watcher = c
|
|
77
|
+
.schema({
|
|
78
|
+
port: c.number({ env: "PORT", defaultValue: 3000 }),
|
|
79
|
+
host: c.string({ defaultValue: "localhost" }),
|
|
80
|
+
})
|
|
81
|
+
.watch(
|
|
82
|
+
{ env: true, args: false, files: "./config.yaml" },
|
|
83
|
+
{
|
|
84
|
+
onChange: (newConfig, oldConfig, changes) => {
|
|
85
|
+
for (const change of changes) {
|
|
86
|
+
console.log(
|
|
87
|
+
`${change.path}: ${String(change.oldValue)} → ${String(change.newValue)}`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
onError: (err) => console.error("Reload failed:", err.message),
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Access current config anytime
|
|
96
|
+
console.log(watcher.config.port);
|
|
97
|
+
|
|
98
|
+
// Stop watching
|
|
99
|
+
watcher.close();
|
|
100
|
+
```
|
|
101
|
+
|
|
71
102
|
## Documentation
|
|
72
103
|
|
|
73
104
|
See the **[full documentation](https://meltstudio.github.io/config-loader/)** for:
|
package/dist/index.js
CHANGED
|
@@ -1258,6 +1258,7 @@ function createWatcher(schema2, sources, options) {
|
|
|
1258
1258
|
if (closed) return;
|
|
1259
1259
|
try {
|
|
1260
1260
|
clearFileCache();
|
|
1261
|
+
clearEnvFileCache();
|
|
1261
1262
|
const settings = new settings_default(schema2, sources);
|
|
1262
1263
|
const newConfig = settings.get();
|
|
1263
1264
|
const changes = diffConfig(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltstudio/config-loader",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"description": "Type-safe configuration loader with full TypeScript inference. Load from YAML, JSON, TOML, .env, environment variables, and CLI args.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|