diff --git a/src/convert/convertContext/recompositionFinalizer.ts b/src/convert/convertContext/recompositionFinalizer.ts index 81e2cacc1..0b27140ca 100644 --- a/src/convert/convertContext/recompositionFinalizer.ts +++ b/src/convert/convertContext/recompositionFinalizer.ts @@ -11,7 +11,6 @@ import { extractUniqueElementValue, getXmlElement, unwrapAndOmitNS } from '../.. import { MetadataComponent } from '../../resolve/types'; import { XML_NS_KEY, XML_NS_URL } from '../../common/constants'; import { ComponentSet } from '../../collections/componentSet'; -import { RecompositionStrategy } from '../../registry/types'; import { SourceComponent } from '../../resolve/sourceComponent'; import { JsToXml } from '../streams'; import { WriterFormat } from '../types'; @@ -127,7 +126,7 @@ const recompose = const getStartingXml = (cache: XmlCache) => async (parent: SourceComponent): Promise => - parent.type.strategies?.recomposition === RecompositionStrategy.StartEmpty + parent.type.strategies?.recomposition === 'startEmpty' ? {} : unwrapAndOmitNS(parent.type.name)(await getXmlFromCache(cache)(parent)) ?? {}; diff --git a/src/convert/streams.ts b/src/convert/streams.ts index 5fc18e171..8fe41c92d 100644 --- a/src/convert/streams.ts +++ b/src/convert/streams.ts @@ -72,11 +72,13 @@ export class ComponentConverter extends Transform { case 'source': if (mergeWith) { for (const mergeComponent of mergeWith) { - converts.push(transformer.toSourceFormat(chunk, mergeComponent)); + converts.push( + transformer.toSourceFormat({ component: chunk, mergeWith: mergeComponent, mergeSet: this.mergeSet }) + ); } } if (converts.length === 0) { - converts.push(transformer.toSourceFormat(chunk)); + converts.push(transformer.toSourceFormat({ component: chunk })); } break; case 'metadata': diff --git a/src/convert/transformers/baseMetadataTransformer.ts b/src/convert/transformers/baseMetadataTransformer.ts index f0c166609..1b695269e 100644 --- a/src/convert/transformers/baseMetadataTransformer.ts +++ b/src/convert/transformers/baseMetadataTransformer.ts @@ -20,5 +20,8 @@ export abstract class BaseMetadataTransformer implements MetadataTransformer { } public abstract toMetadataFormat(component: SourceComponent): Promise; - public abstract toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise; + public abstract toSourceFormat(input: { + component: SourceComponent; + mergeWith?: SourceComponent; + }): Promise; } diff --git a/src/convert/transformers/decomposeLabelsTransformer.ts b/src/convert/transformers/decomposeLabelsTransformer.ts new file mode 100644 index 000000000..b870dd1f6 --- /dev/null +++ b/src/convert/transformers/decomposeLabelsTransformer.ts @@ -0,0 +1,55 @@ +/* + * 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 { CustomLabels, CustomLabel } from '@jsforce/jsforce-node/lib/api/metadata'; +import { SfError } from '@salesforce/core/sfError'; +import { calculateRelativePath } from '../../utils/path'; +import { SourceComponent } from '../../resolve/sourceComponent'; +import { ToSourceFormatInput, WriteInfo } from '../types'; +import { JsToXml } from '../streams'; +import { DefaultMetadataTransformer } from './defaultMetadataTransformer'; + +/* Use for the metadata type CustomLabels */ +export class LabelsMetadataTransformer extends DefaultMetadataTransformer { + // CustomLabels file => CustomLabel + public async toSourceFormat({ component, mergeSet }: ToSourceFormatInput): Promise { + const labelType = this.registry.getTypeByName('CustomLabel'); + const partiallyAppliedPathCalculator = calculateRelativePath('source')({ + self: labelType, + }); + const xml = await component.parseXml(); + // split each label into a separate label file + return xml.labels.filter(customLabelHasFullName).map((l) => ({ + 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 { + // eslint-disable-next-line @typescript-eslint/require-await, class-methods-use-this, @typescript-eslint/no-unused-vars + public async toMetadataFormat(component: SourceComponent): Promise { + // TODO: + // read all each label from the recomposition state, regardless of parents + // merge them all to a single CustomLabels file + // write the CustomLabels file + return []; + } + + // toSourceFormat uses the default (merge them with the existing label) +} + +const customLabelHasFullName = (label: CustomLabel): label is CustomLabel & { fullName: string } => { + if (label.fullName === undefined) { + throw SfError.create({ message: 'Label does not have a fullName', data: label }); + } + return true; +}; diff --git a/src/convert/transformers/decomposedMetadataTransformer.ts b/src/convert/transformers/decomposedMetadataTransformer.ts index fced068fe..27eb82e62 100644 --- a/src/convert/transformers/decomposedMetadataTransformer.ts +++ b/src/convert/transformers/decomposedMetadataTransformer.ts @@ -14,10 +14,10 @@ import { calculateRelativePath } from '../../utils/path'; import { ForceIgnore } from '../../resolve/forceIgnore'; import { extractUniqueElementValue, objectHasSomeRealValues } from '../../utils/decomposed'; import type { MetadataComponent } from '../../resolve/types'; -import { DecompositionStrategy, type MetadataType } from '../../registry/types'; +import { type MetadataType } from '../../registry/types'; import { SourceComponent } from '../../resolve/sourceComponent'; import { JsToXml } from '../streams'; -import type { WriteInfo, XmlObj } from '../types'; +import type { ToSourceFormatInput, WriteInfo, XmlObj } from '../types'; import { META_XML_SUFFIX, XML_NS_KEY, XML_NS_URL } from '../../common/constants'; import type { SourcePath } from '../../common/types'; import { ComponentSet } from '../../collections/componentSet'; @@ -60,7 +60,7 @@ export class DecomposedMetadataTransformer extends BaseMetadataTransformer { return []; } - public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise { + public async toSourceFormat({ component, mergeWith }: ToSourceFormatInput): Promise { const forceIgnore = component.getForceIgnore(); // if the whole parent is ignored, we won't worry about decomposing things @@ -265,7 +265,7 @@ const getDefaultOutput = (component: MetadataComponent): SourcePath => { // there could be a '.' inside the child name (ex: PermissionSet.FieldPermissions.field uses Obj__c.Field__c) const childName = tail.length ? tail.join('.') : undefined; const output = join( - parent?.type.strategies?.decomposition === DecompositionStrategy.FolderPerType ? type.directoryName : '', + parent?.type.strategies?.decomposition === 'folderPerType' ? type.directoryName : '', `${childName ?? baseName}.${ensureString(component.type.suffix)}${META_XML_SUFFIX}` ); return join(calculateRelativePath('source')({ self: parent?.type ?? type })(fullName)(baseName), output); diff --git a/src/convert/transformers/defaultMetadataTransformer.ts b/src/convert/transformers/defaultMetadataTransformer.ts index 586574159..8ca6b5a36 100644 --- a/src/convert/transformers/defaultMetadataTransformer.ts +++ b/src/convert/transformers/defaultMetadataTransformer.ts @@ -31,7 +31,13 @@ export class DefaultMetadataTransformer extends BaseMetadataTransformer { } // eslint-disable-next-line @typescript-eslint/require-await, class-methods-use-this - public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise { + public async toSourceFormat({ + component, + mergeWith, + }: { + component: SourceComponent; + mergeWith?: SourceComponent; + }): Promise { return getWriteInfos(component, 'source', mergeWith); } } diff --git a/src/convert/transformers/metadataTransformerFactory.ts b/src/convert/transformers/metadataTransformerFactory.ts index 311da4d47..d572a7d4e 100644 --- a/src/convert/transformers/metadataTransformerFactory.ts +++ b/src/convert/transformers/metadataTransformerFactory.ts @@ -9,11 +9,11 @@ import { MetadataTransformer } from '../types'; import { SourceComponent } from '../../resolve/sourceComponent'; import { ConvertContext } from '../convertContext/convertContext'; import { RegistryAccess } from '../../registry/registryAccess'; -import { TransformerStrategy } from '../../registry/types'; import { DefaultMetadataTransformer } from './defaultMetadataTransformer'; import { DecomposedMetadataTransformer } from './decomposedMetadataTransformer'; import { StaticResourceMetadataTransformer } from './staticResourceMetadataTransformer'; import { NonDecomposedMetadataTransformer } from './nonDecomposedMetadataTransformer'; +import { LabelMetadataTransformer, LabelsMetadataTransformer } from './decomposeLabelsTransformer'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr'); @@ -32,15 +32,19 @@ export class MetadataTransformerFactory { const type = component.parent ? component.parent.type : component.type; const transformerId = type.strategies?.transformer; switch (transformerId) { - case TransformerStrategy.Standard: + case 'standard': case undefined: return new DefaultMetadataTransformer(this.registry, this.context); - case TransformerStrategy.Decomposed: + case 'decomposed': return new DecomposedMetadataTransformer(this.registry, this.context); - case TransformerStrategy.StaticResource: + case 'staticResource': return new StaticResourceMetadataTransformer(this.registry, this.context); - case TransformerStrategy.NonDecomposed: + case 'nonDecomposed': return new NonDecomposedMetadataTransformer(this.registry, this.context); + case 'decomposedLabels': + return component.type.name === 'CustomLabels' + ? new LabelsMetadataTransformer(this.registry, this.context) + : new LabelMetadataTransformer(this.registry, this.context); default: throw messages.createError('error_missing_transformer', [type.name, transformerId]); } diff --git a/src/convert/transformers/nonDecomposedMetadataTransformer.ts b/src/convert/transformers/nonDecomposedMetadataTransformer.ts index 94c53ef60..6112399f7 100644 --- a/src/convert/transformers/nonDecomposedMetadataTransformer.ts +++ b/src/convert/transformers/nonDecomposedMetadataTransformer.ts @@ -8,8 +8,7 @@ import { get, getString, JsonMap } from '@salesforce/ts-types'; import { ensureArray } from '@salesforce/kit'; import { Messages } from '@salesforce/core'; -import { WriteInfo } from '../types'; -import { SourceComponent } from '../../resolve/sourceComponent'; +import { ToSourceFormatInput, WriteInfo } from '../types'; import { DecomposedMetadataTransformer } from './decomposedMetadataTransformer'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr'); @@ -22,7 +21,7 @@ const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sd export class NonDecomposedMetadataTransformer extends DecomposedMetadataTransformer { // streams uses mergeWith for all types. Removing it would break the interface // eslint-disable-next-line @typescript-eslint/no-unused-vars - public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise { + public async toSourceFormat({ component, mergeWith }: ToSourceFormatInput): Promise { // this will only include the incoming (retrieved) labels, not the local file const parentXml = await component.parseXml(); const xmlPathToChildren = `${component.type.name}.${component.type.directoryName}`; diff --git a/src/convert/transformers/staticResourceMetadataTransformer.ts b/src/convert/transformers/staticResourceMetadataTransformer.ts index 668a1eeb7..d5ca4b537 100644 --- a/src/convert/transformers/staticResourceMetadataTransformer.ts +++ b/src/convert/transformers/staticResourceMetadataTransformer.ts @@ -13,7 +13,7 @@ import { createWriteStream } from 'graceful-fs'; import { Logger, Messages, SfError } from '@salesforce/core'; import { isEmpty } from '@salesforce/kit'; import { baseName } from '../../utils/path'; -import { WriteInfo } from '../types'; +import { ToSourceFormatInput, WriteInfo } from '../types'; import { SourceComponent } from '../../resolve/sourceComponent'; import { SourcePath } from '../../common/types'; import { ensureFileExists } from '../../utils/fileSystemHandler'; @@ -97,7 +97,7 @@ export class StaticResourceMetadataTransformer extends BaseMetadataTransformer { ]; } - public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise { + public async toSourceFormat({ component, mergeWith }: ToSourceFormatInput): Promise { const { xml, content } = component; if (!content) { diff --git a/src/convert/types.ts b/src/convert/types.ts index e0e790a5b..36f30d69e 100644 --- a/src/convert/types.ts +++ b/src/convert/types.ts @@ -6,6 +6,7 @@ */ import { Readable } from 'node:stream'; import { JsonMap } from '@salesforce/ts-types'; +import { ComponentSet } from '../collections/componentSet'; import { XML_NS_KEY, XML_NS_URL } from '../common/constants'; import { FileResponseSuccess } from '../client/types'; import { SourcePath } from '../common/types'; @@ -74,13 +75,19 @@ export type MergeConfig = { forceIgnoredPaths?: Set; }; +export type ToSourceFormatInput = { + component: SourceComponent; + mergeWith?: SourceComponent; + mergeSet?: ComponentSet; +}; +export type ToSourceFormat = (input: ToSourceFormatInput) => Promise; /** * Transforms metadata component files into different SFDX file formats */ export type MetadataTransformer = { defaultDirectory?: string; + toSourceFormat: ToSourceFormat; toMetadataFormat(component: SourceComponent): Promise; - toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise; }; // -------------- diff --git a/src/index.ts b/src/index.ts index 550b1ef50..2e6e92ac4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,15 +90,10 @@ export { FromSourceOptions, FromManifestOptions, } from './collections'; -export { - RegistryAccess, - registry, - getCurrentApiVersion, - MetadataRegistry, - MetadataType, - DecompositionStrategy, - RecompositionStrategy, - TransformerStrategy, -} from './registry'; + +export { RegistryAccess, registry, getCurrentApiVersion, MetadataRegistry, MetadataType } from './registry'; + +// TODO: don't export these strategies +export { DecompositionStrategy, TransformerStrategy, RecompositionStrategy } from './registry/types'; export { presetMap } from './registry/presets/presetMap'; diff --git a/src/registry/index.ts b/src/registry/index.ts index f21418821..d1f892d99 100644 --- a/src/registry/index.ts +++ b/src/registry/index.ts @@ -8,10 +8,4 @@ export { registry } from './registry'; export { standardValueSet } from './standardvalueset'; export { RegistryAccess } from './registryAccess'; export { getCurrentApiVersion } from './coverage'; -export { - MetadataRegistry, - MetadataType, - DecompositionStrategy, - RecompositionStrategy, - TransformerStrategy, -} from './types'; +export { MetadataRegistry, MetadataType } from './types'; diff --git a/src/registry/presets/decomposeCustomLabelsBeta2.json b/src/registry/presets/decomposeCustomLabelsBeta2.json new file mode 100644 index 000000000..aee6b9bf9 --- /dev/null +++ b/src/registry/presets/decomposeCustomLabelsBeta2.json @@ -0,0 +1,28 @@ +{ + "suffixes": { + "label": "customlabel", + "labels": "customlabels" + }, + "types": { + "customlabel": { + "directoryName": "labels", + "id": "customlabel", + "name": "CustomLabel", + "strategies": { + "adapter": "default", + "transformer": "label" + }, + "suffix": "label" + }, + "customlabels": { + "directoryName": "labels", + "id": "customlabels", + "name": "CustomLabels", + "strategies": { + "adapter": "default", + "transformer": "labels" + }, + "suffix": "labels" + } + } +} diff --git a/src/registry/types.ts b/src/registry/types.ts index 034b7ce9c..a0c4bb871 100644 --- a/src/registry/types.ts +++ b/src/registry/types.ts @@ -140,7 +140,7 @@ export type MetadataType = { */ strategies?: { adapter: 'mixedContent' | 'matchingContentFile' | 'decomposed' | 'digitalExperience' | 'bundle' | 'default'; - transformer?: 'decomposed' | 'staticResource' | 'nonDecomposed' | 'standard'; + transformer?: 'decomposed' | 'staticResource' | 'nonDecomposed' | 'standard' | 'decomposedLabels'; decomposition?: 'topLevel' | 'folderPerType'; recomposition?: 'startEmpty'; }; @@ -168,6 +168,7 @@ type DirectoryIndex = { }; /** + * @deprecated. See the strategies union type on the registry types for the valid names * Strategy names for handling component decomposition. */ export const enum DecompositionStrategy { @@ -182,6 +183,7 @@ export const enum DecompositionStrategy { } /** + * @deprecated. See the strategies union type on the registry types for the valid names * Strategy names for handling component recomposition. */ export const enum RecompositionStrategy { @@ -192,6 +194,7 @@ export const enum RecompositionStrategy { } /** + * @deprecated. See the strategies union type on the registry types for the valid names * Strategy names for the type of transformation to use for metadata types. */ export const enum TransformerStrategy { @@ -199,6 +202,7 @@ export const enum TransformerStrategy { Decomposed = 'decomposed', StaticResource = 'staticResource', NonDecomposed = 'nonDecomposed', + DecomposedLabels = 'decomposedLabels', } type Channel = { diff --git a/test/convert/streams.test.ts b/test/convert/streams.test.ts index c93067b8c..dc2d07e87 100644 --- a/test/convert/streams.test.ts +++ b/test/convert/streams.test.ts @@ -12,6 +12,7 @@ import { Logger, SfError, Messages } from '@salesforce/core'; import { expect, assert } from 'chai'; import { createSandbox, SinonStub } from 'sinon'; import JSZip from 'jszip'; +import { ToSourceFormatInput } from '../../src/convert/types'; import * as streams from '../../src/convert/streams'; import * as fsUtil from '../../src/utils/fileSystemHandler'; import { ComponentSet, MetadataResolver, RegistryAccess, SourceComponent, WriteInfo, WriterFormat } from '../../src'; @@ -35,7 +36,7 @@ class TestTransformer extends BaseMetadataTransformer { } // partial implementation only for tests // eslint-disable-next-line class-methods-use-this, @typescript-eslint/require-await - public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise { + public async toSourceFormat({ mergeWith }: ToSourceFormatInput): Promise { const output = mergeWith ? mergeWith.content ?? mergeWith.xml : '/type/file.s'; assert(output); return [{ output, source: new Readable() }]; @@ -106,7 +107,7 @@ describe('Streams', () => { expect(err).to.be.undefined; expect(data).to.deep.equal({ component, - writeInfos: await transformer.toSourceFormat(component), + writeInfos: await transformer.toSourceFormat({ component }), }); done(); } catch (e) { @@ -133,7 +134,7 @@ describe('Streams', () => { expect(err).to.be.undefined; expect(data).to.deep.equal({ component: newComponent, - writeInfos: await transformer.toSourceFormat(newComponent, component), + writeInfos: await transformer.toSourceFormat({ component: newComponent, mergeWith: component }), }); done(); } catch (e) { @@ -162,8 +163,8 @@ describe('Streams', () => { expect(err).to.be.undefined; expect(data).to.deep.equal({ component: newComponent, - writeInfos: (await transformer.toSourceFormat(newComponent, component)).concat( - await transformer.toSourceFormat(newComponent, secondMergeComponent) + writeInfos: (await transformer.toSourceFormat({ component: newComponent, mergeWith: component })).concat( + await transformer.toSourceFormat({ component: newComponent, mergeWith: secondMergeComponent }) ), }); done(); diff --git a/test/convert/transformers/decomposedMetadataTransformer.test.ts b/test/convert/transformers/decomposedMetadataTransformer.test.ts index 1d48d4bfc..980e2ca4e 100644 --- a/test/convert/transformers/decomposedMetadataTransformer.test.ts +++ b/test/convert/transformers/decomposedMetadataTransformer.test.ts @@ -132,7 +132,7 @@ describe('DecomposedMetadataTransformer', () => { }, }); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(context.decomposition.transactionState.size).to.equal(0); expect(result).to.deep.equal([ @@ -193,7 +193,7 @@ describe('DecomposedMetadataTransformer', () => { ) .returns(false); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(context.decomposition.transactionState.size).to.equal(0); expect(result).to.deep.equal([ @@ -239,7 +239,7 @@ describe('DecomposedMetadataTransformer', () => { }, }); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(result).to.deep.equal([ { @@ -277,7 +277,7 @@ describe('DecomposedMetadataTransformer', () => { }, }); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(result).to.deep.equal([ { @@ -327,7 +327,7 @@ describe('DecomposedMetadataTransformer', () => { }, }); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(result).to.deep.equal([ { @@ -378,7 +378,7 @@ describe('DecomposedMetadataTransformer', () => { }, }); - const result = await transformer.toSourceFormat(cft, cot); + const result = await transformer.toSourceFormat({ component: cft, mergeWith: cot }); expect(result).to.deep.equal([ { @@ -417,7 +417,7 @@ describe('DecomposedMetadataTransformer', () => { const transformer = new DecomposedMetadataTransformer(); $$.SANDBOX.stub(component, 'parseXml').resolves({}); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(result).to.be.an('array').with.lengthOf(1); // there will be a file produced, with just the outer type (ex: CustomObject) and the xmlns declaration @@ -446,7 +446,7 @@ describe('DecomposedMetadataTransformer', () => { .withArgs(join('main', 'default', 'objects', 'customObject__c', 'customObject__c.object-meta.xml')) .returns(true); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(result).to.deep.equal([]); }); @@ -472,7 +472,7 @@ describe('DecomposedMetadataTransformer', () => { }); const transformer = new DecomposedMetadataTransformer(registryAccess); - const result = await transformer.toSourceFormat(componentToConvert, component); + const result = await transformer.toSourceFormat({ component: componentToConvert, mergeWith: component }); expect(result).to.deep.equal([ { @@ -509,7 +509,7 @@ describe('DecomposedMetadataTransformer', () => { }); const transformer = new DecomposedMetadataTransformer(); - const result = await transformer.toSourceFormat(componentToConvert, component); + const result = await transformer.toSourceFormat({ component: componentToConvert, mergeWith: component }); expect(result).to.deep.equal([ { @@ -556,7 +556,7 @@ describe('DecomposedMetadataTransformer', () => { try { // NOTE: it doesn't matter what the first component is for this test since it's all // about the child components of the parentComponent. - await transformer.toSourceFormat(component, parentComponent); + await transformer.toSourceFormat({ component, mergeWith: parentComponent }); assert(false, 'expected TypeInferenceError to be thrown'); } catch (err) { assert(err instanceof Error); @@ -590,7 +590,7 @@ describe('DecomposedMetadataTransformer', () => { const context = new ConvertContext(); const transformer = new DecomposedMetadataTransformer(registryAccess, context); - const result = await transformer.toSourceFormat(component, componentToMerge); + const result = await transformer.toSourceFormat({ component, mergeWith: componentToMerge }); expect(result).to.be.empty; expect( context.decomposition.transactionState.get(`${mergeComponentChild.type.name}#${mergeComponentChild.fullName}`) @@ -616,7 +616,7 @@ describe('DecomposedMetadataTransformer', () => { it('should defer write operation for parent xml that is not a member of merge component', async () => { const { fullName, type } = component; const root = join('main', 'default', type.directoryName, fullName); - const componentToMerge = SourceComponent.createVirtualComponent( + const mergeWith = SourceComponent.createVirtualComponent( { name: 'a', type, @@ -633,7 +633,7 @@ describe('DecomposedMetadataTransformer', () => { const context = new ConvertContext(); const transformer = new DecomposedMetadataTransformer(registryAccess, context); - const result = await transformer.toSourceFormat(component, componentToMerge); + const result = await transformer.toSourceFormat({ component, mergeWith }); expect(result).to.be.empty; expect(context.decomposition.transactionState.get(`${type.name}#${fullName}`)).to.deep.equal({ origin: component, diff --git a/test/convert/transformers/defaultMetadataTransformer.test.ts b/test/convert/transformers/defaultMetadataTransformer.test.ts index 67e757246..fc5e25e70 100644 --- a/test/convert/transformers/defaultMetadataTransformer.test.ts +++ b/test/convert/transformers/defaultMetadataTransformer.test.ts @@ -197,7 +197,7 @@ describe('DefaultMetadataTransformer', () => { source: component.tree.stream(component.xml), }); - expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equal(expectedInfos); }); it('should add in the -meta.xml suffix for components with no content', async () => { @@ -213,7 +213,7 @@ describe('DefaultMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equal(expectedInfos); }); it('should handle components in folders with no content', async () => { @@ -234,7 +234,7 @@ describe('DefaultMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equal(expectedInfos); }); it('should not remove file extension and preserve -meta.xml for DigitalExperienceBundle', async () => { @@ -263,7 +263,7 @@ describe('DefaultMetadataTransformer', () => { ), }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equal(expectedInfos); }); it('should handle folder components', async () => { @@ -284,7 +284,7 @@ describe('DefaultMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equal(expectedInfos); }); it('should merge output with merge component when content is a directory', async () => { @@ -322,7 +322,7 @@ describe('DefaultMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component, mergeWith)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component, mergeWith })).to.deep.equal(expectedInfos); }); it('should merge output with merge component when content is a file', async () => { @@ -356,7 +356,7 @@ describe('DefaultMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component, mergeWith)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component, mergeWith })).to.deep.equal(expectedInfos); }); it('should use merge component xml path', async () => { @@ -371,7 +371,7 @@ describe('DefaultMetadataTransformer', () => { [] ); assert(typeof component.xml === 'string'); - expect(await transformer.toSourceFormat(component, mergeWith)).to.deep.contain({ + expect(await transformer.toSourceFormat({ component, mergeWith })).to.deep.contain({ output: mergeWith.xml, source: component.tree.stream(component.xml), }); @@ -388,7 +388,7 @@ describe('DefaultMetadataTransformer', () => { ); assert(typeof component.xml === 'string'); - expect(await transformer.toSourceFormat(component, mergeWith)).to.deep.contain({ + expect(await transformer.toSourceFormat({ component, mergeWith })).to.deep.contain({ output: component.getPackageRelativePath(component.xml, 'source'), source: component.tree.stream(component.xml), }); @@ -411,7 +411,7 @@ describe('DefaultMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equal(expectedInfos); }); }); }); diff --git a/test/convert/transformers/nonDecomposedMetadataTransformer.test.ts b/test/convert/transformers/nonDecomposedMetadataTransformer.test.ts index 90b2219a2..faf7aa796 100644 --- a/test/convert/transformers/nonDecomposedMetadataTransformer.test.ts +++ b/test/convert/transformers/nonDecomposedMetadataTransformer.test.ts @@ -40,7 +40,7 @@ describe('NonDecomposedMetadataTransformer', () => { const context = new ConvertContext(); const transformer = new NonDecomposedMetadataTransformer(registryAccess, context); - const result = await transformer.toSourceFormat(component); + const result = await transformer.toSourceFormat({ component }); expect(result).to.deep.equal([]); expect(context.decomposition.transactionState).to.deep.equal(new Map()); expect(context.recomposition.transactionState).to.deep.equal(new Map()); @@ -68,7 +68,7 @@ describe('NonDecomposedMetadataTransformer', () => { $$.SANDBOX.stub(componentToConvert, 'parseXml').resolves(nonDecomposed.FULL_XML_CONTENT); $$.SANDBOX.stub(componentToConvert, 'parseXmlSync').returns(nonDecomposed.FULL_XML_CONTENT); - const result = await transformer.toSourceFormat(componentToConvert, component); + const result = await transformer.toSourceFormat({ component: componentToConvert, mergeWith: component }); expect(result).to.deep.equal([]); expect(context.nonDecomposition.transactionState).to.deep.equal({ childrenByUniqueElement: new Map([ diff --git a/test/convert/transformers/staticResourceMetadataTransformer.test.ts b/test/convert/transformers/staticResourceMetadataTransformer.test.ts index f7f4043fb..0e5b5d322 100644 --- a/test/convert/transformers/staticResourceMetadataTransformer.test.ts +++ b/test/convert/transformers/staticResourceMetadataTransformer.test.ts @@ -222,7 +222,7 @@ describe('StaticResourceMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equalInAnyOrder(expectedInfos); }); it('should rename extension from .resource for a fallback mime extension', async () => { @@ -247,7 +247,7 @@ describe('StaticResourceMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equalInAnyOrder(expectedInfos); }); it('should rename extension from .resource for an unsupported mime extension', async () => { @@ -273,14 +273,14 @@ describe('StaticResourceMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equalInAnyOrder(expectedInfos); }); it('should ignore components without content', async () => { const component = Object.assign({}, mixedContentSingleFile.COMPONENT); component.content = undefined; - expect(await transformer.toSourceFormat(component)).to.deep.equal([]); + expect(await transformer.toSourceFormat({ component })).to.deep.equal([]); }); it('should extract an archive', async () => { @@ -306,7 +306,7 @@ describe('StaticResourceMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equalInAnyOrder(expectedInfos); expect(pipelineStub.callCount).to.equal(1); expect(pipelineStub.firstCall.args[1]).to.equal( join( @@ -340,7 +340,7 @@ describe('StaticResourceMetadataTransformer', () => { }, ]; - expect(await transformer.toSourceFormat(component)).to.deep.equalInAnyOrder(expectedInfos); + expect(await transformer.toSourceFormat({ component })).to.deep.equalInAnyOrder(expectedInfos); }); it('should merge output with merge component when content is archive', async () => { @@ -349,7 +349,7 @@ describe('StaticResourceMetadataTransformer', () => { assert(component.xml); assert(typeof transformer.defaultDirectory === 'string'); - const mergeComponent = SourceComponent.createVirtualComponent( + const mergeWith = SourceComponent.createVirtualComponent( { name: mixedContentSingleFile.COMPONENT.name, type: registry.types.staticresource, @@ -367,8 +367,8 @@ describe('StaticResourceMetadataTransformer', () => { }, ] ); - assert(mergeComponent.xml); - assert(mergeComponent.content); + assert(mergeWith.xml); + assert(mergeWith.content); env.stub(component, 'parseXml').resolves({ StaticResource: { contentType: 'application/zip', @@ -382,14 +382,14 @@ describe('StaticResourceMetadataTransformer', () => { const expectedInfos: WriteInfo[] = [ { source: component.tree.stream(component.xml), - output: mergeComponent.xml, + output: mergeWith.xml, }, ]; - expect(await transformer.toSourceFormat(component, mergeComponent)).to.deep.equal(expectedInfos); + expect(await transformer.toSourceFormat({ component, mergeWith })).to.deep.equal(expectedInfos); expect(pipelineStub.callCount).to.equal(1); expect(pipelineStub.firstCall.args[1]).to.deep.equal( - join(transformer.defaultDirectory, mergeComponent.content, 'b', 'c.css') + join(transformer.defaultDirectory, mergeWith.content, 'b', 'c.css') ); }); @@ -398,7 +398,7 @@ describe('StaticResourceMetadataTransformer', () => { const component = mixedContentSingleFile.COMPONENT; assert(component.content); assert(component.xml); - const mergeComponent = SourceComponent.createVirtualComponent( + const mergeWith = SourceComponent.createVirtualComponent( { name: mixedContentSingleFile.COMPONENT.name, type: registry.types.staticresource, @@ -416,7 +416,7 @@ describe('StaticResourceMetadataTransformer', () => { }, ] ); - assert(mergeComponent.xml); + assert(mergeWith.xml); env.stub(component, 'parseXml').resolves({ StaticResource: { @@ -426,15 +426,15 @@ describe('StaticResourceMetadataTransformer', () => { const expectedInfos: WriteInfo[] = [ { source: component.tree.stream(component.content), - output: `${mergeComponent.content}.txt`, + output: `${mergeWith.content}.txt`, }, { source: component.tree.stream(component.xml), - output: mergeComponent.xml, + output: mergeWith.xml, }, ]; - expect(await transformer.toSourceFormat(component, mergeComponent)).to.deep.equalInAnyOrder(expectedInfos); + expect(await transformer.toSourceFormat({ component, mergeWith })).to.deep.equalInAnyOrder(expectedInfos); }); }); }); diff --git a/test/registry/registryValidation.test.ts b/test/registry/registryValidation.test.ts index 304fdf18b..230d28493 100644 --- a/test/registry/registryValidation.test.ts +++ b/test/registry/registryValidation.test.ts @@ -5,7 +5,7 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ import { assert, expect } from 'chai'; -import { DecompositionStrategy, MetadataType, TransformerStrategy } from '../../src/registry/types'; +import { MetadataType } from '../../src/registry/types'; import { metadataTypes as UnsupportedTypes } from '../../src/registry/nonSupportedTypes'; import { presets } from './presetTesting'; @@ -324,20 +324,13 @@ for (const preset of presets) { .forEach((type) => { it(`${type.id} has expected properties`, () => { assert(typeof type.strategies?.decomposition === 'string'); - expect( - [DecompositionStrategy.FolderPerType.valueOf(), DecompositionStrategy.TopLevel.valueOf()].includes( - type.strategies.decomposition - ) - ).to.be.true; + expect(['folderPerType', 'topLevel'].includes(type.strategies.decomposition)).to.be.true; assert(typeof type.strategies?.transformer === 'string'); expect( - [ - TransformerStrategy.Standard.valueOf(), - TransformerStrategy.Decomposed.valueOf(), - TransformerStrategy.StaticResource.valueOf(), - TransformerStrategy.NonDecomposed.valueOf(), - ].includes(type.strategies.transformer) + ['decomposed', 'nondecomposed', 'standard', 'staticResource', 'decomposedLabels'].includes( + type.strategies.transformer + ) ).to.be.true; expect(type.strategies.recomposition).to.be.undefined; });