Skip to content

Commit

Permalink
refactor: derive metadataWithContent directly from type, not type => …
Browse files Browse the repository at this point in the history
…adapter
  • Loading branch information
mshanemc committed Jun 25, 2024
1 parent 63ce40e commit fd40840
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/registry/registryAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
5 changes: 2 additions & 3 deletions src/resolve/adapters/baseSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -107,7 +106,7 @@ export abstract class BaseSourceAdapter implements SourceAdapter {
return folderMetadataXml;
}

if (!this.metadataWithContent) {
if (!typeAllowsMetadataWithContent(this.type)) {
return parseAsContentMetadataXml(this.type)(path);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/resolve/adapters/decomposedSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/resolve/adapters/defaultSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/resolve/metadataResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';

0 comments on commit fd40840

Please sign in to comment.