Skip to content

Commit b3f7dbb

Browse files
committed
feat: don't require main/default if dry-run
1 parent cb61953 commit b3f7dbb

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

messages/convert.source-behavior.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ This command moves metadata into a main/default structure, but your package dire
5858

5959
# error.packageDirectoryNeedsMainDefault.actions
6060

61-
- Update %s to have all its metadata inside a main/default directory structure.
62-
- Run the command again.
61+
- Update %s to have all its metadata inside a main/default directory structure, then run the command again.
62+
- Use the `--dry-run` flag. You can move the files in the output directory to wherever you want them. Please read the dry-run results carefully in case files need to be deleted from your project.
6363

6464
# success.dryRun
6565

src/commands/project/convert/source-behavior.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default class ConvertSourceBehavior extends SfCommand<SourceBehaviorResul
5959
const projectJson = getValidatedProjectJson(flags.behavior, this.project!);
6060
const [backupPjsonContents, packageDirsWithDecomposable] = await Promise.all([
6161
flags['dry-run'] ? readFile(projectJson.getPath()) : '',
62-
getPackageDirectoriesForPreset(this.project!, flags.behavior),
62+
getPackageDirectoriesForPreset({ project: this.project!, preset: flags.behavior, dryRun: flags['dry-run'] }),
6363
]);
6464
const filesToDelete = await convertToMdapi(packageDirsWithDecomposable);
6565

src/utils/convertBehavior.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ export const TMP_DIR = process.env.SF_MDAPI_TEMP_DIR ?? 'decompositionConverterT
3333
export const DRY_RUN_DIR = 'DRY-RUN-RESULTS';
3434

3535
/** returns packageDirectories and ComponentsSets where there is metadata of the type we'll change the behavior for */
36-
export const getPackageDirectoriesForPreset = async (
37-
project: SfProject,
38-
preset: string
39-
): Promise<ComponentSetAndPackageDirPath[]> => {
36+
export const getPackageDirectoriesForPreset = async ({
37+
project,
38+
preset,
39+
dryRun,
40+
}: {
41+
project: SfProject;
42+
preset: string;
43+
dryRun: boolean;
44+
}): Promise<ComponentSetAndPackageDirPath[]> => {
4045
const projectDir = project.getPath();
4146
const output = (
4247
await Promise.all(
@@ -45,14 +50,16 @@ export const getPackageDirectoriesForPreset = async (
4550
.map((pd) => pd.path)
4651
.map(componentSetFromPackageDirectory(projectDir)(await getTypesFromPreset(preset)))
4752
)
48-
)
49-
.filter(componentSetIsNonEmpty)
50-
// we do this after filtering componentSets to reduce false positives (ex: dir does not have main/default but also has nothing to decompose)
51-
.map(validateMainDefault(projectDir));
53+
).filter(componentSetIsNonEmpty);
54+
5255
if (output.length === 0) {
5356
loadMessages().createError('error.noTargetTypes', [preset]);
5457
}
55-
return output;
58+
59+
return dryRun
60+
? output // dryRun isn't modifying the project, so we don't need to validate the structure
61+
: // we do this after filtering componentSets to reduce false positives (ex: dir does not have main/default but also has nothing to decompose)
62+
output.map(validateMainDefault(projectDir));
5663
};
5764

5865
/** converts the composed metadata to mdapi format in a temp dir */

0 commit comments

Comments
 (0)