-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: customLabels => customLabel files * test: move existing snapshot project * fix: things snapshots uncovered * test: snapshot for mdapi => source (simple) * test: expected md snapshot * feat: source to madapi finalizer * feat: sorted labels when recomposed * fix: remove original customLabelsBeta * test: remove wrong snapshot path * feat: show all decomposed labels in FileResponses * fix: handling single label * fix: empty string to remove props from normal registry * fix: provide mergeSet for toSourceFormat * fix: error for using -m CustomLabels with the preset * chore: rename file to match class name * test: injectable presets into reg loader * test: ut for label transformer * refactor: move xml parsing to shared const * test: ut for label (source) => labels (mdapi) * refactor: use a new name for the updated beta * refactor: restore the original beta * refactor: separate logging fn * chore: bump core * chore: allow v1 and v2 of CustomLabelsBeta * chore(release): 12.1.13-qa.0 [skip ci] * test: don't test with both CL presets together * fix: only emit variant telemetry when there are presets/variants * chore(release): 12.1.13-qa.1 [skip ci] * chore: manually bump pjson version * chore(release): 12.3.0-qa.1 [skip ci] --------- Co-authored-by: svc-cli-bot <Svc_cli_bot@salesforce.com>
- Loading branch information
1 parent
e51ec5e
commit 51cbe84
Showing
44 changed files
with
831 additions
and
251 deletions.
There are no files selected for viewing
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
Oops, something went wrong.