New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for reading custom env files (for e.g. ormconfig.env) #3361
Conversation
Addes missing extension when reading .env file
Can you please tell what issue you have? Because we have changed this area recently. Do you have something broken or what? adding @steevsachs |
@pleerock for me it stopped to read ‘ormconfig.env’ file as it was trying to load file without any extension. |
I think we should finally fix and unskip tests for this area. I know there is problem with config files not accesible during tests. Maybe using |
@vlapo yes, it will. I'm waiting for @steevsachs review of this PR. |
No problem, I will review this morning. |
I can't reproduce the problem described here, can anyone provide more details in case I'm overlooking something?
This will also break functionality for a plain If you manually move the config file mocks into the appropriate build dir and unskip the last test in |
@steevsachs when I was testing this on But maybe it's already fixed in master. I will try to prepare reproducible case in a separate repository tonight. |
@steevsachs Minimal reproducible code https://github.com/pdeszynski/typeorm-config-failing
It should end up with
Renaming The same problem occurs when running this code against |
Thank you for that, @pdeszynski. So the issue here is specifically support for We can't just append |
@@ -94,7 +94,7 @@ export class ConnectionOptionsReader { | |||
// if .env file found then load all its variables into process.env using dotenv package | |||
if (foundFileFormat === "env") { | |||
const dotenv = PlatformTools.load("dotenv"); | |||
dotenv.config({ path: this.baseFilePath }); | |||
dotenv.config({ path: `${this.baseFilePath}.env` }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extension should only be appended if possibleExtension
is not equal to .env
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@steevsachs you're right, but this was not falling for this foundFileFormat === "env"
condition, if i had .env
file instead of ormconfig.env
What about the else
case at https://github.com/typeorm/typeorm/pull/3361/files/d0e8fa3af49052cd13703f27f7c31e2d6e5d9d5e#diff-fd8d31a6463f188113f6a9f43f77612fR98 ? Isn't it solving .env
file case? When testing after applying this patch I had both cases working correctly (but I didn't run functional tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else condition only fires if the config file format is not .env
, ie ormconfig.json
. This ensure environment is still loaded in those cases.
I believe the reason .env
is working is that
ConnectionOptionsReader
usesormconfig
as its base file name...foundFileFormat
will equalundefined
at line 95 because there is noormconfig.*
at the base file path- Thus the
else
condition fires and loads the.env
file.
Hi all, this is still broken. Will someone merge this to fix this defect in the docs and the config loader? The only useful workaround is to switch to |
Can't believe this fix hasn't been accepted, right now using ormconfig.env or foo.env or bar.env doesnt work at all, the only workaround is to name the file as ".env" cc @steevsachs |
Here is my workaround to deal with the dropped support for loading This allowed me to upgrade from v0.2.7 to v0.2.21 without any (other) issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a test to confirm that it actually does what it's intended to. Can you add at least one that confirms the behavior?
Also there's a conflict. |
This PR seems way out of sync, but I'm pretty sure a viable fix for master is
on line 98 of There's definitely other ways to handle this, but I think this one will restore compat without breaking anything. I don't know that I'll have time to refamiliarize myself with this repo enough to get testing working in the short term, so anyone else please feel free to run with this! If no one does, I'll try to make some time in the next couple weeks. |
Actually - I don't think this is broken? I've created some tests and cannot replicate the issue. Attempting via the repo given. |
Hello all, I've completely forgot about this PR - if you still need it I can take care of it, maybe during this weekend |
Ok - in the repo I can replicate it but not in our tests - weird! In both cases I am using EDIT: No wonder it was working, I was running the wrong test!! |
If you'd like! I'll let you know if I end up getting anywhere today on it. :) |
@pdeszynski I think I've got it fixed in #6922 |
Added missing extension when reading <custom_name>.env file
Tested on TypeORM v0.2.11