From b372387cc01b0061970acd2fffca3de47d712b4a Mon Sep 17 00:00:00 2001 From: Pedro Gomes <37028775+pedro-gomes-92@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:18:45 +0800 Subject: [PATCH] chore: improve mr after review (II) --- .../src/cleanSubspace.ts | 25 ++++++++----------- .../rush-migrate-subspace-plugin/src/cli.ts | 12 ++++++--- .../src/interactMenu.ts | 8 +++--- .../src/migrateProject.ts | 8 +++--- .../src/syncVersions.ts | 16 +++++------- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/rush-plugins/rush-migrate-subspace-plugin/src/cleanSubspace.ts b/rush-plugins/rush-migrate-subspace-plugin/src/cleanSubspace.ts index 6f8af6b..e329eb4 100644 --- a/rush-plugins/rush-migrate-subspace-plugin/src/cleanSubspace.ts +++ b/rush-plugins/rush-migrate-subspace-plugin/src/cleanSubspace.ts @@ -6,7 +6,6 @@ import { scanForAllDependenciesPrompt } from './prompts/subspace'; import Console from './providers/console'; -import { getRootPath } from './utilities/path'; import { Colorize } from '@rushstack/terminal'; import { getRushSubspaceCommonVersionsFilePath, @@ -246,16 +245,14 @@ const removeSupersetDependencyVersions = async ( } while (multipleVersionDependencies.length > 0 && (await confirmNextDependencyPrompt())); }; -export const cleanSubspace = async (targetMonorepoPath: string = getRootPath()): Promise => { +export const cleanSubspace = async (rootPath: string): Promise => { Console.debug('Executing clean subspace command...'); - const targetSubspaces: string[] = querySubspaces(targetMonorepoPath); - if (!isSubspaceSupported(targetMonorepoPath)) { + const targetSubspaces: string[] = querySubspaces(rootPath); + if (!isSubspaceSupported(rootPath)) { Console.error( - `The monorepo ${Colorize.bold( - targetMonorepoPath - )} doesn't support subspaces! Make sure you have ${Colorize.bold( - getRushSubspacesConfigurationJsonPath(targetMonorepoPath) + `The monorepo ${Colorize.bold(rootPath)} doesn't support subspaces! Make sure you have ${Colorize.bold( + getRushSubspacesConfigurationJsonPath(rootPath) )} with the ${Colorize.bold(RushConstants.defaultSubspaceName)} subspace. Exiting...` ); return; @@ -266,20 +263,20 @@ export const cleanSubspace = async (targetMonorepoPath: string = getRootPath()): let subspaceDependencies: Map> = getSubspaceDependencies( targetSubspace, - targetMonorepoPath + rootPath ); if (await scanForDuplicatedDependenciesPrompt()) { - removeDuplicatedDependencies(targetSubspace, targetMonorepoPath); - subspaceDependencies = getSubspaceDependencies(targetSubspace, targetMonorepoPath); + removeDuplicatedDependencies(targetSubspace, rootPath); + subspaceDependencies = getSubspaceDependencies(targetSubspace, rootPath); } if (await scanForSupersetDependencyVersionsPrompt()) { - await removeSupersetDependencyVersions(targetSubspace, subspaceDependencies, targetMonorepoPath); - subspaceDependencies = getSubspaceDependencies(targetSubspace, targetMonorepoPath); + await removeSupersetDependencyVersions(targetSubspace, subspaceDependencies, rootPath); + subspaceDependencies = getSubspaceDependencies(targetSubspace, rootPath); } if (await scanForUnusedDependencyVersionsPrompt()) { - removeUnusedAlternativeVersions(targetSubspace, subspaceDependencies, targetMonorepoPath); + removeUnusedAlternativeVersions(targetSubspace, subspaceDependencies, rootPath); } Console.warn( diff --git a/rush-plugins/rush-migrate-subspace-plugin/src/cli.ts b/rush-plugins/rush-migrate-subspace-plugin/src/cli.ts index 4824f68..31e1f8d 100644 --- a/rush-plugins/rush-migrate-subspace-plugin/src/cli.ts +++ b/rush-plugins/rush-migrate-subspace-plugin/src/cli.ts @@ -8,6 +8,7 @@ import { migrateProject } from './migrateProject'; import Console from './providers/console'; import { interactMenu } from './interactMenu'; import { cleanSubspace } from './cleanSubspace'; +import { getRootPath } from './utilities/path'; inquirer.registerPrompt('search-list', inquirerSearchList); @@ -26,14 +27,17 @@ program Console.title(`🚀 Rush Migrate Subspace Plugin - version ${packageJson.version}`); Console.newLine(); + const sourceMonorepoPath: string = getRootPath(); + const targetMonorepoPath: string = getRootPath(); + if (sync) { - await syncVersions(); + await syncVersions(targetMonorepoPath); } else if (move) { - await migrateProject(); + await migrateProject(sourceMonorepoPath, targetMonorepoPath); } else if (clean) { - await cleanSubspace(); + await cleanSubspace(targetMonorepoPath); } else { - await interactMenu(); + await interactMenu(sourceMonorepoPath, targetMonorepoPath); } }); diff --git a/rush-plugins/rush-migrate-subspace-plugin/src/interactMenu.ts b/rush-plugins/rush-migrate-subspace-plugin/src/interactMenu.ts index efe6a72..89d301a 100644 --- a/rush-plugins/rush-migrate-subspace-plugin/src/interactMenu.ts +++ b/rush-plugins/rush-migrate-subspace-plugin/src/interactMenu.ts @@ -4,7 +4,7 @@ import { chooseCommandPrompt } from './prompts/command'; import Console from './providers/console'; import { syncVersions } from './syncVersions'; -export const interactMenu = async (): Promise => { +export const interactMenu = async (sourceMonorepoPath: string, targetMonorepoPath: string): Promise => { let exitApplication: boolean = false; do { const nextCommand: string = await chooseCommandPrompt(); @@ -14,17 +14,17 @@ export const interactMenu = async (): Promise => { break; case 'move': - await migrateProject(); + await migrateProject(sourceMonorepoPath, targetMonorepoPath); Console.newLine(); break; case 'sync': - await syncVersions(); + await syncVersions(targetMonorepoPath); Console.newLine(); break; case 'clean': - await cleanSubspace(); + await cleanSubspace(targetMonorepoPath); Console.newLine(); break; } diff --git a/rush-plugins/rush-migrate-subspace-plugin/src/migrateProject.ts b/rush-plugins/rush-migrate-subspace-plugin/src/migrateProject.ts index 93060ce..d0bf9b1 100644 --- a/rush-plugins/rush-migrate-subspace-plugin/src/migrateProject.ts +++ b/rush-plugins/rush-migrate-subspace-plugin/src/migrateProject.ts @@ -2,7 +2,6 @@ import { chooseSubspacePrompt } from './prompts/subspace'; import { addProjectToSubspace } from './functions/addProjectToSubspace'; import { chooseProjectPrompt, confirmNextProjectToAddPrompt } from './prompts/project'; import Console from './providers/console'; -import { getRootPath } from './utilities/path'; import { Colorize } from '@rushstack/terminal'; import { updateSubspace } from './functions/updateSubspace'; import { getRushSubspaceConfigurationFolderPath, isSubspaceSupported } from './utilities/subspace'; @@ -16,7 +15,10 @@ import { import { RushConstants } from '@rushstack/rush-sdk'; import { syncProjectMismatchedDependencies } from './functions/syncProjectDependencies'; -export const migrateProject = async (targetMonorepoPath: string = getRootPath()): Promise => { +export const migrateProject = async ( + sourceMonorepoPath: string, + targetMonorepoPath: string +): Promise => { Console.debug('Executing project migration command...'); Console.title(`🔍 Analyzing if monorepo ${Colorize.underline(targetMonorepoPath)} supports subspaces...`); @@ -55,8 +57,6 @@ export const migrateProject = async (targetMonorepoPath: string = getRootPath()) * ); */ - const sourceMonorepoPath: string = getRootPath(); - /** * WARN: Disabling creating new subspaces for now. * const subspaceSelectionType: string = await chooseCreateOrSelectSubspacePrompt(targetSubspaces); diff --git a/rush-plugins/rush-migrate-subspace-plugin/src/syncVersions.ts b/rush-plugins/rush-migrate-subspace-plugin/src/syncVersions.ts index 2ad191c..f831a3c 100644 --- a/rush-plugins/rush-migrate-subspace-plugin/src/syncVersions.ts +++ b/rush-plugins/rush-migrate-subspace-plugin/src/syncVersions.ts @@ -3,7 +3,6 @@ import { VersionMismatchFinderEntity } from '@rushstack/rush-sdk/lib/logic/versi import Console from './providers/console'; import { Colorize } from '@rushstack/terminal'; import { querySubspaces } from './utilities/repository'; -import { getRootPath } from './utilities/path'; import { getSubspaceMismatches } from './utilities/subspace'; import { chooseProjectPrompt, confirmNextProjectToSyncPrompt } from './prompts/project'; import { syncProjectMismatchedDependencies } from './functions/syncProjectDependencies'; @@ -32,22 +31,19 @@ const fetchSubspaceMismatchedProjects = (subspaceName: string, rootPath: string) return mismatchedProjects; }; -export const syncVersions = async (targetMonorepoPath: string = getRootPath()): Promise => { +export const syncVersions = async (rootPath: string): Promise => { Console.debug('Synching project version...'); - const sourceSubspaces: string[] = querySubspaces(targetMonorepoPath); + const sourceSubspaces: string[] = querySubspaces(rootPath); if (sourceSubspaces.length === 0) { - Console.error(`No subspaces found in the monorepo ${Colorize.bold(targetMonorepoPath)}! Exiting...`); + Console.error(`No subspaces found in the monorepo ${Colorize.bold(rootPath)}! Exiting...`); return; } const selectedSubspaceName: string = await chooseSubspacePrompt(sourceSubspaces); Console.title(`🔄 Syncing version mismatches for subspace ${Colorize.bold(selectedSubspaceName)}...`); - let mismatchedProjects: string[] = fetchSubspaceMismatchedProjects( - selectedSubspaceName, - targetMonorepoPath - ); + let mismatchedProjects: string[] = fetchSubspaceMismatchedProjects(selectedSubspaceName, rootPath); if (mismatchedProjects.length === 0) { Console.success(`No mismatches found in the subspace ${Colorize.bold(selectedSubspaceName)}! Exiting...`); return; @@ -55,11 +51,11 @@ export const syncVersions = async (targetMonorepoPath: string = getRootPath()): do { const selectedProjectName: string = await chooseProjectPrompt(mismatchedProjects); - if (!(await syncProjectMismatchedDependencies(selectedProjectName, targetMonorepoPath))) { + if (!(await syncProjectMismatchedDependencies(selectedProjectName, rootPath))) { return; } - mismatchedProjects = fetchSubspaceMismatchedProjects(selectedSubspaceName, targetMonorepoPath); + mismatchedProjects = fetchSubspaceMismatchedProjects(selectedSubspaceName, rootPath); } while (mismatchedProjects.length > 0 && (await confirmNextProjectToSyncPrompt(selectedSubspaceName))); if (mismatchedProjects.length === 0) {