Skip to content

Commit 84ba5bd

Browse files
fix: populate manifestComponents consistently (#1481)
* fix: populate manifestComponents consistently * test: make UT fail without changes
1 parent ce68870 commit 84ba5bd

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/collections/componentSet.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,21 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
511511
this.components.set(key, new DecodeableMap<string, SourceComponent>());
512512
}
513513

514+
if (!deletionType && typeof component.type !== 'string') {
515+
// this component is meant to be added to manifestComponents, even if it's not a fully validated source component,
516+
// this ensures when getObject is called, we created consistent manifests whether using this.components, or this.manifestComponents
517+
// when no destructive changes are present, we use this.components (not fully validated as source components, so typos end up in the generated manifest)
518+
// when destructive changes are used, we use this.manifestComponents (fully validated, would not match this.components)
519+
// this ensures this.components manifest === this.manifestComponents manifest
520+
const sc = new SourceComponent({ type: component.type, name: component.fullName });
521+
const srcKey = sourceKey(sc);
522+
523+
if (!this.manifestComponents.has(key)) {
524+
this.manifestComponents.set(key, new DecodeableMap<string, SourceComponent>());
525+
}
526+
this.manifestComponents.get(key)?.set(srcKey, sc);
527+
}
528+
514529
if (!(component instanceof SourceComponent)) {
515530
return;
516531
}

test/collections/componentSet.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ import {
3131
SourceComponent,
3232
ZipTreeContainer,
3333
} from '../../src';
34-
import { decomposedtoplevel, matchingContentFile, mixedContentSingleFile, digitalExperienceBundle } from '../mock';
34+
import { decomposedtoplevel, digitalExperienceBundle, matchingContentFile, mixedContentSingleFile } from '../mock';
3535
import { MATCHING_RULES_COMPONENT } from '../mock/type-constants/customlabelsConstant';
3636
import * as manifestFiles from '../mock/manifestConstants';
37-
import { testApiVersionAsString } from '../mock/manifestConstants';
37+
import { testApiVersion, testApiVersionAsString } from '../mock/manifestConstants';
3838
import * as coverage from '../../src/registry/coverage';
39-
import { testApiVersion } from '../mock/manifestConstants';
4039

4140
const registryAccess = new RegistryAccess();
4241

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

1252+
it('should keep manifestComponents/components in sync', async () => {
1253+
const set = new ComponentSet(undefined, registryAccess);
1254+
const jerryComponent = { fullName: 'Jerry', type: registry.types.staticresource };
1255+
const billComponent = new SourceComponent({ name: 'Bill', type: registry.types.staticresource });
1256+
const philComponent = new SourceComponent({ name: 'Phil', type: registry.types.staticresource });
1257+
1258+
expect(set.size).to.equal(0);
1259+
1260+
set.add(jerryComponent);
1261+
1262+
expect(set.size).to.equal(1); // @ts-ignore - private
1263+
expect(set.manifestComponents.size).to.equal(1); // @ts-ignore - private
1264+
expect(set.components.size).to.equal(1);
1265+
const allToDeployObject = await set.getObject();
1266+
1267+
set.add(philComponent, DestructiveChangesType.PRE); // @ts-ignore - private
1268+
expect(set.manifestComponents.size).to.equal(1); // @ts-ignore - private
1269+
expect(set.components.size).to.equal(2);
1270+
1271+
set.add(billComponent, DestructiveChangesType.POST); // @ts-ignore - private
1272+
expect(set.manifestComponents.size).to.equal(1); // @ts-ignore - private
1273+
expect(set.components.size).to.equal(3);
1274+
1275+
expect(await set.getObject()).to.deep.equal(allToDeployObject);
1276+
});
1277+
12531278
it('should add metadata component marked for delete to package components', () => {
12541279
const set = new ComponentSet(undefined, registryAccess);
12551280
expect(!!set.getTypesOfDestructiveChanges().length).to.be.false;

0 commit comments

Comments
 (0)