From af5efd62b47a751e2eec21a78d721bc035181a3b Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 17 May 2024 16:20:26 -0500 Subject: [PATCH] feat: error for behavior change with no matching types --- messages/project.decompose.md | 14 +++++++++++--- src/commands/project/decompose.ts | 2 +- src/utils/decomposition.ts | 9 +++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/messages/project.decompose.md b/messages/project.decompose.md index 805141fd..aa4c9e97 100644 --- a/messages/project.decompose.md +++ b/messages/project.decompose.md @@ -15,12 +15,16 @@ Which sourceBehaviorOption to enable. - Switch the project to use decomposed custom labels <%= config.bin %> <%= command.id %> --behavior DecomposeCustomLabels --source-dir . -- Switch one packageDirectory to use decomposed custom labels - <%= config.bin %> <%= command.id %> --behavior DecomposeCustomLabels --source-dir force-app +- Without changing any existing files, see what the command would have produced. + <%= config.bin %> <%= command.id %> --behavior DecomposeCustomLabels --dry-run # flags.dry-run.summary -Explain what the command would do but don't modify the project. +Explain what the command would do. + +# flags.dry-run.description + +Doesn't modify existing files. Lists files that would be deleted, explains modifications to sfdx-project.json, and outputs the resulting modifications to a new folder for review. # flags.preserve-temp-dir.summary @@ -50,3 +54,7 @@ The command will move metadata into main/default which doesn't seem like what yo # success.dryRun Files were created in %s outside your package directories for inspection. + +# error.noTargetTypes + +The project contains no packageDirectories with metadata that matches the specified behavior %s. diff --git a/src/commands/project/decompose.ts b/src/commands/project/decompose.ts index 4116fade..95bf8f9a 100644 --- a/src/commands/project/decompose.ts +++ b/src/commands/project/decompose.ts @@ -56,9 +56,9 @@ export default class ProjectDecompose extends SfCommand if (await flags['target-org']?.supportsSourceTracking()) { throw messages.createError('error.trackingNotSupported'); } + const projectJson = getValidatedProjectJson(flags.behavior, this.project!); const packageDirsWithDecomposable = await getDecomposablePackageDirectories(this.project!, flags.behavior); const filesToDelete = await convertToMdapi(packageDirsWithDecomposable); - const projectJson = getValidatedProjectJson(flags.behavior, this.project!); const backupPjsonContents = flags['dry-run'] ? await readFile(projectJson.getPath()) : ''; // flip the preset in the sfdx-project.json, even for dry-run, since the registry will need for conversions diff --git a/src/utils/decomposition.ts b/src/utils/decomposition.ts index 7ca4840b..e1dbf4e5 100644 --- a/src/utils/decomposition.ts +++ b/src/utils/decomposition.ts @@ -34,8 +34,8 @@ export const TMP_DIR = process.env.SF_MDAPI_TEMP_DIR ?? 'decompositionConverterT export const getDecomposablePackageDirectories = async ( project: SfProject, preset: string -): Promise => - ( +): Promise => { + const output = ( await Promise.all( project .getPackageDirectories() @@ -46,6 +46,11 @@ export const getDecomposablePackageDirectories = async ( .filter(componentSetIsNonEmpty) // we do this after filtering componentSets to reduce false positives (ex: dir does not have main/default but also has nothing to decompose) .map(validateMainDefault(project.getPath())); + if (output.length === 0) { + loadMessages().createError('error.noTargetTypes', [preset]); + } + return output; +}; /** converts the composed metadata to mdapi format in a temp dir */ export const convertToMdapi = async (packageDirsWithDecomposable: ComponentSetAndPackageDirPath[]): Promise =>