bunset 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.7
4
+
5
+ ### Features
6
+
7
+ - prompt for commit/tag when not explicitly set
8
+
9
+ ### Bug Fixes
10
+
11
+ - sync package versions in monorepo when using shared tags
12
+
3
13
  ## 1.0.6
4
14
 
5
15
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunset",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.ts CHANGED
@@ -92,8 +92,8 @@ export function resolveOptions(
92
92
  patch: { type: "boolean", default: false },
93
93
  minor: { type: "boolean", default: false },
94
94
  major: { type: "boolean", default: false },
95
- commit: { type: "boolean", default: true },
96
- tag: { type: "boolean", default: true },
95
+ commit: { type: "boolean" },
96
+ tag: { type: "boolean" },
97
97
  "per-package-tags": { type: "boolean", default: false },
98
98
  sections: { type: "string" },
99
99
  "dry-run": { type: "boolean", default: false },
@@ -124,8 +124,8 @@ export function resolveOptions(
124
124
  const bump = cliBump ?? config.bump ?? null;
125
125
  const scope = cliScope ?? config.scope ?? (isWs ? null : "all");
126
126
 
127
- const commit = values.commit === false ? false : (config.commit ?? true);
128
- const tag = values.tag === false ? false : (config.tag ?? true);
127
+ const commit = values.commit !== undefined ? (values.commit as boolean) : (config.commit ?? null);
128
+ const tag = values.tag !== undefined ? (values.tag as boolean) : (config.tag ?? null);
129
129
  const perPackageTags = values["per-package-tags"]
130
130
  ? true
131
131
  : (config.perPackageTags ?? false);
@@ -145,7 +145,7 @@ export function resolveOptions(
145
145
  ?? config.tagPrefix
146
146
  ?? null;
147
147
 
148
- if (bump && scope) {
148
+ if (bump && scope && commit !== null && tag !== null) {
149
149
  return { scope, bump, commit, tag, perPackageTags, sections, dryRun, filterByPackage, tagPrefix, debug };
150
150
  }
151
151
 
@@ -185,8 +185,8 @@ function parseSections(raw: string | undefined): CommitType[] | null {
185
185
  }
186
186
 
187
187
  interface MergedDefaults {
188
- commit: boolean;
189
- tag: boolean;
188
+ commit: boolean | null;
189
+ tag: boolean | null;
190
190
  perPackageTags: boolean;
191
191
  sections: CommitType[];
192
192
  dryRun: boolean;
@@ -220,10 +220,26 @@ async function promptForMissing(
220
220
  else bump = "patch";
221
221
  }
222
222
 
223
+ let { commit, tag } = merged;
224
+
225
+ if (commit === null) {
226
+ process.stdout.write("Commit changes? (y/n) [default: y]: ");
227
+ const answer = await readLine();
228
+ commit = answer.trim().toLowerCase() !== "n";
229
+ }
230
+
231
+ if (tag === null) {
232
+ process.stdout.write("Tag release? (y/n) [default: y]: ");
233
+ const answer = await readLine();
234
+ tag = answer.trim().toLowerCase() !== "n";
235
+ }
236
+
223
237
  return {
224
238
  scope: scope ?? "all",
225
239
  bump,
226
240
  ...merged,
241
+ commit,
242
+ tag,
227
243
  };
228
244
  }
229
245
 
package/src/index.ts CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  getAllPackages,
22
22
  getChangedPackages,
23
23
  } from "./workspace.ts";
24
- import { bumpVersion, updatePackageVersion } from "./version.ts";
24
+ import { bumpVersion, parseSemver, updatePackageVersion, setPackageVersion } from "./version.ts";
25
25
  import type { ParsedCommit, GroupedCommits } from "./types.ts";
26
26
 
27
27
  const cwd = process.cwd();
@@ -145,6 +145,22 @@ function packageHasChanges(groups: GroupedCommits): boolean {
145
145
  return options.sections.some((type) => groups[type].length > 0);
146
146
  }
147
147
 
148
+ // When using shared tags, sync all packages to the same target version
149
+ let targetVersion: string | null = null;
150
+ if (!options.perPackageTags && packages.length > 1) {
151
+ const maxVersion = packages.reduce((max, pkg) => {
152
+ const v = pkg.version ?? "0.0.0";
153
+ const [mj1, mn1, p1] = parseSemver(max);
154
+ const [mj2, mn2, p2] = parseSemver(v);
155
+ if (mj2 > mj1) return v;
156
+ if (mj2 === mj1 && mn2 > mn1) return v;
157
+ if (mj2 === mj1 && mn2 === mn1 && p2 > p1) return v;
158
+ return max;
159
+ }, "0.0.0");
160
+ targetVersion = bumpVersion(maxVersion, options.bump);
161
+ debug(`shared tag mode: max version = ${maxVersion}, target version = ${targetVersion}`);
162
+ }
163
+
148
164
  if (options.dryRun) {
149
165
  if (!dbg) console.log("--- Dry Run ---\n");
150
166
 
@@ -179,7 +195,7 @@ if (options.dryRun) {
179
195
  }
180
196
 
181
197
  const oldVersion = pkg.version ?? "0.0.0";
182
- const newVersion = bumpVersion(oldVersion, options.bump);
198
+ const newVersion = targetVersion ?? bumpVersion(oldVersion, options.bump);
183
199
  console.log(`${pkg.name}: ${oldVersion} → ${newVersion}`);
184
200
  filesToCommit.push(pkg.packageJsonPath, `${pkg.path}/CHANGELOG.md`);
185
201
 
@@ -212,9 +228,10 @@ if (options.dryRun) {
212
228
  filesToCommit.push(`${cwd}/bun.lock`);
213
229
 
214
230
  if (options.commit) {
231
+ const releaseVersion = targetVersion ?? bumpVersion(packages[0]!.version ?? "0.0.0", options.bump);
215
232
  const msg =
216
233
  packages.length === 1
217
- ? `chore: release ${packages[0]!.name}@${bumpVersion(packages[0]!.version ?? "0.0.0", options.bump)}`
234
+ ? `chore: release ${packages[0]!.name}@${releaseVersion}`
218
235
  : `chore: release ${packages.length} packages`;
219
236
  console.log(`Would commit: ${msg}`);
220
237
  } else {
@@ -247,10 +264,9 @@ for (const pkg of packages) {
247
264
  continue;
248
265
  }
249
266
 
250
- const { oldVersion, newVersion } = await updatePackageVersion(
251
- pkg.packageJsonPath,
252
- options.bump,
253
- );
267
+ const { oldVersion, newVersion } = targetVersion
268
+ ? await setPackageVersion(pkg.packageJsonPath, targetVersion)
269
+ : await updatePackageVersion(pkg.packageJsonPath, options.bump);
254
270
  changedFiles.push(pkg.packageJsonPath);
255
271
  console.log(`${pkg.name}: ${oldVersion} → ${newVersion}`);
256
272
 
package/src/version.ts CHANGED
@@ -30,3 +30,15 @@ export async function updatePackageVersion(
30
30
  await Bun.write(packageJsonPath, JSON.stringify(pkg, null, 2) + "\n");
31
31
  return { oldVersion, newVersion };
32
32
  }
33
+
34
+ export async function setPackageVersion(
35
+ packageJsonPath: string,
36
+ newVersion: string,
37
+ ): Promise<{ oldVersion: string; newVersion: string }> {
38
+ const file = Bun.file(packageJsonPath);
39
+ const pkg = await file.json();
40
+ const oldVersion = pkg.version ?? "0.0.0";
41
+ pkg.version = newVersion;
42
+ await Bun.write(packageJsonPath, JSON.stringify(pkg, null, 2) + "\n");
43
+ return { oldVersion, newVersion };
44
+ }