diff --git a/src/convert/convertContext.ts b/src/convert/convertContext.ts index e588f960cb..08a668b46a 100644 --- a/src/convert/convertContext.ts +++ b/src/convert/convertContext.ts @@ -4,8 +4,9 @@ * 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 { dirname, join, resolve } from 'path'; +import { join } from 'path'; import { getString, JsonArray, JsonMap } from '@salesforce/ts-types'; +import { SfProject } from '@salesforce/core'; import { META_XML_SUFFIX, XML_NS_KEY, XML_NS_URL } from '../common'; import { ComponentSet } from '../collections'; import { normalizeToArray } from '../utils'; @@ -193,12 +194,21 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer pkg.fullPath); + // nondecomposed metadata types can exist in multiple locations under the same name // so we have to find all components that could potentially match inbound components - const allNonDecomposed = this.getAllComponentsOfType( - defaultDirectory, - this.transactionState.exampleComponent.type.name - ); + let allNonDecomposed: SourceComponent[]; + + if (pkgPaths.includes(defaultDirectory)) { + allNonDecomposed = this.getAllComponentsOfType(pkgPaths, this.transactionState.exampleComponent.type.name); + } else { + // defaultDirectory isn't a package, assumes it's the target output dir for conversion + // so no need to scan this folder + allNonDecomposed = []; + } // prepare 3 maps to simplify component merging await this.initMergeMap(allNonDecomposed); @@ -271,11 +281,9 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer { }); describe('NonDecomposition', () => { + let sfProjectStub: sinon.SinonStub; + beforeEach(() => { + sfProjectStub = env.stub(SfProject, 'getInstance').returns({ + getPackageDirectories: () => { + return [ + { + name: 'force-app', + path: 'force-app', + fullPath: nonDecomposed.DEFAULT_DIR, + }, + ]; + }, + } as unknown as SfProject); + }); it('should return WriterFormats for claimed children', async () => { const component = nonDecomposed.COMPONENT_1; const context = new ConvertContext(); @@ -394,11 +409,28 @@ describe('Convert Transaction Constructs', () => { }); it('should merge 1 updated file to non-default dir and not write default file', async () => { + sfProjectStub.restore(); + env.stub(SfProject, 'getInstance').returns({ + getPackageDirectories: () => { + return [ + { + name: 'my-app', + path: 'my-app', + fullPath: nonDecomposed.NON_DEFAULT_DIR, + }, + { + name: 'force-app', + path: 'force-app', + fullPath: nonDecomposed.DEFAULT_DIR, + }, + ]; + }, + } as unknown as SfProject); const component = nonDecomposed.COMPONENT_2; const context = new ConvertContext(); const type = component.type; - // change the word first to 'updated' + // change the word 'third' to 'updated' const updatedChild3Xml = { ...nonDecomposed.CHILD_3_XML, value: nonDecomposed.CHILD_3_XML.value.replace('third', 'updated'),