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

should merge extend objects rather than overwriting #1363

Open
soulgalore opened this issue Jun 12, 2019 · 3 comments
Open

should merge extend objects rather than overwriting #1363

soulgalore opened this issue Jun 12, 2019 · 3 comments

Comments

@soulgalore
Copy link
Contributor

Hi! First I've been a using yargs for many years in sitspeed.io and it works really great. Thanks a lot!

Lately I've started using extends to extend other configurations and I have a question. Let me show an example:
parent.json

{
  "a": {
    "b": 1
  }
}

child.json

{
  "extends": "/path/to/parent.json",
  "a": {
    "c": 2
  }
}

In my case the the child overrides all properties on the parent, so c exists but not b. But if I use the child and add use a cli option like --a.b 2 they are merged and both c and b exists on the object. Is there any reason that it behaves differently?

The way we use extends is that on the server we keep some secrets in the one config file and then we have the rest of the config open in a git repo, so it's easy for users to see our full setup. But we have a couple of clashing namespaces that get overruled.

Or is it a better way to do that?

Best
Peter

@bcoe bcoe added the question label Jun 17, 2019
@bcoe
Copy link
Member

bcoe commented Jun 18, 2019

Hey Peter 👋 thanks for the kind words. I honestly haven't used the extends functionality that much personally 😆

In general we could use a bit of an overall of how our dot notation functionality works ... it's buggy. I think that your example should be equivalent to:

--a.b 1 --a.c 2

I think I'd be open to a patch that corrects this behavior ... I don't think I'll have many cycles to add the functionality myself anytime soon unfortunately (so if anyone reads this and wants to contribute, your patch would be greatly appreciated).

@bcoe bcoe changed the title Question about extends vs cli params should merge extend objects rather than overwriting Jun 18, 2019
@bcoe
Copy link
Member

bcoe commented Jun 18, 2019

@soulgalore just a thought, I might make this a configuration option (and default to the current behavior) ... for folks who are using this to build tools that except a configuration file (like a nycrc.json, or eslint.json) the merging might be a surprise?

@soulgalore
Copy link
Contributor Author

Yes I see. It is not super important for me, I can have a go at a PR when I get back after vacation in the middle of August. At the moment we override with ENV instead, that works fine good for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants