|
4 | 4 | * Licensed under the BSD 3-Clause license.
|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
6 | 6 | */
|
7 |
| -import { dirname, join, resolve } from 'path'; |
| 7 | +import { join } from 'path'; |
8 | 8 | import { getString, JsonArray, JsonMap } from '@salesforce/ts-types';
|
| 9 | +import { SfProject } from '@salesforce/core'; |
9 | 10 | import { META_XML_SUFFIX, XML_NS_KEY, XML_NS_URL } from '../common';
|
10 | 11 | import { ComponentSet } from '../collections';
|
11 | 12 | import { normalizeToArray } from '../utils';
|
@@ -193,12 +194,21 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
|
193 | 194 | return writerData;
|
194 | 195 | }
|
195 | 196 | this.tree = tree;
|
| 197 | + |
| 198 | + const packageDirectories = SfProject.getInstance().getPackageDirectories(); |
| 199 | + const pkgPaths = packageDirectories.map((pkg) => pkg.fullPath); |
| 200 | + |
196 | 201 | // nondecomposed metadata types can exist in multiple locations under the same name
|
197 | 202 | // so we have to find all components that could potentially match inbound components
|
198 |
| - const allNonDecomposed = this.getAllComponentsOfType( |
199 |
| - defaultDirectory, |
200 |
| - this.transactionState.exampleComponent.type.name |
201 |
| - ); |
| 203 | + let allNonDecomposed: SourceComponent[]; |
| 204 | + |
| 205 | + if (pkgPaths.includes(defaultDirectory)) { |
| 206 | + allNonDecomposed = this.getAllComponentsOfType(pkgPaths, this.transactionState.exampleComponent.type.name); |
| 207 | + } else { |
| 208 | + // defaultDirectory isn't a package, assumes it's the target output dir for conversion |
| 209 | + // so no need to scan this folder |
| 210 | + allNonDecomposed = []; |
| 211 | + } |
202 | 212 |
|
203 | 213 | // prepare 3 maps to simplify component merging
|
204 | 214 | await this.initMergeMap(allNonDecomposed);
|
@@ -271,11 +281,9 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
|
271 | 281 | * child type before recomposing the final xml.
|
272 | 282 | * The labels could belong in any of the files OR need to go in the default location which already contains labels
|
273 | 283 | */
|
274 |
| - private getAllComponentsOfType(defaultDirectory: string, componentType: string): SourceComponent[] { |
275 |
| - // assumes that defaultDir is one level below project dir |
276 |
| - const projectDir = resolve(dirname(defaultDirectory)); |
| 284 | + private getAllComponentsOfType(pkgDirs: string[], componentType: string): SourceComponent[] { |
277 | 285 | const unprocessedComponents = ComponentSet.fromSource({
|
278 |
| - fsPaths: [projectDir], |
| 286 | + fsPaths: pkgDirs, |
279 | 287 | include: new ComponentSet([{ fullName: '*', type: componentType }]),
|
280 | 288 | tree: this.tree,
|
281 | 289 | }).getSourceComponents();
|
|
0 commit comments