From 7c055bbd0139da00a0bbbe5591bc235837ad6b67 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Wed, 27 Mar 2024 16:03:52 -0600 Subject: [PATCH] fix: confirm DCL behavior, fix snapshots, add .md entry --- src/Presets.md | 24 ++++++-- src/collections/componentSetBuilder.ts | 11 +++- .../presets/decomposeCustomLabelsBeta.json | 11 ++-- src/registry/registryAccess.ts | 5 +- src/resolve/connectionResolver.ts | 11 ++-- .../labels/CustomLabels.labels | 0 .../verify-md-files.expected/package.xml | 0 .../CustomLabels/CustomLabels.labels-meta.xml | 0 .../CustomLabels/DeleteMe.label-meta.xml | 0 .../CustomLabels/KeepMe1.label-meta.xml | 0 .../CustomLabels/KeepMe2.label-meta.xml | 0 .../originalMdapi/labels/CustomLabels.labels | 0 .../originalMdapi/package.xml | 0 .../preset-decomposeLabels/sfdx-project.json | 13 +++++ .../snapshots.test.ts | 2 +- .../variant-decomposeLabels/sfdx-project.json | 56 ------------------- 16 files changed, 59 insertions(+), 74 deletions(-) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/__snapshots__/verify-md-files.expected/labels/CustomLabels.labels (100%) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/__snapshots__/verify-md-files.expected/package.xml (100%) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/CustomLabels.labels-meta.xml (100%) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/DeleteMe.label-meta.xml (100%) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe1.label-meta.xml (100%) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe2.label-meta.xml (100%) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/originalMdapi/labels/CustomLabels.labels (100%) rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/originalMdapi/package.xml (100%) create mode 100644 test/snapshot/sampleProjects/preset-decomposeLabels/sfdx-project.json rename test/snapshot/sampleProjects/{variant-decomposeLabels => preset-decomposeLabels}/snapshots.test.ts (98%) delete mode 100644 test/snapshot/sampleProjects/variant-decomposeLabels/sfdx-project.json diff --git a/src/Presets.md b/src/Presets.md index 823d415775..aedb086833 100644 --- a/src/Presets.md +++ b/src/Presets.md @@ -1,6 +1,6 @@ # Available Registry Presets -## `decomposePermissionSet` +## `decomposePermissionSetBeta` PermissionSet is decomposed to a folder named after the PermissionSet. @@ -22,7 +22,7 @@ Simple fields (ex: `description`, `userLicense`) remain in the top-level `myPS.p FieldPermissions for all objects are in the same folder (they're not in sub-folders by object). This is intentional--I wanted subfolders but couldn't get it to work well. -## `decomposeSharingRules` +## `decomposeSharingRulesBeta` SharingRules is decomposed to a folder named after the sharingRules (which is named after an object) @@ -42,12 +42,12 @@ source format Each child of SharingRules that is a repeated xml element (ex: sharingTerritoryRules) is saved as a separate file SharingRules has not simple fields, so the top-level `Account.sharingRules-meta.xml` will be an empty xml. -## `decomposeWorkflow` +## `decomposeWorkflowBeta` Workflow is decomposed to a folder named after the Workflow (which is named after an object) metadata format -`/workflows/Account.workflow` +`/workflows/Account.workflowBeta` source format @@ -61,3 +61,19 @@ source format Each child of Workflow that is a repeated xml element (ex: workflowAlerts) is saved as a separate file Simple fields (ex: `fullName`) can remain in the top-level `Account.workflow-meta.xml`. This could also have no children + +## `decomposeCustomLabelsBeta` + +CustomLabels are decomposed to a folder named `CustomLabels` the labels are then placed into individual files + +metadata format +`/labels/CustomLabels.customlabes-meta.xml` + +source format + +```txt +/labels/CustomLabels/CustomLabels.labels-meta.xml (the non-decomposed parts) +/labels/CustomLabels/a.label-meta.xml +/labels/CustomLabels/b.label-meta.xml +/labels/CustomLabels/c.label-meta.xml +``` diff --git a/src/collections/componentSetBuilder.ts b/src/collections/componentSetBuilder.ts index a46a808df5..0e6c368ab9 100644 --- a/src/collections/componentSetBuilder.ts +++ b/src/collections/componentSetBuilder.ts @@ -147,7 +147,7 @@ export class ComponentSetBuilder { fromConnection.toArray().map(addToComponentSet(componentSet)); } } catch (e) { - return fromConnectionErrorHandler(e); + return componentSetBuilderErrorHandler(e); } // there should have been a componentSet created by this point. @@ -167,7 +167,7 @@ const addToComponentSet = return cmp; }; -const fromConnectionErrorHandler = (e: unknown): never => { +const componentSetBuilderErrorHandler = (e: unknown): never => { if (e instanceof Error && e.message.includes('Missing metadata type definition in registry for id')) { // to remain generic to catch missing metadata types regardless of parameters, split on ' // example message : Missing metadata type definition in registry for id 'NonExistentType' @@ -245,7 +245,12 @@ export const entryToTypeAndName = (rawEntry: string): MetadataTypeAndMetadataName => { // split on the first colon, and then join the rest back together to support names that include colons const [typeName, ...name] = rawEntry.split(':').map((entry) => entry.trim()); - return { type: reg.getTypeByName(typeName), metadataName: name.length ? name.join(':') : '*' }; + const type = reg.getTypeByName(typeName); + const parent = reg.getParentType(typeName); + if (type.isAddressable === false && parent !== undefined && !type.unaddressableWithoutParent) { + throw new Error(`Cannot use this type, instead use ${parent.name}`); + } + return { type, metadataName: name.length ? name.join(':') : '*' }; }; const typeAndNameToMetadataComponents = diff --git a/src/registry/presets/decomposeCustomLabelsBeta.json b/src/registry/presets/decomposeCustomLabelsBeta.json index c9b7ea292f..c549c7d610 100644 --- a/src/registry/presets/decomposeCustomLabelsBeta.json +++ b/src/registry/presets/decomposeCustomLabelsBeta.json @@ -5,6 +5,9 @@ "suffixes": { "label": "customlabel" }, + "strictDirectoryNames": { + "labels": "customlabels" + }, "types": { "customlabels": { "children": { @@ -13,27 +16,27 @@ }, "types": { "customlabel": { - "directoryName": "labels", + "directoryName": "test", "id": "customlabel", - "ignoreParentName": true, "name": "CustomLabel", "suffix": "label", + "isAddressable": false, "supportsWildcardAndName": true, "uniqueIdElement": "fullName", "xmlElementName": "labels" } } }, + "strictDirectoryName": true, "directoryName": "labels", "id": "customlabels", - "ignoreParsedFullName": true, + "ignoreParsedFullName": false, "name": "CustomLabels", "strategies": { "adapter": "decomposed", "decomposition": "topLevel", "transformer": "decomposed" }, - "strictDirectoryName": false, "suffix": "labels" } } diff --git a/src/registry/registryAccess.ts b/src/registry/registryAccess.ts index 7d020798be..2b3c2c2d7e 100644 --- a/src/registry/registryAccess.ts +++ b/src/registry/registryAccess.ts @@ -18,7 +18,6 @@ const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sd export class RegistryAccess { private registry: MetadataRegistry; - private strictFolderTypes?: MetadataType[]; private folderContentTypes?: MetadataType[]; private aliasTypes?: MetadataType[]; @@ -27,6 +26,10 @@ export class RegistryAccess { this.registry = registry ?? getEffectiveRegistry({ projectDir }); } + public getRegistry(): MetadataRegistry { + return this.registry; + } + /** * Query a metadata type by its name. * diff --git a/src/resolve/connectionResolver.ts b/src/resolve/connectionResolver.ts index 50fa4d62dd..b5c6e96fc1 100644 --- a/src/resolve/connectionResolver.ts +++ b/src/resolve/connectionResolver.ts @@ -10,7 +10,6 @@ import { PollingClient, StatusResult, Connection, Logger, Messages, Lifecycle, S import { Duration, ensureArray } from '@salesforce/kit'; import { ensurePlainObject, ensureString, isPlainObject } from '@salesforce/ts-types'; import { RegistryAccess } from '../registry/registryAccess'; -import { registry as defaultRegistry } from '../registry/registry'; import { MetadataType } from '../registry/types'; import { standardValueSet } from '../registry/standardvalueset'; import { FileProperties, StdValueSetRecord, ListMetadataQuery } from '../client/types'; @@ -46,7 +45,7 @@ export class ConnectionResolver { this.mdTypeNames = mdTypes?.length ? // ensure the types passed in are valid per the registry mdTypes.filter((t) => this.registry.getTypeByName(t)) - : Object.values(defaultRegistry.types).map((t) => t.name); + : Object.values(this.registry.getRegistry().types).map((t) => t.name); } public async resolve( @@ -161,7 +160,7 @@ export class ConnectionResolver { } // Workaround because metadata.list({ type: 'StandardValueSet' }) returns [] - if (query.type === defaultRegistry.types.standardvalueset.name && members.length === 0) { + if (query.type === this.registry.getRegistry().types.standardvalueset.name && members.length === 0) { const standardValueSetPromises = standardValueSet.fullnames.map(async (standardValueSetFullName) => { try { // The 'singleRecordQuery' method was having connection errors, using `retry` resolves this @@ -189,8 +188,10 @@ export class ConnectionResolver { return ( standardValueSetRecord.Metadata.standardValue.length && { fullName: standardValueSetRecord.MasterLabel, - fileName: `${defaultRegistry.types.standardvalueset.directoryName}/${standardValueSetRecord.MasterLabel}.${defaultRegistry.types.standardvalueset.suffix}`, - type: defaultRegistry.types.standardvalueset.name, + fileName: `${this.registry.getRegistry().types.standardvalueset.directoryName}/${ + standardValueSetRecord.MasterLabel + }.${this.registry.getRegistry().types.standardvalueset.suffix}`, + type: this.registry.getRegistry().types.standardvalueset.name, } ); } catch (err) { diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-md-files.expected/labels/CustomLabels.labels b/test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-md-files.expected/labels/CustomLabels.labels similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-md-files.expected/labels/CustomLabels.labels rename to test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-md-files.expected/labels/CustomLabels.labels diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-md-files.expected/package.xml b/test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-md-files.expected/package.xml similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-md-files.expected/package.xml rename to test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-md-files.expected/package.xml diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/CustomLabels.labels-meta.xml b/test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/CustomLabels.labels-meta.xml similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/CustomLabels.labels-meta.xml rename to test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/CustomLabels.labels-meta.xml diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/DeleteMe.label-meta.xml b/test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/DeleteMe.label-meta.xml similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/DeleteMe.label-meta.xml rename to test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/DeleteMe.label-meta.xml diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe1.label-meta.xml b/test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe1.label-meta.xml similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe1.label-meta.xml rename to test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe1.label-meta.xml diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe2.label-meta.xml b/test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe2.label-meta.xml similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe2.label-meta.xml rename to test/snapshot/sampleProjects/preset-decomposeLabels/__snapshots__/verify-source-files.expected/force-app/main/default/labels/CustomLabels/KeepMe2.label-meta.xml diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/originalMdapi/labels/CustomLabels.labels b/test/snapshot/sampleProjects/preset-decomposeLabels/originalMdapi/labels/CustomLabels.labels similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/originalMdapi/labels/CustomLabels.labels rename to test/snapshot/sampleProjects/preset-decomposeLabels/originalMdapi/labels/CustomLabels.labels diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/originalMdapi/package.xml b/test/snapshot/sampleProjects/preset-decomposeLabels/originalMdapi/package.xml similarity index 100% rename from test/snapshot/sampleProjects/variant-decomposeLabels/originalMdapi/package.xml rename to test/snapshot/sampleProjects/preset-decomposeLabels/originalMdapi/package.xml diff --git a/test/snapshot/sampleProjects/preset-decomposeLabels/sfdx-project.json b/test/snapshot/sampleProjects/preset-decomposeLabels/sfdx-project.json new file mode 100644 index 0000000000..bfd4b4b44b --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposeLabels/sfdx-project.json @@ -0,0 +1,13 @@ +{ + "name": "variantTest", + "namespace": "", + "packageDirectories": [ + { + "default": true, + "path": "force-app" + } + ], + "registryPresets": ["decomposeCustomLabelsBeta"], + "sfdcLoginUrl": "https://login.salesforce.com", + "sourceApiVersion": "60.0" +} diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/snapshots.test.ts b/test/snapshot/sampleProjects/preset-decomposeLabels/snapshots.test.ts similarity index 98% rename from test/snapshot/sampleProjects/variant-decomposeLabels/snapshots.test.ts rename to test/snapshot/sampleProjects/preset-decomposeLabels/snapshots.test.ts index 2043332ac0..d9e71ceb84 100644 --- a/test/snapshot/sampleProjects/variant-decomposeLabels/snapshots.test.ts +++ b/test/snapshot/sampleProjects/preset-decomposeLabels/snapshots.test.ts @@ -20,7 +20,7 @@ import { /* eslint-disable no-await-in-loop */ describe('decomposed custom labels', () => { - const testDir = path.join('test', 'snapshot', 'sampleProjects', 'variant-decomposeLabels'); + const testDir = path.join('test', 'snapshot', 'sampleProjects', 'preset-decomposeLabels'); let sourceFiles: string[]; let mdFiles: string[]; diff --git a/test/snapshot/sampleProjects/variant-decomposeLabels/sfdx-project.json b/test/snapshot/sampleProjects/variant-decomposeLabels/sfdx-project.json deleted file mode 100644 index bb0f7c91ab..0000000000 --- a/test/snapshot/sampleProjects/variant-decomposeLabels/sfdx-project.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "name": "variantTest", - "namespace": "", - "packageDirectories": [ - { - "default": true, - "path": "force-app" - } - ], - "registryCustomizations": { - "childTypes": { - "customlabel": "customlabels" - }, - "strictDirectoryNames": { - "labels": "customlabels" - }, - "types": { - "customlabels": { - "children": { - "directories": { - "label": "customlabel" - }, - "suffixes": { - "label": "customlabel" - }, - "types": { - "customlabel": { - "directoryName": "label", - "id": "customlabel", - "isAddressable": false, - "name": "CustomLabel", - "suffix": "label", - "supportsWildcardAndName": true, - "uniqueIdElement": "fullName", - "xmlElementName": "labels" - } - } - }, - "directoryName": "labels", - "id": "customlabels", - "inFolder": false, - "name": "CustomLabels", - "strategies": { - "adapter": "decomposed", - "decomposition": "topLevel", - "recomposition": "startEmpty", - "transformer": "decomposed" - }, - "strictDirectoryName": true, - "suffix": "labels" - } - } - }, - "sfdcLoginUrl": "https://login.salesforce.com", - "sourceApiVersion": "60.0" -}