fixed env loader issue
This commit is contained in:
parent
521e54fcb9
commit
aca98fdce4
2 changed files with 33 additions and 47 deletions
|
|
@ -59,30 +59,43 @@ export class EnvLoader implements ConfigLoader {
|
|||
private setConfigValue(config: Record<string, any>, key: string, value: string): void {
|
||||
const parsedValue = this.parseValue(value);
|
||||
|
||||
if (this.options.nestedDelimiter && key.includes(this.options.nestedDelimiter)) {
|
||||
// Handle nested delimiter (e.g., APP__NAME -> { APP: { NAME: value } })
|
||||
const parts = key.split(this.options.nestedDelimiter);
|
||||
this.setNestedValue(config, parts, parsedValue);
|
||||
} else if (this.options.convertCase) {
|
||||
// Convert to camelCase
|
||||
const camelKey = this.toCamelCase(key);
|
||||
config[camelKey] = parsedValue;
|
||||
} else {
|
||||
// Convert to nested structure based on underscores
|
||||
const path = key.toLowerCase().split('_');
|
||||
this.setNestedValue(config, path, parsedValue);
|
||||
try {
|
||||
if (this.options.nestedDelimiter && key.includes(this.options.nestedDelimiter)) {
|
||||
// Handle nested delimiter (e.g., APP__NAME -> { APP: { NAME: value } })
|
||||
const parts = key.split(this.options.nestedDelimiter);
|
||||
this.setNestedValue(config, parts, parsedValue);
|
||||
} else if (this.options.convertCase) {
|
||||
// Convert to camelCase
|
||||
const camelKey = this.toCamelCase(key);
|
||||
config[camelKey] = parsedValue;
|
||||
} else {
|
||||
// Convert to nested structure based on underscores
|
||||
const path = key.toLowerCase().split('_');
|
||||
this.setNestedValue(config, path, parsedValue);
|
||||
}
|
||||
} catch (error) {
|
||||
// Skip environment variables that can't be set (readonly properties)
|
||||
// This is expected behavior for system environment variables
|
||||
}
|
||||
}
|
||||
|
||||
private setNestedValue(obj: Record<string, any>, path: string[], value: unknown): void {
|
||||
private setNestedValue(obj: Record<string, any>, path: string[], value: unknown): boolean {
|
||||
const lastKey = path.pop()!;
|
||||
const target = path.reduce((acc, key) => {
|
||||
if (!acc[key]) {
|
||||
acc[key] = {};
|
||||
}
|
||||
return acc[key];
|
||||
}, obj);
|
||||
target[lastKey] = value;
|
||||
|
||||
try {
|
||||
const target = path.reduce((acc, key) => {
|
||||
if (!acc[key]) {
|
||||
acc[key] = {};
|
||||
}
|
||||
return acc[key];
|
||||
}, obj);
|
||||
|
||||
target[lastKey] = value;
|
||||
return true;
|
||||
} catch (error) {
|
||||
// If we can't assign to any property (readonly), skip this env var silently
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private toCamelCase(str: string): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue