Skip to content

Commit

Permalink
fix: populate manifestComponents consistently (#1481)
Browse files Browse the repository at this point in the history
* fix: populate manifestComponents consistently

* test: make UT fail without changes
  • Loading branch information
WillieRuemmele authored Jan 10, 2025
1 parent ce68870 commit 84ba5bd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
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

0 comments on commit 84ba5bd

Please sign in to comment.