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

fix(build): properly handle alias key in config merge #2847

Merged

Conversation

chrissantamaria
Copy link
Contributor

Description

👋 small bug fix - there's some logic in mergeConfig to handle merging particular field types:

const existing = merged[key]
if (Array.isArray(existing) && Array.isArray(value)) {
merged[key] = [...existing, ...value]
continue
}
if (isObject(existing) && isObject(value)) {
merged[key] = mergeConfig(existing, value, false)
continue
}
// root fields that require special handling
if (existing != null && isRoot) {
if (key === 'alias') {
merged[key] = mergeAlias(existing, value)
continue
} else if (key === 'assetsInclude') {
merged[key] = [].concat(existing, value)
continue
}
}

Note the custom handling of alias at the bottom. In some cases this isn't necessary (i.e. if existing and value are both objects / arrays) though it is if the configs use different alias schemas.

It looks like mergeAlias is never being run since alias is (afaik) never a root key. I tweaked the logic to only perform this check when checking a non-root key.

I added a failing test for this case as well as an additional test for the assetsInclude (already passes on main).


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@Shinigami92 Shinigami92 added bug p2-nice-to-have Not breaking anything but nice to have (priority) labels Apr 3, 2021
@antfu antfu added p3-minor-bug An edge case that only affects very specific usage (priority) and removed p2-nice-to-have Not breaking anything but nice to have (priority) labels Apr 4, 2021
@antfu
Copy link
Member

antfu commented Apr 4, 2021

VitePress's alias seems to be affected by this. Rising to P3.

@patak-dev patak-dev merged commit 41261c7 into vitejs:main Apr 14, 2021
@chrissantamaria chrissantamaria deleted the fix-mergeconfig-different-alias-schema branch April 14, 2021 19:31
TobiasMelen pushed a commit to TobiasMelen/vite that referenced this pull request May 3, 2021
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants