configate 0.1.0 → 0.1.3

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.
@@ -1,4 +1,7 @@
1
1
  import type { DefaultConfig, Environment, FileExtension } from './common.ts';
2
+ /**
3
+ * Import multiple config files in defined order and merge them deeply together
4
+ */
2
5
  export declare function importConfigFiles<Config extends DefaultConfig>({ configDir, environment, fileExtensions, }: ImportConfigFilesOptions): Promise<DefaultConfig>;
3
6
  type ImportConfigFilesOptions = {
4
7
  configDir: string;
@@ -1,11 +1,16 @@
1
1
  import { deepMerge } from "./deepMerge.js";
2
2
  import { importConfigFile } from "./importConfigFile.js";
3
+ /**
4
+ * Import multiple config files in defined order and merge them deeply together
5
+ */
3
6
  export async function importConfigFiles({ configDir, environment, fileExtensions, }) {
7
+ /** default.ext **/
4
8
  const defaultConfig = await importConfigFile({
5
9
  filePath: `${configDir}/default`,
6
10
  fileExtensions,
7
11
  shouldThrowError: true,
8
12
  });
13
+ /** {environment}.ext **/
9
14
  let envConfig;
10
15
  if (environment) {
11
16
  try {
@@ -19,16 +24,19 @@ export async function importConfigFiles({ configDir, environment, fileExtensions
19
24
  console.warn(`Environment ${environment} defined but no config file found`);
20
25
  }
21
26
  }
27
+ /** local.ext **/
22
28
  const localConfig = await importConfigFile({
23
29
  filePath: `${configDir}/local`,
24
30
  fileExtensions,
25
31
  });
32
+ /** local-{environment}.ext **/
26
33
  const localEnvConfig = environment
27
34
  ? await importConfigFile({
28
35
  filePath: `${configDir}/local-${environment}`,
29
36
  fileExtensions,
30
37
  })
31
38
  : {};
39
+ /** custom-environment-variables.ext **/
32
40
  const customEnvVarsConfig = await importConfigFile({
33
41
  filePath: `${configDir}/custom-environment-variables`,
34
42
  fileExtensions: fileExtensions.filter((ext) => ext !== 'json'), // JSON not supported because it cannot use `process.env`
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { defineConfig } from './defineConfig.ts';
2
- export type { DeepPartial, Environment, FileExtension } from './common.ts';
1
+ export { loadConfig } from './loadConfig.ts';
2
+ export type { DeepPartial, FileExtension } from './common.ts';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { defineConfig } from "./defineConfig.js";
1
+ export { loadConfig } from "./loadConfig.js";
@@ -25,11 +25,11 @@ import type { DefaultConfig, Environment, FileExtension } from './common.ts';
25
25
  * - `config` - a secure, frozen object with the loaded config. Throws an error if an undefined property is accessed
26
26
  * - `unsecureConfig` - an unsecure config. May be needed if config is passed directly to some module that wants to read undefined props or modify it
27
27
  */
28
- export declare function defineConfig<Config extends DefaultConfig>({ configDirs, environment, fileExtensions, throwOnUndefinedProp, freezeConfig, }: DefineConfigOptions): Promise<{
28
+ export declare function loadConfig<Config extends DefaultConfig>({ configDirs, environment, fileExtensions, throwOnUndefinedProp, freezeConfig, }?: LoadConfigOptions): Promise<{
29
29
  config: Config;
30
30
  unsecureConfig: Config;
31
31
  }>;
32
- type DefineConfigOptions = {
32
+ type LoadConfigOptions = {
33
33
  configDirs?: string[];
34
34
  environment?: Environment;
35
35
  fileExtensions?: FileExtension[];
@@ -28,7 +28,7 @@ import { makeSecureDeepProxy } from "./makeSecureDeepProxy.js";
28
28
  * - `config` - a secure, frozen object with the loaded config. Throws an error if an undefined property is accessed
29
29
  * - `unsecureConfig` - an unsecure config. May be needed if config is passed directly to some module that wants to read undefined props or modify it
30
30
  */
31
- export async function defineConfig({ configDirs = [`${process.cwd()}/config`], environment = process.env.NODE_ENV, fileExtensions = ['ts', 'js'], throwOnUndefinedProp = true, freezeConfig = true, }) {
31
+ export async function loadConfig({ configDirs = [`${process.cwd()}/config`], environment = process.env.NODE_ENV, fileExtensions = ['ts', 'js'], throwOnUndefinedProp = true, freezeConfig = true, } = {}) {
32
32
  let mergedConfig = {};
33
33
  for (const configDir of configDirs) {
34
34
  const config = await importConfigFiles({
package/package.json CHANGED
@@ -1,43 +1,47 @@
1
1
  {
2
- "name": "configate",
3
- "version": "0.1.0",
4
- "type": "module",
5
- "description": "Configuration helper for TypeScript applications",
6
- "main": "dist/index.js",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "default": "./dist/index.js",
12
- "import": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
14
- }
15
- },
16
- "scripts": {
17
- "build": "tsc",
18
- "ci": "node --run test && npm run typecheck && node --run lint",
19
- "lint": "biome check",
20
- "test": "node --test-isolation=none --test-reporter=spec --experimental-test-coverage --test-coverage-exclude='src/{testConfigDirs/**/*,**/*.test.ts}' --test 'src/**/*.test.ts'",
21
- "typecheck": "tsc --noEmit"
22
- },
23
- "files": ["dist"],
24
- "engines": {
25
- "node": ">= 20"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/mdrobny/configate.git"
30
- },
31
- "keywords": ["config"],
32
- "author": "Michal Drobniak",
33
- "license": "Apache-2.0",
34
- "bugs": {
35
- "url": "https://github.com/mdrobny/configate/issues"
36
- },
37
- "homepage": "https://github.com/mdrobny/configate#readme",
38
- "devDependencies": {
39
- "@biomejs/biome": "1.9.4",
40
- "@types/node": "^22.10.6",
41
- "typescript": "^5.7.3"
42
- }
2
+ "name": "configate",
3
+ "version": "0.1.3",
4
+ "type": "module",
5
+ "description": "Configuration helper for TypeScript applications",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "default": "./dist/index.js",
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "ci": "node --run test && npm run typecheck && node --run lint",
19
+ "lint": "biome check",
20
+ "test": "node --test-isolation=none --test-reporter=spec --experimental-test-coverage --test-coverage-exclude='src/{testConfigDirs/**/*,**/*.test.ts}' --test 'src/**/*.test.ts'",
21
+ "typecheck": "tsc --noEmit"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "engines": {
27
+ "node": ">= 20"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/mdrobny/configate.git"
32
+ },
33
+ "keywords": [
34
+ "config"
35
+ ],
36
+ "author": "Michal Drobniak",
37
+ "license": "Apache-2.0",
38
+ "bugs": {
39
+ "url": "https://github.com/mdrobny/configate/issues"
40
+ },
41
+ "homepage": "https://github.com/mdrobny/configate#readme",
42
+ "devDependencies": {
43
+ "@biomejs/biome": "1.9.4",
44
+ "@types/node": "^22.10.6",
45
+ "typescript": "^5.7.3"
46
+ }
43
47
  }