From b9677b110c2bddcd36523a06b2c4d9d3797a412e Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 18 Nov 2024 19:27:20 +0100 Subject: [PATCH] fix(Qenv): Fix environment file path initialization logic. --- changelog.md | 5 +++++ ts/00_commitinfo_data.ts | 2 +- ts/qenv.classes.qenv.ts | 24 ++++++++++-------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index 264d982..2cc7e04 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## 2024-11-18 - 6.0.8 - fix(Qenv) +Fix environment file path initialization logic. + +- Corrected the logic for setting the environment file paths to prevent overwriting each other. + ## 2024-11-18 - 6.0.7 - fix(Qenv) Fix file path initialization for environment variable files diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 1cb3c07..1f95a40 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/qenv', - version: '6.0.7', + version: '6.0.8', description: 'A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.' } diff --git a/ts/qenv.classes.qenv.ts b/ts/qenv.classes.qenv.ts index 6be6070..f94fb73 100644 --- a/ts/qenv.classes.qenv.ts +++ b/ts/qenv.classes.qenv.ts @@ -32,25 +32,21 @@ export class Qenv { plugins.path.resolve(qenvFileBasePathArg), 'qenv.yml' ); + if (envFileBasePathArg) { - const envFileJsonPath = this.envFilePathAbsolute = plugins.path.join( - plugins.path.resolve(envFileBasePathArg), - 'env.json' - ); - const envFileYmlPath = this.envFilePathAbsolute = plugins.path.join( - plugins.path.resolve(envFileBasePathArg), - 'env.yml' - ); - const envFileYamlPath = this.envFilePathAbsolute = plugins.path.join( - plugins.path.resolve(envFileBasePathArg), - 'env.yaml' - ); + const envFileBasePath = plugins.path.resolve(envFileBasePathArg); + + const envFileJsonPath = plugins.path.join(envFileBasePath, 'env.json'); + const envFileYmlPath = plugins.path.join(envFileBasePath, 'env.yml'); + const envFileYamlPath = plugins.path.join(envFileBasePath, 'env.yaml'); + const envFileJsonExists = plugins.smartfile.fs.fileExistsSync(envFileJsonPath); const envFileYmlExists = plugins.smartfile.fs.fileExistsSync(envFileYmlPath); const envFileYamlExists = plugins.smartfile.fs.fileExistsSync(envFileYamlPath); - - if (envFileJsonExists && (envFileYamlExists || envFileYmlExists)) { + + if (envFileJsonExists && (envFileYmlExists || envFileYamlExists)) { this.logger.log('warn', 'Both env.json and env.yml files exist! Using env.json'); + this.envFilePathAbsolute = envFileJsonPath; } else if (envFileJsonExists) { this.envFilePathAbsolute = envFileJsonPath; } else if (envFileYmlExists) {