c12 1.6.1 → 1.7.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
@@ -9,10 +9,11 @@ c12 (pronounced as /siːtwelv/, like c-twelve) is a smart configuration loader.
9
9
 
10
10
  ## Features
11
11
 
12
- - JSON, CJS, Typescript, and ESM config loader with [unjs/jiti](https://github.com/unjs/jiti)
13
- - RC config support with [unjs/rc9](https://github.com/unjs/rc9)
14
- - Multiple sources merged with [unjs/defu](https://github.com/unjs/defu)
12
+ - `.js`, `.ts`, `.cjs`, `.mjs` config loader with [unjs/jiti](https://github.com/unjs/jiti)
13
+ - `.json`, `.json5` and `.jsonc` config support.
14
+ - `.rc` config support with [unjs/rc9](https://github.com/unjs/rc9)
15
15
  - `.env` support with [dotenv](https://www.npmjs.com/package/dotenv)
16
+ - Multiple sources merged with [unjs/defu](https://github.com/unjs/defu)
16
17
  - Reads config from the nearest `package.json` file
17
18
  - [Extends configurations](https://github.com/unjs/c12#extending-configuration) from multiple local or git sources
18
19
  - Overwrite with [environment-specific configuration](#environment-specific-configuration)
package/dist/index.cjs CHANGED
@@ -120,6 +120,17 @@ async function loadConfig(options) {
120
120
  interopDefault: true,
121
121
  requireCache: false,
122
122
  esmResolve: true,
123
+ extensions: [
124
+ ".js",
125
+ ".mjs",
126
+ ".cjs",
127
+ ".ts",
128
+ ".mts",
129
+ ".cts",
130
+ ".json",
131
+ ".jsonc",
132
+ ".json5"
133
+ ],
123
134
  ...options.jitiOptions
124
135
  });
125
136
  const r = {
@@ -325,7 +336,15 @@ async function resolveConfig(source, options, sourceOptions = {}) {
325
336
  if (!node_fs.existsSync(res.configFile)) {
326
337
  return res;
327
338
  }
328
- res.config = options.jiti(res.configFile);
339
+ if (res.configFile.endsWith(".jsonc")) {
340
+ const { parse } = await import('jsonc-parser');
341
+ res.config = parse(await promises.readFile(res.configFile, "utf8"));
342
+ } else if (res.configFile.endsWith(".json5")) {
343
+ const { parse } = await import('json5');
344
+ res.config = parse(await promises.readFile(res.configFile, "utf8"));
345
+ } else {
346
+ res.config = options.jiti(res.configFile);
347
+ }
329
348
  if (res.config instanceof Function) {
330
349
  res.config = await res.config();
331
350
  }
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { existsSync, promises } from 'node:fs';
2
2
  import { resolve, dirname, basename, join, extname } from 'pathe';
3
3
  import * as dotenv from 'dotenv';
4
- import { rm } from 'node:fs/promises';
4
+ import { rm, readFile } from 'node:fs/promises';
5
5
  import { homedir } from 'node:os';
6
6
  import createJiti from 'jiti';
7
7
  import * as rc9 from 'rc9';
@@ -100,6 +100,17 @@ async function loadConfig(options) {
100
100
  interopDefault: true,
101
101
  requireCache: false,
102
102
  esmResolve: true,
103
+ extensions: [
104
+ ".js",
105
+ ".mjs",
106
+ ".cjs",
107
+ ".ts",
108
+ ".mts",
109
+ ".cts",
110
+ ".json",
111
+ ".jsonc",
112
+ ".json5"
113
+ ],
103
114
  ...options.jitiOptions
104
115
  });
105
116
  const r = {
@@ -305,7 +316,15 @@ async function resolveConfig(source, options, sourceOptions = {}) {
305
316
  if (!existsSync(res.configFile)) {
306
317
  return res;
307
318
  }
308
- res.config = options.jiti(res.configFile);
319
+ if (res.configFile.endsWith(".jsonc")) {
320
+ const { parse } = await import('jsonc-parser');
321
+ res.config = parse(await readFile(res.configFile, "utf8"));
322
+ } else if (res.configFile.endsWith(".json5")) {
323
+ const { parse } = await import('json5');
324
+ res.config = parse(await readFile(res.configFile, "utf8"));
325
+ } else {
326
+ res.config = options.jiti(res.configFile);
327
+ }
309
328
  if (res.config instanceof Function) {
310
329
  res.config = await res.config();
311
330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c12",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Smart Config Loader",
5
5
  "repository": "unjs/c12",
6
6
  "license": "MIT",
@@ -31,28 +31,30 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "chokidar": "^3.5.3",
34
- "defu": "^6.1.3",
35
- "dotenv": "^16.3.1",
34
+ "defu": "^6.1.4",
35
+ "dotenv": "^16.3.2",
36
36
  "giget": "^1.2.1",
37
37
  "jiti": "^1.21.0",
38
- "mlly": "^1.4.2",
38
+ "json5": "^2.2.3",
39
+ "jsonc-parser": "^3.2.1",
40
+ "mlly": "^1.5.0",
39
41
  "ohash": "^1.1.3",
40
- "pathe": "^1.1.1",
42
+ "pathe": "^1.1.2",
41
43
  "perfect-debounce": "^1.0.0",
42
44
  "pkg-types": "^1.0.3",
43
45
  "rc9": "^2.1.1"
44
46
  },
45
47
  "devDependencies": {
46
- "@types/node": "^20.10.5",
47
- "@vitest/coverage-v8": "^1.1.0",
48
+ "@types/node": "^20.11.5",
49
+ "@vitest/coverage-v8": "^1.2.1",
48
50
  "changelogen": "^0.5.5",
49
51
  "eslint": "^8.56.0",
50
52
  "eslint-config-unjs": "^0.2.1",
51
53
  "expect-type": "^0.17.3",
52
- "prettier": "^3.1.1",
54
+ "prettier": "^3.2.4",
53
55
  "typescript": "^5.3.3",
54
56
  "unbuild": "^2.0.0",
55
- "vitest": "^1.1.0"
57
+ "vitest": "^1.2.1"
56
58
  },
57
- "packageManager": "pnpm@8.13.1"
59
+ "packageManager": "pnpm@8.14.1"
58
60
  }