c12 1.6.0 → 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 +4 -3
- package/dist/index.cjs +22 -2
- package/dist/index.mjs +23 -3
- package/package.json +12 -10
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
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
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 = {
|
|
@@ -286,12 +297,13 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
286
297
|
} else {
|
|
287
298
|
cloneDir = process.env.XDG_CACHE_HOME ? pathe.resolve(process.env.XDG_CACHE_HOME, "c12", cloneName) : pathe.resolve(node_os.homedir(), ".cache/c12", cloneName);
|
|
288
299
|
}
|
|
289
|
-
if (node_fs.existsSync(cloneDir)) {
|
|
300
|
+
if (node_fs.existsSync(cloneDir) && !sourceOptions.install) {
|
|
290
301
|
await promises.rm(cloneDir, { recursive: true });
|
|
291
302
|
}
|
|
292
303
|
const cloned = await downloadTemplate(source, {
|
|
293
304
|
dir: cloneDir,
|
|
294
305
|
install: sourceOptions.install,
|
|
306
|
+
force: sourceOptions.install,
|
|
295
307
|
...options.giget,
|
|
296
308
|
...sourceOptions.giget
|
|
297
309
|
});
|
|
@@ -324,7 +336,15 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
324
336
|
if (!node_fs.existsSync(res.configFile)) {
|
|
325
337
|
return res;
|
|
326
338
|
}
|
|
327
|
-
res.
|
|
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
|
+
}
|
|
328
348
|
if (res.config instanceof Function) {
|
|
329
349
|
res.config = await res.config();
|
|
330
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 = {
|
|
@@ -266,12 +277,13 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
266
277
|
} else {
|
|
267
278
|
cloneDir = process.env.XDG_CACHE_HOME ? resolve(process.env.XDG_CACHE_HOME, "c12", cloneName) : resolve(homedir(), ".cache/c12", cloneName);
|
|
268
279
|
}
|
|
269
|
-
if (existsSync(cloneDir)) {
|
|
280
|
+
if (existsSync(cloneDir) && !sourceOptions.install) {
|
|
270
281
|
await rm(cloneDir, { recursive: true });
|
|
271
282
|
}
|
|
272
283
|
const cloned = await downloadTemplate(source, {
|
|
273
284
|
dir: cloneDir,
|
|
274
285
|
install: sourceOptions.install,
|
|
286
|
+
force: sourceOptions.install,
|
|
275
287
|
...options.giget,
|
|
276
288
|
...sourceOptions.giget
|
|
277
289
|
});
|
|
@@ -304,7 +316,15 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
304
316
|
if (!existsSync(res.configFile)) {
|
|
305
317
|
return res;
|
|
306
318
|
}
|
|
307
|
-
res.
|
|
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
|
+
}
|
|
308
328
|
if (res.config instanceof Function) {
|
|
309
329
|
res.config = await res.config();
|
|
310
330
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c12",
|
|
3
|
-
"version": "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.
|
|
35
|
-
"dotenv": "^16.3.
|
|
34
|
+
"defu": "^6.1.4",
|
|
35
|
+
"dotenv": "^16.3.2",
|
|
36
36
|
"giget": "^1.2.1",
|
|
37
37
|
"jiti": "^1.21.0",
|
|
38
|
-
"
|
|
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.
|
|
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.
|
|
47
|
-
"@vitest/coverage-v8": "^1.1
|
|
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.
|
|
54
|
+
"prettier": "^3.2.4",
|
|
53
55
|
"typescript": "^5.3.3",
|
|
54
56
|
"unbuild": "^2.0.0",
|
|
55
|
-
"vitest": "^1.1
|
|
57
|
+
"vitest": "^1.2.1"
|
|
56
58
|
},
|
|
57
|
-
"packageManager": "pnpm@8.
|
|
59
|
+
"packageManager": "pnpm@8.14.1"
|
|
58
60
|
}
|