c12 0.2.5 → 0.2.8
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 -1
- package/dist/index.cjs +17 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +17 -9
- package/package.json +15 -16
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -161,6 +161,7 @@ async function extendConfig(config, opts) {
|
|
|
161
161
|
for (const extendSource of extendSources) {
|
|
162
162
|
const _config = await resolveConfig(extendSource, opts);
|
|
163
163
|
if (!_config.config) {
|
|
164
|
+
console.warn(`Cannot extend config from ${extendSource} in ${opts.cwd}`);
|
|
164
165
|
continue;
|
|
165
166
|
}
|
|
166
167
|
await extendConfig(_config.config, { ...opts, cwd: _config.cwd });
|
|
@@ -172,6 +173,7 @@ async function extendConfig(config, opts) {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
const GIT_PREFIXES = ["github:", "gitlab:", "bitbucket:", "https://"];
|
|
176
|
+
const NPM_PACKAGE_RE = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
175
177
|
const jiti = createJiti__default(null, { cache: false, interopDefault: true, requireCache: false });
|
|
176
178
|
async function resolveConfig(source, opts) {
|
|
177
179
|
if (opts.resolve) {
|
|
@@ -192,22 +194,28 @@ async function resolveConfig(source, opts) {
|
|
|
192
194
|
await gittar.extract(tarFile, tmpdir);
|
|
193
195
|
source = pathe.resolve(tmpdir, subPath);
|
|
194
196
|
}
|
|
197
|
+
if (NPM_PACKAGE_RE.test(source)) {
|
|
198
|
+
try {
|
|
199
|
+
source = jiti.resolve(source, { paths: [opts.cwd] });
|
|
200
|
+
} catch (_err) {
|
|
201
|
+
}
|
|
202
|
+
}
|
|
195
203
|
const isDir = !pathe.extname(source);
|
|
196
204
|
const cwd = pathe.resolve(opts.cwd, isDir ? source : pathe.dirname(source));
|
|
197
205
|
if (isDir) {
|
|
198
206
|
source = opts.configFile;
|
|
199
207
|
}
|
|
200
|
-
const res = { config:
|
|
208
|
+
const res = { config: null, cwd };
|
|
201
209
|
try {
|
|
202
210
|
res.configFile = jiti.resolve(pathe.resolve(cwd, source), { paths: [cwd] });
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
} catch (_err) {
|
|
212
|
+
}
|
|
213
|
+
if (!fs.existsSync(res.configFile)) {
|
|
214
|
+
return res;
|
|
215
|
+
}
|
|
216
|
+
res.config = jiti(res.configFile);
|
|
217
|
+
if (typeof res.config === "function") {
|
|
218
|
+
res.config = await res.config();
|
|
211
219
|
}
|
|
212
220
|
return res;
|
|
213
221
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ declare function loadDotenv(opts: DotenvOptions): Promise<Env>;
|
|
|
37
37
|
interface InputConfig extends Record<string, any> {
|
|
38
38
|
}
|
|
39
39
|
interface ConfigLayer<T extends InputConfig = InputConfig> {
|
|
40
|
-
config: T;
|
|
40
|
+
config: T | null;
|
|
41
41
|
cwd?: string;
|
|
42
42
|
configFile?: string;
|
|
43
43
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -137,6 +137,7 @@ async function extendConfig(config, opts) {
|
|
|
137
137
|
for (const extendSource of extendSources) {
|
|
138
138
|
const _config = await resolveConfig(extendSource, opts);
|
|
139
139
|
if (!_config.config) {
|
|
140
|
+
console.warn(`Cannot extend config from ${extendSource} in ${opts.cwd}`);
|
|
140
141
|
continue;
|
|
141
142
|
}
|
|
142
143
|
await extendConfig(_config.config, { ...opts, cwd: _config.cwd });
|
|
@@ -148,6 +149,7 @@ async function extendConfig(config, opts) {
|
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
const GIT_PREFIXES = ["github:", "gitlab:", "bitbucket:", "https://"];
|
|
152
|
+
const NPM_PACKAGE_RE = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
151
153
|
const jiti = createJiti(null, { cache: false, interopDefault: true, requireCache: false });
|
|
152
154
|
async function resolveConfig(source, opts) {
|
|
153
155
|
if (opts.resolve) {
|
|
@@ -168,22 +170,28 @@ async function resolveConfig(source, opts) {
|
|
|
168
170
|
await gittar.extract(tarFile, tmpdir);
|
|
169
171
|
source = resolve(tmpdir, subPath);
|
|
170
172
|
}
|
|
173
|
+
if (NPM_PACKAGE_RE.test(source)) {
|
|
174
|
+
try {
|
|
175
|
+
source = jiti.resolve(source, { paths: [opts.cwd] });
|
|
176
|
+
} catch (_err) {
|
|
177
|
+
}
|
|
178
|
+
}
|
|
171
179
|
const isDir = !extname(source);
|
|
172
180
|
const cwd = resolve(opts.cwd, isDir ? source : dirname(source));
|
|
173
181
|
if (isDir) {
|
|
174
182
|
source = opts.configFile;
|
|
175
183
|
}
|
|
176
|
-
const res = { config:
|
|
184
|
+
const res = { config: null, cwd };
|
|
177
185
|
try {
|
|
178
186
|
res.configFile = jiti.resolve(resolve(cwd, source), { paths: [cwd] });
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
+
} catch (_err) {
|
|
188
|
+
}
|
|
189
|
+
if (!existsSync(res.configFile)) {
|
|
190
|
+
return res;
|
|
191
|
+
}
|
|
192
|
+
res.config = jiti(res.configFile);
|
|
193
|
+
if (typeof res.config === "function") {
|
|
194
|
+
res.config = await res.config();
|
|
187
195
|
}
|
|
188
196
|
return res;
|
|
189
197
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c12",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Smart Config Loader",
|
|
5
5
|
"repository": "unjs/c12",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,22 +18,14 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "unbuild",
|
|
23
|
-
"dev": "vitest dev",
|
|
24
|
-
"lint": "eslint --ext .ts,.js,.mjs,.cjs .",
|
|
25
|
-
"prepack": "unbuild",
|
|
26
|
-
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
|
|
27
|
-
"test": "vitest run --coverage"
|
|
28
|
-
},
|
|
29
21
|
"dependencies": {
|
|
30
22
|
"defu": "^6.0.0",
|
|
31
|
-
"dotenv": "^16.0.
|
|
23
|
+
"dotenv": "^16.0.1",
|
|
32
24
|
"gittar": "^0.1.1",
|
|
33
|
-
"jiti": "^1.
|
|
34
|
-
"mlly": "^0.5.
|
|
35
|
-
"pathe": "^0.2
|
|
36
|
-
"rc9": "^1.2.
|
|
25
|
+
"jiti": "^1.14.0",
|
|
26
|
+
"mlly": "^0.5.4",
|
|
27
|
+
"pathe": "^0.3.2",
|
|
28
|
+
"rc9": "^1.2.2"
|
|
37
29
|
},
|
|
38
30
|
"devDependencies": {
|
|
39
31
|
"@nuxtjs/eslint-config-typescript": "latest",
|
|
@@ -44,5 +36,12 @@
|
|
|
44
36
|
"unbuild": "latest",
|
|
45
37
|
"vitest": "latest"
|
|
46
38
|
},
|
|
47
|
-
"packageManager": "pnpm@
|
|
48
|
-
|
|
39
|
+
"packageManager": "pnpm@7.4.0",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "unbuild",
|
|
42
|
+
"dev": "vitest dev",
|
|
43
|
+
"lint": "eslint --ext .ts,.js,.mjs,.cjs .",
|
|
44
|
+
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
|
|
45
|
+
"test": "vitest run --coverage"
|
|
46
|
+
}
|
|
47
|
+
}
|