Skip to content

Commit

Permalink
fix env loading
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbryanyu committed Jan 18, 2024
1 parent 6e2a4b4 commit 05aa4f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.1.4 - 1/17/24
Minor change to where resetting dotenv fields is called.

## 1.1.3 - 1/17/24
Update README.md to notify users about input path validation.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-app-config",
"version": "1.1.3",
"version": "1.1.4",
"description": "A simple configuration manager for different environments",
"license": "MIT",
"repository": {
Expand Down
11 changes: 5 additions & 6 deletions src/simple-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,9 @@ export class Config {
* - Environment variables
* - The path corresponding to the environment
*
* If the path specified in each of the above doesn't exist, it will try the next highest priority value. Clears previously
* loaded values from a .env file
* If the path specified in each of the above doesn't exist, it will try the next highest priority value.
*/
private static findEnvFile(): string | undefined {
/* Reset previously set dotenv values */
Config.resetDotEnv();

/* Load path specified by command line argument if it exists */
for (const arg of process.argv) {
if (arg.startsWith(CommandLineArgs.EnvPath)) {
Expand Down Expand Up @@ -332,9 +328,12 @@ export class Config {
}

/**
* Loads the .env file if it has been found and set.
* Loads the .env file if it has been found and set. Clears previously loaded values from a .env file
*/
private static loadEnvFile(path: string | undefined): void {
/* Reset previously set dotenv values */
Config.resetDotEnv();

if (path !== undefined) {
dotenv.config({ path: path });
Config.prevDotenvValues = dotenv.parse(fs.readFileSync(path)); /* Set prev dotenv values */
Expand Down

0 comments on commit 05aa4f0

Please sign in to comment.