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

Lists are handled unintuitively #12

Closed
moqmar opened this issue May 18, 2020 · 1 comment
Closed

Lists are handled unintuitively #12

moqmar opened this issue May 18, 2020 · 1 comment

Comments

@moqmar
Copy link
Contributor

moqmar commented May 18, 2020

# first.yml
hello:
- world
- alex

# second.yml
hello:
- moritz

# yaml-merge first.yml second.yml
hello:
- moritz
- alex

It makes sense, as .hello[0] in first.yml gets overwritten with .hello[0] from second.yml, but when using this to merge e.g. configuration files, most people probably expect something like ["world", "alex", "moritz"] from that. If someone really wants the second behaviour, you could still allow the following YAML file to override values:

hello:
  0: moritz

To implement this, there's https://lodash.com/docs/4.17.15#mergeWith:

_.mergeWith({}, ...files, (objValue, srcValue, key, object, source, stack) => Array.isArray(objValue) && Array.isArray(srcValue) ? [...objValue, ...srcValue] : undefined)
@moqmar
Copy link
Contributor Author

moqmar commented May 18, 2020

This would make yaml-merge really useful to organize Fedora CoreOS configuration files.

moqmar added a commit to moqmar/yaml-merge that referenced this issue May 18, 2020
alexlafroscia added a commit that referenced this issue Oct 16, 2020
Fix #12 by adding a _.mergeWith customizer function
alexlafroscia pushed a commit that referenced this issue Oct 16, 2020
BREAKING CHANGE: Arrays are merged, rather than overwritten
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