c12 1.11.0 → 2.0.0-beta.1
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 +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +2 -2
- package/dist/shared/{c12.cab0c9da.mjs → c12.72yV1YOl.mjs} +6 -7
- package/dist/shared/{c12.24612422.cjs → c12.CkVjnBFL.cjs} +5 -9
- package/dist/update.cjs +9 -5
- package/dist/update.mjs +9 -5
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ c12 (pronounced as /siːtwelv/, like c-twelve) is a smart configuration loader.
|
|
|
32
32
|
- [Automd](https://automd.unjs.io)
|
|
33
33
|
- [Changelogen](https://changelogen.unjs.io)
|
|
34
34
|
- [RemixKit](https://github.com/jrestall/remix-kit)
|
|
35
|
+
- [Hey API](https://github.com/hey-api/openapi-ts)
|
|
35
36
|
|
|
36
37
|
## Usage
|
|
37
38
|
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JITIOptions } from 'jiti/dist/types';
|
|
1
|
+
import { Jiti, JitiOptions } from 'jiti';
|
|
3
2
|
import { DownloadTemplateOptions } from 'giget';
|
|
4
3
|
import { WatchOptions } from 'chokidar';
|
|
5
4
|
import { diff } from 'ohash';
|
|
@@ -110,8 +109,8 @@ interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT exte
|
|
|
110
109
|
overrides?: ResolvableConfig<T>;
|
|
111
110
|
omit$Keys?: boolean;
|
|
112
111
|
resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
|
|
113
|
-
jiti?:
|
|
114
|
-
jitiOptions?:
|
|
112
|
+
jiti?: Jiti;
|
|
113
|
+
jitiOptions?: JitiOptions;
|
|
115
114
|
giget?: DownloadTemplateOptions;
|
|
116
115
|
merger?: (...sources: Array<T | null | undefined>) => T;
|
|
117
116
|
extend?: false | {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JITIOptions } from 'jiti/dist/types';
|
|
1
|
+
import { Jiti, JitiOptions } from 'jiti';
|
|
3
2
|
import { DownloadTemplateOptions } from 'giget';
|
|
4
3
|
import { WatchOptions } from 'chokidar';
|
|
5
4
|
import { diff } from 'ohash';
|
|
@@ -110,8 +109,8 @@ interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT exte
|
|
|
110
109
|
overrides?: ResolvableConfig<T>;
|
|
111
110
|
omit$Keys?: boolean;
|
|
112
111
|
resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
|
|
113
|
-
jiti?:
|
|
114
|
-
jitiOptions?:
|
|
112
|
+
jiti?: Jiti;
|
|
113
|
+
jitiOptions?: JitiOptions;
|
|
115
114
|
giget?: DownloadTemplateOptions;
|
|
116
115
|
merger?: (...sources: Array<T | null | undefined>) => T;
|
|
117
116
|
extend?: false | {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JITIOptions } from 'jiti/dist/types';
|
|
1
|
+
import { Jiti, JitiOptions } from 'jiti';
|
|
3
2
|
import { DownloadTemplateOptions } from 'giget';
|
|
4
3
|
import { WatchOptions } from 'chokidar';
|
|
5
4
|
import { diff } from 'ohash';
|
|
@@ -110,8 +109,8 @@ interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT exte
|
|
|
110
109
|
overrides?: ResolvableConfig<T>;
|
|
111
110
|
omit$Keys?: boolean;
|
|
112
111
|
resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
|
|
113
|
-
jiti?:
|
|
114
|
-
jitiOptions?:
|
|
112
|
+
jiti?: Jiti;
|
|
113
|
+
jitiOptions?: JitiOptions;
|
|
115
114
|
giget?: DownloadTemplateOptions;
|
|
116
115
|
merger?: (...sources: Array<T | null | undefined>) => T;
|
|
117
116
|
extend?: false | {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as loadConfig, S as SUPPORTED_EXTENSIONS } from './shared/c12.
|
|
2
|
-
export { a as loadDotenv, s as setupDotenv } from './shared/c12.
|
|
1
|
+
import { l as loadConfig, S as SUPPORTED_EXTENSIONS } from './shared/c12.72yV1YOl.mjs';
|
|
2
|
+
export { a as loadDotenv, s as setupDotenv } from './shared/c12.72yV1YOl.mjs';
|
|
3
3
|
import { debounce } from 'perfect-debounce';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
5
5
|
import { diff } from 'ohash';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, promises } from 'node:fs';
|
|
2
2
|
import { rm, readFile } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import { resolve, dirname, basename,
|
|
5
|
-
import createJiti from 'jiti';
|
|
4
|
+
import { resolve, join, dirname, basename, extname } from 'pathe';
|
|
5
|
+
import { createJiti } from 'jiti';
|
|
6
6
|
import * as rc9 from 'rc9';
|
|
7
7
|
import { defu } from 'defu';
|
|
8
8
|
import { hash } from 'ohash';
|
|
@@ -118,10 +118,9 @@ async function loadConfig(options) {
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
const _merger = options.merger || defu;
|
|
121
|
-
options.jiti = options.jiti || createJiti(
|
|
121
|
+
options.jiti = options.jiti || createJiti(join(options.cwd, options.configFile), {
|
|
122
122
|
interopDefault: true,
|
|
123
|
-
|
|
124
|
-
esmResolve: true,
|
|
123
|
+
moduleCache: false,
|
|
125
124
|
extensions: [...SUPPORTED_EXTENSIONS],
|
|
126
125
|
...options.jitiOptions
|
|
127
126
|
});
|
|
@@ -312,7 +311,7 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
312
311
|
}
|
|
313
312
|
const tryResolve = (id) => {
|
|
314
313
|
try {
|
|
315
|
-
return options.jiti.
|
|
314
|
+
return options.jiti.esmResolve(id, { try: true });
|
|
316
315
|
} catch {
|
|
317
316
|
}
|
|
318
317
|
};
|
|
@@ -342,7 +341,7 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
342
341
|
const contents = await readFile(res.configFile, "utf8");
|
|
343
342
|
res.config = asyncLoader(contents);
|
|
344
343
|
} else {
|
|
345
|
-
res.config = options.jiti(res.configFile);
|
|
344
|
+
res.config = await options.jiti.import(res.configFile);
|
|
346
345
|
}
|
|
347
346
|
if (res.config instanceof Function) {
|
|
348
347
|
res.config = await res.config();
|
|
@@ -4,15 +4,13 @@ const node_fs = require('node:fs');
|
|
|
4
4
|
const promises = require('node:fs/promises');
|
|
5
5
|
const node_os = require('node:os');
|
|
6
6
|
const pathe = require('pathe');
|
|
7
|
-
const
|
|
7
|
+
const jiti = require('jiti');
|
|
8
8
|
const rc9 = require('rc9');
|
|
9
9
|
const defu = require('defu');
|
|
10
10
|
const ohash = require('ohash');
|
|
11
11
|
const pkgTypes = require('pkg-types');
|
|
12
12
|
const dotenv = require('dotenv');
|
|
13
13
|
|
|
14
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
|
-
|
|
16
14
|
function _interopNamespaceCompat(e) {
|
|
17
15
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
18
16
|
const n = Object.create(null);
|
|
@@ -25,7 +23,6 @@ function _interopNamespaceCompat(e) {
|
|
|
25
23
|
return n;
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
const createJiti__default = /*#__PURE__*/_interopDefaultCompat(createJiti);
|
|
29
26
|
const rc9__namespace = /*#__PURE__*/_interopNamespaceCompat(rc9);
|
|
30
27
|
const dotenv__namespace = /*#__PURE__*/_interopNamespaceCompat(dotenv);
|
|
31
28
|
|
|
@@ -138,10 +135,9 @@ async function loadConfig(options) {
|
|
|
138
135
|
};
|
|
139
136
|
}
|
|
140
137
|
const _merger = options.merger || defu.defu;
|
|
141
|
-
options.jiti = options.jiti ||
|
|
138
|
+
options.jiti = options.jiti || jiti.createJiti(pathe.join(options.cwd, options.configFile), {
|
|
142
139
|
interopDefault: true,
|
|
143
|
-
|
|
144
|
-
esmResolve: true,
|
|
140
|
+
moduleCache: false,
|
|
145
141
|
extensions: [...SUPPORTED_EXTENSIONS],
|
|
146
142
|
...options.jitiOptions
|
|
147
143
|
});
|
|
@@ -332,7 +328,7 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
332
328
|
}
|
|
333
329
|
const tryResolve = (id) => {
|
|
334
330
|
try {
|
|
335
|
-
return options.jiti.
|
|
331
|
+
return options.jiti.esmResolve(id, { try: true });
|
|
336
332
|
} catch {
|
|
337
333
|
}
|
|
338
334
|
};
|
|
@@ -362,7 +358,7 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
362
358
|
const contents = await promises.readFile(res.configFile, "utf8");
|
|
363
359
|
res.config = asyncLoader(contents);
|
|
364
360
|
} else {
|
|
365
|
-
res.config = options.jiti(res.configFile);
|
|
361
|
+
res.config = await options.jiti.import(res.configFile);
|
|
366
362
|
}
|
|
367
363
|
if (res.config instanceof Function) {
|
|
368
364
|
res.config = await res.config();
|
package/dist/update.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const mlly = require('mlly');
|
|
4
|
-
const loader = require('./shared/c12.
|
|
4
|
+
const loader = require('./shared/c12.CkVjnBFL.cjs');
|
|
5
5
|
const pathe = require('pathe');
|
|
6
6
|
const promises = require('node:fs/promises');
|
|
7
7
|
const node_path = require('node:path');
|
|
@@ -17,8 +17,12 @@ require('dotenv');
|
|
|
17
17
|
const UPDATABLE_EXTS = [".js", ".ts", ".mjs", ".cjs", ".mts", ".cts"];
|
|
18
18
|
async function updateConfig(opts) {
|
|
19
19
|
const { parseModule } = await import('magicast');
|
|
20
|
-
let configFile = await _tryResolve(
|
|
21
|
-
|
|
20
|
+
let configFile = await _tryResolve(
|
|
21
|
+
`./${opts.configFile}`,
|
|
22
|
+
opts.cwd,
|
|
23
|
+
loader.SUPPORTED_EXTENSIONS
|
|
24
|
+
) || await _tryResolve(
|
|
25
|
+
`./.config/${opts.configFile}`,
|
|
22
26
|
opts.cwd,
|
|
23
27
|
loader.SUPPORTED_EXTENSIONS
|
|
24
28
|
);
|
|
@@ -28,7 +32,7 @@ async function updateConfig(opts) {
|
|
|
28
32
|
opts.cwd,
|
|
29
33
|
opts.configFile + (opts.createExtension || ".ts")
|
|
30
34
|
);
|
|
31
|
-
const createResult = await opts.onCreate?.({ configFile })
|
|
35
|
+
const createResult = await opts.onCreate?.({ configFile }) ?? true;
|
|
32
36
|
if (!createResult) {
|
|
33
37
|
throw new Error("Config file creation aborted.");
|
|
34
38
|
}
|
|
@@ -51,7 +55,7 @@ async function updateConfig(opts) {
|
|
|
51
55
|
throw new Error("Default export is missing in the config file!");
|
|
52
56
|
}
|
|
53
57
|
const configObj = defaultExport.$type === "function-call" ? defaultExport.$args[0] : defaultExport;
|
|
54
|
-
opts.onUpdate?.(configObj);
|
|
58
|
+
await opts.onUpdate?.(configObj);
|
|
55
59
|
await promises.writeFile(configFile, _module.generate().code);
|
|
56
60
|
return {
|
|
57
61
|
configFile,
|
package/dist/update.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolvePath } from 'mlly';
|
|
2
|
-
import { S as SUPPORTED_EXTENSIONS } from './shared/c12.
|
|
2
|
+
import { S as SUPPORTED_EXTENSIONS } from './shared/c12.72yV1YOl.mjs';
|
|
3
3
|
import { join } from 'pathe';
|
|
4
4
|
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
|
5
5
|
import { dirname, extname } from 'node:path';
|
|
@@ -15,8 +15,12 @@ import 'dotenv';
|
|
|
15
15
|
const UPDATABLE_EXTS = [".js", ".ts", ".mjs", ".cjs", ".mts", ".cts"];
|
|
16
16
|
async function updateConfig(opts) {
|
|
17
17
|
const { parseModule } = await import('magicast');
|
|
18
|
-
let configFile = await _tryResolve(
|
|
19
|
-
|
|
18
|
+
let configFile = await _tryResolve(
|
|
19
|
+
`./${opts.configFile}`,
|
|
20
|
+
opts.cwd,
|
|
21
|
+
SUPPORTED_EXTENSIONS
|
|
22
|
+
) || await _tryResolve(
|
|
23
|
+
`./.config/${opts.configFile}`,
|
|
20
24
|
opts.cwd,
|
|
21
25
|
SUPPORTED_EXTENSIONS
|
|
22
26
|
);
|
|
@@ -26,7 +30,7 @@ async function updateConfig(opts) {
|
|
|
26
30
|
opts.cwd,
|
|
27
31
|
opts.configFile + (opts.createExtension || ".ts")
|
|
28
32
|
);
|
|
29
|
-
const createResult = await opts.onCreate?.({ configFile })
|
|
33
|
+
const createResult = await opts.onCreate?.({ configFile }) ?? true;
|
|
30
34
|
if (!createResult) {
|
|
31
35
|
throw new Error("Config file creation aborted.");
|
|
32
36
|
}
|
|
@@ -49,7 +53,7 @@ async function updateConfig(opts) {
|
|
|
49
53
|
throw new Error("Default export is missing in the config file!");
|
|
50
54
|
}
|
|
51
55
|
const configObj = defaultExport.$type === "function-call" ? defaultExport.$args[0] : defaultExport;
|
|
52
|
-
opts.onUpdate?.(configObj);
|
|
56
|
+
await opts.onUpdate?.(configObj);
|
|
53
57
|
await writeFile(configFile, _module.generate().code);
|
|
54
58
|
return {
|
|
55
59
|
configFile,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c12",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Smart Config Loader",
|
|
5
5
|
"repository": "unjs/c12",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"lint": "eslint . && prettier -c src test",
|
|
32
32
|
"lint:fix": "eslint . --fix && prettier -w src test",
|
|
33
33
|
"prepack": "unbuild",
|
|
34
|
-
"release": "pnpm test && changelogen --release
|
|
34
|
+
"release": "pnpm build && pnpm test && changelogen --release --prerelease --push --publish --publishTag beta",
|
|
35
35
|
"test": "pnpm lint && vitest run --coverage && pnpm test:types",
|
|
36
36
|
"test:types": "tsc --noEmit"
|
|
37
37
|
},
|
|
@@ -41,26 +41,26 @@
|
|
|
41
41
|
"defu": "^6.1.4",
|
|
42
42
|
"dotenv": "^16.4.5",
|
|
43
43
|
"giget": "^1.2.3",
|
|
44
|
-
"jiti": "^
|
|
44
|
+
"jiti": "^2.0.0-beta.3",
|
|
45
45
|
"mlly": "^1.7.1",
|
|
46
46
|
"ohash": "^1.1.3",
|
|
47
47
|
"pathe": "^1.1.2",
|
|
48
48
|
"perfect-debounce": "^1.0.0",
|
|
49
|
-
"pkg-types": "^1.1.
|
|
49
|
+
"pkg-types": "^1.1.2",
|
|
50
50
|
"rc9": "^2.1.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^20.14.
|
|
53
|
+
"@types/node": "^20.14.9",
|
|
54
54
|
"@vitest/coverage-v8": "^1.6.0",
|
|
55
55
|
"automd": "^0.3.7",
|
|
56
56
|
"changelogen": "^0.5.5",
|
|
57
|
-
"eslint": "^9.
|
|
57
|
+
"eslint": "^9.6.0",
|
|
58
58
|
"eslint-config-unjs": "^0.3.2",
|
|
59
59
|
"expect-type": "^0.19.0",
|
|
60
60
|
"magicast": "^0.3.4",
|
|
61
61
|
"prettier": "^3.3.2",
|
|
62
|
-
"typescript": "^5.
|
|
63
|
-
"unbuild": "^
|
|
62
|
+
"typescript": "^5.5.3",
|
|
63
|
+
"unbuild": "^3.0.0-rc.3",
|
|
64
64
|
"vitest": "^1.6.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"optional": true
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
-
"packageManager": "pnpm@9.
|
|
74
|
+
"packageManager": "pnpm@9.4.0"
|
|
75
75
|
}
|