-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into sm/registry-from-inte…
…rnal-describe
- Loading branch information
Showing
45 changed files
with
1,249 additions
and
1,861 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { join } from 'node:path'; | ||
import { ensure, JsonMap } from '@salesforce/ts-types'; | ||
import type { CustomLabel } from '@jsforce/jsforce-node/lib/api/metadata'; | ||
import { customLabelHasFullName } from '../../utils/metadata'; | ||
import { MetadataType } from '../../registry'; | ||
import { XML_NS_KEY, XML_NS_URL } from '../../common/constants'; | ||
import { JsToXml } from '../streams'; | ||
import { WriterFormat } from '../types'; | ||
import { ConvertTransactionFinalizer } from './transactionFinalizer'; | ||
|
||
type CustomLabelState = { | ||
/* | ||
* Incoming child xml (CustomLabel) keyed by label fullname | ||
*/ | ||
customLabelByFullName: Map<string, CustomLabel>; | ||
}; | ||
|
||
/** | ||
* Merges child components that share the same parent in the conversion pipeline | ||
* into a single file. | ||
* | ||
* Inserts unclaimed child components into the parent that belongs to the default package | ||
*/ | ||
export class DecomposedLabelsFinalizer extends ConvertTransactionFinalizer<CustomLabelState> { | ||
public transactionState: CustomLabelState = { | ||
customLabelByFullName: new Map(), | ||
}; | ||
|
||
/** to support custom presets (the only way this code should get hit at all pass in the type from a transformer that has registry access */ | ||
public customLabelsType?: MetadataType; | ||
|
||
// have to maintain the existing interface | ||
// eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars | ||
public async finalize(defaultDirectory?: string): Promise<WriterFormat[]> { | ||
if (this.transactionState.customLabelByFullName.size === 0) { | ||
return []; | ||
} | ||
return [ | ||
{ | ||
component: { | ||
type: ensure(this.customLabelsType, 'DecomposedCustomLabelsFinalizer should have set customLabelsType'), | ||
fullName: 'CustomLabels', | ||
}, | ||
writeInfos: [ | ||
{ | ||
output: join( | ||
ensure(this.customLabelsType?.directoryName, 'directoryName missing from customLabels type'), | ||
'CustomLabels.labels' | ||
), | ||
source: new JsToXml(generateXml(this.transactionState.customLabelByFullName)), | ||
}, | ||
], | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
/** Return a json object that's built up from the mergeMap children */ | ||
const generateXml = (children: Map<string, CustomLabel>): JsonMap => ({ | ||
['CustomLabels']: { | ||
[XML_NS_KEY]: XML_NS_URL, | ||
// for CustomLabels, that's `labels` | ||
labels: Array.from(children.values()).filter(customLabelHasFullName).sort(sortLabelsByFullName), | ||
}, | ||
}); | ||
|
||
type CustomLabelWithFullName = CustomLabel & { fullName: string }; | ||
|
||
const sortLabelsByFullName = (a: CustomLabelWithFullName, b: CustomLabelWithFullName): number => | ||
a.fullName.localeCompare(b.fullName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import type { CustomLabel } from '@jsforce/jsforce-node/lib/api/metadata'; | ||
import { ensureArray } from '@salesforce/kit'; | ||
import { customLabelHasFullName } from '../../utils/metadata'; | ||
import { calculateRelativePath } from '../../utils/path'; | ||
import { SourceComponent } from '../../resolve/sourceComponent'; | ||
import { ToSourceFormatInput, WriteInfo } from '../types'; | ||
import { JsToXml } from '../streams'; | ||
import { unwrapAndOmitNS } from '../../utils/decomposed'; | ||
import { DefaultMetadataTransformer } from './defaultMetadataTransformer'; | ||
|
||
/* Use for the metadata type CustomLabels */ | ||
export class LabelsMetadataTransformer extends DefaultMetadataTransformer { | ||
/** CustomLabels file => Array of CustomLabel WriteInfo (one for each label) */ | ||
public async toSourceFormat({ component, mergeSet }: ToSourceFormatInput): Promise<WriteInfo[]> { | ||
const labelType = this.registry.getTypeByName('CustomLabel'); | ||
const partiallyAppliedPathCalculator = calculateRelativePath('source')({ | ||
self: labelType, | ||
}); | ||
const xml = unwrapAndOmitNS('CustomLabels')(await component.parseXml()) as { labels: CustomLabel | CustomLabel[] }; | ||
return ensureArray(xml.labels) // labels could parse to a single object and not an array if there's only 1 label | ||
.filter(customLabelHasFullName) | ||
.map((l) => ({ | ||
// split each label into a separate label file | ||
output: | ||
// if present in the merge set, use that xml path, otherwise use the default path | ||
mergeSet?.getComponentFilenamesByNameAndType({ fullName: l.fullName, type: labelType.name })?.[0] ?? | ||
partiallyAppliedPathCalculator(l.fullName)(`${l.fullName}.label-meta.xml`), | ||
source: new JsToXml({ CustomLabel: l }), | ||
})); | ||
} | ||
} | ||
|
||
/* Use for the metadata type CustomLabel */ | ||
export class LabelMetadataTransformer extends DefaultMetadataTransformer { | ||
public async toMetadataFormat(component: SourceComponent): Promise<WriteInfo[]> { | ||
// only need to do this once | ||
this.context.decomposedLabels.customLabelsType ??= this.registry.getTypeByName('CustomLabels'); | ||
this.context.decomposedLabels.transactionState.customLabelByFullName.set( | ||
component.fullName, | ||
unwrapAndOmitNS('CustomLabel')(await component.parseXml()) as CustomLabel | ||
); | ||
return []; | ||
} | ||
|
||
// toSourceFormat uses the default (merge them with the existing label) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
a39b463
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
eda-componentSetCreate-linux
236
ms234
ms1.01
eda-sourceToMdapi-linux
2407
ms2417
ms1.00
eda-sourceToZip-linux
1893
ms1862
ms1.02
eda-mdapiToSource-linux
2900
ms2832
ms1.02
lotsOfClasses-componentSetCreate-linux
427
ms433
ms0.99
lotsOfClasses-sourceToMdapi-linux
3695
ms3632
ms1.02
lotsOfClasses-sourceToZip-linux
3171
ms3097
ms1.02
lotsOfClasses-mdapiToSource-linux
3604
ms3567
ms1.01
lotsOfClassesOneDir-componentSetCreate-linux
749
ms756
ms0.99
lotsOfClassesOneDir-sourceToMdapi-linux
6539
ms6482
ms1.01
lotsOfClassesOneDir-sourceToZip-linux
5633
ms5607
ms1.00
lotsOfClassesOneDir-mdapiToSource-linux
6531
ms6477
ms1.01
This comment was automatically generated by workflow using github-action-benchmark.
a39b463
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
eda-componentSetCreate-win32
614
ms624
ms0.98
eda-sourceToMdapi-win32
4219
ms4211
ms1.00
eda-sourceToZip-win32
3113
ms2872
ms1.08
eda-mdapiToSource-win32
5766
ms5612
ms1.03
lotsOfClasses-componentSetCreate-win32
1180
ms1161
ms1.02
lotsOfClasses-sourceToMdapi-win32
7601
ms7496
ms1.01
lotsOfClasses-sourceToZip-win32
5052
ms4955
ms1.02
lotsOfClasses-mdapiToSource-win32
7604
ms7558
ms1.01
lotsOfClassesOneDir-componentSetCreate-win32
2068
ms2076
ms1.00
lotsOfClassesOneDir-sourceToMdapi-win32
13557
ms13490
ms1.00
lotsOfClassesOneDir-sourceToZip-win32
9109
ms8863
ms1.03
lotsOfClassesOneDir-mdapiToSource-win32
13824
ms13761
ms1.00
This comment was automatically generated by workflow using github-action-benchmark.