Skip to content

Commit

Permalink
fix: empty string to remove props from normal registry
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 9, 2024
1 parent 26cf2cd commit 378c61f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions HANDBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 16 additions & 2 deletions src/registry/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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<string, string>): Record<string, string> =>
Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== ''));
5 changes: 2 additions & 3 deletions src/utils/filePathGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

Expand All @@ -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}`),
]);
Expand Down

2 comments on commit 378c61f

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 378c61f Previous: ed13fd5 Ratio
eda-componentSetCreate-linux 222 ms 237 ms 0.94
eda-sourceToMdapi-linux 1985 ms 2349 ms 0.85
eda-sourceToZip-linux 2000 ms 1894 ms 1.06
eda-mdapiToSource-linux 2909 ms 2860 ms 1.02
lotsOfClasses-componentSetCreate-linux 420 ms 423 ms 0.99
lotsOfClasses-sourceToMdapi-linux 3654 ms 3637 ms 1.00
lotsOfClasses-sourceToZip-linux 3033 ms 3140 ms 0.97
lotsOfClasses-mdapiToSource-linux 3483 ms 3570 ms 0.98
lotsOfClassesOneDir-componentSetCreate-linux 746 ms 755 ms 0.99
lotsOfClassesOneDir-sourceToMdapi-linux 6343 ms 6465 ms 0.98
lotsOfClassesOneDir-sourceToZip-linux 5470 ms 5726 ms 0.96
lotsOfClassesOneDir-mdapiToSource-linux 6330 ms 6433 ms 0.98

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 378c61f Previous: ed13fd5 Ratio
eda-componentSetCreate-win32 707 ms 620 ms 1.14
eda-sourceToMdapi-win32 4841 ms 4673 ms 1.04
eda-sourceToZip-win32 3289 ms 2971 ms 1.11
eda-mdapiToSource-win32 6290 ms 5814 ms 1.08
lotsOfClasses-componentSetCreate-win32 1170 ms 1206 ms 0.97
lotsOfClasses-sourceToMdapi-win32 7768 ms 7765 ms 1.00
lotsOfClasses-sourceToZip-win32 5194 ms 5096 ms 1.02
lotsOfClasses-mdapiToSource-win32 7870 ms 7868 ms 1.00
lotsOfClassesOneDir-componentSetCreate-win32 2108 ms 2100 ms 1.00
lotsOfClassesOneDir-sourceToMdapi-win32 13963 ms 13758 ms 1.01
lotsOfClassesOneDir-sourceToZip-win32 9332 ms 9139 ms 1.02
lotsOfClassesOneDir-mdapiToSource-win32 14258 ms 14125 ms 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.