Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions pgpm/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions pgpm/cli/src/utils/module-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParsedArgs>,
Expand All @@ -18,8 +21,10 @@ export async function selectPackage(
log?: Logger
): Promise<string | undefined> {
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) {
Expand Down