diff --git a/pgpm/cli/src/commands/deploy.ts b/pgpm/cli/src/commands/deploy.ts index 286920f7d..e2dfb91d1 100644 --- a/pgpm/cli/src/commands/deploy.ts +++ b/pgpm/cli/src/commands/deploy.ts @@ -128,36 +128,50 @@ export default async ( }); } + const project = new PgpmPackage(cwd); + + // Determine package name based on context (similar to tag.ts pattern) let packageName: string | undefined; - if (recursive) { + + if (argv.package) { + // User explicitly specified a package + packageName = resolvePackageAlias(argv.package as string, cwd); + log.info(`Using specified package: ${packageName}`); + } else if (project.isInModule()) { + // We're inside a module, use the current module + packageName = project.getModuleName(); + log.info(`Using current module: ${packageName}`); + } else if (project.isInWorkspace() && recursive) { + // We're in a workspace and recursive is enabled, prompt for package selection packageName = await selectPackage(argv, prompter, cwd, 'deploy', log); + if (!packageName) { + log.error('No package selected. Cannot deploy without specifying a target package.'); + return; + } } + // If not in module and not recursive, packageName stays undefined which means deploy all const cliOverrides = { pg: getPgEnvOptions({ database }), deployment: { useTx: tx !== false, - fast: fast !== false, + fast: fast === true, usePlan: argv.usePlan !== false, cache: argv.cache !== false, - logOnly: argv.logOnly !== false, + logOnly: logOnly === true, } }; const opts = getEnvOptions(cliOverrides); - - const project = new PgpmPackage(cwd); let target: string | undefined; if (packageName && argv.to) { target = `${packageName}:${argv.to}`; } else if (packageName) { target = packageName; - } else if (argv.package && argv.to) { - const resolvedPackage = resolvePackageAlias(argv.package as string, cwd); - target = `${resolvedPackage}:${argv.to}`; - } else if (argv.package) { - target = resolvePackageAlias(argv.package as string, cwd); + } else if (argv.to) { + // --to specified without --package, use just the target + target = argv.to as string; } await project.deploy( diff --git a/pgpm/cli/src/utils/module-utils.ts b/pgpm/cli/src/utils/module-utils.ts index e6eba11d3..71d11ec3e 100644 --- a/pgpm/cli/src/utils/module-utils.ts +++ b/pgpm/cli/src/utils/module-utils.ts @@ -9,6 +9,9 @@ import { resolvePackageAlias } from './package-alias'; /** * Handle package selection for operations that need a specific package * Returns the selected package name, or undefined if validation fails or no packages exist + * + * Uses getModuleMap() which discovers modules by scanning for .control files, + * ensuring consistency with how core deploy discovers modules. */ export async function selectPackage( argv: Partial, @@ -18,8 +21,10 @@ export async function selectPackage( log?: Logger ): Promise { const pkg = new PgpmPackage(cwd); - const modules = await pkg.getModules(); - const moduleNames = modules.map(mod => mod.getModuleName()); + // Use getModuleMap() instead of getModules() for consistency with core deploy + // getModuleMap() scans for .control files, while getModules() uses pgpm.json patterns + const modules = pkg.getModuleMap(); + const moduleNames = Object.keys(modules); // Check if any modules exist if (!moduleNames.length) {