-
Notifications
You must be signed in to change notification settings - Fork 47
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
Accept loading multiple files with precedence #90
Comments
I also wanted to know if this is possible, if not already implemented. |
I upvote this feature request. In total, I expect the following files,
mode is This behavior is beautifully explained in the Vite build tool and I copied most of this from there. Vite also includes For this feature implementation, most of the existing functions can be used. The only extra code needed is to check if these files exist and merge them in the relevant order depending on the current mode. By checking if the file exists, I mean checking if the files are included in the project through |
Why not let users manually set the files they want to load in the order they want to load it? Simple and effective. |
But this is the usual way. I am saying, merge these files only if they exist. Most of the times these are the requirements. If those files don't exist, they won't be merged. Assume, a developer has most of these files. It won't be simple for that developer to merge those .ENVs by checking the current mode. That is why most of the build tools (Vite, CRA, Nest etc.) support this behavior out of the box. The explained feature wouldn't break any existing code and it will make development much easier when there is a lot of configuration. Anyway, I am planning to fork and develop the feature I mentioned. |
I agree with @lucasoares that this is standard. One question though, how and where does |
created by the developer
That depends on the platform you are building for. Flutter decides how the files mentioned in |
Not necessarily, think CI/CD
Think CI/CD In other words, the And thus I'm starting to wonder if one ever would create / generate a production env file... |
When doing local development, the developer has to. Plus, can you confirm if the Flutter apps built process can be automated? |
Yes it can. |
@pimvanderheijden Oh wow didn't see that!
You said, "it is common to". So you know in some cases, developers put the |
Exactly, but where do you keep that file (surely not in Git) and decide to
activate it yes/no? That’s an important question I think.
Additionally, assuming it is common to inject env vars from the platform
(as opposed to only from an .env file), you need some mechanism that allows
them to have precedence. For example, ‘API_KEY’ can be defined in both the
development .env ánd in the CI/CD platform. Both get injected
independently, so how to create precedence?
I think this repository deals with these challenges, but I don’t know how:
https://www.npmjs.com/package/dotenv
…On Mon, 25 Mar 2024 at 05:42, Lasindu Weerasinghe ***@***.***> wrote:
@pimvanderheijden <https://github.com/pimvanderheijden> Oh wow didn't see
that!
However, on these CI/CD platforms it is common to inject env vars
directly, for example from the repository settings. In that case, there is
no production file...
And thus I'm starting to wonder if one ever would create / generate a
production env file...
You said, "it is common to". So you know in some cases, developers put the
.env file instead of the commands because it is easy to manage env vars
that way. When env vars change, just replace the file instead of changing
commands. To do that the developer needs to keep a production level .env
somewhere.
—
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFL2SSUPY5BPBZY5SPW57HLYZ6TMZAVCNFSM6AAAAAA2ZJCV52VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJXGE4TSMRUGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
It can be kept locally in the repository. Even the production .env files need to be Git ignored.
In Flutter, you can check if the current environment is development or production. According to that, the library can give priority to the specific
The package you mentioned does that. It is the goto package for |
I get that you can use production .env files when deploying from a local machine. However, the consequence of CI/CD is that local files (not checked in with Git) are irrelevant. I really don't know yet if I'm going to do CI/CD for my app anytime soon so won't really be able to tell you more. I do expect it's going to be a lot different than "just" an .env file.
So, load production .env file depending on |
Good luck with that. But I still don't understand how a pipeline can build and publish Android and iOS apps to relevant stores. Sounds very impossible with all the restrictions they have. Specially Apple ones.
Oh yeah! |
There is CI/CD for iOS with the help of fastlane: https://docs.fastlane.tools |
Looks like they have spent a lot of money to get those permissions |
And hence the user of |
If you use this service to build a CD pipeline, disregardless of using this library, you will have to spend money. |
Hahah yes, clear. But I get a sense you're suggesting it's not worth the effort for |
No! 😕 |
I found another part of the docs describing CI/CD for Flutter: https://docs.flutter.dev/deployment/ios#create-a-build-archive-with-codemagic-cli-tools Doesn't sound like it's paid... |
Guys, what CI/CD have to do with having precedent .env files, lol hahaha
But it can be simplified if this library lets users load multiple .env files as they want:
How the .env file will be shipped with the application, the priority of the loading, and anything go to the dev to decide. What I need and what is the main point of this issue are documented here: https://vitejs.dev/guide/env-and-mode.html#env-files Anything else doesn't belong to this issue. Discuss it elsewhere, not in here! Thanks! |
@pimvanderheijden sounds cool.
Adding production
Not always. Only in projects where inexperienced developers make decisions. |
Future<void> loadEnvs(List<String> envs, {Map<String, String> merge = const {}}) async {
if (envs.isEmpty) return;
if (envs.length == 1) return dotenv.load(fileName: envs[0], mergeWith: merge);
final de = DotEnv();
await de.load(fileName: envs[0], mergeWith: merge);
await _loadEnvs(envs.skip(1).toList(), merge: de.env);
} This loads any number of dotenv files serially. The firstmost have priority, later dotenvs do not override them. After the function ends, all are loaded in the |
Future<void> loadEnv() async {
const isProduction = 'production' == String.fromEnvironment('ENVIRONMENT');
// priority: environment > .env
if (isProduction) {
await dotenv.load(fileName: '.env', mergeWith: Platform.environment);
}
// priority: environment > .env.local > .env
await dotenv.load(fileName: '.env.local', mergeWith: Platform.environment);
await dotenv.load(fileName: '.env', mergeWith: {...dotenv.env});
} In production builds,
|
Hello.
I would like this library to accept multiple files.
Use case scenario: to have both
.env.local
and.env
files, where my.env
can be committed to the source control (usually constants, etc) but with a.env.local
where I can have these constants changed only locally and ignored by git. This will let developers change the environment without changing the main file.The text was updated successfully, but these errors were encountered: