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: properly merge DigitalExperience components W-16646427 #1496

Merged
merged 8 commits into from
Feb 7, 2025

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Jan 31, 2025

What does this PR do?

Fixes SDR retrieving and writing DigitalExperience metadata to the wrong paths in this scenario:

  1. MPD project with 1 DE in the default pkg and another one in a non-default pkg dir (all defined in sfdx-project.json)
  2. retrieving the specific DE in the non-default dir or its DEB parent.

Given this project structure:

➜  mpdProject git:(cd/deb-mpd-nut) ✗ tree -L 6 -P digitalExperiences
.
├── config
├── force-app
│   └── main
│       └── default
│           ├── classes
│           ├── digitalExperienceConfigs
│           ├── digitalExperiences
│           │   └── site
│           │       └── Capricorn_Coffee_A1
│           ├── networks
│           ├── pages
│           └── sites
├── my-app
│   └── main
│       └── default
│           └── digitalExperiences
│               └── site
│                   └── Capricorn_Coffee_B1

where force-app (default pkg dir) and my-app contain 1 DE each, if you retrieve one of Capricorn_Coffee_B1's files sf/SDR writes the retrieve to force-app instead of merging it with the contents in my-app:

Screenshot 2025-02-06 at 12 53 55

Bug

project retrieve start builds the correct source-backed DE components for merging here:
https://github.com/salesforcecli/plugin-deploy-retrieve/blob/0bc486a28e3d4b49f42093144b3e435d34404ffe/src/commands/project/retrieve/start.ts#L171

but the metadata converter prefers the component parent if present for merging (I assume for decomposed types that aren't individually addressable):
https://github.com/forcedotcom/source-deploy-retrieve/blob/68c3a4e034ee0dbb09c33df974d47e0ff78769d2/src/convert/metadataConverter.ts#L183C18-L183C34

so the metadata transformer would always try to merge a retrieved DE against its local DEB (no match so the retrieved DE would get saved to the default pkg dir):

transformer.toSourceFormat({ component: chunk, mergeWith: mergeComponent, mergeSet: this.mergeSet })

Fix

  • Make the metadata converter prefer a DE component over its parent when building the merge set.
  • Update the default transformer to properly calculate the source destination when merging DEs

Testing

This PR adds a small UT for the converter fix and salesforcecli/plugin-deploy-retrieve#1279 includes a full MPD project with NUTs to test component merging of DEB/single DEs retrieves.

  1. checkout test: add digitalexperience MPD NUT W-16646427 salesforcecli/plugin-deploy-retrieve#1279
  2. cd test/nuts/digitalExperienceBundle/mpdProject
  3. create org: sf org create scratch -d -f config/project-scratch-def.json -a deb-mpd
  4. full deploy: sf project deploy start
  5. retrieve the DE in my-app, see sf writes it into force-app

What issues does this PR fix or reference?

@W-16646427@

for (const component of output.mergeWith) {
mergeSet.add(component.parent ?? component);
if (component.type.id === 'digitalexperience' && !component.parent?.content) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this only happen for DEs? are there other bundle types? you could actually check component.type.strategies.adapter==='digitalExperience' so it would apply to all of the types that use that adapter, which I think is only DEB anyways

Copy link
Member Author

@cristiand391 cristiand391 Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this only happen for DEs?

technically it should happen with any child type that's addressable without its parent, but yes only DE/DEB use this adapter.
In the investigation the customer mentioned sitedotcom sites were working ok on MPDs, those don't have childs.

you could actually check component.type.strategies.adapter==='digitalExperience'

done ✅

src/convert/transformers/defaultMetadataTransformer.ts Outdated Show resolved Hide resolved
@WillieRuemmele WillieRuemmele merged commit 251278f into main Feb 7, 2025
50 of 51 checks passed
@WillieRuemmele WillieRuemmele deleted the cd/deb branch February 7, 2025 20:52
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

Successfully merging this pull request may close these issues.

4 participants