fix(core): Improve handling of env.json and env.yml file checks
This commit is contained in:
parent
fa00f33c13
commit
bedefd3efe
49
changelog.md
Normal file
49
changelog.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-11-18 - 6.0.6 - fix(core)
|
||||||
|
Improve handling of env.json and env.yml file checks
|
||||||
|
|
||||||
|
- Check for existence of both env.json and env.yml files and prioritize env.json.
|
||||||
|
- Consolidate getFromEnvJsonFile and getFromEnvYamlFile methods into getFromEnvYamlOrJsonFile.
|
||||||
|
|
||||||
|
## 2024-05-29 to 2024-02-09 - 6.0.5 - update
|
||||||
|
Updates related to configuration files and data handling.
|
||||||
|
|
||||||
|
- Updated description
|
||||||
|
- Updated tsconfig
|
||||||
|
- Updated npmextra.json for githost
|
||||||
|
|
||||||
|
## 2023-08-09 - 6.0.0 to 6.0.4 - core
|
||||||
|
Various fixes within the core functionality.
|
||||||
|
|
||||||
|
- Fixes and improvements across multiple minor versions
|
||||||
|
|
||||||
|
## 2023-08-09 - 5.0.5 - core
|
||||||
|
Breaking change that impacts core functionality.
|
||||||
|
|
||||||
|
- Significant updates leading to breaking changes
|
||||||
|
|
||||||
|
## 2023-07-11 to 2022-07-28 - 5.0.2 - organization
|
||||||
|
Transition to a new organization scheme.
|
||||||
|
|
||||||
|
- Switched to new organizational scheme
|
||||||
|
|
||||||
|
## 2022-07-28 - 4.0.11 - core
|
||||||
|
Breaking change introducing ESM modules.
|
||||||
|
|
||||||
|
- Switch to ECMAScript modules
|
||||||
|
|
||||||
|
## 2019-01-15 - 3.1.1 - environment
|
||||||
|
Breaking change in environment handling.
|
||||||
|
|
||||||
|
- Treat environment variables as immutable
|
||||||
|
|
||||||
|
## 2019-01-14 - 3.0.7 - docker
|
||||||
|
New feature for Docker secret management.
|
||||||
|
|
||||||
|
- Allow Docker secret.json to be named flexibly
|
||||||
|
|
||||||
|
## 2018-08-13 - 1.1.7 - scope
|
||||||
|
Scope update for package management.
|
||||||
|
|
||||||
|
- Change scope to @pushrocks/
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/qenv',
|
name: '@push.rocks/qenv',
|
||||||
version: '6.0.5',
|
version: '6.0.6',
|
||||||
description: 'easy promised environments'
|
description: 'A module for easily handling environment variables in Node.js projects with support for .yml and .json configuration.'
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,24 @@ export class Qenv {
|
|||||||
'qenv.yml'
|
'qenv.yml'
|
||||||
);
|
);
|
||||||
if (envFileBasePathArg) {
|
if (envFileBasePathArg) {
|
||||||
this.envFilePathAbsolute = plugins.path.join(
|
const envFileJsonPath = this.envFilePathAbsolute = plugins.path.join(
|
||||||
plugins.path.resolve(envFileBasePathArg),
|
plugins.path.resolve(envFileBasePathArg),
|
||||||
'env.json'
|
'env.json'
|
||||||
);
|
);
|
||||||
|
const envFileYamlPath = this.envFilePathAbsolute = plugins.path.join(
|
||||||
|
plugins.path.resolve(envFileBasePathArg),
|
||||||
|
'env.yml'
|
||||||
|
);
|
||||||
|
const envFileJsonExists = plugins.smartfile.fs.fileExistsSync(envFileJsonPath);
|
||||||
|
const envFileYamlExists = plugins.smartfile.fs.fileExistsSync(envFileYamlPath);
|
||||||
|
|
||||||
|
if (envFileJsonExists && envFileYamlExists) {
|
||||||
|
this.logger.log('warn', 'Both env.json and env.yml files exist! Using env.json');
|
||||||
|
} else if (envFileJsonExists) {
|
||||||
|
this.envFilePathAbsolute = envFileJsonPath;
|
||||||
|
} else if (envFileYamlExists) {
|
||||||
|
this.envFilePathAbsolute = envFileYamlPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +140,7 @@ export class Qenv {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
this.getFromEnvironmentVariable(envVarRefArg) ||
|
this.getFromEnvironmentVariable(envVarRefArg) ||
|
||||||
this.getFromEnvJsonFile(envVarRefArg) ||
|
this.getFromEnvYamlOrJsonFile(envVarRefArg) ||
|
||||||
this.getFromDockerSecret(envVarRefArg) ||
|
this.getFromDockerSecret(envVarRefArg) ||
|
||||||
this.getFromDockerSecretJson(envVarRefArg)
|
this.getFromDockerSecretJson(envVarRefArg)
|
||||||
);
|
);
|
||||||
@ -135,7 +149,7 @@ export class Qenv {
|
|||||||
private tryGetEnvVarSync(envVarName: string): string | undefined {
|
private tryGetEnvVarSync(envVarName: string): string | undefined {
|
||||||
return (
|
return (
|
||||||
this.getFromEnvironmentVariable(envVarName) ||
|
this.getFromEnvironmentVariable(envVarName) ||
|
||||||
this.getFromEnvJsonFile(envVarName) ||
|
this.getFromEnvYamlOrJsonFile(envVarName) ||
|
||||||
this.getFromDockerSecret(envVarName) ||
|
this.getFromDockerSecret(envVarName) ||
|
||||||
this.getFromDockerSecretJson(envVarName)
|
this.getFromDockerSecretJson(envVarName)
|
||||||
);
|
);
|
||||||
@ -145,7 +159,7 @@ export class Qenv {
|
|||||||
return process.env[envVarName];
|
return process.env[envVarName];
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFromEnvJsonFile(envVarName: string): string | undefined {
|
private getFromEnvYamlOrJsonFile(envVarName: string): string | undefined {
|
||||||
if (!plugins.smartfile.fs.fileExistsSync(this.envFilePathAbsolute)) {
|
if (!plugins.smartfile.fs.fileExistsSync(this.envFilePathAbsolute)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user