c12 4.0.0-beta.4 → 4.0.0-beta.5

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
@@ -30,6 +30,7 @@ c12 (pronounced as /siːtwelv/, like c-twelve) is a smart configuration loader.
30
30
  ## 🦴 Used by
31
31
 
32
32
  - [Hey API](https://github.com/hey-api/openapi-ts)
33
+ - [Gen API](https://github.com/hairyf/genapi)
33
34
  - [Kysely](https://github.com/kysely-org/kysely-ctl)
34
35
  - [Nitro](https://nitro.build/)
35
36
  - [Nuxt](https://nuxt.com/)
@@ -205,6 +206,21 @@ const { config } = await loadConfig({
205
206
  });
206
207
  ```
207
208
 
209
+ ### `jitiOptions`
210
+
211
+ Options passed to [unjs/jiti](https://github.com/unjs/jiti) when c12 falls back to it for loading config files. Has no effect if a custom `import` is provided.
212
+
213
+ **Example:**
214
+
215
+ ```js
216
+ const { config } = await loadConfig({
217
+ jitiOptions: {
218
+ fsCache: false,
219
+ transformOptions: { /* ... */ },
220
+ },
221
+ });
222
+ ```
223
+
208
224
  ### `resolveModule`
209
225
 
210
226
  Custom resolver for picking which export to use from the loaded module. Default: `(mod) => mod.default || mod`.
@@ -1,4 +1,3 @@
1
- //#region node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/utils/index.d.mts
2
1
  /**
3
2
  * Calculates the difference between two objects and returns a list of differences.
4
3
  *
@@ -26,5 +25,4 @@ declare class DiffHashedObject {
26
25
  toString(): string;
27
26
  toJSON(): string;
28
27
  }
29
- //#endregion
30
28
  export { diff as t };
@@ -1,5 +1,4 @@
1
1
  import { createHash } from "node:crypto";
2
- //#region \0rolldown/runtime.js
3
2
  var __defProp = Object.defineProperty;
4
3
  var __exportAll = (all, no_symbols) => {
5
4
  let target = {};
@@ -10,8 +9,6 @@ var __exportAll = (all, no_symbols) => {
10
9
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
10
  return target;
12
11
  };
13
- //#endregion
14
- //#region node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/shared/ohash.D__AXeF1.mjs
15
12
  function serialize(o) {
16
13
  return typeof o == "string" ? `'${o}'` : new c().serialize(o);
17
14
  }
@@ -113,19 +110,13 @@ const c = /* @__PURE__ */ function() {
113
110
  };
114
111
  return o;
115
112
  }();
116
- //#endregion
117
- //#region node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/crypto/node/index.mjs
118
113
  const e = globalThis.process?.getBuiltinModule?.("crypto")?.hash, r = "sha256", s = "base64url";
119
114
  function digest(t) {
120
115
  if (e) return e(r, t, s);
121
116
  const o = createHash(r).update(t);
122
117
  return globalThis.process?.versions?.webcontainer ? o.digest().toString(s) : o.digest(s);
123
118
  }
124
- //#endregion
125
- //#region node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/index.mjs
126
119
  var dist_exports = /* @__PURE__ */ __exportAll({ digest: () => digest });
127
- //#endregion
128
- //#region node_modules/.pnpm/ohash@2.0.11/node_modules/ohash/dist/utils/index.mjs
129
120
  var utils_exports = /* @__PURE__ */ __exportAll({ diff: () => diff });
130
121
  function diff(obj1, obj2) {
131
122
  return _diff(_toHashedObject(obj1), _toHashedObject(obj2));
@@ -187,5 +178,4 @@ var DiffHashedObject = class {
187
178
  return `${k}(${this.value})`;
188
179
  }
189
180
  };
190
- //#endregion
191
181
  export { dist_exports as n, utils_exports as t };
@@ -1,23 +1,4 @@
1
- //#region node_modules/.pnpm/perfect-debounce@2.1.0/node_modules/perfect-debounce/dist/index.mjs
2
1
  const DEBOUNCE_DEFAULTS = { trailing: true };
3
- /**
4
- Debounce functions
5
- @param fn - Promise-returning/async function to debounce.
6
- @param wait - Milliseconds to wait before calling `fn`. Default value is 25ms
7
- @returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
8
- @example
9
- ```
10
- import { debounce } from 'perfect-debounce';
11
- const expensiveCall = async input => input;
12
- const debouncedFn = debounce(expensiveCall, 200);
13
- for (const number of [1, 2, 3]) {
14
- console.log(await debouncedFn(number));
15
- }
16
- //=> 1
17
- //=> 2
18
- //=> 3
19
- ```
20
- */
21
2
  function debounce(fn, wait = 25, options = {}) {
22
3
  options = {
23
4
  ...DEBOUNCE_DEFAULTS,
@@ -84,5 +65,4 @@ function debounce(fn, wait = 25, options = {}) {
84
65
  async function _applyPromised(fn, _this, args) {
85
66
  return await fn.apply(_this, args);
86
67
  }
87
- //#endregion
88
68
  export { debounce as t };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { t as diff } from "./_chunks/libs/ohash.mjs";
2
- import { ChokidarOptions } from "chokidar";
2
+ import * as _$jiti from "jiti";
3
3
  import { DownloadTemplateOptions } from "giget";
4
-
5
- //#region src/dotenv.d.ts
4
+ import { ChokidarOptions } from "chokidar";
6
5
  interface DotenvOptions {
7
6
  /**
8
7
  * The project root directory (either absolute or relative to the current working directory).
@@ -60,8 +59,7 @@ declare function loadDotenv(options: DotenvOptions): Promise<Env>;
60
59
  declare global {
61
60
  var __c12_dotenv_vars__: Map<Record<string, any>, Set<string>>;
62
61
  }
63
- //#endregion
64
- //#region src/types.d.ts
62
+ type JitiOptions = NonNullable<Parameters<typeof _$jiti.createJiti>[1]>;
65
63
  interface ConfigLayerMeta {
66
64
  name?: string;
67
65
  [key: string]: any;
@@ -144,6 +142,8 @@ interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT exte
144
142
  import?: (id: string) => Promise<unknown>;
145
143
  /** Custom resolver for picking which export to use from the loaded module. Default: `(mod) => mod.default || mod` */
146
144
  resolveModule?: (mod: any) => any;
145
+ /** Options to override defaults when c12 falls back to [jiti](https://github.com/unjs/jiti) for loading config files. */
146
+ jitiOptions?: JitiOptions;
147
147
  giget?: false | DownloadTemplateOptions;
148
148
  merger?: (...sources: Array<T | null | undefined>) => T;
149
149
  extend?: false | {
@@ -153,12 +153,8 @@ interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT exte
153
153
  }
154
154
  type DefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = (input: InputConfig<T, MT>) => InputConfig<T, MT>;
155
155
  declare function createDefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(): DefineConfig<T, MT>;
156
- //#endregion
157
- //#region src/loader.d.ts
158
156
  declare const SUPPORTED_EXTENSIONS: string[];
159
157
  declare function loadConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>>;
160
- //#endregion
161
- //#region src/watch.d.ts
162
158
  type DiffEntries = ReturnType<typeof diff>;
163
159
  type ConfigWatcher<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = ResolvedConfig<T, MT> & {
164
160
  watchingFiles: string[];
@@ -183,5 +179,4 @@ interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT ext
183
179
  }) => void | Promise<void>;
184
180
  }
185
181
  declare function watchConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>>;
186
- //#endregion
187
182
  export { C12InputConfig, ConfigFunctionContext, ConfigLayer, ConfigLayerMeta, ConfigSource, type ConfigWatcher, DefineConfig, type DotenvOptions, type Env, InputConfig, LoadConfigOptions, ResolvableConfig, ResolvableConfigContext, ResolvedConfig, SUPPORTED_EXTENSIONS, SourceOptions, UserInputConfig, type WatchConfigOptions, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
package/dist/index.mjs CHANGED
@@ -9,12 +9,6 @@ import { resolveModulePath } from "exsolve";
9
9
  import * as rc9 from "rc9";
10
10
  import { defu } from "defu";
11
11
  import { findWorkspaceDir, readPackageJSON } from "pkg-types";
12
- //#region src/dotenv.ts
13
- /**
14
- * Load and interpolate environment variables into `process.env`.
15
- * If you need more control (or access to the values), consider using `loadDotenv` instead
16
- *
17
- */
18
12
  async function setupDotenv(options) {
19
13
  const targetEnvironment = options.env ?? process.env;
20
14
  const environment = await loadDotenv({
@@ -31,7 +25,6 @@ async function setupDotenv(options) {
31
25
  }
32
26
  return environment;
33
27
  }
34
- /** Load environment variables into an object. */
35
28
  async function loadDotenv(options) {
36
29
  const environment = Object.create(null);
37
30
  const cwd = resolve(options.cwd || ".");
@@ -108,8 +101,6 @@ function getDotEnvVars(targetEnvironment) {
108
101
  if (!globalRegistry.has(targetEnvironment)) globalRegistry.set(targetEnvironment, /* @__PURE__ */ new Set());
109
102
  return globalRegistry.get(targetEnvironment);
110
103
  }
111
- //#endregion
112
- //#region src/loader.ts
113
104
  const _normalize = (p) => p?.replace(/\\/g, "/");
114
105
  let importCounter = 0;
115
106
  const ASYNC_LOADERS = {
@@ -348,7 +339,8 @@ async function resolveConfig(source, options, sourceOptions = {}) {
348
339
  const jiti = createJiti(join(options.cwd || ".", options.configFile || "/"), {
349
340
  interopDefault: true,
350
341
  moduleCache: false,
351
- extensions: [...SUPPORTED_EXTENSIONS]
342
+ extensions: [...SUPPORTED_EXTENSIONS],
343
+ ...options.jitiOptions
352
344
  });
353
345
  options.import = (id) => jiti.import(id);
354
346
  return _resolveModule(await options.import(res.configFile));
@@ -380,7 +372,6 @@ function tryResolve(id, options) {
380
372
  });
381
373
  return res ? normalize(res) : void 0;
382
374
  }
383
- /** Returns `true`/`false` if the path exists, `null` if it doesn't. */
384
375
  function _isDirectory(path) {
385
376
  try {
386
377
  return statSync(path).isDirectory();
@@ -388,13 +379,9 @@ function _isDirectory(path) {
388
379
  return null;
389
380
  }
390
381
  }
391
- //#endregion
392
- //#region src/types.ts
393
382
  function createDefineConfig() {
394
383
  return (input) => input;
395
384
  }
396
- //#endregion
397
- //#region src/watch.ts
398
385
  const eventMap = {
399
386
  add: "created",
400
387
  change: "updated",
@@ -457,5 +444,4 @@ async function watchConfig(options) {
457
444
  return config[prop];
458
445
  } });
459
446
  }
460
- //#endregion
461
447
  export { SUPPORTED_EXTENSIONS, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
package/dist/update.d.mts CHANGED
@@ -1,6 +1,4 @@
1
- import * as magicast from "magicast";
2
-
3
- //#region src/update.d.ts
1
+ import * as _$magicast from "magicast";
4
2
  /**
5
3
  * @experimental Update a config file or create a new one.
6
4
  */
@@ -10,7 +8,7 @@ interface UpdateConfigResult {
10
8
  created?: boolean;
11
9
  }
12
10
  type MaybePromise<T> = T | Promise<T>;
13
- type MagicAstOptions = Exclude<Parameters<(typeof magicast)["parseModule"]>[1], undefined>;
11
+ type MagicAstOptions = Exclude<Parameters<(typeof _$magicast)["parseModule"]>[1], undefined>;
14
12
  interface UpdateConfigOptions {
15
13
  /**
16
14
  * Current working directory
@@ -49,5 +47,4 @@ interface UpdateConfigOptions {
49
47
  configFile: string;
50
48
  }) => MaybePromise<string | boolean>;
51
49
  }
52
- //#endregion
53
50
  export { UpdateConfigOptions, UpdateConfigResult, updateConfig };
package/dist/update.mjs CHANGED
@@ -1,11 +1,7 @@
1
1
  import { resolveModulePath } from "exsolve";
2
2
  import { mkdir, readFile, writeFile } from "node:fs/promises";
3
3
  import { join, normalize } from "pathe";
4
- import * as nodeUtil from "node:util";
5
4
  import { dirname, extname } from "node:path";
6
- nodeUtil.parseEnv;
7
- //#endregion
8
- //#region src/loader.ts
9
5
  const SUPPORTED_EXTENSIONS = Object.freeze([
10
6
  ".js",
11
7
  ".ts",
@@ -20,8 +16,6 @@ const SUPPORTED_EXTENSIONS = Object.freeze([
20
16
  ".yml",
21
17
  ".toml"
22
18
  ]);
23
- //#endregion
24
- //#region src/update.ts
25
19
  const UPDATABLE_EXTS = [
26
20
  ".js",
27
21
  ".ts",
@@ -30,9 +24,6 @@ const UPDATABLE_EXTS = [
30
24
  ".mts",
31
25
  ".cts"
32
26
  ];
33
- /**
34
- * @experimental Update a config file or create a new one.
35
- */
36
27
  async function updateConfig(opts) {
37
28
  const { parseModule } = await import("magicast");
38
29
  let configFile = tryResolve(`./${opts.configFile}`, opts.cwd, SUPPORTED_EXTENSIONS) || tryResolve(`./.config/${opts.configFile}`, opts.cwd, SUPPORTED_EXTENSIONS) || tryResolve(`./.config/${opts.configFile.split(".")[0]}`, opts.cwd, SUPPORTED_EXTENSIONS);
@@ -69,5 +60,4 @@ function tryResolve(path, cwd, extensions) {
69
60
  });
70
61
  return res ? normalize(res) : void 0;
71
62
  }
72
- //#endregion
73
63
  export { updateConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c12",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0-beta.5",
4
4
  "description": "Smart Config Loader",
5
5
  "license": "MIT",
6
6
  "repository": "unjs/c12",
@@ -19,38 +19,38 @@
19
19
  "dev": "vitest dev",
20
20
  "lint": "oxlint . && oxfmt --check src test",
21
21
  "lint:fix": "automd && oxlint . --fix && oxfmt src test",
22
- "release": "pnpm test && pnpm build && changelogen --release --prerelease --publish && git push --follow-tags",
22
+ "release": "pnpm test && pnpm build && changelogen --release --prerelease --push && npm publish",
23
23
  "test": "pnpm lint && vitest run --coverage && pnpm test:types",
24
24
  "test:types": "tsgo --noEmit"
25
25
  },
26
26
  "dependencies": {
27
27
  "confbox": "^0.2.4",
28
- "defu": "^6.1.4",
28
+ "defu": "^6.1.7",
29
29
  "exsolve": "^1.0.8",
30
30
  "pathe": "^2.0.3",
31
- "pkg-types": "^2.3.0",
32
- "rc9": "^3.0.0"
31
+ "pkg-types": "^2.3.1",
32
+ "rc9": "^3.0.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/node": "^25.5.0",
36
- "@typescript/native-preview": "^7.0.0-dev.20260314.1",
37
- "@vitest/coverage-v8": "^4.1.0",
35
+ "@types/node": "^25.6.0",
36
+ "@typescript/native-preview": "^7.0.0-dev.20260505.1",
37
+ "@vitest/coverage-v8": "^4.1.5",
38
38
  "automd": "^0.4.3",
39
39
  "changelogen": "^0.6.2",
40
40
  "chokidar": "^5.0.0",
41
- "dotenv": "^17.3.1",
41
+ "dotenv": "^17.4.2",
42
42
  "eslint-config-unjs": "^0.6.2",
43
43
  "expect-type": "^1.3.0",
44
- "giget": "^3.1.2",
45
- "jiti": "^2.6.1",
44
+ "giget": "^3.2.0",
45
+ "jiti": "^2.7.0",
46
46
  "magicast": "^0.5.2",
47
- "obuild": "^0.4.32",
47
+ "obuild": "^0.4.34",
48
48
  "ohash": "^2.0.11",
49
- "oxfmt": "^0.40.0",
50
- "oxlint": "^1.55.0",
49
+ "oxfmt": "^0.48.0",
50
+ "oxlint": "^1.63.0",
51
51
  "perfect-debounce": "^2.1.0",
52
- "typescript": "^5.9.3",
53
- "vitest": "^4.1.0"
52
+ "typescript": "^6.0.3",
53
+ "vitest": "^4.1.5"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "chokidar": "^5",
@@ -76,5 +76,5 @@
76
76
  "optional": true
77
77
  }
78
78
  },
79
- "packageManager": "pnpm@10.32.1"
79
+ "packageManager": "pnpm@10.33.3"
80
80
  }