Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .bumpy/status-json-enhancements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@varlock/bumpy': patch
---

Add `inCurrentBranch` and `publishTargets` fields to `status --json` output
64 changes: 52 additions & 12 deletions packages/bumpy/src/commands/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { log, colorize } from '../utils/logger.ts';
import { loadConfig } from '../core/config.ts';
import { discoverPackages } from '../core/workspace.ts';
import { DependencyGraph } from '../core/dep-graph.ts';
import { readBumpFiles } from '../core/bump-file.ts';
import { readBumpFiles, filterBranchBumpFiles } from '../core/bump-file.ts';
import { assembleReleasePlan } from '../core/release-plan.ts';
import type { PlannedRelease, WorkspacePackage } from '../types.ts';
import { getCurrentBranch, getChangedFiles } from '../core/git.ts';
import type { BumpyConfig, PackageConfig, PlannedRelease, WorkspacePackage } from '../types.ts';

interface StatusOptions {
json?: boolean;
Expand Down Expand Up @@ -35,6 +36,15 @@ export async function statusCommand(rootDir: string, opts: StatusOptions): Promi

const plan = assembleReleasePlan(bumpFiles, packages, depGraph, config);

// Determine which bump files belong to the current branch (if not on base branch)
let branchBumpFileIds: Set<string> | undefined;
const currentBranch = getCurrentBranch({ cwd: rootDir });
if (currentBranch && currentBranch !== config.baseBranch) {
const changedFiles = getChangedFiles(rootDir, config.baseBranch);
const result = filterBranchBumpFiles(bumpFiles, changedFiles, rootDir);
branchBumpFileIds = result.branchBumpFileIds;
}

// Apply filters
let releases = plan.releases;
if (opts.bumpType) {
Expand All @@ -53,17 +63,28 @@ export async function statusCommand(rootDir: string, opts: StatusOptions): Promi
id: bf.id,
summary: bf.summary,
releases: bf.releases.map((r) => ({ name: r.name, type: r.type })),
...(branchBumpFileIds ? { inCurrentBranch: branchBumpFileIds.has(bf.id) } : {}),
})),
releases: releases.map((r) => ({
name: r.name,
type: r.type,
oldVersion: r.oldVersion,
newVersion: r.newVersion,
dir: packages.get(r.name)?.relativeDir,
bumpFiles: r.bumpFiles,
isDependencyBump: r.isDependencyBump,
isCascadeBump: r.isCascadeBump,
})),
releases: releases.map((r) => {
const pkg = packages.get(r.name);
const pkgConfig = pkg?.bumpy || {};
return {
name: r.name,
type: r.type,
oldVersion: r.oldVersion,
newVersion: r.newVersion,
dir: pkg?.relativeDir,
bumpFiles: r.bumpFiles,
isDependencyBump: r.isDependencyBump,
isCascadeBump: r.isCascadeBump,
...(branchBumpFileIds
? {
inCurrentBranch: r.bumpFiles.some((id) => branchBumpFileIds!.has(id)),
}
: {}),
publishTargets: getPublishTargets(pkg, pkgConfig, config),
};
}),
packageNames: releases.map((r) => r.name),
};
console.log(JSON.stringify(jsonOutput, null, 2));
Expand Down Expand Up @@ -133,3 +154,22 @@ function printRelease(r: PlannedRelease, packages: Map<string, WorkspacePackage>
: '';
console.log(` ${r.name}: ${r.oldVersion} → ${colorize(r.newVersion, 'cyan')}${suffix}${dir}`);
}

/** Determine which publish targets a package will use */
function getPublishTargets(
pkg: WorkspacePackage | undefined,
pkgConfig: Partial<PackageConfig>,
_config: BumpyConfig,
): string[] {
if (!pkg) return [];
// Private packages with no custom command won't publish
if (pkg.private && !pkgConfig.publishCommand) return [];
const targets: string[] = [];
if (pkgConfig.publishCommand) {
targets.push('custom');
}
if (!pkgConfig.publishCommand && !pkgConfig.skipNpmPublish) {
targets.push('npm');
}
return targets;
}