Skip to content

Commit

Permalink
refactor: complexity, simplified naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jul 24, 2024
1 parent f36a40f commit b60ca89
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,26 @@ export class ComponentSetBuilder {
* @param options: options for creating a ComponentSet
*/

// eslint-disable-next-line complexity
public static async build(options: ComponentSetOptions): Promise<ComponentSet> {
const logger = Logger.childFromRoot('componentSetBuilder');
let componentSet: ComponentSet | undefined;

const { sourcepath, manifest, metadata, packagenames, apiversion, sourceapiversion, org, projectDir } = options;
const registryAccess = new RegistryAccess(undefined, projectDir);
const { sourcepath, manifest, metadata, packagenames, org } = options;
const registry = new RegistryAccess(undefined, options.projectDir);

if (sourcepath) {
logger.debug(`Building ComponentSet from sourcepath: ${sourcepath.join(', ')}`);
const fsPaths = sourcepath.map(validateAndResolvePath);
componentSet = ComponentSet.fromSource({
fsPaths,
registry: registryAccess,
registry,
});
}

// Return empty ComponentSet and use packageNames in the connection via `.retrieve` options
if (packagenames) {
logger.debug(`Building ComponentSet for packagenames: ${packagenames.toString()}`);
componentSet ??= new ComponentSet(undefined, registryAccess);
componentSet ??= new ComponentSet(undefined, registry);
}

// Resolve manifest with source in package directories.
Expand All @@ -105,21 +104,21 @@ export class ComponentSetBuilder {
forceAddWildcards: true,
destructivePre: manifest.destructiveChangesPre,
destructivePost: manifest.destructiveChangesPost,
registry: registryAccess,
registry,
});
}

// Resolve metadata entries with source in package directories.
if (metadata) {
logger.debug(`Building ComponentSet from metadata: ${metadata.metadataEntries.toString()}`);
const directoryPaths = metadata.directoryPaths;
componentSet ??= new ComponentSet(undefined, registryAccess);
const componentSetFilter = new ComponentSet(undefined, registryAccess);
componentSet ??= new ComponentSet(undefined, registry);
const componentSetFilter = new ComponentSet(undefined, registry);

// Build a Set of metadata entries
metadata.metadataEntries
.map(entryToTypeAndName(registryAccess))
.flatMap(typeAndNameToMetadataComponents({ directoryPaths, registry: registryAccess }))
.map(entryToTypeAndName(registry))
.flatMap(typeAndNameToMetadataComponents({ directoryPaths, registry }))
.map(addToComponentSet(componentSet))
.map(addToComponentSet(componentSetFilter));

Expand All @@ -129,31 +128,31 @@ export class ComponentSetBuilder {
// are resolved to SourceComponents
if (metadata.destructiveEntriesPre) {
metadata.destructiveEntriesPre
.map(entryToTypeAndName(registryAccess))
.map(entryToTypeAndName(registry))
.map(assertNoWildcardInDestructiveEntries)
.flatMap(typeAndNameToMetadataComponents({ directoryPaths, registry: registryAccess }))
.flatMap(typeAndNameToMetadataComponents({ directoryPaths, registry }))
.map((mdComponent) => new SourceComponent({ type: mdComponent.type, name: mdComponent.fullName }))
.map(addToComponentSet(componentSet, DestructiveChangesType.PRE));
}
if (metadata.destructiveEntriesPost) {
metadata.destructiveEntriesPost
.map(entryToTypeAndName(registryAccess))
.map(entryToTypeAndName(registry))
.map(assertNoWildcardInDestructiveEntries)
.flatMap(typeAndNameToMetadataComponents({ directoryPaths, registry: registryAccess }))
.flatMap(typeAndNameToMetadataComponents({ directoryPaths, registry }))
.map((mdComponent) => new SourceComponent({ type: mdComponent.type, name: mdComponent.fullName }))
.map(addToComponentSet(componentSet, DestructiveChangesType.POST));
}

const resolvedComponents = ComponentSet.fromSource({
fsPaths: directoryPaths,
include: componentSetFilter,
registry: registryAccess,
registry,
});

if (resolvedComponents.forceIgnoredPaths) {
// if useFsForceIgnore = true, then we won't be able to resolve a forceignored path,
// which we need to do to get the ignored source component
const resolver = new MetadataResolver(registryAccess, undefined, false);
const resolver = new MetadataResolver(registry, undefined, false);

for (const ignoredPath of resolvedComponents.forceIgnoredPaths ?? []) {
resolver.getComponentsFromPath(ignoredPath).map((ignored) => {
Expand All @@ -170,7 +169,7 @@ export class ComponentSetBuilder {

// Resolve metadata entries with an org connection
if (org) {
componentSet ??= new ComponentSet(undefined, registryAccess);
componentSet ??= new ComponentSet(undefined, registry);

logger.debug(
`Building ComponentSet from targetUsername: ${org.username} ${
Expand All @@ -179,24 +178,24 @@ export class ComponentSetBuilder {
);

const mdMap = metadata
? buildMapFromComponents(metadata.metadataEntries.map(entryToTypeAndName(registryAccess)))
? buildMapFromComponents(metadata.metadataEntries.map(entryToTypeAndName(registry)))
: (new Map() as MetadataMap);

const fromConnection = await ComponentSet.fromConnection({
usernameOrConnection: (await StateAggregator.getInstance()).aliases.getUsername(org.username) ?? org.username,
componentFilter: getOrgComponentFilter(org, mdMap, metadata),
metadataTypes: mdMap.size ? Array.from(mdMap.keys()) : undefined,
registry: registryAccess,
registry,
});

fromConnection.toArray().map(addToComponentSet(componentSet));
}

// there should have been a componentSet created by this point.
componentSet = assertComponentSetIsNotUndefined(componentSet);
componentSet.apiVersion ??= apiversion;
componentSet.sourceApiVersion ??= sourceapiversion;
componentSet.projectDirectory = projectDir;
componentSet.apiVersion ??= options.apiversion;
componentSet.sourceApiVersion ??= options.sourceapiversion;
componentSet.projectDirectory = options.projectDir;

logComponents(logger, componentSet);
return componentSet;
Expand Down

2 comments on commit b60ca89

@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: b60ca89 Previous: f36a40f Ratio
eda-componentSetCreate-linux 188 ms 204 ms 0.92
eda-sourceToMdapi-linux 2360 ms 2439 ms 0.97
eda-sourceToZip-linux 1783 ms 1917 ms 0.93
eda-mdapiToSource-linux 2906 ms 2862 ms 1.02
lotsOfClasses-componentSetCreate-linux 363 ms 370 ms 0.98
lotsOfClasses-sourceToMdapi-linux 3679 ms 3747 ms 0.98
lotsOfClasses-sourceToZip-linux 3129 ms 3223 ms 0.97
lotsOfClasses-mdapiToSource-linux 3511 ms 3526 ms 1.00
lotsOfClassesOneDir-componentSetCreate-linux 616 ms 658 ms 0.94
lotsOfClassesOneDir-sourceToMdapi-linux 6571 ms 6583 ms 1.00
lotsOfClassesOneDir-sourceToZip-linux 5765 ms 5819 ms 0.99
lotsOfClassesOneDir-mdapiToSource-linux 6346 ms 6533 ms 0.97

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: b60ca89 Previous: f36a40f Ratio
eda-componentSetCreate-win32 421 ms 369 ms 1.14
eda-sourceToMdapi-win32 3839 ms 3985 ms 0.96
eda-sourceToZip-win32 2789 ms 2679 ms 1.04
eda-mdapiToSource-win32 5841 ms 5564 ms 1.05
lotsOfClasses-componentSetCreate-win32 923 ms 810 ms 1.14
lotsOfClasses-sourceToMdapi-win32 8024 ms 7333 ms 1.09
lotsOfClasses-sourceToZip-win32 5117 ms 4784 ms 1.07
lotsOfClasses-mdapiToSource-win32 8138 ms 7373 ms 1.10
lotsOfClassesOneDir-componentSetCreate-win32 1627 ms 1429 ms 1.14
lotsOfClassesOneDir-sourceToMdapi-win32 14294 ms 13154 ms 1.09
lotsOfClassesOneDir-sourceToZip-win32 9468 ms 8856 ms 1.07
lotsOfClassesOneDir-mdapiToSource-win32 14425 ms 13597 ms 1.06

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

Please sign in to comment.