configate 1.1.0 → 1.2.0

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 CHANGED
@@ -124,8 +124,10 @@ Do the same for other environments if you need to override more properties for t
124
124
  When you need to define secrets in configuration, they should be defined via environment variables.
125
125
 
126
126
  Create `custom-environment-variables.ts` file in `config` directory and export a `config` object.
127
+
127
128
  - use `process.env` to read environment variables and assign to property in your configuration
128
- - this file will be merged with other configs as last one so environment variables always have priority
129
+ - this file is merged last within its directory, so its defined values override other files in that directory
130
+ - when loading multiple directories, later directories can override these values.
129
131
 
130
132
  ```ts
131
133
  // config/custom-environment-variables.ts
@@ -190,6 +192,8 @@ This keeps the base config reusable while still letting you target per-variant o
190
192
 
191
193
  ### Order of loading configuration files
192
194
 
195
+ The following order applies separately within each configuration directory.
196
+
193
197
  ```
194
198
  1. default.ext
195
199
  2. default-{variant}.ext
@@ -250,6 +254,11 @@ const host = config.database.host;
250
254
 
251
255
  #### Loading configurations from multiple directories
252
256
 
257
+ Directories are fully loaded and merged in `configDirs` order.
258
+ Values from later directories override matching properties from earlier directories.
259
+
260
+ For example, a value in the second directory's `default.ts` can override the same property from the first directory's `custom-environment-variables.ts`.
261
+
253
262
  ```ts
254
263
  import { loadConfig } from 'configate';
255
264
 
@@ -4,7 +4,7 @@ import { isObject } from "./common.js";
4
4
  */
5
5
  export function deepFreezeConfig(config) {
6
6
  for (const key in config) {
7
- if (isObject(config[key])) {
7
+ if (isObject(config[key]) || Array.isArray(config[key])) {
8
8
  config[key] = deepFreezeConfig(config[key]);
9
9
  }
10
10
  }
@@ -60,10 +60,17 @@ export async function importConfigFiles({ configDir, environment, variant, fileE
60
60
  fileExtensions,
61
61
  })
62
62
  : {};
63
+ /** local-{environment}-{variant}.ext **/
64
+ const localEnvVariantConfig = environment && variant
65
+ ? await importConfigFile({
66
+ filePath: `${configDir}/local-${environment}-${variant}`,
67
+ fileExtensions,
68
+ })
69
+ : {};
63
70
  /** custom-environment-variables.ext **/
64
71
  const customEnvVarsConfig = await importConfigFile({
65
72
  filePath: `${configDir}/custom-environment-variables`,
66
73
  fileExtensions: fileExtensions.filter((ext) => ext !== 'json'), // JSON not supported because it cannot use `process.env`
67
74
  });
68
- return deepMerge(structuredClone(defaultConfig), structuredClone(defaultVariantConfig ?? {}), structuredClone(environmentConfig ?? {}), structuredClone(environmentVariantConfig ?? {}), structuredClone(localConfig), structuredClone(localVariantConfig ?? {}), structuredClone(localEnvConfig), structuredClone(customEnvVarsConfig));
75
+ return deepMerge(structuredClone(defaultConfig), structuredClone(defaultVariantConfig ?? {}), structuredClone(environmentConfig ?? {}), structuredClone(environmentVariantConfig ?? {}), structuredClone(localConfig), structuredClone(localVariantConfig ?? {}), structuredClone(localEnvConfig), structuredClone(localEnvVariantConfig), structuredClone(customEnvVarsConfig));
69
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configate",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "description": "Configuration helper for TypeScript applications",
6
6
  "main": "dist/index.js",
@@ -30,6 +30,10 @@
30
30
  "type": "git",
31
31
  "url": "git+https://github.com/mdrobny/configate.git"
32
32
  },
33
+ "publishConfig": {
34
+ "registry": "https://registry.npmjs.org",
35
+ "provenance": true
36
+ },
33
37
  "keywords": [
34
38
  "config"
35
39
  ],
@@ -40,8 +44,18 @@
40
44
  },
41
45
  "homepage": "https://github.com/mdrobny/configate#readme",
42
46
  "devDependencies": {
43
- "@biomejs/biome": "2.3.8",
47
+ "@biomejs/biome": "2.5.13",
44
48
  "@types/node": "^22.10.6",
45
49
  "typescript": "^5.7.3"
50
+ },
51
+ "devEngines": {
52
+ "runtime": {
53
+ "name": "node",
54
+ "onFail": "error"
55
+ },
56
+ "packageManager": {
57
+ "name": "npm",
58
+ "onFail": "error"
59
+ }
46
60
  }
47
61
  }