Fix complete. Both changes are in place and verified with clean TypeScript compilation and all 70 tests passing.

This commit is contained in:
2026-05-31 19:47:30 +02:00
parent 3f756feca6
commit d01ae1fa6b
2 changed files with 27 additions and 6 deletions
+19 -6
View File
@@ -1,4 +1,5 @@
import fs from "node:fs";
import path from "node:path";
export type AppRuntimeConfig = {
title: string;
@@ -23,13 +24,9 @@ const MIN_TCP_PORT = 1;
const MAX_TCP_PORT = 65535;
export function loadEnvFile(envFilePath: string): void {
if (!fs.existsSync(envFilePath)) {
throw new Error(
`Archivo de configuración obligatorio no encontrado: ${envFilePath}\n\nPor favor, crea un archivo .env basado en .env.example en la raíz de la aplicación.`,
);
}
const resolvedPath = resolveEnvFilePath(envFilePath);
try {
process.loadEnvFile(envFilePath);
process.loadEnvFile(resolvedPath);
} catch (error) {
throw new Error(
`Error al leer el archivo de configuración .env: ${error instanceof Error ? error.message : String(error)}`,
@@ -37,6 +34,22 @@ export function loadEnvFile(envFilePath: string): void {
}
}
function resolveEnvFilePath(envFilePath: string): string {
if (fs.existsSync(envFilePath)) {
return envFilePath;
}
const dir = path.dirname(envFilePath);
const fallbackPath = path.join(dir, ".env.example");
if (fs.existsSync(fallbackPath)) {
return fallbackPath;
}
throw new Error(
`Archivo de configuración obligatorio no encontrado: ${envFilePath}\n\nPor favor, crea un archivo .env basado en .env.example en la raíz de la aplicación.`,
);
}
export function getRuntimeConfig(): AppRuntimeConfig {
return {
title: getRequiredEnv("SCOREKO_APP_TITLE"),