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

W-17425220 fix: populate manifestComponents consistently #1481

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,21 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
this.components.set(key, new DecodeableMap<string, SourceComponent>());
}

if (!deletionType && typeof component.type !== 'string') {
// this component is meant to be added to manifestComponents, even if it's not a fully validated source component,
// this ensures when getObject is called, we created consistent manifests whether using this.components, or this.manifestComponents
// when no destructive changes are present, we use this.components (not fully validated as source components, so typos end up in the generated manifest)
// when destructive changes are used, we use this.manifestComponents (fully validated, would not match this.components)
// this ensures this.components manifest === this.manifestComponents manifest
const sc = new SourceComponent({ type: component.type, name: component.fullName });
const srcKey = sourceKey(sc);

if (!this.manifestComponents.has(key)) {
this.manifestComponents.set(key, new DecodeableMap<string, SourceComponent>());
}
this.manifestComponents.get(key)?.set(srcKey, sc);
}

if (!(component instanceof SourceComponent)) {
return;
}
Expand Down
31 changes: 28 additions & 3 deletions test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ import {
SourceComponent,
ZipTreeContainer,
} from '../../src';
import { decomposedtoplevel, matchingContentFile, mixedContentSingleFile, digitalExperienceBundle } from '../mock';
import { decomposedtoplevel, digitalExperienceBundle, matchingContentFile, mixedContentSingleFile } from '../mock';
import { MATCHING_RULES_COMPONENT } from '../mock/type-constants/customlabelsConstant';
import * as manifestFiles from '../mock/manifestConstants';
import { testApiVersionAsString } from '../mock/manifestConstants';
import { testApiVersion, testApiVersionAsString } from '../mock/manifestConstants';
import * as coverage from '../../src/registry/coverage';
import { testApiVersion } from '../mock/manifestConstants';

const registryAccess = new RegistryAccess();

Expand Down Expand Up @@ -1250,6 +1249,32 @@ describe('ComponentSet', () => {
expect(Array.from(set)).to.deep.equal([component]);
});

it('should keep manifestComponents/components in sync', async () => {
const set = new ComponentSet(undefined, registryAccess);
const jerryComponent = { fullName: 'Jerry', type: registry.types.staticresource };
const billComponent = new SourceComponent({ name: 'Bill', type: registry.types.staticresource });
const philComponent = new SourceComponent({ name: 'Phil', type: registry.types.staticresource });

expect(set.size).to.equal(0);

set.add(jerryComponent);

expect(set.size).to.equal(1); // @ts-ignore - private
expect(set.manifestComponents.size).to.equal(1); // @ts-ignore - private
expect(set.components.size).to.equal(1);
const allToDeployObject = await set.getObject();

set.add(philComponent, DestructiveChangesType.PRE); // @ts-ignore - private
expect(set.manifestComponents.size).to.equal(1); // @ts-ignore - private
expect(set.components.size).to.equal(2);

set.add(billComponent, DestructiveChangesType.POST); // @ts-ignore - private
expect(set.manifestComponents.size).to.equal(1); // @ts-ignore - private
expect(set.components.size).to.equal(3);

expect(await set.getObject()).to.deep.equal(allToDeployObject);
});

it('should add metadata component marked for delete to package components', () => {
const set = new ComponentSet(undefined, registryAccess);
expect(!!set.getTypesOfDestructiveChanges().length).to.be.false;
Expand Down
Loading