Skip to content

Commit

Permalink
feat: error for behavior change with no matching types
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed May 17, 2024
1 parent d0cc74f commit af5efd6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 11 additions & 3 deletions messages/project.decompose.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion src/commands/project/decompose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export default class ProjectDecompose extends SfCommand<ProjectDecomposeResult>
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
Expand Down
9 changes: 7 additions & 2 deletions src/utils/decomposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const TMP_DIR = process.env.SF_MDAPI_TEMP_DIR ?? 'decompositionConverterT
export const getDecomposablePackageDirectories = async (
project: SfProject,
preset: string
): Promise<ComponentSetAndPackageDirPath[]> =>
(
): Promise<ComponentSetAndPackageDirPath[]> => {
const output = (
await Promise.all(
project
.getPackageDirectories()
Expand All @@ -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<string[]> =>
Expand Down

0 comments on commit af5efd6

Please sign in to comment.