diff --git a/src/collections/componentSetBuilder.ts b/src/collections/componentSetBuilder.ts index 6c82b1ff2..205f190c6 100644 --- a/src/collections/componentSetBuilder.ts +++ b/src/collections/componentSetBuilder.ts @@ -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 { 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. @@ -105,7 +104,7 @@ export class ComponentSetBuilder { forceAddWildcards: true, destructivePre: manifest.destructiveChangesPre, destructivePost: manifest.destructiveChangesPost, - registry: registryAccess, + registry, }); } @@ -113,13 +112,13 @@ export class ComponentSetBuilder { 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)); @@ -129,17 +128,17 @@ 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)); } @@ -147,13 +146,13 @@ export class ComponentSetBuilder { 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) => { @@ -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} ${ @@ -179,14 +178,14 @@ 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)); @@ -194,9 +193,9 @@ export class ComponentSetBuilder { // 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;