Skip to content

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

Open

Description

@martin-braun

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.

Activity

  1. changed the title [-]mergeWith itself not working[/-] [+]mergeWith too limited (cannot merge with itself / cannot overwrite values)[/+] on Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions