From fd4084058819fea040dca5742bb88745d370f2a7 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 25 Jun 2024 11:49:57 -0500 Subject: [PATCH] refactor: derive metadataWithContent directly from type, not type => adapter --- src/registry/registryAccess.ts | 6 ++++++ src/resolve/adapters/baseSourceAdapter.ts | 5 ++--- src/resolve/adapters/decomposedSourceAdapter.ts | 1 - src/resolve/adapters/defaultSourceAdapter.ts | 2 -- src/resolve/metadataResolver.ts | 8 +------- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/registry/registryAccess.ts b/src/registry/registryAccess.ts index 2b3c2c2d7e..25b7dbefb1 100644 --- a/src/registry/registryAccess.ts +++ b/src/registry/registryAccess.ts @@ -178,3 +178,9 @@ export class RegistryAccess { } } } + +/** decomposed and default types are `false`, everything else is true */ +export const typeAllowsMetadataWithContent = (type: MetadataType): boolean => + type.strategies?.adapter !== undefined && // another way of saying default + type.strategies.adapter !== 'decomposed' && + type.strategies.adapter !== 'default'; diff --git a/src/resolve/adapters/baseSourceAdapter.ts b/src/resolve/adapters/baseSourceAdapter.ts index 9f37ee05af..b1c5ec7dd0 100644 --- a/src/resolve/adapters/baseSourceAdapter.ts +++ b/src/resolve/adapters/baseSourceAdapter.ts @@ -14,7 +14,7 @@ import { NodeFSTreeContainer, TreeContainer } from '../treeContainers'; import { SourceComponent } from '../sourceComponent'; import { SourcePath } from '../../common/types'; import { MetadataType } from '../../registry/types'; -import { RegistryAccess } from '../../registry/registryAccess'; +import { RegistryAccess, typeAllowsMetadataWithContent } from '../../registry/registryAccess'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr'); @@ -30,7 +30,6 @@ export abstract class BaseSourceAdapter implements SourceAdapter { * folder, including its root metadata xml file. */ protected ownFolder = false; - protected metadataWithContent = true; public constructor( type: MetadataType, @@ -107,7 +106,7 @@ export abstract class BaseSourceAdapter implements SourceAdapter { return folderMetadataXml; } - if (!this.metadataWithContent) { + if (!typeAllowsMetadataWithContent(this.type)) { return parseAsContentMetadataXml(this.type)(path); } } diff --git a/src/resolve/adapters/decomposedSourceAdapter.ts b/src/resolve/adapters/decomposedSourceAdapter.ts index aef8af0ad4..b68f1d8d6a 100644 --- a/src/resolve/adapters/decomposedSourceAdapter.ts +++ b/src/resolve/adapters/decomposedSourceAdapter.ts @@ -43,7 +43,6 @@ const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sd */ export class DecomposedSourceAdapter extends MixedContentSourceAdapter { protected ownFolder = true; - protected metadataWithContent = false; public getComponent(path: SourcePath, isResolvingSource = true): SourceComponent | undefined { let rootMetadata = super.parseAsRootMetadataXml(path); diff --git a/src/resolve/adapters/defaultSourceAdapter.ts b/src/resolve/adapters/defaultSourceAdapter.ts index 7f8a8a22c5..35218b9b9a 100644 --- a/src/resolve/adapters/defaultSourceAdapter.ts +++ b/src/resolve/adapters/defaultSourceAdapter.ts @@ -23,8 +23,6 @@ import { BaseSourceAdapter } from './baseSourceAdapter'; *``` */ export class DefaultSourceAdapter extends BaseSourceAdapter { - protected metadataWithContent = false; - /* istanbul ignore next */ // retained to preserve API // eslint-disable-next-line class-methods-use-this diff --git a/src/resolve/metadataResolver.ts b/src/resolve/metadataResolver.ts index 59cb6cef3f..e4f1fe1bca 100644 --- a/src/resolve/metadataResolver.ts +++ b/src/resolve/metadataResolver.ts @@ -7,7 +7,7 @@ import { basename, dirname, sep } from 'node:path'; import { Lifecycle, Messages, SfError, Logger } from '@salesforce/core'; import { extName, fnJoin, parentName, parseMetadataXml } from '../utils/path'; -import { RegistryAccess } from '../registry/registryAccess'; +import { RegistryAccess, typeAllowsMetadataWithContent } from '../registry/registryAccess'; import { MetadataType } from '../registry/types'; import { ComponentSet } from '../collections/componentSet'; import { META_XML_SUFFIX } from '../common/constants'; @@ -442,9 +442,3 @@ const pathIncludesDirName = * @param fsPath File path of a potential metadata xml file */ const parseAsRootMetadataXml = (fsPath: string): boolean => Boolean(parseMetadataXml(fsPath)); - -/** decomposed and default types are `false`, everything else is true */ -const typeAllowsMetadataWithContent = (type: MetadataType): boolean => - type.strategies?.adapter !== undefined && // another way of saying default - type.strategies.adapter !== 'decomposed' && - type.strategies.adapter !== 'default';