@abdokouta/react-config 1.0.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/.examples/01-basic-usage.ts +289 -0
- package/.examples/02-env-helper.ts +282 -0
- package/.examples/README.md +285 -0
- package/.prettierrc.js +1 -0
- package/README.md +261 -0
- package/__tests__/config.module.test.ts +244 -0
- package/__tests__/drivers/env.driver.test.ts +259 -0
- package/__tests__/services/config.service.test.ts +328 -0
- package/__tests__/setup.d.ts +11 -0
- package/__tests__/vitest.setup.ts +30 -0
- package/config/config.config.ts +62 -0
- package/dist/index.d.mts +474 -0
- package/dist/index.d.ts +474 -0
- package/dist/index.js +516 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +501 -0
- package/dist/index.mjs.map +1 -0
- package/eslint.config.js +13 -0
- package/package.json +77 -0
- package/src/config.module.ts +154 -0
- package/src/constants/index.ts +5 -0
- package/src/constants/tokens.constant.ts +38 -0
- package/src/drivers/env.driver.ts +194 -0
- package/src/drivers/file.driver.ts +81 -0
- package/src/drivers/index.ts +6 -0
- package/src/index.ts +92 -0
- package/src/interfaces/config-driver.interface.ts +30 -0
- package/src/interfaces/config-module-options.interface.ts +84 -0
- package/src/interfaces/config-service.interface.ts +71 -0
- package/src/interfaces/index.ts +8 -0
- package/src/interfaces/vite-config-plugin-options.interface.ts +56 -0
- package/src/plugins/index.ts +5 -0
- package/src/plugins/vite.plugin.ts +115 -0
- package/src/services/config.service.ts +172 -0
- package/src/services/index.ts +5 -0
- package/src/utils/get-nested-value.util.ts +56 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/load-config-file.util.ts +37 -0
- package/src/utils/scan-config-files.util.ts +40 -0
- package/tsconfig.json +28 -0
- package/tsup.config.ts +105 -0
- package/vitest.config.ts +66 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
21
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
22
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
23
|
+
if (decorator = decorators[i])
|
|
24
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
25
|
+
if (kind && result) __defProp(target, key, result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
29
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
ConfigModule: () => ConfigModule,
|
|
35
|
+
ConfigService: () => ConfigService,
|
|
36
|
+
EnvDriver: () => EnvDriver,
|
|
37
|
+
FileDriver: () => FileDriver,
|
|
38
|
+
getNestedValue: () => getNestedValue,
|
|
39
|
+
hasNestedValue: () => hasNestedValue,
|
|
40
|
+
loadConfigFile: () => loadConfigFile
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
|
|
44
|
+
// src/config.module.ts
|
|
45
|
+
var import_react_di2 = require("@abdokouta/react-di");
|
|
46
|
+
|
|
47
|
+
// src/utils/get-nested-value.util.ts
|
|
48
|
+
function getNestedValue(obj, path, defaultValue) {
|
|
49
|
+
const keys = path.split(".");
|
|
50
|
+
let current = obj;
|
|
51
|
+
for (const key of keys) {
|
|
52
|
+
if (current === null || current === void 0) {
|
|
53
|
+
return defaultValue;
|
|
54
|
+
}
|
|
55
|
+
current = current[key];
|
|
56
|
+
}
|
|
57
|
+
return current !== void 0 ? current : defaultValue;
|
|
58
|
+
}
|
|
59
|
+
function hasNestedValue(obj, path) {
|
|
60
|
+
const keys = path.split(".");
|
|
61
|
+
let current = obj;
|
|
62
|
+
for (const key of keys) {
|
|
63
|
+
if (current === null || current === void 0 || !(key in current)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
current = current[key];
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/drivers/env.driver.ts
|
|
72
|
+
var import_meta = {};
|
|
73
|
+
var EnvDriver = class {
|
|
74
|
+
constructor(options = {}) {
|
|
75
|
+
this.options = options;
|
|
76
|
+
__publicField(this, "config", {});
|
|
77
|
+
__publicField(this, "loaded", false);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Load environment variables
|
|
81
|
+
*/
|
|
82
|
+
load() {
|
|
83
|
+
if (this.loaded) {
|
|
84
|
+
console.log("[EnvDriver] Already loaded, returning cached config");
|
|
85
|
+
return this.config;
|
|
86
|
+
}
|
|
87
|
+
console.log("[EnvDriver] Loading environment variables...");
|
|
88
|
+
console.log("[EnvDriver] Options:", { ...this.options });
|
|
89
|
+
if (!this.options.ignoreEnvFile) {
|
|
90
|
+
this.loadDotEnv();
|
|
91
|
+
}
|
|
92
|
+
const globalName = this.options.globalName || "__APP_CONFIG__";
|
|
93
|
+
if (typeof window !== "undefined" && window[globalName]) {
|
|
94
|
+
this.config = { ...window[globalName] };
|
|
95
|
+
console.log(`[EnvDriver] Loaded config from window.${globalName}:`, Object.keys(this.config).length, "keys");
|
|
96
|
+
} else if (typeof process !== "undefined" && process.env) {
|
|
97
|
+
this.config = { ...process.env };
|
|
98
|
+
console.log("[EnvDriver] Loaded config from process.env:", Object.keys(this.config).length, "keys");
|
|
99
|
+
} else {
|
|
100
|
+
console.warn("[EnvDriver] No config source available (neither window." + globalName + " nor process.env)");
|
|
101
|
+
this.config = {};
|
|
102
|
+
}
|
|
103
|
+
console.log("[EnvDriver] Initial config keys:", [...Object.keys(this.config).filter((k) => k.includes("APP") || k.includes("VITE"))]);
|
|
104
|
+
if (this.options.envPrefix !== false) {
|
|
105
|
+
console.log("[EnvDriver] Stripping prefix...");
|
|
106
|
+
this.stripPrefix();
|
|
107
|
+
console.log("[EnvDriver] After stripPrefix, config keys:", [...Object.keys(this.config).filter((k) => k.includes("APP") || k.includes("VITE"))]);
|
|
108
|
+
}
|
|
109
|
+
if (this.options.expandVariables) {
|
|
110
|
+
this.expandEnvVariables();
|
|
111
|
+
}
|
|
112
|
+
this.loaded = true;
|
|
113
|
+
console.log("[EnvDriver] Load complete. Sample values:", {
|
|
114
|
+
APP_NAME: this.config.APP_NAME,
|
|
115
|
+
VITE_APP_NAME: this.config.VITE_APP_NAME
|
|
116
|
+
});
|
|
117
|
+
return this.config;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get configuration value
|
|
121
|
+
*/
|
|
122
|
+
get(key, defaultValue) {
|
|
123
|
+
if (!this.loaded) {
|
|
124
|
+
this.load();
|
|
125
|
+
}
|
|
126
|
+
const value = getNestedValue(this.config, key, defaultValue);
|
|
127
|
+
console.log(`[EnvDriver] get("${key}", "${defaultValue}") = "${value}"`);
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if key exists
|
|
132
|
+
*/
|
|
133
|
+
has(key) {
|
|
134
|
+
if (!this.loaded) {
|
|
135
|
+
this.load();
|
|
136
|
+
}
|
|
137
|
+
return hasNestedValue(this.config, key);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get all configuration
|
|
141
|
+
*/
|
|
142
|
+
all() {
|
|
143
|
+
if (!this.loaded) {
|
|
144
|
+
this.load();
|
|
145
|
+
}
|
|
146
|
+
return { ...this.config };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Load .env file using dotenv
|
|
150
|
+
*/
|
|
151
|
+
loadDotEnv() {
|
|
152
|
+
try {
|
|
153
|
+
const dotenv = require("dotenv");
|
|
154
|
+
const paths = Array.isArray(this.options.envFilePath) ? this.options.envFilePath : [this.options.envFilePath || ".env"];
|
|
155
|
+
for (const path of paths) {
|
|
156
|
+
dotenv.config({ path });
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Expand environment variables (e.g., ${VAR_NAME})
|
|
163
|
+
*/
|
|
164
|
+
expandEnvVariables() {
|
|
165
|
+
const regex = /\$\{([^}]+)\}/g;
|
|
166
|
+
const expand = (value) => {
|
|
167
|
+
return value.replace(regex, (_, key) => {
|
|
168
|
+
return this.config[key] || "";
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
for (const [key, value] of Object.entries(this.config)) {
|
|
172
|
+
if (typeof value === "string" && value.includes("${")) {
|
|
173
|
+
this.config[key] = expand(value);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Strip environment variable prefix
|
|
179
|
+
* Auto-detects framework (Vite, Next.js) or uses custom prefix
|
|
180
|
+
*/
|
|
181
|
+
stripPrefix() {
|
|
182
|
+
let prefix = this.options.envPrefix;
|
|
183
|
+
if (prefix === "auto" || prefix === void 0) {
|
|
184
|
+
const hasViteVars = Object.keys(this.config).some((key) => key.startsWith("VITE_"));
|
|
185
|
+
if (hasViteVars || typeof import_meta !== "undefined") {
|
|
186
|
+
prefix = "VITE_";
|
|
187
|
+
} else if (Object.keys(this.config).some((key) => key.startsWith("NEXT_PUBLIC_"))) {
|
|
188
|
+
prefix = "NEXT_PUBLIC_";
|
|
189
|
+
} else {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (typeof prefix === "string" && prefix.length > 0) {
|
|
194
|
+
const newConfig = {};
|
|
195
|
+
for (const [key, value] of Object.entries(this.config)) {
|
|
196
|
+
if (key.startsWith(prefix)) {
|
|
197
|
+
const unprefixedKey = key.substring(prefix.length);
|
|
198
|
+
newConfig[unprefixedKey] = value;
|
|
199
|
+
newConfig[key] = value;
|
|
200
|
+
} else {
|
|
201
|
+
newConfig[key] = value;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
this.config = newConfig;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/drivers/file.driver.ts
|
|
210
|
+
var FileDriver = class {
|
|
211
|
+
constructor(options = {}) {
|
|
212
|
+
__publicField(this, "config", {});
|
|
213
|
+
__publicField(this, "loaded", false);
|
|
214
|
+
if (options.config) {
|
|
215
|
+
this.config = options.config;
|
|
216
|
+
this.loaded = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Load configuration
|
|
221
|
+
* Config should be pre-loaded via Vite plugin or passed in constructor
|
|
222
|
+
*/
|
|
223
|
+
async load() {
|
|
224
|
+
if (this.loaded) {
|
|
225
|
+
return this.config;
|
|
226
|
+
}
|
|
227
|
+
const isServer = typeof globalThis !== "undefined" && typeof globalThis.window === "undefined";
|
|
228
|
+
if (isServer) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
"FileDriver requires pre-loaded configuration. Use Vite plugin for client-side or pass config in constructor for server-side."
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
this.loaded = true;
|
|
234
|
+
return this.config;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get configuration value
|
|
238
|
+
*/
|
|
239
|
+
get(key, defaultValue) {
|
|
240
|
+
if (!this.loaded) {
|
|
241
|
+
throw new Error("Configuration not loaded. Call load() first or use async initialization.");
|
|
242
|
+
}
|
|
243
|
+
return getNestedValue(this.config, key, defaultValue);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Check if key exists
|
|
247
|
+
*/
|
|
248
|
+
has(key) {
|
|
249
|
+
if (!this.loaded) {
|
|
250
|
+
throw new Error("Configuration not loaded. Call load() first or use async initialization.");
|
|
251
|
+
}
|
|
252
|
+
return hasNestedValue(this.config, key);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Get all configuration
|
|
256
|
+
*/
|
|
257
|
+
all() {
|
|
258
|
+
if (!this.loaded) {
|
|
259
|
+
throw new Error("Configuration not loaded. Call load() first or use async initialization.");
|
|
260
|
+
}
|
|
261
|
+
return { ...this.config };
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/services/config.service.ts
|
|
266
|
+
var import_react_di = require("@abdokouta/react-di");
|
|
267
|
+
|
|
268
|
+
// src/constants/tokens.constant.ts
|
|
269
|
+
var CONFIG_DRIVER = /* @__PURE__ */ Symbol("CONFIG_DRIVER");
|
|
270
|
+
var CONFIG_OPTIONS = /* @__PURE__ */ Symbol("CONFIG_OPTIONS");
|
|
271
|
+
var CONFIG_SERVICE = /* @__PURE__ */ Symbol("CONFIG_SERVICE");
|
|
272
|
+
|
|
273
|
+
// src/services/config.service.ts
|
|
274
|
+
var ConfigService = class {
|
|
275
|
+
constructor(driver) {
|
|
276
|
+
this.driver = driver;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get configuration value
|
|
280
|
+
*/
|
|
281
|
+
get(key, defaultValue) {
|
|
282
|
+
return this.driver.get(key, defaultValue);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get configuration value or throw if not found
|
|
286
|
+
*/
|
|
287
|
+
getOrThrow(key) {
|
|
288
|
+
const value = this.get(key);
|
|
289
|
+
if (value === void 0) {
|
|
290
|
+
throw new Error(`Configuration key "${key}" is required but not set`);
|
|
291
|
+
}
|
|
292
|
+
return value;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Get string value
|
|
296
|
+
*/
|
|
297
|
+
getString(key, defaultValue) {
|
|
298
|
+
const value = this.get(key, defaultValue);
|
|
299
|
+
return value !== void 0 ? String(value) : void 0;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Get string value or throw
|
|
303
|
+
*/
|
|
304
|
+
getStringOrThrow(key) {
|
|
305
|
+
return String(this.getOrThrow(key));
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get number value
|
|
309
|
+
*/
|
|
310
|
+
getNumber(key, defaultValue) {
|
|
311
|
+
const value = this.get(key, defaultValue);
|
|
312
|
+
if (value === void 0) {
|
|
313
|
+
return void 0;
|
|
314
|
+
}
|
|
315
|
+
const parsed = Number(value);
|
|
316
|
+
return isNaN(parsed) ? defaultValue : parsed;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get number value or throw
|
|
320
|
+
*/
|
|
321
|
+
getNumberOrThrow(key) {
|
|
322
|
+
const value = this.getNumber(key);
|
|
323
|
+
if (value === void 0) {
|
|
324
|
+
throw new Error(`Configuration key "${key}" is required but not set`);
|
|
325
|
+
}
|
|
326
|
+
return value;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Get boolean value
|
|
330
|
+
* Treats 'true', '1', 'yes', 'on' as true
|
|
331
|
+
*/
|
|
332
|
+
getBool(key, defaultValue) {
|
|
333
|
+
const value = this.get(key, defaultValue);
|
|
334
|
+
if (value === void 0) {
|
|
335
|
+
return void 0;
|
|
336
|
+
}
|
|
337
|
+
if (typeof value === "boolean") {
|
|
338
|
+
return value;
|
|
339
|
+
}
|
|
340
|
+
return ["true", "1", "yes", "on"].includes(String(value).toLowerCase());
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get boolean value or throw
|
|
344
|
+
*/
|
|
345
|
+
getBoolOrThrow(key) {
|
|
346
|
+
const value = this.getBool(key);
|
|
347
|
+
if (value === void 0) {
|
|
348
|
+
throw new Error(`Configuration key "${key}" is required but not set`);
|
|
349
|
+
}
|
|
350
|
+
return value;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Get array value (comma-separated string or actual array)
|
|
354
|
+
*/
|
|
355
|
+
getArray(key, defaultValue) {
|
|
356
|
+
const value = this.get(key, defaultValue);
|
|
357
|
+
if (value === void 0) {
|
|
358
|
+
return void 0;
|
|
359
|
+
}
|
|
360
|
+
if (Array.isArray(value)) {
|
|
361
|
+
return value.map(String);
|
|
362
|
+
}
|
|
363
|
+
return String(value).split(",").map((v) => v.trim()).filter(Boolean);
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Get JSON value
|
|
367
|
+
*/
|
|
368
|
+
getJson(key, defaultValue) {
|
|
369
|
+
const value = this.get(key, defaultValue);
|
|
370
|
+
if (value === void 0) {
|
|
371
|
+
return void 0;
|
|
372
|
+
}
|
|
373
|
+
if (typeof value === "object") {
|
|
374
|
+
return value;
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
return JSON.parse(String(value));
|
|
378
|
+
} catch {
|
|
379
|
+
return defaultValue;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Check if configuration key exists
|
|
384
|
+
*/
|
|
385
|
+
has(key) {
|
|
386
|
+
return this.driver.has(key);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Get all configuration values
|
|
390
|
+
*/
|
|
391
|
+
all() {
|
|
392
|
+
return this.driver.all();
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Clear cache (no-op since we don't cache in ConfigService)
|
|
396
|
+
*/
|
|
397
|
+
clearCache() {
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
ConfigService = __decorateClass([
|
|
401
|
+
(0, import_react_di.Injectable)(),
|
|
402
|
+
__decorateParam(0, (0, import_react_di.Inject)(CONFIG_DRIVER))
|
|
403
|
+
], ConfigService);
|
|
404
|
+
|
|
405
|
+
// src/config.module.ts
|
|
406
|
+
var ConfigModule = class {
|
|
407
|
+
/**
|
|
408
|
+
* Register configuration module with options
|
|
409
|
+
*
|
|
410
|
+
* @param options - Configuration options
|
|
411
|
+
* @returns Dynamic module
|
|
412
|
+
*/
|
|
413
|
+
static forRoot(options = {}) {
|
|
414
|
+
const driver = this.createDriver(options);
|
|
415
|
+
const isGlobal = options.isGlobal ?? false;
|
|
416
|
+
const providers = [
|
|
417
|
+
{
|
|
418
|
+
provide: CONFIG_OPTIONS,
|
|
419
|
+
useValue: options,
|
|
420
|
+
isGlobal
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
provide: CONFIG_DRIVER,
|
|
424
|
+
useValue: driver,
|
|
425
|
+
isGlobal
|
|
426
|
+
},
|
|
427
|
+
ConfigService,
|
|
428
|
+
{
|
|
429
|
+
provide: CONFIG_SERVICE,
|
|
430
|
+
useExisting: ConfigService,
|
|
431
|
+
isGlobal
|
|
432
|
+
}
|
|
433
|
+
];
|
|
434
|
+
return {
|
|
435
|
+
module: ConfigModule,
|
|
436
|
+
providers,
|
|
437
|
+
exports: [ConfigService]
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Register configuration module asynchronously
|
|
442
|
+
*
|
|
443
|
+
* @param options - Async configuration options
|
|
444
|
+
* @returns Dynamic module
|
|
445
|
+
*/
|
|
446
|
+
static async forRootAsync(options) {
|
|
447
|
+
const resolvedOptions = options.useFactory ? await options.useFactory() : options;
|
|
448
|
+
return this.forRoot(resolvedOptions);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Create configuration driver based on options
|
|
452
|
+
*/
|
|
453
|
+
static createDriver(options) {
|
|
454
|
+
const driverType = options.driver || "env";
|
|
455
|
+
switch (driverType) {
|
|
456
|
+
case "env":
|
|
457
|
+
const envDriver = new EnvDriver({
|
|
458
|
+
envFilePath: options.envFilePath,
|
|
459
|
+
ignoreEnvFile: options.ignoreEnvFile,
|
|
460
|
+
expandVariables: options.expandVariables,
|
|
461
|
+
envPrefix: options.envPrefix,
|
|
462
|
+
globalName: options.globalName
|
|
463
|
+
});
|
|
464
|
+
envDriver.load();
|
|
465
|
+
if (options.load) {
|
|
466
|
+
this.mergeCustomConfig(envDriver, options.load);
|
|
467
|
+
}
|
|
468
|
+
return envDriver;
|
|
469
|
+
case "file":
|
|
470
|
+
const fileDriver = new FileDriver({
|
|
471
|
+
config: typeof options.load === "object" ? options.load : void 0
|
|
472
|
+
});
|
|
473
|
+
return fileDriver;
|
|
474
|
+
default:
|
|
475
|
+
throw new Error(`Unknown configuration driver: ${driverType}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Merge custom configuration into driver
|
|
480
|
+
*/
|
|
481
|
+
static mergeCustomConfig(driver, load) {
|
|
482
|
+
const customConfig = typeof load === "function" ? load() : load;
|
|
483
|
+
if (customConfig instanceof Promise) {
|
|
484
|
+
customConfig.then((config) => {
|
|
485
|
+
Object.assign(driver.all(), config);
|
|
486
|
+
});
|
|
487
|
+
} else {
|
|
488
|
+
Object.assign(driver.all(), customConfig);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
ConfigModule = __decorateClass([
|
|
493
|
+
(0, import_react_di2.Module)({})
|
|
494
|
+
], ConfigModule);
|
|
495
|
+
|
|
496
|
+
// src/utils/load-config-file.util.ts
|
|
497
|
+
async function loadConfigFile(filePath) {
|
|
498
|
+
try {
|
|
499
|
+
const module2 = await import(
|
|
500
|
+
/* @vite-ignore */
|
|
501
|
+
filePath
|
|
502
|
+
);
|
|
503
|
+
const config = module2.default || module2;
|
|
504
|
+
if (typeof config === "function") {
|
|
505
|
+
return await config();
|
|
506
|
+
}
|
|
507
|
+
return config;
|
|
508
|
+
} catch (error) {
|
|
509
|
+
console.warn(
|
|
510
|
+
`[vite-plugin-config] Failed to load config file: ${filePath}`,
|
|
511
|
+
error
|
|
512
|
+
);
|
|
513
|
+
return {};
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.module.ts","../src/utils/get-nested-value.util.ts","../src/drivers/env.driver.ts","../src/drivers/file.driver.ts","../src/services/config.service.ts","../src/constants/tokens.constant.ts","../src/utils/load-config-file.util.ts"],"sourcesContent":["/**\n * @abdokouta/config\n *\n * NestJS-inspired configuration management with multiple drivers for loading\n * configuration from various sources (environment variables, files, etc.).\n * Provides type-safe access to configuration values with support for nested\n * properties and default values.\n *\n * @example\n * Basic usage with environment variables:\n * ```typescript\n * import { ConfigModule, ConfigService, EnvDriver } from '@abdokouta/config';\n * import { Module, Injectable, Inject } from '@abdokouta/react-di';\n *\n * @Module({\n * imports: [\n * ConfigModule.forRoot({\n * driver: new EnvDriver(),\n * }),\n * ],\n * })\n * export class AppModule {}\n *\n * @Injectable()\n * class DatabaseService {\n * constructor(@Inject(ConfigService) private config: ConfigService) {}\n *\n * connect() {\n * const host = this.config.get('DATABASE_HOST', 'localhost');\n * const port = this.config.get('DATABASE_PORT', 5432);\n * // Connect to database...\n * }\n * }\n * ```\n *\n * @example\n * Using file-based configuration:\n * ```typescript\n * import { ConfigModule, FileDriver } from '@abdokouta/config';\n *\n * @Module({\n * imports: [\n * ConfigModule.forRoot({\n * driver: new FileDriver({\n * path: './config/app.json',\n * }),\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n *\n * @example\n * Accessing nested configuration:\n * ```typescript\n * // config.json: { \"database\": { \"host\": \"localhost\", \"port\": 5432 } }\n * const host = config.get('database.host');\n * const port = config.get('database.port', 3306);\n * ```\n *\n * @module @abdokouta/config\n */\n\n// ============================================================================\n// Module (DI Configuration)\n// ============================================================================\nexport { ConfigModule } from './config.module';\n\n// ============================================================================\n// Core Service\n// ============================================================================\nexport { ConfigService } from './services/config.service';\n\n// ============================================================================\n// Drivers\n// ============================================================================\nexport { EnvDriver } from './drivers/env.driver';\nexport { FileDriver } from './drivers/file.driver';\n\n// ============================================================================\n// Interfaces\n// ============================================================================\nexport type { ConfigDriver } from './interfaces/config-driver.interface';\nexport type { ConfigModuleOptions } from './interfaces/config-module-options.interface';\nexport type { ConfigServiceInterface } from './interfaces/config-service.interface';\nexport type { ViteConfigPluginOptions } from './interfaces/vite-config-plugin-options.interface';\n\n// ============================================================================\n// Utilities\n// ============================================================================\nexport { getNestedValue, hasNestedValue } from './utils/get-nested-value.util';\nexport { loadConfigFile } from './utils/load-config-file.util';\n","import { Module, DynamicModule } from '@abdokouta/react-di';\n\nimport { EnvDriver } from './drivers/env.driver';\nimport { FileDriver } from './drivers/file.driver';\nimport { ConfigService } from './services/config.service';\nimport type { ConfigDriver } from './interfaces/config-driver.interface';\nimport type { ConfigModuleOptions } from './interfaces/config-module-options.interface';\nimport { CONFIG_DRIVER, CONFIG_OPTIONS, CONFIG_SERVICE } from './constants/tokens.constant';\n\n/**\n * Configuration Module\n * \n * Provides configuration management with multiple drivers.\n * Similar to NestJS ConfigModule.\n * \n * @example\n * ```typescript\n * // Using environment variables (default)\n * @Module({\n * imports: [\n * ConfigModule.forRoot({\n * envFilePath: '.env',\n * isGlobal: true,\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n * \n * @example\n * ```typescript\n * // Using file-based configuration\n * @Module({\n * imports: [\n * ConfigModule.forRoot({\n * driver: 'file',\n * filePattern: 'config/**\\/*.config.ts',\n * isGlobal: true,\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n@Module({})\nexport class ConfigModule {\n /**\n * Register configuration module with options\n * \n * @param options - Configuration options\n * @returns Dynamic module\n */\n static forRoot(options: ConfigModuleOptions = {}): DynamicModule {\n const driver = this.createDriver(options);\n \n const isGlobal = options.isGlobal ?? false;\n \n const providers = [\n {\n provide: CONFIG_OPTIONS,\n useValue: options,\n isGlobal,\n },\n {\n provide: CONFIG_DRIVER,\n useValue: driver,\n isGlobal,\n },\n ConfigService,\n {\n provide: CONFIG_SERVICE,\n useExisting: ConfigService,\n isGlobal,\n },\n ];\n\n return {\n module: ConfigModule,\n providers: providers as any,\n exports: [ConfigService],\n };\n }\n\n /**\n * Register configuration module asynchronously\n * \n * @param options - Async configuration options\n * @returns Dynamic module\n */\n static async forRootAsync(\n options: ConfigModuleOptions & {\n useFactory?: () => Promise<ConfigModuleOptions> | ConfigModuleOptions;\n }\n ): Promise<DynamicModule> {\n const resolvedOptions = options.useFactory\n ? await options.useFactory()\n : options;\n\n return this.forRoot(resolvedOptions);\n }\n\n /**\n * Create configuration driver based on options\n */\n private static createDriver(options: ConfigModuleOptions): ConfigDriver {\n const driverType = options.driver || 'env';\n\n switch (driverType) {\n case 'env':\n const envDriver = new EnvDriver({\n envFilePath: options.envFilePath,\n ignoreEnvFile: options.ignoreEnvFile,\n expandVariables: options.expandVariables,\n envPrefix: options.envPrefix,\n globalName: options.globalName,\n });\n envDriver.load();\n \n // Merge custom load function if provided\n if (options.load) {\n this.mergeCustomConfig(envDriver, options.load);\n }\n \n return envDriver;\n\n case 'file':\n const fileDriver = new FileDriver({\n config: typeof options.load === 'object' ? options.load : undefined,\n });\n return fileDriver;\n\n default:\n throw new Error(`Unknown configuration driver: ${driverType}`);\n }\n }\n\n /**\n * Merge custom configuration into driver\n */\n private static mergeCustomConfig(\n driver: ConfigDriver,\n load: Record<string, any> | (() => Record<string, any> | Promise<Record<string, any>>)\n ): void {\n const customConfig = typeof load === 'function' ? load() : load;\n \n if (customConfig instanceof Promise) {\n customConfig.then(config => {\n Object.assign(driver.all(), config);\n });\n } else {\n Object.assign(driver.all(), customConfig);\n }\n }\n}\n","/**\n * Get nested value from object using dot notation\n * \n * @param obj - Source object\n * @param path - Dot-notated path (e.g., 'database.host')\n * @param defaultValue - Default value if path not found\n * @returns Value at path or default value\n * \n * @example\n * ```typescript\n * const config = { database: { host: 'localhost' } };\n * getNestedValue(config, 'database.host'); // 'localhost'\n * getNestedValue(config, 'database.port', 5432); // 5432\n * ```\n */\nexport function getNestedValue<T = any>(\n obj: Record<string, any>,\n path: string,\n defaultValue?: T\n): T | undefined {\n const keys = path.split('.');\n let current: any = obj;\n\n for (const key of keys) {\n if (current === null || current === undefined) {\n return defaultValue;\n }\n current = current[key];\n }\n\n return current !== undefined ? current : defaultValue;\n}\n\n/**\n * Check if nested path exists in object\n * \n * @param obj - Source object\n * @param path - Dot-notated path\n * @returns True if path exists\n */\nexport function hasNestedValue(\n obj: Record<string, any>,\n path: string\n): boolean {\n const keys = path.split('.');\n let current: any = obj;\n\n for (const key of keys) {\n if (current === null || current === undefined || !(key in current)) {\n return false;\n }\n current = current[key];\n }\n\n return true;\n}\n","import type { ConfigDriver } from '../interfaces/config-driver.interface';\nimport { getNestedValue, hasNestedValue } from '../utils/get-nested-value.util';\n\n/**\n * Environment Variable Configuration Driver\n * \n * Loads configuration from environment variables (process.env).\n * Supports .env files via dotenv.\n */\nexport class EnvDriver implements ConfigDriver {\n private config: Record<string, any> = {};\n private loaded = false;\n\n constructor(\n private options: {\n envFilePath?: string | string[];\n ignoreEnvFile?: boolean;\n expandVariables?: boolean;\n envPrefix?: string | false;\n globalName?: string; // Custom global variable name\n } = {}\n ) {}\n\n /**\n * Load environment variables\n */\n load(): Record<string, any> {\n if (this.loaded) {\n console.log('[EnvDriver] Already loaded, returning cached config');\n return this.config;\n }\n\n console.log('[EnvDriver] Loading environment variables...');\n console.log('[EnvDriver] Options:', { ...this.options });\n\n // Load .env file if not ignored\n if (!this.options.ignoreEnvFile) {\n this.loadDotEnv();\n }\n\n // Get global config name (default: __APP_CONFIG__)\n const globalName = this.options.globalName || '__APP_CONFIG__';\n\n // Try to load from custom global variable first (browser environment)\n if (typeof window !== 'undefined' && (window as any)[globalName]) {\n this.config = { ...(window as any)[globalName] };\n console.log(`[EnvDriver] Loaded config from window.${globalName}:`, Object.keys(this.config).length, 'keys');\n }\n // Fallback to process.env (Node.js environment or backward compatibility)\n else if (typeof process !== 'undefined' && process.env) {\n this.config = { ...process.env };\n console.log('[EnvDriver] Loaded config from process.env:', Object.keys(this.config).length, 'keys');\n }\n // No config source available\n else {\n console.warn('[EnvDriver] No config source available (neither window.' + globalName + ' nor process.env)');\n this.config = {};\n }\n\n console.log('[EnvDriver] Initial config keys:', [...Object.keys(this.config).filter(k => k.includes('APP') || k.includes('VITE'))]);\n\n // Strip prefix if configured\n if (this.options.envPrefix !== false) {\n console.log('[EnvDriver] Stripping prefix...');\n this.stripPrefix();\n console.log('[EnvDriver] After stripPrefix, config keys:', [...Object.keys(this.config).filter(k => k.includes('APP') || k.includes('VITE'))]);\n }\n\n // Expand variables if enabled\n if (this.options.expandVariables) {\n this.expandEnvVariables();\n }\n\n this.loaded = true;\n console.log('[EnvDriver] Load complete. Sample values:', {\n APP_NAME: this.config.APP_NAME,\n VITE_APP_NAME: this.config.VITE_APP_NAME,\n });\n return this.config;\n }\n\n /**\n * Get configuration value\n */\n get<T = any>(key: string, defaultValue?: T): T | undefined {\n if (!this.loaded) {\n this.load();\n }\n const value = getNestedValue(this.config, key, defaultValue);\n console.log(`[EnvDriver] get(\"${key}\", \"${defaultValue}\") = \"${value}\"`);\n return value;\n }\n\n /**\n * Check if key exists\n */\n has(key: string): boolean {\n if (!this.loaded) {\n this.load();\n }\n return hasNestedValue(this.config, key);\n }\n\n /**\n * Get all configuration\n */\n all(): Record<string, any> {\n if (!this.loaded) {\n this.load();\n }\n return { ...this.config };\n }\n\n /**\n * Load .env file using dotenv\n */\n private loadDotEnv(): void {\n try {\n // Try to load dotenv\n const dotenv = require('dotenv');\n const paths = Array.isArray(this.options.envFilePath)\n ? this.options.envFilePath\n : [this.options.envFilePath || '.env'];\n\n for (const path of paths) {\n dotenv.config({ path });\n }\n } catch (error) {\n // dotenv not installed, skip\n }\n }\n\n /**\n * Expand environment variables (e.g., ${VAR_NAME})\n */\n private expandEnvVariables(): void {\n const regex = /\\$\\{([^}]+)\\}/g;\n\n const expand = (value: string): string => {\n return value.replace(regex, (_, key) => {\n return this.config[key] || '';\n });\n };\n\n for (const [key, value] of Object.entries(this.config)) {\n if (typeof value === 'string' && value.includes('${')) {\n this.config[key] = expand(value);\n }\n }\n }\n\n /**\n * Strip environment variable prefix\n * Auto-detects framework (Vite, Next.js) or uses custom prefix\n */\n private stripPrefix(): void {\n let prefix = this.options.envPrefix;\n\n // Auto-detect framework prefix\n if (prefix === 'auto' || prefix === undefined) {\n // Check for Vite (import.meta.env exists or VITE_ variables present)\n const hasViteVars = Object.keys(this.config).some(key => key.startsWith('VITE_'));\n if (hasViteVars || typeof import.meta !== 'undefined') {\n prefix = 'VITE_';\n }\n // Check for Next.js (NEXT_PUBLIC_ variables present)\n else if (Object.keys(this.config).some(key => key.startsWith('NEXT_PUBLIC_'))) {\n prefix = 'NEXT_PUBLIC_';\n }\n // No framework detected, don't strip\n else {\n return;\n }\n }\n\n // Strip the prefix from all matching keys\n if (typeof prefix === 'string' && prefix.length > 0) {\n const newConfig: Record<string, any> = {};\n \n for (const [key, value] of Object.entries(this.config)) {\n if (key.startsWith(prefix)) {\n // Add both prefixed and unprefixed versions\n const unprefixedKey = key.substring(prefix.length);\n newConfig[unprefixedKey] = value;\n newConfig[key] = value; // Keep original too\n } else {\n newConfig[key] = value;\n }\n }\n \n this.config = newConfig;\n }\n }\n}\n","import type { ConfigDriver } from '@/interfaces/config-driver.interface';\nimport { getNestedValue, hasNestedValue } from '@/utils/get-nested-value.util';\n\n/**\n * File-based Configuration Driver\n * \n * Loads configuration from TypeScript/JavaScript files.\n * This is a server-side only driver. For client-side, use the Vite plugin.\n * \n * @see packages/pixielity/config/src/plugins/vite-config.plugin.ts\n */\nexport class FileDriver implements ConfigDriver {\n private config: Record<string, any> = {};\n private loaded = false;\n\n constructor(\n options: {\n config?: Record<string, any>;\n } = {}\n ) {\n // Pre-loaded config from Vite plugin or server\n if (options.config) {\n this.config = options.config;\n this.loaded = true;\n }\n }\n\n /**\n * Load configuration\n * Config should be pre-loaded via Vite plugin or passed in constructor\n */\n async load(): Promise<Record<string, any>> {\n if (this.loaded) {\n return this.config;\n }\n\n // If running on server (Node.js), throw error\n const isServer = typeof globalThis !== 'undefined' && \n typeof (globalThis as typeof globalThis & { window?: any }).window === 'undefined';\n \n if (isServer) {\n throw new Error(\n 'FileDriver requires pre-loaded configuration. ' +\n 'Use Vite plugin for client-side or pass config in constructor for server-side.'\n );\n }\n\n this.loaded = true;\n return this.config;\n }\n\n /**\n * Get configuration value\n */\n get<T = any>(key: string, defaultValue?: T): T | undefined {\n if (!this.loaded) {\n throw new Error('Configuration not loaded. Call load() first or use async initialization.');\n }\n return getNestedValue(this.config, key, defaultValue);\n }\n\n /**\n * Check if key exists\n */\n has(key: string): boolean {\n if (!this.loaded) {\n throw new Error('Configuration not loaded. Call load() first or use async initialization.');\n }\n return hasNestedValue(this.config, key);\n }\n\n /**\n * Get all configuration\n */\n all(): Record<string, any> {\n if (!this.loaded) {\n throw new Error('Configuration not loaded. Call load() first or use async initialization.');\n }\n return { ...this.config };\n }\n}\n","import { Inject, Injectable } from \"@abdokouta/react-di\";\n\nimport { CONFIG_DRIVER } from \"@/constants/tokens.constant\";\nimport type { ConfigDriver } from \"@/interfaces/config-driver.interface\";\nimport type { ConfigServiceInterface } from \"@/interfaces/config-service.interface\";\n\n/**\n * Configuration Service\n *\n * Provides type-safe access to configuration values with various getter methods.\n * Similar to NestJS ConfigService.\n *\n * @example\n * ```typescript\n * class MyService {\n * constructor(private config: ConfigService) {}\n *\n * getDbConfig() {\n * return {\n * host: this.config.getString('DB_HOST', 'localhost'),\n * port: this.config.getNumber('DB_PORT', 5432),\n * ssl: this.config.getBool('DB_SSL', false),\n * };\n * }\n * }\n * ```\n */\n@Injectable()\nexport class ConfigService implements ConfigServiceInterface {\n constructor(\n @Inject(CONFIG_DRIVER)\n private driver: ConfigDriver,\n ) {}\n\n /**\n * Get configuration value\n */\n get<T = any>(key: string, defaultValue?: T): T | undefined {\n return this.driver.get<T>(key, defaultValue);\n }\n\n /**\n * Get configuration value or throw if not found\n */\n getOrThrow<T = any>(key: string): T {\n const value = this.get<T>(key);\n if (value === undefined) {\n throw new Error(`Configuration key \"${key}\" is required but not set`);\n }\n return value;\n }\n\n /**\n * Get string value\n */\n getString(key: string, defaultValue?: string): string | undefined {\n const value = this.get(key, defaultValue);\n return value !== undefined ? String(value) : undefined;\n }\n\n /**\n * Get string value or throw\n */\n getStringOrThrow(key: string): string {\n return String(this.getOrThrow(key));\n }\n\n /**\n * Get number value\n */\n getNumber(key: string, defaultValue?: number): number | undefined {\n const value = this.get(key, defaultValue);\n if (value === undefined) {\n return undefined;\n }\n const parsed = Number(value);\n return isNaN(parsed) ? defaultValue : parsed;\n }\n\n /**\n * Get number value or throw\n */\n getNumberOrThrow(key: string): number {\n const value = this.getNumber(key);\n if (value === undefined) {\n throw new Error(`Configuration key \"${key}\" is required but not set`);\n }\n return value;\n }\n\n /**\n * Get boolean value\n * Treats 'true', '1', 'yes', 'on' as true\n */\n getBool(key: string, defaultValue?: boolean): boolean | undefined {\n const value = this.get(key, defaultValue);\n if (value === undefined) {\n return undefined;\n }\n if (typeof value === \"boolean\") {\n return value;\n }\n return [\"true\", \"1\", \"yes\", \"on\"].includes(String(value).toLowerCase());\n }\n\n /**\n * Get boolean value or throw\n */\n getBoolOrThrow(key: string): boolean {\n const value = this.getBool(key);\n if (value === undefined) {\n throw new Error(`Configuration key \"${key}\" is required but not set`);\n }\n return value;\n }\n\n /**\n * Get array value (comma-separated string or actual array)\n */\n getArray(key: string, defaultValue?: string[]): string[] | undefined {\n const value = this.get(key, defaultValue);\n if (value === undefined) {\n return undefined;\n }\n if (Array.isArray(value)) {\n return value.map(String);\n }\n return String(value)\n .split(\",\")\n .map((v) => v.trim())\n .filter(Boolean);\n }\n\n /**\n * Get JSON value\n */\n getJson<T = any>(key: string, defaultValue?: T): T | undefined {\n const value = this.get(key, defaultValue);\n if (value === undefined) {\n return undefined;\n }\n if (typeof value === \"object\") {\n return value as T;\n }\n try {\n return JSON.parse(String(value)) as T;\n } catch {\n return defaultValue;\n }\n }\n\n /**\n * Check if configuration key exists\n */\n has(key: string): boolean {\n return this.driver.has(key);\n }\n\n /**\n * Get all configuration values\n */\n all(): Record<string, any> {\n return this.driver.all();\n }\n\n /**\n * Clear cache (no-op since we don't cache in ConfigService)\n */\n clearCache(): void {\n // No-op - caching should be done at a higher level if needed\n }\n}\n","/**\n * Dependency Injection Tokens\n * \n * Used for injecting configuration dependencies.\n */\n\n/**\n * Configuration driver token\n * \n * @example\n * ```typescript\n * @Inject(CONFIG_DRIVER)\n * private driver: ConfigDriver\n * ```\n */\nexport const CONFIG_DRIVER = Symbol('CONFIG_DRIVER');\n\n/**\n * Configuration options token\n * \n * @example\n * ```typescript\n * @Inject(CONFIG_OPTIONS)\n * private options: ConfigModuleOptions\n * ```\n */\nexport const CONFIG_OPTIONS = Symbol('CONFIG_OPTIONS');\n\n/**\n * Configuration service token\n * \n * @example\n * ```typescript\n * @Inject(CONFIG_SERVICE)\n * private config: ConfigService\n * ```\n */\nexport const CONFIG_SERVICE = Symbol('CONFIG_SERVICE');\n","/**\n * Load Config File Utility\n *\n * Dynamically loads and parses a config file.\n */\n\n/**\n * Load and parse config file\n *\n * @param filePath - Absolute path to the config file\n * @returns Parsed config object\n */\nexport async function loadConfigFile(\n filePath: string\n): Promise<Record<string, any>> {\n try {\n // Dynamic import of the config file\n // @ts-ignore - Dynamic import path\n const module = await import(/* @vite-ignore */ filePath);\n\n // Extract config object (could be default export or named export)\n const config = module.default || module;\n\n // If it's a function, call it\n if (typeof config === 'function') {\n return await config();\n }\n\n return config;\n } catch (error) {\n console.warn(\n `[vite-plugin-config] Failed to load config file: ${filePath}`,\n error\n );\n return {};\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,mBAAsC;;;ACe/B,SAAS,eACd,KACA,MACA,cACe;AACf,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,UAAe;AAEnB,aAAW,OAAO,MAAM;AACtB,QAAI,YAAY,QAAQ,YAAY,QAAW;AAC7C,aAAO;AAAA,IACT;AACA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,SAAO,YAAY,SAAY,UAAU;AAC3C;AASO,SAAS,eACd,KACA,MACS;AACT,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,UAAe;AAEnB,aAAW,OAAO,MAAM;AACtB,QAAI,YAAY,QAAQ,YAAY,UAAa,EAAE,OAAO,UAAU;AAClE,aAAO;AAAA,IACT;AACA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACvDA;AASO,IAAM,YAAN,MAAwC;AAAA,EAI7C,YACU,UAMJ,CAAC,GACL;AAPQ;AAJV,wBAAQ,UAA8B,CAAC;AACvC,wBAAQ,UAAS;AAAA,EAUd;AAAA;AAAA;AAAA;AAAA,EAKH,OAA4B;AAC1B,QAAI,KAAK,QAAQ;AACf,cAAQ,IAAI,qDAAqD;AACjE,aAAO,KAAK;AAAA,IACd;AAEA,YAAQ,IAAI,8CAA8C;AAC1D,YAAQ,IAAI,wBAAwB,EAAE,GAAG,KAAK,QAAQ,CAAC;AAGvD,QAAI,CAAC,KAAK,QAAQ,eAAe;AAC/B,WAAK,WAAW;AAAA,IAClB;AAGA,UAAM,aAAa,KAAK,QAAQ,cAA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