bumpp 9.3.1 → 9.4.1

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.
@@ -624,7 +624,7 @@ var log_symbols_default = logSymbols;
624
624
 
625
625
  // src/release-type.ts
626
626
  var prereleaseTypes = ["premajor", "preminor", "prepatch", "prerelease"];
627
- var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch"]);
627
+ var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch", "next"]);
628
628
  function isPrerelease(value) {
629
629
  return prereleaseTypes.includes(value);
630
630
  }
@@ -662,7 +662,7 @@ import prompts from "prompts";
662
662
  import semver, { SemVer, clean as cleanVersion, valid as isValidVersion } from "semver";
663
663
  async function getNewVersion(operation) {
664
664
  const { release } = operation.options;
665
- const { oldVersion } = operation.state;
665
+ const { currentVersion } = operation.state;
666
666
  switch (release.type) {
667
667
  case "prompt":
668
668
  return promptForNewVersion(operation);
@@ -673,42 +673,41 @@ async function getNewVersion(operation) {
673
673
  default:
674
674
  return operation.update({
675
675
  release: release.type,
676
- newVersion: getNextVersion(oldVersion, release)
676
+ newVersion: getNextVersion(currentVersion, release)
677
677
  });
678
678
  }
679
679
  }
680
- function getNextVersion(oldVersion, bump) {
681
- const oldSemVer = new SemVer(oldVersion);
682
- const newSemVer = oldSemVer.inc(bump.type, bump.preid);
680
+ function getNextVersion(currentVersion, bump) {
681
+ const oldSemVer = new SemVer(currentVersion);
682
+ const type = bump.type === "next" ? oldSemVer.prerelease.length ? "prerelease" : "patch" : bump.type;
683
+ const newSemVer = oldSemVer.inc(type, bump.preid);
683
684
  if (isPrerelease(bump.type) && newSemVer.prerelease.length === 2 && newSemVer.prerelease[0] === bump.preid && String(newSemVer.prerelease[1]) === "0") {
684
685
  newSemVer.prerelease[1] = "1";
685
686
  newSemVer.format();
686
687
  }
687
688
  return newSemVer.version;
688
689
  }
689
- function getNextVersions(oldVersion, preid) {
690
- var _a;
690
+ function getNextVersions(currentVersion, preid) {
691
691
  const next = {};
692
- const parse = semver.parse(oldVersion);
692
+ const parse = semver.parse(currentVersion);
693
693
  if (typeof (parse == null ? void 0 : parse.prerelease[0]) === "string")
694
694
  preid = (parse == null ? void 0 : parse.prerelease[0]) || "preid";
695
695
  for (const type of releaseTypes)
696
- next[type] = semver.inc(oldVersion, type, preid);
697
- next.next = ((_a = parse == null ? void 0 : parse.prerelease) == null ? void 0 : _a.length) ? semver.inc(oldVersion, "prerelease", preid) : semver.inc(oldVersion, "patch");
696
+ next[type] = getNextVersion(currentVersion, { type, preid });
698
697
  return next;
699
698
  }
700
699
  async function promptForNewVersion(operation) {
701
700
  var _a, _b;
702
- const { oldVersion } = operation.state;
701
+ const { currentVersion } = operation.state;
703
702
  const release = operation.options.release;
704
- const next = getNextVersions(oldVersion, release.preid);
705
- const configCustomVersion = await ((_b = (_a = operation.options).customVersion) == null ? void 0 : _b.call(_a, oldVersion, semver));
703
+ const next = getNextVersions(currentVersion, release.preid);
704
+ const configCustomVersion = await ((_b = (_a = operation.options).customVersion) == null ? void 0 : _b.call(_a, currentVersion, semver));
706
705
  const PADDING = 13;
707
706
  const answers = await prompts([
708
707
  {
709
708
  type: "autocomplete",
710
709
  name: "release",
711
- message: `Current version ${import_picocolors.default.green(oldVersion)}`,
710
+ message: `Current version ${import_picocolors.default.green(currentVersion)}`,
712
711
  initial: configCustomVersion ? "config" : "next",
713
712
  choices: [
714
713
  { value: "major", title: `${"major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.major)}` },
@@ -721,7 +720,7 @@ async function promptForNewVersion(operation) {
721
720
  { value: "prepatch", title: `${"pre-patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.prepatch)}` },
722
721
  { value: "preminor", title: `${"pre-minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.preminor)}` },
723
722
  { value: "premajor", title: `${"pre-major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.premajor)}` },
724
- { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(oldVersion)}` },
723
+ { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(currentVersion)}` },
725
724
  { value: "custom", title: "custom ...".padStart(PADDING + 4, " ") }
726
725
  ]
727
726
  },
@@ -729,13 +728,13 @@ async function promptForNewVersion(operation) {
729
728
  type: (prev) => prev === "custom" ? "text" : null,
730
729
  name: "custom",
731
730
  message: "Enter the new version number:",
732
- initial: oldVersion,
731
+ initial: currentVersion,
733
732
  validate: (custom) => {
734
733
  return isValidVersion(custom) ? true : "That's not a valid version number";
735
734
  }
736
735
  }
737
736
  ]);
738
- const newVersion = answers.release === "none" ? oldVersion : answers.release === "custom" ? cleanVersion(answers.custom) : answers.release === "config" ? cleanVersion(configCustomVersion) : next[answers.release];
737
+ const newVersion = answers.release === "none" ? currentVersion : answers.release === "custom" ? cleanVersion(answers.custom) : answers.release === "config" ? cleanVersion(configCustomVersion) : next[answers.release];
739
738
  if (!newVersion)
740
739
  process4.exit(1);
741
740
  switch (answers.release) {
@@ -749,7 +748,7 @@ async function promptForNewVersion(operation) {
749
748
  }
750
749
  }
751
750
 
752
- // src/get-old-version.ts
751
+ // src/get-current-version.ts
753
752
  import { valid as isValidVersion2 } from "semver";
754
753
 
755
754
  // src/fs.ts
@@ -923,8 +922,10 @@ function isOptionalString(value) {
923
922
  return value === null || type === "undefined" || type === "string";
924
923
  }
925
924
 
926
- // src/get-old-version.ts
927
- async function getOldVersion(operation) {
925
+ // src/get-current-version.ts
926
+ async function getCurrentVersion(operation) {
927
+ if (operation.state.currentVersion)
928
+ return operation;
928
929
  const { cwd, files } = operation.options;
929
930
  const filesToCheck = files.filter((file) => file.endsWith(".json"));
930
931
  if (!filesToCheck.includes("package.json"))
@@ -933,8 +934,8 @@ async function getOldVersion(operation) {
933
934
  const version = await readVersion(file, cwd);
934
935
  if (version) {
935
936
  return operation.update({
936
- oldVersionSource: file,
937
- oldVersion: version
937
+ currentVersionSource: file,
938
+ currentVersion: version
938
939
  });
939
940
  }
940
941
  }
@@ -1011,9 +1012,12 @@ function formatVersionString(template, newVersion) {
1011
1012
 
1012
1013
  // src/normalize-options.ts
1013
1014
  import process5 from "process";
1015
+ import fs2 from "fs/promises";
1016
+ import fsSync from "fs";
1014
1017
  import fg from "fast-glob";
1018
+ import yaml from "js-yaml";
1015
1019
  async function normalizeOptions(raw) {
1016
- var _a;
1020
+ var _a, _b;
1017
1021
  const preid = typeof raw.preid === "string" ? raw.preid : "beta";
1018
1022
  const push = Boolean(raw.push);
1019
1023
  const all = Boolean(raw.all);
@@ -1021,10 +1025,11 @@ async function normalizeOptions(raw) {
1021
1025
  const cwd = raw.cwd || process5.cwd();
1022
1026
  const ignoreScripts = Boolean(raw.ignoreScripts);
1023
1027
  const execute = raw.execute;
1028
+ const recursive = Boolean(raw.recursive);
1024
1029
  let release;
1025
1030
  if (!raw.release || raw.release === "prompt")
1026
1031
  release = { type: "prompt", preid };
1027
- else if (isReleaseType(raw.release))
1032
+ else if (isReleaseType(raw.release) || raw.release === "next")
1028
1033
  release = { type: raw.release, preid };
1029
1034
  else
1030
1035
  release = { type: "version", version: raw.release };
@@ -1038,8 +1043,29 @@ async function normalizeOptions(raw) {
1038
1043
  commit = { all, noVerify, message: raw.commit };
1039
1044
  else if (raw.commit || tag || push)
1040
1045
  commit = { all, noVerify, message: "chore: release v" };
1046
+ if (recursive && !((_a = raw.files) == null ? void 0 : _a.length)) {
1047
+ raw.files = [
1048
+ "package.json",
1049
+ "package-lock.json",
1050
+ "packages/**/package.json",
1051
+ "jsr.json",
1052
+ "jsr.jsonc"
1053
+ ];
1054
+ if (fsSync.existsSync("pnpm-workspace.yaml")) {
1055
+ const pnpmWorkspace = await fs2.readFile("pnpm-workspace.yaml", "utf8");
1056
+ const workspaces = yaml.load(pnpmWorkspace);
1057
+ const workspacesWithPackageJson = workspaces.packages.map((workspace) => `${workspace}/package.json`);
1058
+ const withoutExcludedWorkspaces = workspacesWithPackageJson.filter((workspace) => {
1059
+ var _a2;
1060
+ return !workspace.startsWith("!") && !((_a2 = raw.files) == null ? void 0 : _a2.includes(workspace));
1061
+ });
1062
+ raw.files = raw.files.concat(withoutExcludedWorkspaces);
1063
+ }
1064
+ } else {
1065
+ raw.files = ((_b = raw.files) == null ? void 0 : _b.length) ? raw.files : ["package.json", "package-lock.json", "jsr.json", "jsr.jsonc"];
1066
+ }
1041
1067
  const files = await fg(
1042
- ((_a = raw.files) == null ? void 0 : _a.length) ? raw.files : ["package.json", "package-lock.json", "jsr.json", "jsr.jsonc"],
1068
+ raw.files,
1043
1069
  {
1044
1070
  cwd,
1045
1071
  onlyFiles: true,
@@ -1054,7 +1080,7 @@ async function normalizeOptions(raw) {
1054
1080
  } else if (raw.interface === true || !raw.interface) {
1055
1081
  ui = { input: process5.stdin, output: process5.stdout };
1056
1082
  } else {
1057
- let _b = raw.interface, { input, output } = _b, other = __objRest(_b, ["input", "output"]);
1083
+ let _c = raw.interface, { input, output } = _c, other = __objRest(_c, ["input", "output"]);
1058
1084
  if (input === true || input !== false && !input)
1059
1085
  input = process5.stdin;
1060
1086
  if (output === true || output !== false && !output)
@@ -1073,7 +1099,8 @@ async function normalizeOptions(raw) {
1073
1099
  interface: ui,
1074
1100
  ignoreScripts,
1075
1101
  execute,
1076
- customVersion: raw.customVersion
1102
+ customVersion: raw.customVersion,
1103
+ currentVersion: raw.currentVersion
1077
1104
  };
1078
1105
  }
1079
1106
 
@@ -1088,8 +1115,8 @@ var Operation = class _Operation {
1088
1115
  */
1089
1116
  this.state = {
1090
1117
  release: void 0,
1091
- oldVersion: "",
1092
- oldVersionSource: "",
1118
+ currentVersion: "",
1119
+ currentVersionSource: "",
1093
1120
  newVersion: "",
1094
1121
  commitMessage: "",
1095
1122
  tagName: "",
@@ -1098,6 +1125,12 @@ var Operation = class _Operation {
1098
1125
  };
1099
1126
  this.options = options;
1100
1127
  this._progress = progress;
1128
+ if (options.currentVersion) {
1129
+ this.update({
1130
+ currentVersion: options.currentVersion,
1131
+ currentVersionSource: "user"
1132
+ });
1133
+ }
1101
1134
  }
1102
1135
  /**
1103
1136
  * The results of the operation.
@@ -1107,7 +1140,7 @@ var Operation = class _Operation {
1107
1140
  const state = this.state;
1108
1141
  return {
1109
1142
  release: state.release,
1110
- oldVersion: state.oldVersion,
1143
+ currentVersion: state.currentVersion,
1111
1144
  newVersion: state.newVersion,
1112
1145
  commit: options.commit ? state.commitMessage : false,
1113
1146
  tag: options.tag ? state.tagName : false,
@@ -1195,9 +1228,8 @@ async function updateManifestFile(relPath, operation) {
1195
1228
  const file = await readJsonFile(relPath, cwd);
1196
1229
  if (isManifest(file.data) && file.data.version !== newVersion) {
1197
1230
  file.data.version = newVersion;
1198
- if (isPackageLockManifest(file.data)) {
1231
+ if (isPackageLockManifest(file.data))
1199
1232
  file.data.packages[""].version = newVersion;
1200
- }
1201
1233
  await writeJsonFile(file);
1202
1234
  modified = true;
1203
1235
  }
@@ -1205,11 +1237,11 @@ async function updateManifestFile(relPath, operation) {
1205
1237
  }
1206
1238
  async function updateTextFile(relPath, operation) {
1207
1239
  const { cwd } = operation.options;
1208
- const { oldVersion, newVersion } = operation.state;
1240
+ const { currentVersion, newVersion } = operation.state;
1209
1241
  const modified = false;
1210
1242
  const file = await readTextFile(relPath, cwd);
1211
- if (file.data.includes(oldVersion)) {
1212
- const sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
1243
+ if (file.data.includes(currentVersion)) {
1244
+ const sanitizedVersion = currentVersion.replace(/(\W)/g, "\\$1");
1213
1245
  const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
1214
1246
  file.data = file.data.replace(replacePattern, `$1${newVersion}`);
1215
1247
  await writeTextFile(file);
@@ -1223,7 +1255,7 @@ async function versionBump(arg = {}) {
1223
1255
  if (typeof arg === "string")
1224
1256
  arg = { release: arg };
1225
1257
  const operation = await Operation.start(arg);
1226
- await getOldVersion(operation);
1258
+ await getCurrentVersion(operation);
1227
1259
  await getNewVersion(operation);
1228
1260
  if (arg.confirm) {
1229
1261
  printSummary(operation);
@@ -1261,7 +1293,7 @@ function printSummary(operation) {
1261
1293
  if (operation.options.push)
1262
1294
  console.log(` push ${import_picocolors2.default.cyan(import_picocolors2.default.bold("yes"))}`);
1263
1295
  console.log();
1264
- console.log(` from ${import_picocolors2.default.bold(operation.state.oldVersion)}`);
1296
+ console.log(` from ${import_picocolors2.default.bold(operation.state.currentVersion)}`);
1265
1297
  console.log(` to ${import_picocolors2.default.green(import_picocolors2.default.bold(operation.state.newVersion))}`);
1266
1298
  console.log();
1267
1299
  }
@@ -1269,14 +1301,16 @@ async function versionBumpInfo(arg = {}) {
1269
1301
  if (typeof arg === "string")
1270
1302
  arg = { release: arg };
1271
1303
  const operation = await Operation.start(arg);
1272
- await getOldVersion(operation);
1304
+ await getCurrentVersion(operation);
1273
1305
  await getNewVersion(operation);
1274
1306
  return operation;
1275
1307
  }
1276
1308
 
1277
1309
  // src/config.ts
1278
1310
  import process7 from "process";
1311
+ import { dirname } from "path";
1279
1312
  import { loadConfig } from "c12";
1313
+ import escalade from "escalade/sync";
1280
1314
  var bumpConfigDefaults = {
1281
1315
  commit: true,
1282
1316
  push: true,
@@ -1289,19 +1323,49 @@ var bumpConfigDefaults = {
1289
1323
  files: []
1290
1324
  };
1291
1325
  async function loadBumpConfig(overrides, cwd = process7.cwd()) {
1326
+ const name = "bump";
1327
+ const configFile = findConfigFile(name, cwd);
1292
1328
  const { config } = await loadConfig({
1293
- name: "bump",
1329
+ name,
1294
1330
  defaults: bumpConfigDefaults,
1295
1331
  overrides: __spreadValues({}, overrides),
1296
- cwd
1332
+ cwd: configFile ? dirname(configFile) : cwd
1297
1333
  });
1298
1334
  return config;
1299
1335
  }
1336
+ function findConfigFile(name, cwd) {
1337
+ let foundRepositoryRoot = false;
1338
+ try {
1339
+ const candidates = ["js", "mjs", "ts", "mts", "json"].map((ext) => `${name}.config.${ext}`);
1340
+ return escalade(cwd, (_dir, files) => {
1341
+ const match = files.find((file) => {
1342
+ if (candidates.includes(file))
1343
+ return true;
1344
+ if (file === ".git")
1345
+ foundRepositoryRoot = true;
1346
+ return false;
1347
+ });
1348
+ if (match)
1349
+ return match;
1350
+ if (foundRepositoryRoot) {
1351
+ throw null;
1352
+ }
1353
+ return false;
1354
+ });
1355
+ } catch (error) {
1356
+ if (foundRepositoryRoot)
1357
+ return null;
1358
+ throw error;
1359
+ }
1360
+ }
1300
1361
  function defineConfig(config) {
1301
1362
  return config;
1302
1363
  }
1303
1364
 
1304
1365
  export {
1366
+ __spreadValues,
1367
+ __spreadProps,
1368
+ __objRest,
1305
1369
  __toESM,
1306
1370
  require_picocolors,
1307
1371
  log_symbols_default,