diff --git a/HANDBOOK.md b/HANDBOOK.md index 20c662365..e80562e84 100644 --- a/HANDBOOK.md +++ b/HANDBOOK.md @@ -172,6 +172,16 @@ Be careful when instantiating classes (ex: ComponentSet) that will default a Reg **Updating presets** If you do need to update a preset to make a breaking change, it's better to copy it to a new preset and give it a unique name (ex: `decomposeFooV2`). This preserves the existing behavior for existing projects with the old preset. +Presets **can** remove strings from the default metadataRegistry by setting values to empty string ex: + +```json +{ + "childTypes": { + "somethingThatIsUsuallyAChild": "" + } +} +``` + ### Querying registry data While it’s perfectly fine to reference the registry export directly, the `RegistryAccess` class was created to make accessing the object a bit more streamlined. Querying types and searching the registry is oftentimes easier and cleaner this way and contains built-in checking for whether or not a metadata type exists. Here’s a comparison of using each: diff --git a/src/registry/variants.ts b/src/registry/variants.ts index 78532d9b4..59d4174ba 100644 --- a/src/registry/variants.ts +++ b/src/registry/variants.ts @@ -20,7 +20,7 @@ export type RegistryLoadInput = { /** combine the standard registration with any overrides specific in the sfdx-project.json */ export const getEffectiveRegistry = (input?: RegistryLoadInput): MetadataRegistry => - deepFreeze(firstLevelMerge(registryData as MetadataRegistry, loadVariants(input))); + deepFreeze(removeEmptyStrings(firstLevelMerge(registryData as MetadataRegistry, loadVariants(input)))); /** read the project to get additional registry customizations and sourceBehaviorOptions */ const loadVariants = ({ projectDir }: RegistryLoadInput = {}): MetadataRegistry => { @@ -101,5 +101,19 @@ export const firstLevelMerge = (original: MetadataRegistry, overrides: MetadataR types: { ...original.types, ...(overrides.types ?? {}) }, childTypes: { ...original.childTypes, ...(overrides.childTypes ?? {}) }, suffixes: { ...original.suffixes, ...(overrides.suffixes ?? {}) }, - strictDirectoryNames: { ...original.strictDirectoryNames, ...(overrides.strictDirectoryNames ?? {}) }, + strictDirectoryNames: { + ...original.strictDirectoryNames, + ...(overrides.strictDirectoryNames ?? {}), + }, }); + +const removeEmptyStrings = (reg: MetadataRegistry): MetadataRegistry => ({ + types: reg.types, + childTypes: removeEmptyString(reg.childTypes), + suffixes: removeEmptyString(reg.suffixes), + strictDirectoryNames: removeEmptyString(reg.strictDirectoryNames), +}); + +// presets can remove an entry by setting it to an empty string ex: { "childTypes": { "foo": "" } } +const removeEmptyString = (obj: Record): Record => + Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== '')); diff --git a/src/utils/filePathGenerator.ts b/src/utils/filePathGenerator.ts index b133a0a73..273720fdb 100644 --- a/src/utils/filePathGenerator.ts +++ b/src/utils/filePathGenerator.ts @@ -10,7 +10,6 @@ import { isPlainObject } from '@salesforce/ts-types'; import { MetadataComponent } from '../resolve/types'; import { META_XML_SUFFIX } from '../common/constants'; import { RegistryAccess } from '../registry/registryAccess'; -import { registry } from '../registry/registry'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr'); @@ -65,7 +64,7 @@ export const filePathsFromMetadataComponent = ( } // this needs to be done before the other types because of potential overlaps - if (!type.children && Object.keys(registry.childTypes).includes(type.id)) { + if (!type.children && Object.keys(registryAccess.getRegistry().childTypes).includes(type.id)) { return getDecomposedChildType({ fullName, type }, packageDir); } @@ -75,7 +74,7 @@ export const filePathsFromMetadataComponent = ( } // basic metadata (with or without folders) - if (!type.children && !type.strategies && type.suffix) { + if (!type.children && type.suffix && (!type.strategies || type.strategies.transformer === 'decomposedLabels')) { return (type.inFolder ?? type.folderType ? generateFolders({ fullName, type }, packageDirWithTypeDir) : []).concat([ join(packageDirWithTypeDir, `${fullName}.${type.suffix}${META_XML_SUFFIX}`), ]);