made config async

This commit is contained in:
Boki 2025-06-20 20:47:31 -04:00
parent 92d4b90987
commit caf1c5fcaf
6 changed files with 91 additions and 143 deletions

View file

@ -25,11 +25,7 @@ export class EnvLoader implements ConfigLoader {
};
}
async load(): Promise<Record<string, unknown>> {
return this.loadSync();
}
loadSync(): Record<string, unknown> {
load(): Record<string, unknown> {
try {
// Load root .env file - try multiple possible locations
const possiblePaths = ['./.env', '../.env', '../../.env'];
@ -67,7 +63,7 @@ export class EnvLoader implements ConfigLoader {
}
}
private setConfigValue(config: Record<string, any>, key: string, value: string): void {
private setConfigValue(config: Record<string, unknown>, key: string, value: string): void {
const parsedValue = this.parseValue(value);
try {
@ -104,7 +100,7 @@ export class EnvLoader implements ConfigLoader {
}
}
private setNestedValue(obj: Record<string, any>, path: string[], value: unknown): boolean {
private setNestedValue(obj: Record<string, unknown>, path: string[], value: unknown): boolean {
if (path.length === 0) {
return false; // Cannot set value on empty path
}
@ -115,13 +111,13 @@ export class EnvLoader implements ConfigLoader {
try {
const target = path.reduce((acc, key) => {
if (!acc[key]) {
if (!acc[key] || typeof acc[key] !== 'object') {
acc[key] = {};
}
return acc[key];
return acc[key] as Record<string, unknown>;
}, obj);
target[lastKey] = value;
(target as Record<string, unknown>)[lastKey] = value;
return true;
} catch {
// If we can't assign to any property (readonly), skip this env var silently
@ -257,11 +253,11 @@ export class EnvLoader implements ConfigLoader {
process.env[key] = value;
}
}
} catch (error: any) {
} catch (error: unknown) {
// File not found is not an error (env files are optional)
if (error.code !== 'ENOENT') {
if (error && typeof error === 'object' && 'code' in error && error.code !== 'ENOENT') {
// eslint-disable-next-line no-console
console.warn(`Warning: Could not load env file ${filePath}:`, error.message);
console.warn(`Warning: Could not load env file ${filePath}:`, error instanceof Error ? error.message : String(error));
}
}
}