c12 3.0.4 → 3.1.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
@@ -27,7 +27,7 @@ c12 (pronounced as /siːtwelv/, like c-twelve) is a smart configuration loader.
27
27
  ## 🦴 Used by
28
28
 
29
29
  - [Nuxt](https://nuxt.com/)
30
- - [Nitro](https://nitro.unjs.io/)
30
+ - [Nitro](https://nitro.build/)
31
31
  - [Unbuild](https://unbuild.unjs.io)
32
32
  - [Automd](https://automd.unjs.io)
33
33
  - [Changelogen](https://changelogen.unjs.io)
package/dist/index.d.mts CHANGED
@@ -93,8 +93,10 @@ interface ResolvedConfig<T extends UserInputConfig = UserInputConfig, MT extends
93
93
  layers?: ConfigLayer<T, MT>[];
94
94
  cwd?: string;
95
95
  }
96
+ type ConfigSource = "overrides" | "main" | "rc" | "packageJson" | "defaultConfig";
96
97
  interface ResolvableConfigContext<T extends UserInputConfig = UserInputConfig> {
97
- configs: Record<"overrides" | "main" | "rc" | "packageJson" | "defaultConfig", T | null | undefined>;
98
+ configs: Record<ConfigSource, T | null | undefined>;
99
+ rawConfigs: Record<ConfigSource, ResolvableConfig<T> | null | undefined>;
98
100
  }
99
101
  type MaybePromise<T> = T | Promise<T>;
100
102
  type ResolvableConfig<T extends UserInputConfig = UserInputConfig> = MaybePromise<T | null | undefined> | ((ctx: ResolvableConfigContext<T>) => MaybePromise<T | null | undefined>);
@@ -152,4 +154,4 @@ interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT ext
152
154
  declare function watchConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>>;
153
155
 
154
156
  export { SUPPORTED_EXTENSIONS, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
155
- export type { C12InputConfig, ConfigLayer, ConfigLayerMeta, ConfigWatcher, DefineConfig, DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolvableConfig, ResolvableConfigContext, ResolvedConfig, SourceOptions, UserInputConfig, WatchConfigOptions };
157
+ export type { C12InputConfig, ConfigLayer, ConfigLayerMeta, ConfigSource, ConfigWatcher, DefineConfig, DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolvableConfig, ResolvableConfigContext, ResolvedConfig, SourceOptions, UserInputConfig, WatchConfigOptions };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { l as loadConfig, S as SUPPORTED_EXTENSIONS } from './shared/c12.CEGFwQZa.mjs';
2
- export { a as loadDotenv, s as setupDotenv } from './shared/c12.CEGFwQZa.mjs';
1
+ import { l as loadConfig, S as SUPPORTED_EXTENSIONS } from './shared/c12.BXpNC6YI.mjs';
2
+ export { a as loadDotenv, s as setupDotenv } from './shared/c12.BXpNC6YI.mjs';
3
3
  import { debounce } from 'perfect-debounce';
4
4
  import { resolve } from 'pathe';
5
5
  import 'node:fs';
@@ -146,7 +146,7 @@ async function loadConfig(options) {
146
146
  configFile: resolve(options.cwd, options.configFile),
147
147
  layers: []
148
148
  };
149
- const _configs = {
149
+ const rawConfigs = {
150
150
  overrides: options.overrides,
151
151
  main: void 0,
152
152
  rc: void 0,
@@ -161,7 +161,7 @@ async function loadConfig(options) {
161
161
  }
162
162
  const _mainConfig = await resolveConfig(".", options);
163
163
  if (_mainConfig.configFile) {
164
- _configs.main = _mainConfig.config;
164
+ rawConfigs.main = _mainConfig.config;
165
165
  r.configFile = _mainConfig.configFile;
166
166
  }
167
167
  if (_mainConfig.meta) {
@@ -178,7 +178,7 @@ async function loadConfig(options) {
178
178
  }
179
179
  rcSources.push(rc9.readUser({ name: options.rcFile, dir: options.cwd }));
180
180
  }
181
- _configs.rc = _merger({}, ...rcSources);
181
+ rawConfigs.rc = _merger({}, ...rcSources);
182
182
  }
183
183
  if (options.packageJson) {
184
184
  const keys = (Array.isArray(options.packageJson) ? options.packageJson : [
@@ -187,12 +187,12 @@ async function loadConfig(options) {
187
187
  const pkgJsonFile = await readPackageJSON(options.cwd).catch(() => {
188
188
  });
189
189
  const values = keys.map((key) => pkgJsonFile?.[key]);
190
- _configs.packageJson = _merger({}, ...values);
190
+ rawConfigs.packageJson = _merger({}, ...values);
191
191
  }
192
192
  const configs = {};
193
- for (const key in _configs) {
194
- const value = _configs[key];
195
- configs[key] = await (typeof value === "function" ? value({ configs }) : value);
193
+ for (const key in rawConfigs) {
194
+ const value = rawConfigs[key];
195
+ configs[key] = await (typeof value === "function" ? value({ configs, rawConfigs }) : value);
196
196
  }
197
197
  r.config = _merger(
198
198
  configs.overrides,
@@ -366,7 +366,7 @@ async function resolveConfig(source, options, sourceOptions = {}) {
366
366
  default: true
367
367
  });
368
368
  }
369
- if (res.config instanceof Function) {
369
+ if (typeof res.config === "function") {
370
370
  res.config = await res.config();
371
371
  }
372
372
  if (options.envName) {
package/dist/update.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolveModulePath } from 'exsolve';
2
- import { S as SUPPORTED_EXTENSIONS } from './shared/c12.CEGFwQZa.mjs';
2
+ import { S as SUPPORTED_EXTENSIONS } from './shared/c12.BXpNC6YI.mjs';
3
3
  import { join, normalize } from 'pathe';
4
4
  import { mkdir, writeFile, readFile } from 'node:fs/promises';
5
5
  import { dirname, extname } from 'node:path';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c12",
3
- "version": "3.0.4",
3
+ "version": "3.1.0",
4
4
  "description": "Smart Config Loader",
5
5
  "repository": "unjs/c12",
6
6
  "license": "MIT",
@@ -34,29 +34,29 @@
34
34
  "chokidar": "^4.0.3",
35
35
  "confbox": "^0.2.2",
36
36
  "defu": "^6.1.4",
37
- "dotenv": "^16.5.0",
38
- "exsolve": "^1.0.5",
37
+ "dotenv": "^16.6.1",
38
+ "exsolve": "^1.0.7",
39
39
  "giget": "^2.0.0",
40
40
  "jiti": "^2.4.2",
41
41
  "ohash": "^2.0.11",
42
42
  "pathe": "^2.0.3",
43
43
  "perfect-debounce": "^1.0.0",
44
- "pkg-types": "^2.1.0",
44
+ "pkg-types": "^2.2.0",
45
45
  "rc9": "^2.1.2"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/node": "^22.15.18",
49
- "@vitest/coverage-v8": "^3.1.3",
48
+ "@types/node": "^24.0.13",
49
+ "@vitest/coverage-v8": "^3.2.4",
50
50
  "automd": "^0.4.0",
51
- "changelogen": "^0.6.1",
52
- "eslint": "^9.27.0",
53
- "eslint-config-unjs": "^0.4.2",
54
- "expect-type": "^1.2.1",
51
+ "changelogen": "^0.6.2",
52
+ "eslint": "^9.31.0",
53
+ "eslint-config-unjs": "^0.5.0",
54
+ "expect-type": "^1.2.2",
55
55
  "magicast": "^0.3.5",
56
- "prettier": "^3.5.3",
56
+ "prettier": "^3.6.2",
57
57
  "typescript": "^5.8.3",
58
58
  "unbuild": "^3.5.0",
59
- "vitest": "^3.1.3"
59
+ "vitest": "^3.2.4"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "magicast": "^0.3.5"
@@ -66,5 +66,5 @@
66
66
  "optional": true
67
67
  }
68
68
  },
69
- "packageManager": "pnpm@10.11.0"
69
+ "packageManager": "pnpm@10.13.1"
70
70
  }