Skip to content

Commit 63eb50a

Browse files
authored
Merge pull request #40 from dmno-dev/feat/status-json-enhancements
Add isCurrentBranch and publishTo to status --json
2 parents 97defdc + 4cec321 commit 63eb50a

2 files changed

Lines changed: 57 additions & 12 deletions

File tree

.bumpy/status-json-enhancements.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@varlock/bumpy': patch
3+
---
4+
5+
Add `inCurrentBranch` and `publishTargets` fields to `status --json` output

packages/bumpy/src/commands/status.ts

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { log, colorize } from '../utils/logger.ts';
22
import { loadConfig } from '../core/config.ts';
33
import { discoverPackages } from '../core/workspace.ts';
44
import { DependencyGraph } from '../core/dep-graph.ts';
5-
import { readBumpFiles } from '../core/bump-file.ts';
5+
import { readBumpFiles, filterBranchBumpFiles } from '../core/bump-file.ts';
66
import { assembleReleasePlan } from '../core/release-plan.ts';
7-
import type { PlannedRelease, WorkspacePackage } from '../types.ts';
7+
import { getCurrentBranch, getChangedFiles } from '../core/git.ts';
8+
import type { BumpyConfig, PackageConfig, PlannedRelease, WorkspacePackage } from '../types.ts';
89

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

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

39+
// Determine which bump files belong to the current branch (if not on base branch)
40+
let branchBumpFileIds: Set<string> | undefined;
41+
const currentBranch = getCurrentBranch({ cwd: rootDir });
42+
if (currentBranch && currentBranch !== config.baseBranch) {
43+
const changedFiles = getChangedFiles(rootDir, config.baseBranch);
44+
const result = filterBranchBumpFiles(bumpFiles, changedFiles, rootDir);
45+
branchBumpFileIds = result.branchBumpFileIds;
46+
}
47+
3848
// Apply filters
3949
let releases = plan.releases;
4050
if (opts.bumpType) {
@@ -53,17 +63,28 @@ export async function statusCommand(rootDir: string, opts: StatusOptions): Promi
5363
id: bf.id,
5464
summary: bf.summary,
5565
releases: bf.releases.map((r) => ({ name: r.name, type: r.type })),
66+
...(branchBumpFileIds ? { inCurrentBranch: branchBumpFileIds.has(bf.id) } : {}),
5667
})),
57-
releases: releases.map((r) => ({
58-
name: r.name,
59-
type: r.type,
60-
oldVersion: r.oldVersion,
61-
newVersion: r.newVersion,
62-
dir: packages.get(r.name)?.relativeDir,
63-
bumpFiles: r.bumpFiles,
64-
isDependencyBump: r.isDependencyBump,
65-
isCascadeBump: r.isCascadeBump,
66-
})),
68+
releases: releases.map((r) => {
69+
const pkg = packages.get(r.name);
70+
const pkgConfig = pkg?.bumpy || {};
71+
return {
72+
name: r.name,
73+
type: r.type,
74+
oldVersion: r.oldVersion,
75+
newVersion: r.newVersion,
76+
dir: pkg?.relativeDir,
77+
bumpFiles: r.bumpFiles,
78+
isDependencyBump: r.isDependencyBump,
79+
isCascadeBump: r.isCascadeBump,
80+
...(branchBumpFileIds
81+
? {
82+
inCurrentBranch: r.bumpFiles.some((id) => branchBumpFileIds!.has(id)),
83+
}
84+
: {}),
85+
publishTargets: getPublishTargets(pkg, pkgConfig, config),
86+
};
87+
}),
6788
packageNames: releases.map((r) => r.name),
6889
};
6990
console.log(JSON.stringify(jsonOutput, null, 2));
@@ -133,3 +154,22 @@ function printRelease(r: PlannedRelease, packages: Map<string, WorkspacePackage>
133154
: '';
134155
console.log(` ${r.name}: ${r.oldVersion}${colorize(r.newVersion, 'cyan')}${suffix}${dir}`);
135156
}
157+
158+
/** Determine which publish targets a package will use */
159+
function getPublishTargets(
160+
pkg: WorkspacePackage | undefined,
161+
pkgConfig: Partial<PackageConfig>,
162+
_config: BumpyConfig,
163+
): string[] {
164+
if (!pkg) return [];
165+
// Private packages with no custom command won't publish
166+
if (pkg.private && !pkgConfig.publishCommand) return [];
167+
const targets: string[] = [];
168+
if (pkgConfig.publishCommand) {
169+
targets.push('custom');
170+
}
171+
if (!pkgConfig.publishCommand && !pkgConfig.skipNpmPublish) {
172+
targets.push('npm');
173+
}
174+
return targets;
175+
}

0 commit comments

Comments
 (0)