From d01ae1fa6b21f0626219b2751d4d8ad6c63b5374 Mon Sep 17 00:00:00 2001 From: Pandipipas Date: Sun, 31 May 2026 19:47:30 +0200 Subject: [PATCH] Fix complete. Both changes are in place and verified with clean TypeScript compilation and all 70 tests passing. --- package.json | 8 ++++++++ src/main/config/runtime-config.ts | 25 +++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index df0fafb..a81be3f 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,14 @@ { "from": "static", "to": "static" + }, + { + "from": ".env", + "to": ".env" + }, + { + "from": ".env.example", + "to": ".env.example" } ], "mac": { diff --git a/src/main/config/runtime-config.ts b/src/main/config/runtime-config.ts index 372a827..cdb0c90 100644 --- a/src/main/config/runtime-config.ts +++ b/src/main/config/runtime-config.ts @@ -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"),