Skip to content

Commit

Permalink
fix: populate manifestComponents consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jan 9, 2025
1 parent ca6eb8d commit 369f8d1
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 = new SourceComponent({ name: '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

2 comments on commit 369f8d1

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 369f8d1 Previous: 5f64455 Ratio
eda-componentSetCreate-linux 227 ms 211 ms 1.08
eda-sourceToMdapi-linux 2053 ms 1952 ms 1.05
eda-sourceToZip-linux 1882 ms 1801 ms 1.04
eda-mdapiToSource-linux 2748 ms 3457 ms 0.79
lotsOfClasses-componentSetCreate-linux 483 ms 429 ms 1.13
lotsOfClasses-sourceToMdapi-linux 3700 ms 3594 ms 1.03
lotsOfClasses-sourceToZip-linux 2912 ms 2864 ms 1.02
lotsOfClasses-mdapiToSource-linux 3467 ms 3446 ms 1.01
lotsOfClassesOneDir-componentSetCreate-linux 834 ms 741 ms 1.13
lotsOfClassesOneDir-sourceToMdapi-linux 6298 ms 6275 ms 1.00
lotsOfClassesOneDir-sourceToZip-linux 5080 ms 4944 ms 1.03
lotsOfClassesOneDir-mdapiToSource-linux 6282 ms 6141 ms 1.02

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 369f8d1 Previous: 5f64455 Ratio
eda-componentSetCreate-win32 637 ms 895 ms 0.71
eda-sourceToMdapi-win32 3832 ms 5105 ms 0.75
eda-sourceToZip-win32 3041 ms 3851 ms 0.79
eda-mdapiToSource-win32 5545 ms 7408 ms 0.75
lotsOfClasses-componentSetCreate-win32 1326 ms 1818 ms 0.73
lotsOfClasses-sourceToMdapi-win32 7649 ms 12397 ms 0.62
lotsOfClasses-sourceToZip-win32 4864 ms 7189 ms 0.68
lotsOfClasses-mdapiToSource-win32 7647 ms 11002 ms 0.70
lotsOfClassesOneDir-componentSetCreate-win32 2257 ms 2997 ms 0.75
lotsOfClassesOneDir-sourceToMdapi-win32 13482 ms 17689 ms 0.76
lotsOfClassesOneDir-sourceToZip-win32 8740 ms 10522 ms 0.83
lotsOfClassesOneDir-mdapiToSource-win32 13777 ms 18737 ms 0.74

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.