c12 1.4.2 → 1.5.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 +37 -0
- package/dist/index.cjs +17 -9
- package/dist/index.d.cts +123 -0
- package/dist/index.d.mts +123 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +18 -10
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -123,6 +123,10 @@ Custom [unjs/jiti](https://github.com/unjs/jiti) instance used to import configu
|
|
|
123
123
|
|
|
124
124
|
Custom [unjs/jiti](https://github.com/unjs/jiti) options to import configuration files.
|
|
125
125
|
|
|
126
|
+
### `giget`
|
|
127
|
+
|
|
128
|
+
Options passed to [unjs/giget](https://github.com/unjs/giget) when extending layer from git source.
|
|
129
|
+
|
|
126
130
|
### `envName`
|
|
127
131
|
|
|
128
132
|
Environment name used for [environment specific configuration](#environment-specific-configuration).
|
|
@@ -205,6 +209,39 @@ Layers:
|
|
|
205
209
|
]
|
|
206
210
|
```
|
|
207
211
|
|
|
212
|
+
## Extending Config Layer from Remote Sources
|
|
213
|
+
|
|
214
|
+
You can also extend configuration from remote sources such as npm or github.
|
|
215
|
+
|
|
216
|
+
In the repo, there should be a `config.ts` (or `config.{name}.ts`) file to be considered as a valid config layer.
|
|
217
|
+
|
|
218
|
+
**Example:** Extend from a github repository
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
// config.ts
|
|
222
|
+
export default {
|
|
223
|
+
extends: "gh:repo/owner",
|
|
224
|
+
};
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**Example:** Extend from a github repository with branch and subpath
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
// config.ts
|
|
231
|
+
export default {
|
|
232
|
+
extends: "gh:repo/owner/theme#dev",
|
|
233
|
+
};
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Example:** Extend with custom configuration ([giget](https://github.com/unjs/giget) options)
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
// config.ts
|
|
240
|
+
export default {
|
|
241
|
+
extends: ["gh:repo/owner", { giget: { auth: process.env.GITHUB_TOKEN } }],
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
208
245
|
## Environment-specific configuration
|
|
209
246
|
|
|
210
247
|
Users can define environment-specific configuration using these config keys:
|
package/dist/index.cjs
CHANGED
|
@@ -8,10 +8,10 @@ const node_os = require('node:os');
|
|
|
8
8
|
const createJiti = require('jiti');
|
|
9
9
|
const rc9 = require('rc9');
|
|
10
10
|
const defu = require('defu');
|
|
11
|
+
const ohash = require('ohash');
|
|
11
12
|
const pkgTypes = require('pkg-types');
|
|
12
13
|
const chokidar = require('chokidar');
|
|
13
14
|
const perfectDebounce = require('perfect-debounce');
|
|
14
|
-
const ohash = require('ohash');
|
|
15
15
|
|
|
16
16
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
17
17
|
|
|
@@ -249,7 +249,7 @@ async function extendConfig(config, options) {
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
const GIT_PREFIXES = ["github:", "gitlab:", "bitbucket:", "https://"];
|
|
252
|
+
const GIT_PREFIXES = ["gh:", "github:", "gitlab:", "bitbucket:", "https://"];
|
|
253
253
|
const NPM_PACKAGE_RE = /^(@[\da-z~-][\d._a-z~-]*\/)?[\da-z~-][\d._a-z~-]*($|\/.*)/;
|
|
254
254
|
async function resolveConfig(source, options, sourceOptions = {}) {
|
|
255
255
|
if (options.resolve) {
|
|
@@ -260,14 +260,22 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
260
260
|
}
|
|
261
261
|
if (GIT_PREFIXES.some((prefix) => source.startsWith(prefix))) {
|
|
262
262
|
const { downloadTemplate } = await import('giget');
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
263
|
+
const cloneName = source.replace(/\W+/g, "_").split("_").splice(0, 3).join("_") + "_" + ohash.hash(source);
|
|
264
|
+
let cloneDir;
|
|
265
|
+
const localNodeModules = pathe.resolve(options.cwd, "node_modules");
|
|
266
|
+
if (node_fs.existsSync(localNodeModules)) {
|
|
267
|
+
cloneDir = pathe.join(localNodeModules, ".c12", cloneName);
|
|
268
|
+
} else {
|
|
269
|
+
cloneDir = process.env.XDG_CACHE_HOME ? pathe.resolve(process.env.XDG_CACHE_HOME, "c12", cloneName) : pathe.resolve(node_os.homedir(), ".cache/c12", cloneName);
|
|
269
270
|
}
|
|
270
|
-
|
|
271
|
+
if (node_fs.existsSync(cloneDir)) {
|
|
272
|
+
await promises.rm(cloneDir, { recursive: true });
|
|
273
|
+
}
|
|
274
|
+
const cloned = await downloadTemplate(source, {
|
|
275
|
+
dir: cloneDir,
|
|
276
|
+
...options.giget,
|
|
277
|
+
...sourceOptions.giget
|
|
278
|
+
});
|
|
271
279
|
source = cloned.dir;
|
|
272
280
|
}
|
|
273
281
|
if (NPM_PACKAGE_RE.test(source)) {
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { JITI } from 'jiti';
|
|
2
|
+
import { JITIOptions } from 'jiti/dist/types';
|
|
3
|
+
import { DownloadTemplateOptions } from 'giget';
|
|
4
|
+
import { WatchOptions } from 'chokidar';
|
|
5
|
+
import { diff } from 'ohash';
|
|
6
|
+
|
|
7
|
+
interface DotenvOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The project root directory (either absolute or relative to the current working directory).
|
|
10
|
+
*/
|
|
11
|
+
cwd: string;
|
|
12
|
+
/**
|
|
13
|
+
* What file to look in for environment variables (either absolute or relative
|
|
14
|
+
* to the current working directory). For example, `.env`.
|
|
15
|
+
*/
|
|
16
|
+
fileName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to interpolate variables within .env.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```env
|
|
22
|
+
* BASE_DIR="/test"
|
|
23
|
+
* # resolves to "/test/further"
|
|
24
|
+
* ANOTHER_DIR="${BASE_DIR}/further"
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interpolate?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* An object describing environment variables (key, value pairs).
|
|
30
|
+
*/
|
|
31
|
+
env?: NodeJS.ProcessEnv;
|
|
32
|
+
}
|
|
33
|
+
type Env = typeof process.env;
|
|
34
|
+
/**
|
|
35
|
+
* Load and interpolate environment variables into `process.env`.
|
|
36
|
+
* If you need more control (or access to the values), consider using `loadDotenv` instead
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
declare function setupDotenv(options: DotenvOptions): Promise<Env>;
|
|
40
|
+
/** Load environment variables into an object. */
|
|
41
|
+
declare function loadDotenv(options: DotenvOptions): Promise<Env>;
|
|
42
|
+
|
|
43
|
+
interface ConfigLayerMeta {
|
|
44
|
+
name?: string;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
type UserInputConfig = Record<string, any>;
|
|
48
|
+
interface C12InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
49
|
+
$test?: T;
|
|
50
|
+
$development?: T;
|
|
51
|
+
$production?: T;
|
|
52
|
+
$env?: Record<string, T>;
|
|
53
|
+
$meta?: MT;
|
|
54
|
+
}
|
|
55
|
+
type InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = C12InputConfig<T, MT> & T;
|
|
56
|
+
interface SourceOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
57
|
+
meta?: MT;
|
|
58
|
+
giget?: DownloadTemplateOptions;
|
|
59
|
+
overrides?: T;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
interface ConfigLayer<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
63
|
+
config: T | null;
|
|
64
|
+
source?: string;
|
|
65
|
+
sourceOptions?: SourceOptions<T, MT>;
|
|
66
|
+
meta?: MT;
|
|
67
|
+
cwd?: string;
|
|
68
|
+
configFile?: string;
|
|
69
|
+
}
|
|
70
|
+
interface ResolvedConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends ConfigLayer<T, MT> {
|
|
71
|
+
layers?: ConfigLayer<T, MT>[];
|
|
72
|
+
cwd?: string;
|
|
73
|
+
}
|
|
74
|
+
interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
75
|
+
name?: string;
|
|
76
|
+
cwd?: string;
|
|
77
|
+
configFile?: string;
|
|
78
|
+
rcFile?: false | string;
|
|
79
|
+
globalRc?: boolean;
|
|
80
|
+
dotenv?: boolean | DotenvOptions;
|
|
81
|
+
envName?: string | false;
|
|
82
|
+
packageJson?: boolean | string | string[];
|
|
83
|
+
defaults?: T;
|
|
84
|
+
defaultConfig?: T;
|
|
85
|
+
overrides?: T;
|
|
86
|
+
resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
|
|
87
|
+
jiti?: JITI;
|
|
88
|
+
jitiOptions?: JITIOptions;
|
|
89
|
+
giget?: DownloadTemplateOptions;
|
|
90
|
+
extend?: false | {
|
|
91
|
+
extendKey?: string | string[];
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
type DefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = (input: InputConfig<T, MT>) => InputConfig<T, MT>;
|
|
95
|
+
declare function createDefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(): DefineConfig<T, MT>;
|
|
96
|
+
|
|
97
|
+
declare function loadConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>>;
|
|
98
|
+
|
|
99
|
+
type ConfigWatcher<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = ResolvedConfig<T, MT> & {
|
|
100
|
+
watchingFiles: string[];
|
|
101
|
+
unwatch: () => Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends LoadConfigOptions<T, MT> {
|
|
104
|
+
chokidarOptions?: WatchOptions;
|
|
105
|
+
debounce?: false | number;
|
|
106
|
+
onWatch?: (event: {
|
|
107
|
+
type: "created" | "updated" | "removed";
|
|
108
|
+
path: string;
|
|
109
|
+
}) => void | Promise<void>;
|
|
110
|
+
acceptHMR?: (context: {
|
|
111
|
+
getDiff: () => ReturnType<typeof diff>;
|
|
112
|
+
newConfig: ResolvedConfig<T, MT>;
|
|
113
|
+
oldConfig: ResolvedConfig<T, MT>;
|
|
114
|
+
}) => void | boolean | Promise<void | boolean>;
|
|
115
|
+
onUpdate?: (context: {
|
|
116
|
+
getDiff: () => ReturnType<typeof diff>;
|
|
117
|
+
newConfig: ResolvedConfig<T, MT>;
|
|
118
|
+
oldConfig: ResolvedConfig<T, MT>;
|
|
119
|
+
}) => void | Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
declare function watchConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>>;
|
|
122
|
+
|
|
123
|
+
export { type C12InputConfig, type ConfigLayer, type ConfigLayerMeta, type ConfigWatcher, type DefineConfig, type DotenvOptions, type Env, type InputConfig, type LoadConfigOptions, type ResolvedConfig, type SourceOptions, type UserInputConfig, type WatchConfigOptions, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { JITI } from 'jiti';
|
|
2
|
+
import { JITIOptions } from 'jiti/dist/types';
|
|
3
|
+
import { DownloadTemplateOptions } from 'giget';
|
|
4
|
+
import { WatchOptions } from 'chokidar';
|
|
5
|
+
import { diff } from 'ohash';
|
|
6
|
+
|
|
7
|
+
interface DotenvOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The project root directory (either absolute or relative to the current working directory).
|
|
10
|
+
*/
|
|
11
|
+
cwd: string;
|
|
12
|
+
/**
|
|
13
|
+
* What file to look in for environment variables (either absolute or relative
|
|
14
|
+
* to the current working directory). For example, `.env`.
|
|
15
|
+
*/
|
|
16
|
+
fileName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to interpolate variables within .env.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```env
|
|
22
|
+
* BASE_DIR="/test"
|
|
23
|
+
* # resolves to "/test/further"
|
|
24
|
+
* ANOTHER_DIR="${BASE_DIR}/further"
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interpolate?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* An object describing environment variables (key, value pairs).
|
|
30
|
+
*/
|
|
31
|
+
env?: NodeJS.ProcessEnv;
|
|
32
|
+
}
|
|
33
|
+
type Env = typeof process.env;
|
|
34
|
+
/**
|
|
35
|
+
* Load and interpolate environment variables into `process.env`.
|
|
36
|
+
* If you need more control (or access to the values), consider using `loadDotenv` instead
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
declare function setupDotenv(options: DotenvOptions): Promise<Env>;
|
|
40
|
+
/** Load environment variables into an object. */
|
|
41
|
+
declare function loadDotenv(options: DotenvOptions): Promise<Env>;
|
|
42
|
+
|
|
43
|
+
interface ConfigLayerMeta {
|
|
44
|
+
name?: string;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
type UserInputConfig = Record<string, any>;
|
|
48
|
+
interface C12InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
49
|
+
$test?: T;
|
|
50
|
+
$development?: T;
|
|
51
|
+
$production?: T;
|
|
52
|
+
$env?: Record<string, T>;
|
|
53
|
+
$meta?: MT;
|
|
54
|
+
}
|
|
55
|
+
type InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = C12InputConfig<T, MT> & T;
|
|
56
|
+
interface SourceOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
57
|
+
meta?: MT;
|
|
58
|
+
giget?: DownloadTemplateOptions;
|
|
59
|
+
overrides?: T;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
interface ConfigLayer<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
63
|
+
config: T | null;
|
|
64
|
+
source?: string;
|
|
65
|
+
sourceOptions?: SourceOptions<T, MT>;
|
|
66
|
+
meta?: MT;
|
|
67
|
+
cwd?: string;
|
|
68
|
+
configFile?: string;
|
|
69
|
+
}
|
|
70
|
+
interface ResolvedConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends ConfigLayer<T, MT> {
|
|
71
|
+
layers?: ConfigLayer<T, MT>[];
|
|
72
|
+
cwd?: string;
|
|
73
|
+
}
|
|
74
|
+
interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
75
|
+
name?: string;
|
|
76
|
+
cwd?: string;
|
|
77
|
+
configFile?: string;
|
|
78
|
+
rcFile?: false | string;
|
|
79
|
+
globalRc?: boolean;
|
|
80
|
+
dotenv?: boolean | DotenvOptions;
|
|
81
|
+
envName?: string | false;
|
|
82
|
+
packageJson?: boolean | string | string[];
|
|
83
|
+
defaults?: T;
|
|
84
|
+
defaultConfig?: T;
|
|
85
|
+
overrides?: T;
|
|
86
|
+
resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
|
|
87
|
+
jiti?: JITI;
|
|
88
|
+
jitiOptions?: JITIOptions;
|
|
89
|
+
giget?: DownloadTemplateOptions;
|
|
90
|
+
extend?: false | {
|
|
91
|
+
extendKey?: string | string[];
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
type DefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = (input: InputConfig<T, MT>) => InputConfig<T, MT>;
|
|
95
|
+
declare function createDefineConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(): DefineConfig<T, MT>;
|
|
96
|
+
|
|
97
|
+
declare function loadConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>>;
|
|
98
|
+
|
|
99
|
+
type ConfigWatcher<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = ResolvedConfig<T, MT> & {
|
|
100
|
+
watchingFiles: string[];
|
|
101
|
+
unwatch: () => Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> extends LoadConfigOptions<T, MT> {
|
|
104
|
+
chokidarOptions?: WatchOptions;
|
|
105
|
+
debounce?: false | number;
|
|
106
|
+
onWatch?: (event: {
|
|
107
|
+
type: "created" | "updated" | "removed";
|
|
108
|
+
path: string;
|
|
109
|
+
}) => void | Promise<void>;
|
|
110
|
+
acceptHMR?: (context: {
|
|
111
|
+
getDiff: () => ReturnType<typeof diff>;
|
|
112
|
+
newConfig: ResolvedConfig<T, MT>;
|
|
113
|
+
oldConfig: ResolvedConfig<T, MT>;
|
|
114
|
+
}) => void | boolean | Promise<void | boolean>;
|
|
115
|
+
onUpdate?: (context: {
|
|
116
|
+
getDiff: () => ReturnType<typeof diff>;
|
|
117
|
+
newConfig: ResolvedConfig<T, MT>;
|
|
118
|
+
oldConfig: ResolvedConfig<T, MT>;
|
|
119
|
+
}) => void | Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
declare function watchConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>>;
|
|
122
|
+
|
|
123
|
+
export { type C12InputConfig, type ConfigLayer, type ConfigLayerMeta, type ConfigWatcher, type DefineConfig, type DotenvOptions, type Env, type InputConfig, type LoadConfigOptions, type ResolvedConfig, type SourceOptions, type UserInputConfig, type WatchConfigOptions, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JITI } from 'jiti';
|
|
2
2
|
import { JITIOptions } from 'jiti/dist/types';
|
|
3
|
+
import { DownloadTemplateOptions } from 'giget';
|
|
3
4
|
import { WatchOptions } from 'chokidar';
|
|
4
5
|
import { diff } from 'ohash';
|
|
5
6
|
|
|
@@ -54,6 +55,7 @@ interface C12InputConfig<T extends UserInputConfig = UserInputConfig, MT extends
|
|
|
54
55
|
type InputConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> = C12InputConfig<T, MT> & T;
|
|
55
56
|
interface SourceOptions<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta> {
|
|
56
57
|
meta?: MT;
|
|
58
|
+
giget?: DownloadTemplateOptions;
|
|
57
59
|
overrides?: T;
|
|
58
60
|
[key: string]: any;
|
|
59
61
|
}
|
|
@@ -84,6 +86,7 @@ interface LoadConfigOptions<T extends UserInputConfig = UserInputConfig, MT exte
|
|
|
84
86
|
resolve?: (id: string, options: LoadConfigOptions<T, MT>) => null | undefined | ResolvedConfig<T, MT> | Promise<ResolvedConfig<T, MT> | undefined | null>;
|
|
85
87
|
jiti?: JITI;
|
|
86
88
|
jitiOptions?: JITIOptions;
|
|
89
|
+
giget?: DownloadTemplateOptions;
|
|
87
90
|
extend?: false | {
|
|
88
91
|
extendKey?: string | string[];
|
|
89
92
|
};
|
|
@@ -117,4 +120,4 @@ interface WatchConfigOptions<T extends UserInputConfig = UserInputConfig, MT ext
|
|
|
117
120
|
}
|
|
118
121
|
declare function watchConfig<T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta>(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>>;
|
|
119
122
|
|
|
120
|
-
export { C12InputConfig, ConfigLayer, ConfigLayerMeta, ConfigWatcher, DefineConfig, DotenvOptions, Env, InputConfig, LoadConfigOptions, ResolvedConfig, SourceOptions, UserInputConfig, WatchConfigOptions, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
|
|
123
|
+
export { type C12InputConfig, type ConfigLayer, type ConfigLayerMeta, type ConfigWatcher, type DefineConfig, type DotenvOptions, type Env, type InputConfig, type LoadConfigOptions, type ResolvedConfig, type SourceOptions, type UserInputConfig, type WatchConfigOptions, createDefineConfig, loadConfig, loadDotenv, setupDotenv, watchConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { existsSync, promises } from 'node:fs';
|
|
2
|
-
import { resolve, extname, basename, dirname } from 'pathe';
|
|
2
|
+
import { resolve, join, extname, basename, dirname } from 'pathe';
|
|
3
3
|
import * as dotenv from 'dotenv';
|
|
4
4
|
import { rm } from 'node:fs/promises';
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
6
|
import createJiti from 'jiti';
|
|
7
7
|
import * as rc9 from 'rc9';
|
|
8
8
|
import { defu } from 'defu';
|
|
9
|
+
import { hash, diff } from 'ohash';
|
|
9
10
|
import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
|
|
10
11
|
import { watch } from 'chokidar';
|
|
11
12
|
import { debounce } from 'perfect-debounce';
|
|
12
|
-
import { diff } from 'ohash';
|
|
13
13
|
|
|
14
14
|
async function setupDotenv(options) {
|
|
15
15
|
const targetEnvironment = options.env ?? process.env;
|
|
@@ -229,7 +229,7 @@ async function extendConfig(config, options) {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
const GIT_PREFIXES = ["github:", "gitlab:", "bitbucket:", "https://"];
|
|
232
|
+
const GIT_PREFIXES = ["gh:", "github:", "gitlab:", "bitbucket:", "https://"];
|
|
233
233
|
const NPM_PACKAGE_RE = /^(@[\da-z~-][\d._a-z~-]*\/)?[\da-z~-][\d._a-z~-]*($|\/.*)/;
|
|
234
234
|
async function resolveConfig(source, options, sourceOptions = {}) {
|
|
235
235
|
if (options.resolve) {
|
|
@@ -240,14 +240,22 @@ async function resolveConfig(source, options, sourceOptions = {}) {
|
|
|
240
240
|
}
|
|
241
241
|
if (GIT_PREFIXES.some((prefix) => source.startsWith(prefix))) {
|
|
242
242
|
const { downloadTemplate } = await import('giget');
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
243
|
+
const cloneName = source.replace(/\W+/g, "_").split("_").splice(0, 3).join("_") + "_" + hash(source);
|
|
244
|
+
let cloneDir;
|
|
245
|
+
const localNodeModules = resolve(options.cwd, "node_modules");
|
|
246
|
+
if (existsSync(localNodeModules)) {
|
|
247
|
+
cloneDir = join(localNodeModules, ".c12", cloneName);
|
|
248
|
+
} else {
|
|
249
|
+
cloneDir = process.env.XDG_CACHE_HOME ? resolve(process.env.XDG_CACHE_HOME, "c12", cloneName) : resolve(homedir(), ".cache/c12", cloneName);
|
|
249
250
|
}
|
|
250
|
-
|
|
251
|
+
if (existsSync(cloneDir)) {
|
|
252
|
+
await rm(cloneDir, { recursive: true });
|
|
253
|
+
}
|
|
254
|
+
const cloned = await downloadTemplate(source, {
|
|
255
|
+
dir: cloneDir,
|
|
256
|
+
...options.giget,
|
|
257
|
+
...sourceOptions.giget
|
|
258
|
+
});
|
|
251
259
|
source = cloned.dir;
|
|
252
260
|
}
|
|
253
261
|
if (NPM_PACKAGE_RE.test(source)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c12",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Smart Config Loader",
|
|
5
5
|
"repository": "unjs/c12",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint": "eslint --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
|
|
26
26
|
"lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test",
|
|
27
27
|
"prepack": "unbuild",
|
|
28
|
-
"release": "changelogen --release && npm publish && git push --follow-tags",
|
|
28
|
+
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
29
29
|
"test": "pnpm lint && vitest run --coverage && pnpm test:types",
|
|
30
30
|
"test:types": "tsc --noEmit"
|
|
31
31
|
},
|
|
@@ -33,25 +33,25 @@
|
|
|
33
33
|
"chokidar": "^3.5.3",
|
|
34
34
|
"defu": "^6.1.2",
|
|
35
35
|
"dotenv": "^16.3.1",
|
|
36
|
-
"giget": "^1.1.
|
|
37
|
-
"jiti": "^1.
|
|
38
|
-
"mlly": "^1.4.
|
|
39
|
-
"ohash": "^1.1.
|
|
36
|
+
"giget": "^1.1.3",
|
|
37
|
+
"jiti": "^1.20.0",
|
|
38
|
+
"mlly": "^1.4.2",
|
|
39
|
+
"ohash": "^1.1.3",
|
|
40
40
|
"pathe": "^1.1.1",
|
|
41
41
|
"perfect-debounce": "^1.0.0",
|
|
42
42
|
"pkg-types": "^1.0.3",
|
|
43
43
|
"rc9": "^2.1.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@vitest/coverage-v8": "^0.
|
|
47
|
-
"changelogen": "^0.5.
|
|
48
|
-
"eslint": "^8.
|
|
46
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
47
|
+
"changelogen": "^0.5.5",
|
|
48
|
+
"eslint": "^8.51.0",
|
|
49
49
|
"eslint-config-unjs": "^0.2.1",
|
|
50
|
-
"expect-type": "^0.
|
|
51
|
-
"prettier": "^
|
|
52
|
-
"typescript": "^5.
|
|
53
|
-
"unbuild": "^
|
|
54
|
-
"vitest": "^0.
|
|
50
|
+
"expect-type": "^0.17.3",
|
|
51
|
+
"prettier": "^3.0.3",
|
|
52
|
+
"typescript": "^5.2.2",
|
|
53
|
+
"unbuild": "^2.0.0",
|
|
54
|
+
"vitest": "^0.34.6"
|
|
55
55
|
},
|
|
56
|
-
"packageManager": "pnpm@8.
|
|
56
|
+
"packageManager": "pnpm@8.8.0"
|
|
57
57
|
}
|