From 45aece8d10d3aceb5f54661ac6c89a0d9775c818 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 30 Oct 2023 16:02:28 -0600 Subject: [PATCH] chore: simplify logic --- .../decomposedMetadataTransformer.ts | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/convert/transformers/decomposedMetadataTransformer.ts b/src/convert/transformers/decomposedMetadataTransformer.ts index 71455a0fd7..3f7d93590a 100644 --- a/src/convert/transformers/decomposedMetadataTransformer.ts +++ b/src/convert/transformers/decomposedMetadataTransformer.ts @@ -4,8 +4,7 @@ * 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 'path'; -import * as path from 'path'; +import { dirname, join } from 'path'; import { JsonMap } from '@salesforce/ts-types'; import { ensureArray } from '@salesforce/kit'; import { Messages } from '@salesforce/core'; @@ -109,7 +108,7 @@ export class DecomposedMetadataTransformer extends BaseMetadataTransformer { } // if there's nothing to merge with, push write operation now to default location - if (!mergeWith && !childType.unaddressableWithoutParent) { + if (!mergeWith) { writeInfos.push({ source, output: getDefaultOutput(childComponent), @@ -128,29 +127,24 @@ export class DecomposedMetadataTransformer extends BaseMetadataTransformer { }); this.setDecomposedState(childComponent, { foundMerge: true }); } - // if no child component is found to merge with yet, mark it as so in the state + // If we have a parent and the child is unaddressable without the parent, keep them + // together on the file system, meaning a new child will not be written to the default dir. + else if (childType.unaddressableWithoutParent) { + // get output path from parent + const childFileName = `${entryName}.${childComponent.type.suffix}${META_XML_SUFFIX}`; + const output = join(dirname(mergeWith.xml as string), childFileName); + writeInfos.push({ source, output }); + } + // if no child component is found to merge with yet, mark it as so in + // the state else if (!this.getDecomposedState(childComponent)?.foundMerge) { - if (mergeWith?.content && childComponent.type.unaddressableWithoutParent && childComponent.type.suffix) { - // if the child can't exist without the parent, and we found a parent (mergeWith) redirect the output to the parents output, rather than the default output - writeInfos.push({ - source, - output: path.join(mergeWith.content, `${entryName}.${childComponent.type.suffix}${META_XML_SUFFIX}`), - }); - } else if (!mergeWith) { - // if the child can't exist without a parent, and there's no parent found, redirect to the default pkg dir - writeInfos.push({ + this.setDecomposedState(childComponent, { + foundMerge: false, + writeInfo: { source, output: getDefaultOutput(childComponent), - }); - } else { - this.setDecomposedState(childComponent, { - foundMerge: false, - writeInfo: { - source, - output: getDefaultOutput(childComponent), - }, - }); - } + }, + }); } } }