Skip to content
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

mergeWith too limited (cannot merge with itself / cannot overwrite values) #69

Open
martin-braun opened this issue Sep 11, 2022 · 0 comments

Comments

@martin-braun
Copy link

martin-braun commented Sep 11, 2022

I try to load an additional .env when running in a emulator/simulator like so:

dotenv.load(fileName: '.env').then((value) => {
  SafeDevice.isRealDevice.then((isReal) => {
    if (!isReal && (Platform.isAndroid || Platform.isIOS))
    {
      dotenv.load(
        fileName: '.env.' + (Platform.isAndroid ? "emulator" : "simulator"),
        mergeWith: dotenv.env)
      .then((value) => _runApp())
    }
  })
});

Nope, that it not working. It ends up with a map that contains only the keys of .env.emulator / .env.simulator. All keys from .env are lost. Hitting a breakpoint before the 2nd load reveals that the .env file is properly load.

EDIT: Workaround is to run mergeWith: {...dotenv.env}, but maybe this lib should do it by itself. Also it seems the merged map has higher priority, which feels wrong. I have to load the .env.emulator/ .env.simulator first, although the term mergeWith implies that it will be merged into the given map and thus values should be replaced.

Maybe an argument that defines if merged values will be overwritten or not? Last load values should have higher priority, but this would introduce a breaking change. An argument to toggle priority/overwrite would not.

@martin-braun martin-braun changed the title mergeWith itself not working mergeWith too limited (cannot merge with itself / cannot overwrite values) Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant