c12 3.3.0 → 3.3.2

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/dist/update.mjs CHANGED
@@ -1,74 +1,80 @@
1
- import { resolveModulePath } from 'exsolve';
2
- import { S as SUPPORTED_EXTENSIONS } from './shared/c12.Bzgyhsy6.mjs';
3
- import { join, normalize } from 'pathe';
4
- import { mkdir, writeFile, readFile } from 'node:fs/promises';
5
- import { dirname, extname } from 'node:path';
6
- import 'node:fs';
7
- import 'node:url';
8
- import 'node:os';
9
- import 'jiti';
10
- import 'rc9';
11
- import 'defu';
12
- import 'pkg-types';
13
- import 'dotenv';
1
+ import { resolveModulePath } from "exsolve";
2
+ import "node:fs";
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
+ import "node:url";
5
+ import "node:os";
6
+ import { join, normalize } from "pathe";
7
+ import "jiti";
8
+ import "rc9";
9
+ import "defu";
10
+ import "pkg-types";
11
+ import { dirname, extname } from "node:path";
14
12
 
15
- const UPDATABLE_EXTS = [".js", ".ts", ".mjs", ".cjs", ".mts", ".cts"];
13
+ //#region src/loader.ts
14
+ const SUPPORTED_EXTENSIONS = Object.freeze([
15
+ ".js",
16
+ ".ts",
17
+ ".mjs",
18
+ ".cjs",
19
+ ".mts",
20
+ ".cts",
21
+ ".json",
22
+ ".jsonc",
23
+ ".json5",
24
+ ".yaml",
25
+ ".yml",
26
+ ".toml"
27
+ ]);
28
+
29
+ //#endregion
30
+ //#region src/update.ts
31
+ const UPDATABLE_EXTS = [
32
+ ".js",
33
+ ".ts",
34
+ ".mjs",
35
+ ".cjs",
36
+ ".mts",
37
+ ".cts"
38
+ ];
39
+ /**
40
+ * @experimental Update a config file or create a new one.
41
+ */
16
42
  async function updateConfig(opts) {
17
- const { parseModule } = await import('magicast');
18
- let configFile = tryResolve(`./${opts.configFile}`, opts.cwd, SUPPORTED_EXTENSIONS) || tryResolve(
19
- `./.config/${opts.configFile}`,
20
- opts.cwd,
21
- SUPPORTED_EXTENSIONS
22
- ) || tryResolve(
23
- `./.config/${opts.configFile.split(".")[0]}`,
24
- opts.cwd,
25
- SUPPORTED_EXTENSIONS
26
- );
27
- let created = false;
28
- if (!configFile) {
29
- configFile = join(
30
- opts.cwd,
31
- opts.configFile + (opts.createExtension || ".ts")
32
- );
33
- const createResult = await opts.onCreate?.({ configFile }) ?? true;
34
- if (!createResult) {
35
- throw new Error("Config file creation aborted.");
36
- }
37
- const content = typeof createResult === "string" ? createResult : `export default {}
38
- `;
39
- await mkdir(dirname(configFile), { recursive: true });
40
- await writeFile(configFile, content, "utf8");
41
- created = true;
42
- }
43
- const ext = extname(configFile);
44
- if (!UPDATABLE_EXTS.includes(ext)) {
45
- throw new Error(
46
- `Unsupported config file extension: ${ext} (${configFile}) (supported: ${UPDATABLE_EXTS.join(", ")})`
47
- );
48
- }
49
- const contents = await readFile(configFile, "utf8");
50
- const _module = parseModule(contents, opts.magicast);
51
- const defaultExport = _module.exports.default;
52
- if (!defaultExport) {
53
- throw new Error("Default export is missing in the config file!");
54
- }
55
- const configObj = defaultExport.$type === "function-call" ? defaultExport.$args[0] : defaultExport;
56
- await opts.onUpdate?.(configObj);
57
- await writeFile(configFile, _module.generate().code);
58
- return {
59
- configFile,
60
- created
61
- };
43
+ const { parseModule } = await import("magicast");
44
+ let configFile = tryResolve(`./${opts.configFile}`, opts.cwd, SUPPORTED_EXTENSIONS) || tryResolve(`./.config/${opts.configFile}`, opts.cwd, SUPPORTED_EXTENSIONS) || tryResolve(`./.config/${opts.configFile.split(".")[0]}`, opts.cwd, SUPPORTED_EXTENSIONS);
45
+ let created = false;
46
+ if (!configFile) {
47
+ configFile = join(opts.cwd, opts.configFile + (opts.createExtension || ".ts"));
48
+ const createResult = await opts.onCreate?.({ configFile }) ?? true;
49
+ if (!createResult) throw new Error("Config file creation aborted.");
50
+ const content = typeof createResult === "string" ? createResult : `export default {}\n`;
51
+ await mkdir(dirname(configFile), { recursive: true });
52
+ await writeFile(configFile, content, "utf8");
53
+ created = true;
54
+ }
55
+ const ext = extname(configFile);
56
+ if (!UPDATABLE_EXTS.includes(ext)) throw new Error(`Unsupported config file extension: ${ext} (${configFile}) (supported: ${UPDATABLE_EXTS.join(", ")})`);
57
+ const _module = parseModule(await readFile(configFile, "utf8"), opts.magicast);
58
+ const defaultExport = _module.exports.default;
59
+ if (!defaultExport) throw new Error("Default export is missing in the config file!");
60
+ const configObj = defaultExport.$type === "function-call" ? defaultExport.$args[0] : defaultExport;
61
+ await opts.onUpdate?.(configObj);
62
+ await writeFile(configFile, _module.generate().code);
63
+ return {
64
+ configFile,
65
+ created
66
+ };
62
67
  }
63
68
  function tryResolve(path, cwd, extensions) {
64
- const res = resolveModulePath(path, {
65
- try: true,
66
- from: join(cwd, "/"),
67
- extensions,
68
- suffixes: ["", "/index"],
69
- cache: false
70
- });
71
- return res ? normalize(res) : void 0;
69
+ const res = resolveModulePath(path, {
70
+ try: true,
71
+ from: join(cwd, "/"),
72
+ extensions,
73
+ suffixes: ["", "/index"],
74
+ cache: false
75
+ });
76
+ return res ? normalize(res) : void 0;
72
77
  }
73
78
 
74
- export { updateConfig };
79
+ //#endregion
80
+ export { updateConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c12",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "description": "Smart Config Loader",
5
5
  "repository": "unjs/c12",
6
6
  "license": "MIT",
@@ -21,10 +21,10 @@
21
21
  "dist"
22
22
  ],
23
23
  "scripts": {
24
- "build": "automd && unbuild",
24
+ "build": "obuild",
25
25
  "dev": "vitest dev",
26
26
  "lint": "eslint . && prettier -c src test",
27
- "lint:fix": "eslint . --fix && prettier -w src test",
27
+ "lint:fix": "automd && eslint . --fix && prettier -w src test",
28
28
  "prepack": "unbuild",
29
29
  "release": "pnpm build && pnpm test && changelogen --release --push --publish",
30
30
  "test": "pnpm lint && vitest run --coverage && pnpm test:types",
@@ -34,10 +34,10 @@
34
34
  "chokidar": "^4.0.3",
35
35
  "confbox": "^0.2.2",
36
36
  "defu": "^6.1.4",
37
- "dotenv": "^17.2.2",
38
- "exsolve": "^1.0.7",
37
+ "dotenv": "^17.2.3",
38
+ "exsolve": "^1.0.8",
39
39
  "giget": "^2.0.0",
40
- "jiti": "^2.5.1",
40
+ "jiti": "^2.6.1",
41
41
  "ohash": "^2.0.11",
42
42
  "pathe": "^2.0.3",
43
43
  "perfect-debounce": "^2.0.0",
@@ -45,26 +45,26 @@
45
45
  "rc9": "^2.1.2"
46
46
  },
47
47
  "devDependencies": {
48
- "@types/node": "^24.4.0",
49
- "@vitest/coverage-v8": "^3.2.4",
50
- "automd": "^0.4.0",
48
+ "@types/node": "^24.10.0",
49
+ "@vitest/coverage-v8": "^4.0.8",
50
+ "automd": "^0.4.2",
51
51
  "changelogen": "^0.6.2",
52
- "eslint": "^9.35.0",
52
+ "eslint": "^9.39.1",
53
53
  "eslint-config-unjs": "^0.5.0",
54
54
  "expect-type": "^1.2.2",
55
- "magicast": "^0.3.5",
55
+ "magicast": "^0.5.1",
56
+ "obuild": "^0.4.1",
56
57
  "prettier": "^3.6.2",
57
- "typescript": "^5.9.2",
58
- "unbuild": "^3.6.1",
59
- "vitest": "^3.2.4"
58
+ "typescript": "^5.9.3",
59
+ "vitest": "^4.0.8"
60
60
  },
61
61
  "peerDependencies": {
62
- "magicast": "^0.3.5"
62
+ "magicast": "*"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
65
  "magicast": {
66
66
  "optional": true
67
67
  }
68
68
  },
69
- "packageManager": "pnpm@10.16.1"
69
+ "packageManager": "pnpm@10.21.0"
70
70
  }
@@ -1,418 +0,0 @@
1
- import { statSync, promises, existsSync } from 'node:fs';
2
- import { rm, readFile } from 'node:fs/promises';
3
- import { pathToFileURL } from 'node:url';
4
- import { homedir } from 'node:os';
5
- import { resolve, join, dirname, basename, extname, normalize } from 'pathe';
6
- import { resolveModulePath } from 'exsolve';
7
- import { createJiti } from 'jiti';
8
- import * as rc9 from 'rc9';
9
- import { defu } from 'defu';
10
- import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
11
- import * as dotenv from 'dotenv';
12
-
13
- async function setupDotenv(options) {
14
- const targetEnvironment = options.env ?? process.env;
15
- const environment = await loadDotenv({
16
- cwd: options.cwd,
17
- fileName: options.fileName ?? ".env",
18
- env: targetEnvironment,
19
- interpolate: options.interpolate ?? true
20
- });
21
- const dotenvVars = getDotEnvVars(targetEnvironment);
22
- for (const key in environment) {
23
- if (key.startsWith("_")) {
24
- continue;
25
- }
26
- if (targetEnvironment[key] === void 0 || dotenvVars.has(key)) {
27
- targetEnvironment[key] = environment[key];
28
- }
29
- }
30
- return environment;
31
- }
32
- async function loadDotenv(options) {
33
- const environment = /* @__PURE__ */ Object.create(null);
34
- const cwd = resolve(options.cwd || ".");
35
- const _fileName = options.fileName || ".env";
36
- const dotenvFiles = typeof _fileName === "string" ? [_fileName] : _fileName;
37
- const dotenvVars = getDotEnvVars(options.env || {});
38
- Object.assign(environment, options.env);
39
- for (const file of dotenvFiles) {
40
- const dotenvFile = resolve(cwd, file);
41
- if (!statSync(dotenvFile, { throwIfNoEntry: false })?.isFile()) {
42
- continue;
43
- }
44
- const parsed = dotenv.parse(await promises.readFile(dotenvFile, "utf8"));
45
- for (const key in parsed) {
46
- if (key in environment && !dotenvVars.has(key)) {
47
- continue;
48
- }
49
- environment[key] = parsed[key];
50
- dotenvVars.add(key);
51
- }
52
- }
53
- if (options.interpolate) {
54
- interpolate(environment);
55
- }
56
- return environment;
57
- }
58
- function interpolate(target, source = {}, parse = (v) => v) {
59
- function getValue(key) {
60
- return source[key] === void 0 ? target[key] : source[key];
61
- }
62
- function interpolate2(value, parents = []) {
63
- if (typeof value !== "string") {
64
- return value;
65
- }
66
- const matches = value.match(/(.?\${?(?:[\w:]+)?}?)/g) || [];
67
- return parse(
68
- // eslint-disable-next-line unicorn/no-array-reduce
69
- matches.reduce((newValue, match) => {
70
- const parts = /(.?)\${?([\w:]+)?}?/g.exec(match) || [];
71
- const prefix = parts[1];
72
- let value2, replacePart;
73
- if (prefix === "\\") {
74
- replacePart = parts[0] || "";
75
- value2 = replacePart.replace(String.raw`\$`, "$");
76
- } else {
77
- const key = parts[2];
78
- replacePart = (parts[0] || "").slice(prefix.length);
79
- if (parents.includes(key)) {
80
- console.warn(
81
- `Please avoid recursive environment variables ( loop: ${parents.join(
82
- " > "
83
- )} > ${key} )`
84
- );
85
- return "";
86
- }
87
- value2 = getValue(key);
88
- value2 = interpolate2(value2, [...parents, key]);
89
- }
90
- return value2 === void 0 ? newValue : newValue.replace(replacePart, value2);
91
- }, value)
92
- );
93
- }
94
- for (const key in target) {
95
- target[key] = interpolate2(getValue(key));
96
- }
97
- }
98
- function getDotEnvVars(targetEnvironment) {
99
- const globalRegistry = globalThis.__c12_dotenv_vars__ ||= /* @__PURE__ */ new Map();
100
- if (!globalRegistry.has(targetEnvironment)) {
101
- globalRegistry.set(targetEnvironment, /* @__PURE__ */ new Set());
102
- }
103
- return globalRegistry.get(targetEnvironment);
104
- }
105
-
106
- const _normalize = (p) => p?.replace(/\\/g, "/");
107
- const ASYNC_LOADERS = {
108
- ".yaml": () => import('confbox/yaml').then((r) => r.parseYAML),
109
- ".yml": () => import('confbox/yaml').then((r) => r.parseYAML),
110
- ".jsonc": () => import('confbox/jsonc').then((r) => r.parseJSONC),
111
- ".json5": () => import('confbox/json5').then((r) => r.parseJSON5),
112
- ".toml": () => import('confbox/toml').then((r) => r.parseTOML)
113
- };
114
- const SUPPORTED_EXTENSIONS = Object.freeze([
115
- // with jiti
116
- ".js",
117
- ".ts",
118
- ".mjs",
119
- ".cjs",
120
- ".mts",
121
- ".cts",
122
- ".json",
123
- // with confbox
124
- ".jsonc",
125
- ".json5",
126
- ".yaml",
127
- ".yml",
128
- ".toml"
129
- ]);
130
- async function loadConfig(options) {
131
- options.cwd = resolve(process.cwd(), options.cwd || ".");
132
- options.name = options.name || "config";
133
- options.envName = options.envName ?? process.env.NODE_ENV;
134
- options.configFile = options.configFile ?? (options.name === "config" ? "config" : `${options.name}.config`);
135
- options.rcFile = options.rcFile ?? `.${options.name}rc`;
136
- if (options.extend !== false) {
137
- options.extend = {
138
- extendKey: "extends",
139
- ...options.extend
140
- };
141
- }
142
- const _merger = options.merger || defu;
143
- options.jiti = options.jiti || createJiti(join(options.cwd, options.configFile), {
144
- interopDefault: true,
145
- moduleCache: false,
146
- extensions: [...SUPPORTED_EXTENSIONS],
147
- ...options.jitiOptions
148
- });
149
- const r = {
150
- config: {},
151
- cwd: options.cwd,
152
- configFile: resolve(options.cwd, options.configFile),
153
- layers: [],
154
- _configFile: void 0
155
- };
156
- const rawConfigs = {
157
- overrides: options.overrides,
158
- main: void 0,
159
- rc: void 0,
160
- packageJson: void 0,
161
- defaultConfig: options.defaultConfig
162
- };
163
- if (options.dotenv) {
164
- await setupDotenv({
165
- cwd: options.cwd,
166
- ...options.dotenv === true ? {} : options.dotenv
167
- });
168
- }
169
- const _mainConfig = await resolveConfig(".", options);
170
- if (_mainConfig.configFile) {
171
- rawConfigs.main = _mainConfig.config;
172
- r.configFile = _mainConfig.configFile;
173
- r._configFile = _mainConfig._configFile;
174
- }
175
- if (_mainConfig.meta) {
176
- r.meta = _mainConfig.meta;
177
- }
178
- if (options.rcFile) {
179
- const rcSources = [];
180
- rcSources.push(rc9.read({ name: options.rcFile, dir: options.cwd }));
181
- if (options.globalRc) {
182
- const workspaceDir = await findWorkspaceDir(options.cwd).catch(() => {
183
- });
184
- if (workspaceDir) {
185
- rcSources.push(rc9.read({ name: options.rcFile, dir: workspaceDir }));
186
- }
187
- rcSources.push(rc9.readUser({ name: options.rcFile, dir: options.cwd }));
188
- }
189
- rawConfigs.rc = _merger({}, ...rcSources);
190
- }
191
- if (options.packageJson) {
192
- const keys = (Array.isArray(options.packageJson) ? options.packageJson : [
193
- typeof options.packageJson === "string" ? options.packageJson : options.name
194
- ]).filter((t) => t && typeof t === "string");
195
- const pkgJsonFile = await readPackageJSON(options.cwd).catch(() => {
196
- });
197
- const values = keys.map((key) => pkgJsonFile?.[key]);
198
- rawConfigs.packageJson = _merger({}, ...values);
199
- }
200
- const configs = {};
201
- for (const key in rawConfigs) {
202
- const value = rawConfigs[key];
203
- configs[key] = await (typeof value === "function" ? value({ configs, rawConfigs }) : value);
204
- }
205
- if (Array.isArray(configs.main)) {
206
- r.config = configs.main;
207
- } else {
208
- r.config = _merger(
209
- configs.overrides,
210
- configs.main,
211
- configs.rc,
212
- configs.packageJson,
213
- configs.defaultConfig
214
- );
215
- if (options.extend) {
216
- await extendConfig(r.config, options);
217
- r.layers = r.config._layers;
218
- delete r.config._layers;
219
- r.config = _merger(r.config, ...r.layers.map((e) => e.config));
220
- }
221
- }
222
- const baseLayers = [
223
- configs.overrides && {
224
- config: configs.overrides,
225
- configFile: void 0,
226
- cwd: void 0
227
- },
228
- { config: configs.main, configFile: options.configFile, cwd: options.cwd },
229
- configs.rc && { config: configs.rc, configFile: options.rcFile },
230
- configs.packageJson && {
231
- config: configs.packageJson,
232
- configFile: "package.json"
233
- }
234
- ].filter((l) => l && l.config);
235
- r.layers = [...baseLayers, ...r.layers];
236
- if (options.defaults) {
237
- r.config = _merger(r.config, options.defaults);
238
- }
239
- if (options.omit$Keys) {
240
- for (const key in r.config) {
241
- if (key.startsWith("$")) {
242
- delete r.config[key];
243
- }
244
- }
245
- }
246
- if (options.configFileRequired && !r._configFile) {
247
- throw new Error(`Required config (${r.configFile}) cannot be resolved.`);
248
- }
249
- return r;
250
- }
251
- async function extendConfig(config, options) {
252
- config._layers = config._layers || [];
253
- if (!options.extend) {
254
- return;
255
- }
256
- let keys = options.extend.extendKey;
257
- if (typeof keys === "string") {
258
- keys = [keys];
259
- }
260
- const extendSources = [];
261
- for (const key of keys) {
262
- extendSources.push(
263
- ...(Array.isArray(config[key]) ? config[key] : [config[key]]).filter(
264
- Boolean
265
- )
266
- );
267
- delete config[key];
268
- }
269
- for (let extendSource of extendSources) {
270
- const originalExtendSource = extendSource;
271
- let sourceOptions = {};
272
- if (extendSource.source) {
273
- sourceOptions = extendSource.options || {};
274
- extendSource = extendSource.source;
275
- }
276
- if (Array.isArray(extendSource)) {
277
- sourceOptions = extendSource[1] || {};
278
- extendSource = extendSource[0];
279
- }
280
- if (typeof extendSource !== "string") {
281
- console.warn(
282
- `Cannot extend config from \`${JSON.stringify(
283
- originalExtendSource
284
- )}\` in ${options.cwd}`
285
- );
286
- continue;
287
- }
288
- const _config = await resolveConfig(extendSource, options, sourceOptions);
289
- if (!_config.config) {
290
- console.warn(
291
- `Cannot extend config from \`${extendSource}\` in ${options.cwd}`
292
- );
293
- continue;
294
- }
295
- await extendConfig(_config.config, { ...options, cwd: _config.cwd });
296
- config._layers.push(_config);
297
- if (_config.config._layers) {
298
- config._layers.push(..._config.config._layers);
299
- delete _config.config._layers;
300
- }
301
- }
302
- }
303
- const GIGET_PREFIXES = [
304
- "gh:",
305
- "github:",
306
- "gitlab:",
307
- "bitbucket:",
308
- "https://",
309
- "http://"
310
- ];
311
- const NPM_PACKAGE_RE = /^(@[\da-z~-][\d._a-z~-]*\/)?[\da-z~-][\d._a-z~-]*($|\/.*)/;
312
- async function resolveConfig(source, options, sourceOptions = {}) {
313
- const originalSource = source;
314
- if (options.resolve) {
315
- const res2 = await options.resolve(source, options);
316
- if (res2) {
317
- return res2;
318
- }
319
- }
320
- const _merger = options.merger || defu;
321
- const customProviderKeys = Object.keys(
322
- sourceOptions.giget?.providers || {}
323
- ).map((key) => `${key}:`);
324
- const gigetPrefixes = customProviderKeys.length > 0 ? [.../* @__PURE__ */ new Set([...customProviderKeys, ...GIGET_PREFIXES])] : GIGET_PREFIXES;
325
- if (options.giget !== false && gigetPrefixes.some((prefix) => source.startsWith(prefix))) {
326
- const { downloadTemplate } = await import('giget');
327
- const { digest } = await import('ohash');
328
- const cloneName = source.replace(/\W+/g, "_").split("_").splice(0, 3).join("_") + "_" + digest(source).slice(0, 10).replace(/[-_]/g, "");
329
- let cloneDir;
330
- const localNodeModules = resolve(options.cwd, "node_modules");
331
- const parentDir = dirname(options.cwd);
332
- if (basename(parentDir) === ".c12") {
333
- cloneDir = join(parentDir, cloneName);
334
- } else if (existsSync(localNodeModules)) {
335
- cloneDir = join(localNodeModules, ".c12", cloneName);
336
- } else {
337
- cloneDir = process.env.XDG_CACHE_HOME ? resolve(process.env.XDG_CACHE_HOME, "c12", cloneName) : resolve(homedir(), ".cache/c12", cloneName);
338
- }
339
- if (existsSync(cloneDir) && !sourceOptions.install) {
340
- await rm(cloneDir, { recursive: true });
341
- }
342
- const cloned = await downloadTemplate(source, {
343
- dir: cloneDir,
344
- install: sourceOptions.install,
345
- force: sourceOptions.install,
346
- auth: sourceOptions.auth,
347
- ...options.giget,
348
- ...sourceOptions.giget
349
- });
350
- source = cloned.dir;
351
- }
352
- if (NPM_PACKAGE_RE.test(source)) {
353
- source = tryResolve(source, options) || source;
354
- }
355
- const ext = extname(source);
356
- const isDir = !ext || ext === basename(source);
357
- const cwd = resolve(options.cwd, isDir ? source : dirname(source));
358
- if (isDir) {
359
- source = options.configFile;
360
- }
361
- const res = {
362
- config: void 0,
363
- configFile: void 0,
364
- cwd,
365
- source,
366
- sourceOptions
367
- };
368
- res.configFile = tryResolve(resolve(cwd, source), options) || tryResolve(
369
- resolve(cwd, ".config", source.replace(/\.config$/, "")),
370
- options
371
- ) || tryResolve(resolve(cwd, ".config", source), options) || tryResolve(resolve(options.cwd || cwd, originalSource), options) || source;
372
- if (!existsSync(res.configFile)) {
373
- return res;
374
- }
375
- res._configFile = res.configFile;
376
- const configFileExt = extname(res.configFile) || "";
377
- if (configFileExt in ASYNC_LOADERS) {
378
- const asyncLoader = await ASYNC_LOADERS[configFileExt]();
379
- const contents = await readFile(res.configFile, "utf8");
380
- res.config = asyncLoader(contents);
381
- } else {
382
- res.config = await options.jiti.import(res.configFile, {
383
- default: true
384
- });
385
- }
386
- if (typeof res.config === "function") {
387
- res.config = await res.config(options.context);
388
- }
389
- if (options.envName) {
390
- const envConfig = {
391
- ...res.config["$" + options.envName],
392
- ...res.config.$env?.[options.envName]
393
- };
394
- if (Object.keys(envConfig).length > 0) {
395
- res.config = _merger(envConfig, res.config);
396
- }
397
- }
398
- res.meta = defu(res.sourceOptions.meta, res.config.$meta);
399
- delete res.config.$meta;
400
- if (res.sourceOptions.overrides) {
401
- res.config = _merger(res.sourceOptions.overrides, res.config);
402
- }
403
- res.configFile = _normalize(res.configFile);
404
- res.source = _normalize(res.source);
405
- return res;
406
- }
407
- function tryResolve(id, options) {
408
- const res = resolveModulePath(id, {
409
- try: true,
410
- from: pathToFileURL(join(options.cwd || ".", options.configFile || "/")),
411
- suffixes: ["", "/index"],
412
- extensions: SUPPORTED_EXTENSIONS,
413
- cache: false
414
- });
415
- return res ? normalize(res) : void 0;
416
- }
417
-
418
- export { SUPPORTED_EXTENSIONS as S, loadDotenv as a, loadConfig as l, setupDotenv as s };