bumpp 9.3.1 → 9.4.0

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
  }
@@ -1024,7 +1025,7 @@ async function normalizeOptions(raw) {
1024
1025
  let release;
1025
1026
  if (!raw.release || raw.release === "prompt")
1026
1027
  release = { type: "prompt", preid };
1027
- else if (isReleaseType(raw.release))
1028
+ else if (isReleaseType(raw.release) || raw.release === "next")
1028
1029
  release = { type: raw.release, preid };
1029
1030
  else
1030
1031
  release = { type: "version", version: raw.release };
@@ -1073,7 +1074,8 @@ async function normalizeOptions(raw) {
1073
1074
  interface: ui,
1074
1075
  ignoreScripts,
1075
1076
  execute,
1076
- customVersion: raw.customVersion
1077
+ customVersion: raw.customVersion,
1078
+ currentVersion: raw.currentVersion
1077
1079
  };
1078
1080
  }
1079
1081
 
@@ -1088,8 +1090,8 @@ var Operation = class _Operation {
1088
1090
  */
1089
1091
  this.state = {
1090
1092
  release: void 0,
1091
- oldVersion: "",
1092
- oldVersionSource: "",
1093
+ currentVersion: "",
1094
+ currentVersionSource: "",
1093
1095
  newVersion: "",
1094
1096
  commitMessage: "",
1095
1097
  tagName: "",
@@ -1098,6 +1100,12 @@ var Operation = class _Operation {
1098
1100
  };
1099
1101
  this.options = options;
1100
1102
  this._progress = progress;
1103
+ if (options.currentVersion) {
1104
+ this.update({
1105
+ currentVersion: options.currentVersion,
1106
+ currentVersionSource: "user"
1107
+ });
1108
+ }
1101
1109
  }
1102
1110
  /**
1103
1111
  * The results of the operation.
@@ -1107,7 +1115,7 @@ var Operation = class _Operation {
1107
1115
  const state = this.state;
1108
1116
  return {
1109
1117
  release: state.release,
1110
- oldVersion: state.oldVersion,
1118
+ currentVersion: state.currentVersion,
1111
1119
  newVersion: state.newVersion,
1112
1120
  commit: options.commit ? state.commitMessage : false,
1113
1121
  tag: options.tag ? state.tagName : false,
@@ -1195,9 +1203,8 @@ async function updateManifestFile(relPath, operation) {
1195
1203
  const file = await readJsonFile(relPath, cwd);
1196
1204
  if (isManifest(file.data) && file.data.version !== newVersion) {
1197
1205
  file.data.version = newVersion;
1198
- if (isPackageLockManifest(file.data)) {
1206
+ if (isPackageLockManifest(file.data))
1199
1207
  file.data.packages[""].version = newVersion;
1200
- }
1201
1208
  await writeJsonFile(file);
1202
1209
  modified = true;
1203
1210
  }
@@ -1205,11 +1212,11 @@ async function updateManifestFile(relPath, operation) {
1205
1212
  }
1206
1213
  async function updateTextFile(relPath, operation) {
1207
1214
  const { cwd } = operation.options;
1208
- const { oldVersion, newVersion } = operation.state;
1215
+ const { currentVersion, newVersion } = operation.state;
1209
1216
  const modified = false;
1210
1217
  const file = await readTextFile(relPath, cwd);
1211
- if (file.data.includes(oldVersion)) {
1212
- const sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
1218
+ if (file.data.includes(currentVersion)) {
1219
+ const sanitizedVersion = currentVersion.replace(/(\W)/g, "\\$1");
1213
1220
  const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
1214
1221
  file.data = file.data.replace(replacePattern, `$1${newVersion}`);
1215
1222
  await writeTextFile(file);
@@ -1223,7 +1230,7 @@ async function versionBump(arg = {}) {
1223
1230
  if (typeof arg === "string")
1224
1231
  arg = { release: arg };
1225
1232
  const operation = await Operation.start(arg);
1226
- await getOldVersion(operation);
1233
+ await getCurrentVersion(operation);
1227
1234
  await getNewVersion(operation);
1228
1235
  if (arg.confirm) {
1229
1236
  printSummary(operation);
@@ -1261,7 +1268,7 @@ function printSummary(operation) {
1261
1268
  if (operation.options.push)
1262
1269
  console.log(` push ${import_picocolors2.default.cyan(import_picocolors2.default.bold("yes"))}`);
1263
1270
  console.log();
1264
- console.log(` from ${import_picocolors2.default.bold(operation.state.oldVersion)}`);
1271
+ console.log(` from ${import_picocolors2.default.bold(operation.state.currentVersion)}`);
1265
1272
  console.log(` to ${import_picocolors2.default.green(import_picocolors2.default.bold(operation.state.newVersion))}`);
1266
1273
  console.log();
1267
1274
  }
@@ -1269,14 +1276,16 @@ async function versionBumpInfo(arg = {}) {
1269
1276
  if (typeof arg === "string")
1270
1277
  arg = { release: arg };
1271
1278
  const operation = await Operation.start(arg);
1272
- await getOldVersion(operation);
1279
+ await getCurrentVersion(operation);
1273
1280
  await getNewVersion(operation);
1274
1281
  return operation;
1275
1282
  }
1276
1283
 
1277
1284
  // src/config.ts
1278
1285
  import process7 from "process";
1286
+ import { dirname } from "path";
1279
1287
  import { loadConfig } from "c12";
1288
+ import escalade from "escalade/sync";
1280
1289
  var bumpConfigDefaults = {
1281
1290
  commit: true,
1282
1291
  push: true,
@@ -1289,19 +1298,49 @@ var bumpConfigDefaults = {
1289
1298
  files: []
1290
1299
  };
1291
1300
  async function loadBumpConfig(overrides, cwd = process7.cwd()) {
1301
+ const name = "bump";
1302
+ const configFile = findConfigFile(name, cwd);
1292
1303
  const { config } = await loadConfig({
1293
- name: "bump",
1304
+ name,
1294
1305
  defaults: bumpConfigDefaults,
1295
1306
  overrides: __spreadValues({}, overrides),
1296
- cwd
1307
+ cwd: configFile ? dirname(configFile) : cwd
1297
1308
  });
1298
1309
  return config;
1299
1310
  }
1311
+ function findConfigFile(name, cwd) {
1312
+ let foundRepositoryRoot = false;
1313
+ try {
1314
+ const candidates = ["js", "mjs", "ts", "mts", "json"].map((ext) => `${name}.config.${ext}`);
1315
+ return escalade(cwd, (_dir, files) => {
1316
+ const match = files.find((file) => {
1317
+ if (candidates.includes(file))
1318
+ return true;
1319
+ if (file === ".git")
1320
+ foundRepositoryRoot = true;
1321
+ return false;
1322
+ });
1323
+ if (match)
1324
+ return match;
1325
+ if (foundRepositoryRoot) {
1326
+ throw null;
1327
+ }
1328
+ return false;
1329
+ });
1330
+ } catch (error) {
1331
+ if (foundRepositoryRoot)
1332
+ return null;
1333
+ throw error;
1334
+ }
1335
+ }
1300
1336
  function defineConfig(config) {
1301
1337
  return config;
1302
1338
  }
1303
1339
 
1304
1340
  export {
1341
+ __spreadValues,
1342
+ __spreadProps,
1343
+ __objRest,
1305
1344
  __toESM,
1306
1345
  require_picocolors,
1307
1346
  log_symbols_default,
package/dist/cli/index.js CHANGED
@@ -60,7 +60,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
60
60
 
61
61
  // node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js
62
62
  var require_picocolors = __commonJS({
63
- "node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js"(exports, module2) {
63
+ "node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js"(exports2, module2) {
64
64
  var tty2 = require("tty");
65
65
  var isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty2.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
66
66
  var formatter = (open, close, replace = open) => (input) => {
@@ -628,7 +628,7 @@ var logSymbols = isUnicodeSupported() ? main : fallback;
628
628
  var log_symbols_default = logSymbols;
629
629
 
630
630
  // package.json
631
- var version = "9.3.1";
631
+ var version = "9.4.0";
632
632
 
633
633
  // src/version-bump.ts
634
634
  var import_node_process5 = __toESM(require("process"));
@@ -644,7 +644,7 @@ var import_semver = __toESM(require("semver"));
644
644
 
645
645
  // src/release-type.ts
646
646
  var prereleaseTypes = ["premajor", "preminor", "prepatch", "prerelease"];
647
- var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch"]);
647
+ var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch", "next"]);
648
648
  function isPrerelease(value) {
649
649
  return prereleaseTypes.includes(value);
650
650
  }
@@ -655,7 +655,7 @@ function isReleaseType(value) {
655
655
  // src/get-new-version.ts
656
656
  async function getNewVersion(operation) {
657
657
  const { release } = operation.options;
658
- const { oldVersion } = operation.state;
658
+ const { currentVersion } = operation.state;
659
659
  switch (release.type) {
660
660
  case "prompt":
661
661
  return promptForNewVersion(operation);
@@ -666,42 +666,41 @@ async function getNewVersion(operation) {
666
666
  default:
667
667
  return operation.update({
668
668
  release: release.type,
669
- newVersion: getNextVersion(oldVersion, release)
669
+ newVersion: getNextVersion(currentVersion, release)
670
670
  });
671
671
  }
672
672
  }
673
- function getNextVersion(oldVersion, bump) {
674
- const oldSemVer = new import_semver.SemVer(oldVersion);
675
- const newSemVer = oldSemVer.inc(bump.type, bump.preid);
673
+ function getNextVersion(currentVersion, bump) {
674
+ const oldSemVer = new import_semver.SemVer(currentVersion);
675
+ const type = bump.type === "next" ? oldSemVer.prerelease.length ? "prerelease" : "patch" : bump.type;
676
+ const newSemVer = oldSemVer.inc(type, bump.preid);
676
677
  if (isPrerelease(bump.type) && newSemVer.prerelease.length === 2 && newSemVer.prerelease[0] === bump.preid && String(newSemVer.prerelease[1]) === "0") {
677
678
  newSemVer.prerelease[1] = "1";
678
679
  newSemVer.format();
679
680
  }
680
681
  return newSemVer.version;
681
682
  }
682
- function getNextVersions(oldVersion, preid) {
683
- var _a;
683
+ function getNextVersions(currentVersion, preid) {
684
684
  const next = {};
685
- const parse = import_semver.default.parse(oldVersion);
685
+ const parse = import_semver.default.parse(currentVersion);
686
686
  if (typeof (parse == null ? void 0 : parse.prerelease[0]) === "string")
687
687
  preid = (parse == null ? void 0 : parse.prerelease[0]) || "preid";
688
688
  for (const type of releaseTypes)
689
- next[type] = import_semver.default.inc(oldVersion, type, preid);
690
- next.next = ((_a = parse == null ? void 0 : parse.prerelease) == null ? void 0 : _a.length) ? import_semver.default.inc(oldVersion, "prerelease", preid) : import_semver.default.inc(oldVersion, "patch");
689
+ next[type] = getNextVersion(currentVersion, { type, preid });
691
690
  return next;
692
691
  }
693
692
  async function promptForNewVersion(operation) {
694
693
  var _a, _b;
695
- const { oldVersion } = operation.state;
694
+ const { currentVersion } = operation.state;
696
695
  const release = operation.options.release;
697
- const next = getNextVersions(oldVersion, release.preid);
698
- const configCustomVersion = await ((_b = (_a = operation.options).customVersion) == null ? void 0 : _b.call(_a, oldVersion, import_semver.default));
696
+ const next = getNextVersions(currentVersion, release.preid);
697
+ const configCustomVersion = await ((_b = (_a = operation.options).customVersion) == null ? void 0 : _b.call(_a, currentVersion, import_semver.default));
699
698
  const PADDING = 13;
700
699
  const answers = await (0, import_prompts.default)([
701
700
  {
702
701
  type: "autocomplete",
703
702
  name: "release",
704
- message: `Current version ${import_picocolors.default.green(oldVersion)}`,
703
+ message: `Current version ${import_picocolors.default.green(currentVersion)}`,
705
704
  initial: configCustomVersion ? "config" : "next",
706
705
  choices: [
707
706
  { value: "major", title: `${"major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.major)}` },
@@ -714,7 +713,7 @@ async function promptForNewVersion(operation) {
714
713
  { value: "prepatch", title: `${"pre-patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.prepatch)}` },
715
714
  { value: "preminor", title: `${"pre-minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.preminor)}` },
716
715
  { value: "premajor", title: `${"pre-major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.premajor)}` },
717
- { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(oldVersion)}` },
716
+ { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(currentVersion)}` },
718
717
  { value: "custom", title: "custom ...".padStart(PADDING + 4, " ") }
719
718
  ]
720
719
  },
@@ -722,13 +721,13 @@ async function promptForNewVersion(operation) {
722
721
  type: (prev) => prev === "custom" ? "text" : null,
723
722
  name: "custom",
724
723
  message: "Enter the new version number:",
725
- initial: oldVersion,
724
+ initial: currentVersion,
726
725
  validate: (custom) => {
727
726
  return (0, import_semver.valid)(custom) ? true : "That's not a valid version number";
728
727
  }
729
728
  }
730
729
  ]);
731
- const newVersion = answers.release === "none" ? oldVersion : answers.release === "custom" ? (0, import_semver.clean)(answers.custom) : answers.release === "config" ? (0, import_semver.clean)(configCustomVersion) : next[answers.release];
730
+ const newVersion = answers.release === "none" ? currentVersion : answers.release === "custom" ? (0, import_semver.clean)(answers.custom) : answers.release === "config" ? (0, import_semver.clean)(configCustomVersion) : next[answers.release];
732
731
  if (!newVersion)
733
732
  import_node_process3.default.exit(1);
734
733
  switch (answers.release) {
@@ -742,7 +741,7 @@ async function promptForNewVersion(operation) {
742
741
  }
743
742
  }
744
743
 
745
- // src/get-old-version.ts
744
+ // src/get-current-version.ts
746
745
  var import_semver2 = require("semver");
747
746
 
748
747
  // src/fs.ts
@@ -916,8 +915,10 @@ function isOptionalString(value) {
916
915
  return value === null || type === "undefined" || type === "string";
917
916
  }
918
917
 
919
- // src/get-old-version.ts
920
- async function getOldVersion(operation) {
918
+ // src/get-current-version.ts
919
+ async function getCurrentVersion(operation) {
920
+ if (operation.state.currentVersion)
921
+ return operation;
921
922
  const { cwd, files } = operation.options;
922
923
  const filesToCheck = files.filter((file) => file.endsWith(".json"));
923
924
  if (!filesToCheck.includes("package.json"))
@@ -926,8 +927,8 @@ async function getOldVersion(operation) {
926
927
  const version2 = await readVersion(file, cwd);
927
928
  if (version2) {
928
929
  return operation.update({
929
- oldVersionSource: file,
930
- oldVersion: version2
930
+ currentVersionSource: file,
931
+ currentVersion: version2
931
932
  });
932
933
  }
933
934
  }
@@ -1017,7 +1018,7 @@ async function normalizeOptions(raw) {
1017
1018
  let release;
1018
1019
  if (!raw.release || raw.release === "prompt")
1019
1020
  release = { type: "prompt", preid };
1020
- else if (isReleaseType(raw.release))
1021
+ else if (isReleaseType(raw.release) || raw.release === "next")
1021
1022
  release = { type: raw.release, preid };
1022
1023
  else
1023
1024
  release = { type: "version", version: raw.release };
@@ -1066,7 +1067,8 @@ async function normalizeOptions(raw) {
1066
1067
  interface: ui,
1067
1068
  ignoreScripts,
1068
1069
  execute,
1069
- customVersion: raw.customVersion
1070
+ customVersion: raw.customVersion,
1071
+ currentVersion: raw.currentVersion
1070
1072
  };
1071
1073
  }
1072
1074
 
@@ -1081,8 +1083,8 @@ var Operation = class _Operation {
1081
1083
  */
1082
1084
  this.state = {
1083
1085
  release: void 0,
1084
- oldVersion: "",
1085
- oldVersionSource: "",
1086
+ currentVersion: "",
1087
+ currentVersionSource: "",
1086
1088
  newVersion: "",
1087
1089
  commitMessage: "",
1088
1090
  tagName: "",
@@ -1091,6 +1093,12 @@ var Operation = class _Operation {
1091
1093
  };
1092
1094
  this.options = options;
1093
1095
  this._progress = progress2;
1096
+ if (options.currentVersion) {
1097
+ this.update({
1098
+ currentVersion: options.currentVersion,
1099
+ currentVersionSource: "user"
1100
+ });
1101
+ }
1094
1102
  }
1095
1103
  /**
1096
1104
  * The results of the operation.
@@ -1100,7 +1108,7 @@ var Operation = class _Operation {
1100
1108
  const state = this.state;
1101
1109
  return {
1102
1110
  release: state.release,
1103
- oldVersion: state.oldVersion,
1111
+ currentVersion: state.currentVersion,
1104
1112
  newVersion: state.newVersion,
1105
1113
  commit: options.commit ? state.commitMessage : false,
1106
1114
  tag: options.tag ? state.tagName : false,
@@ -1188,9 +1196,8 @@ async function updateManifestFile(relPath, operation) {
1188
1196
  const file = await readJsonFile(relPath, cwd);
1189
1197
  if (isManifest(file.data) && file.data.version !== newVersion) {
1190
1198
  file.data.version = newVersion;
1191
- if (isPackageLockManifest(file.data)) {
1199
+ if (isPackageLockManifest(file.data))
1192
1200
  file.data.packages[""].version = newVersion;
1193
- }
1194
1201
  await writeJsonFile(file);
1195
1202
  modified = true;
1196
1203
  }
@@ -1198,11 +1205,11 @@ async function updateManifestFile(relPath, operation) {
1198
1205
  }
1199
1206
  async function updateTextFile(relPath, operation) {
1200
1207
  const { cwd } = operation.options;
1201
- const { oldVersion, newVersion } = operation.state;
1208
+ const { currentVersion, newVersion } = operation.state;
1202
1209
  const modified = false;
1203
1210
  const file = await readTextFile(relPath, cwd);
1204
- if (file.data.includes(oldVersion)) {
1205
- const sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
1211
+ if (file.data.includes(currentVersion)) {
1212
+ const sanitizedVersion = currentVersion.replace(/(\W)/g, "\\$1");
1206
1213
  const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
1207
1214
  file.data = file.data.replace(replacePattern, `$1${newVersion}`);
1208
1215
  await writeTextFile(file);
@@ -1216,7 +1223,7 @@ async function versionBump(arg = {}) {
1216
1223
  if (typeof arg === "string")
1217
1224
  arg = { release: arg };
1218
1225
  const operation = await Operation.start(arg);
1219
- await getOldVersion(operation);
1226
+ await getCurrentVersion(operation);
1220
1227
  await getNewVersion(operation);
1221
1228
  if (arg.confirm) {
1222
1229
  printSummary(operation);
@@ -1254,7 +1261,7 @@ function printSummary(operation) {
1254
1261
  if (operation.options.push)
1255
1262
  console.log(` push ${import_picocolors2.default.cyan(import_picocolors2.default.bold("yes"))}`);
1256
1263
  console.log();
1257
- console.log(` from ${import_picocolors2.default.bold(operation.state.oldVersion)}`);
1264
+ console.log(` from ${import_picocolors2.default.bold(operation.state.currentVersion)}`);
1258
1265
  console.log(` to ${import_picocolors2.default.green(import_picocolors2.default.bold(operation.state.newVersion))}`);
1259
1266
  console.log();
1260
1267
  }
@@ -1270,7 +1277,9 @@ var import_js_yaml = __toESM(require("js-yaml"));
1270
1277
 
1271
1278
  // src/config.ts
1272
1279
  var import_node_process6 = __toESM(require("process"));
1280
+ var import_node_path2 = require("path");
1273
1281
  var import_c12 = require("c12");
1282
+ var import_sync = __toESM(require("escalade/sync"));
1274
1283
  var bumpConfigDefaults = {
1275
1284
  commit: true,
1276
1285
  push: true,
@@ -1283,37 +1292,62 @@ var bumpConfigDefaults = {
1283
1292
  files: []
1284
1293
  };
1285
1294
  async function loadBumpConfig(overrides, cwd = import_node_process6.default.cwd()) {
1295
+ const name = "bump";
1296
+ const configFile = findConfigFile(name, cwd);
1286
1297
  const { config } = await (0, import_c12.loadConfig)({
1287
- name: "bump",
1298
+ name,
1288
1299
  defaults: bumpConfigDefaults,
1289
1300
  overrides: __spreadValues({}, overrides),
1290
- cwd
1301
+ cwd: configFile ? (0, import_node_path2.dirname)(configFile) : cwd
1291
1302
  });
1292
1303
  return config;
1293
1304
  }
1305
+ function findConfigFile(name, cwd) {
1306
+ let foundRepositoryRoot = false;
1307
+ try {
1308
+ const candidates = ["js", "mjs", "ts", "mts", "json"].map((ext) => `${name}.config.${ext}`);
1309
+ return (0, import_sync.default)(cwd, (_dir, files) => {
1310
+ const match = files.find((file) => {
1311
+ if (candidates.includes(file))
1312
+ return true;
1313
+ if (file === ".git")
1314
+ foundRepositoryRoot = true;
1315
+ return false;
1316
+ });
1317
+ if (match)
1318
+ return match;
1319
+ if (foundRepositoryRoot) {
1320
+ throw null;
1321
+ }
1322
+ return false;
1323
+ });
1324
+ } catch (error) {
1325
+ if (foundRepositoryRoot)
1326
+ return null;
1327
+ throw error;
1328
+ }
1329
+ }
1294
1330
 
1295
1331
  // src/cli/parse-args.ts
1296
1332
  async function parseArgs() {
1297
1333
  var _a;
1298
1334
  try {
1299
- const cli = (0, import_cac.default)("bumpp");
1300
- cli.version(version).usage("[...files]").option("--preid <preid>", "ID for prerelease").option("--all", `Include all files (default: ${bumpConfigDefaults.all})`).option("-c, --commit [msg]", `Commit message (default: ${bumpConfigDefaults.commit})`).option("--no-commit", "Skip commit").option("-t, --tag [tag]", `Tag name (default: ${bumpConfigDefaults.tag})`).option("--no-tag", "Skip tag").option("-p, --push", `Push to remote (default: ${bumpConfigDefaults.push})`).option("-y, --yes", `Skip confirmation (default: ${!bumpConfigDefaults.confirm})`).option("-r, --recursive", `Bump package.json files recursively (default: ${bumpConfigDefaults.recursive})`).option("--no-verify", "Skip git verification").option("--ignore-scripts", `Ignore scripts (default: ${bumpConfigDefaults.ignoreScripts})`).option("-q, --quiet", "Quiet mode").option("-v, --version <version>", "Target version").option("-x, --execute <command>", "Commands to execute after version bumps").help();
1301
- const result = cli.parse();
1302
- const args = result.options;
1335
+ const { args, resultArgs } = loadCliArgs();
1303
1336
  const parsedArgs = {
1304
1337
  help: args.help,
1305
1338
  version: args.version,
1306
1339
  quiet: args.quiet,
1307
1340
  options: await loadBumpConfig({
1308
1341
  preid: args.preid,
1309
- commit: !args.noCommit && args.commit,
1310
- tag: !args.noTag && args.tag,
1342
+ commit: args.commit,
1343
+ tag: args.tag,
1311
1344
  push: args.push,
1312
1345
  all: args.all,
1313
1346
  confirm: !args.yes,
1314
1347
  noVerify: !args.verify,
1315
- files: [...args["--"] || [], ...result.args],
1348
+ files: [...args["--"] || [], ...resultArgs],
1316
1349
  ignoreScripts: args.ignoreScripts,
1350
+ currentVersion: args.currentVersion,
1317
1351
  execute: args.execute,
1318
1352
  recursive: !!args.recursive
1319
1353
  })
@@ -1353,6 +1387,23 @@ async function parseArgs() {
1353
1387
  return errorHandler(error);
1354
1388
  }
1355
1389
  }
1390
+ function loadCliArgs(argv = import_node_process7.default.argv) {
1391
+ const cli = (0, import_cac.default)("bumpp");
1392
+ cli.version(version).usage("[...files]").option("--preid <preid>", "ID for prerelease").option("--all", `Include all files (default: ${bumpConfigDefaults.all})`).option("-c, --commit [msg]", "Commit message", { default: true }).option("--no-commit", "Skip commit", { default: false }).option("-t, --tag [tag]", "Tag name", { default: true }).option("--no-tag", "Skip tag", { default: false }).option("-p, --push", `Push to remote (default: ${bumpConfigDefaults.push})`).option("-y, --yes", `Skip confirmation (default: ${!bumpConfigDefaults.confirm})`).option("-r, --recursive", `Bump package.json files recursively (default: ${bumpConfigDefaults.recursive})`).option("--no-verify", "Skip git verification").option("--ignore-scripts", `Ignore scripts (default: ${bumpConfigDefaults.ignoreScripts})`).option("-q, --quiet", "Quiet mode").option("-v, --version <version>", "Target version").option("--current-version <version>", "Current version").option("-x, --execute <command>", "Commands to execute after version bumps").help();
1393
+ const result = cli.parse(argv);
1394
+ const rawArgs = cli.rawArgs;
1395
+ const args = result.options;
1396
+ const hasCommitFlag = rawArgs.some((arg) => ["-c", "--commit", "--no-commit"].includes(arg));
1397
+ const hasTagFlag = rawArgs.some((arg) => ["-t", "--tag", "--no-tag"].includes(arg));
1398
+ const _a = args, { tag, commit } = _a, rest = __objRest(_a, ["tag", "commit"]);
1399
+ return {
1400
+ args: __spreadProps(__spreadValues({}, rest), {
1401
+ commit: hasCommitFlag ? commit : void 0,
1402
+ tag: hasTagFlag ? tag : void 0
1403
+ }),
1404
+ resultArgs: result.args
1405
+ };
1406
+ }
1356
1407
  function errorHandler(error) {
1357
1408
  console.error(error.message);
1358
1409
  return import_node_process7.default.exit(9 /* InvalidArgument */);
@@ -1,5 +1,8 @@
1
1
  import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url);
2
2
  import {
3
+ __objRest,
4
+ __spreadProps,
5
+ __spreadValues,
3
6
  __toESM,
4
7
  bumpConfigDefaults,
5
8
  isReleaseType,
@@ -7,13 +10,13 @@ import {
7
10
  log_symbols_default,
8
11
  require_picocolors,
9
12
  versionBump
10
- } from "../chunk-2LHJGPFO.mjs";
13
+ } from "../chunk-OMAU23UL.mjs";
11
14
 
12
15
  // src/cli/index.ts
13
16
  import process2 from "process";
14
17
 
15
18
  // package.json
16
- var version = "9.3.1";
19
+ var version = "9.4.0";
17
20
 
18
21
  // src/cli/parse-args.ts
19
22
  var import_picocolors = __toESM(require_picocolors());
@@ -26,24 +29,22 @@ import yaml from "js-yaml";
26
29
  async function parseArgs() {
27
30
  var _a;
28
31
  try {
29
- const cli = cac("bumpp");
30
- cli.version(version).usage("[...files]").option("--preid <preid>", "ID for prerelease").option("--all", `Include all files (default: ${bumpConfigDefaults.all})`).option("-c, --commit [msg]", `Commit message (default: ${bumpConfigDefaults.commit})`).option("--no-commit", "Skip commit").option("-t, --tag [tag]", `Tag name (default: ${bumpConfigDefaults.tag})`).option("--no-tag", "Skip tag").option("-p, --push", `Push to remote (default: ${bumpConfigDefaults.push})`).option("-y, --yes", `Skip confirmation (default: ${!bumpConfigDefaults.confirm})`).option("-r, --recursive", `Bump package.json files recursively (default: ${bumpConfigDefaults.recursive})`).option("--no-verify", "Skip git verification").option("--ignore-scripts", `Ignore scripts (default: ${bumpConfigDefaults.ignoreScripts})`).option("-q, --quiet", "Quiet mode").option("-v, --version <version>", "Target version").option("-x, --execute <command>", "Commands to execute after version bumps").help();
31
- const result = cli.parse();
32
- const args = result.options;
32
+ const { args, resultArgs } = loadCliArgs();
33
33
  const parsedArgs = {
34
34
  help: args.help,
35
35
  version: args.version,
36
36
  quiet: args.quiet,
37
37
  options: await loadBumpConfig({
38
38
  preid: args.preid,
39
- commit: !args.noCommit && args.commit,
40
- tag: !args.noTag && args.tag,
39
+ commit: args.commit,
40
+ tag: args.tag,
41
41
  push: args.push,
42
42
  all: args.all,
43
43
  confirm: !args.yes,
44
44
  noVerify: !args.verify,
45
- files: [...args["--"] || [], ...result.args],
45
+ files: [...args["--"] || [], ...resultArgs],
46
46
  ignoreScripts: args.ignoreScripts,
47
+ currentVersion: args.currentVersion,
47
48
  execute: args.execute,
48
49
  recursive: !!args.recursive
49
50
  })
@@ -83,6 +84,23 @@ async function parseArgs() {
83
84
  return errorHandler(error);
84
85
  }
85
86
  }
87
+ function loadCliArgs(argv = process.argv) {
88
+ const cli = cac("bumpp");
89
+ cli.version(version).usage("[...files]").option("--preid <preid>", "ID for prerelease").option("--all", `Include all files (default: ${bumpConfigDefaults.all})`).option("-c, --commit [msg]", "Commit message", { default: true }).option("--no-commit", "Skip commit", { default: false }).option("-t, --tag [tag]", "Tag name", { default: true }).option("--no-tag", "Skip tag", { default: false }).option("-p, --push", `Push to remote (default: ${bumpConfigDefaults.push})`).option("-y, --yes", `Skip confirmation (default: ${!bumpConfigDefaults.confirm})`).option("-r, --recursive", `Bump package.json files recursively (default: ${bumpConfigDefaults.recursive})`).option("--no-verify", "Skip git verification").option("--ignore-scripts", `Ignore scripts (default: ${bumpConfigDefaults.ignoreScripts})`).option("-q, --quiet", "Quiet mode").option("-v, --version <version>", "Target version").option("--current-version <version>", "Current version").option("-x, --execute <command>", "Commands to execute after version bumps").help();
90
+ const result = cli.parse(argv);
91
+ const rawArgs = cli.rawArgs;
92
+ const args = result.options;
93
+ const hasCommitFlag = rawArgs.some((arg) => ["-c", "--commit", "--no-commit"].includes(arg));
94
+ const hasTagFlag = rawArgs.some((arg) => ["-t", "--tag", "--no-tag"].includes(arg));
95
+ const _a = args, { tag, commit } = _a, rest = __objRest(_a, ["tag", "commit"]);
96
+ return {
97
+ args: __spreadProps(__spreadValues({}, rest), {
98
+ commit: hasCommitFlag ? commit : void 0,
99
+ tag: hasTagFlag ? tag : void 0
100
+ }),
101
+ resultArgs: result.args
102
+ };
103
+ }
86
104
  function errorHandler(error) {
87
105
  console.error(error.message);
88
106
  return process.exit(9 /* InvalidArgument */);
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import _semver, { ReleaseType } from 'semver';
2
- export { ReleaseType } from 'semver';
1
+ import _semver, { ReleaseType as ReleaseType$1 } from 'semver';
2
+
3
+ type ReleaseType = ReleaseType$1 | 'next';
3
4
 
4
5
  /**
5
6
  * Information about the work that was performed by the `versionBump()` function.
@@ -12,7 +13,7 @@ interface VersionBumpResults {
12
13
  /**
13
14
  * The previous version number in package.json.
14
15
  */
15
- oldVersion: string;
16
+ currentVersion: string;
16
17
  /**
17
18
  * The new version number.
18
19
  */
@@ -82,6 +83,11 @@ interface VersionBumpOptions {
82
83
  * Defaults to "prompt".
83
84
  */
84
85
  release?: string;
86
+ /**
87
+ * The current version number to be bumpped.
88
+ * If not provide, it will be read from the first file in the `files` array.
89
+ */
90
+ currentVersion?: string;
85
91
  /**
86
92
  * The prerelease type (e.g. "alpha", "beta", "next").
87
93
  *
@@ -165,7 +171,7 @@ interface VersionBumpOptions {
165
171
  /**
166
172
  * A callback that is provides information about the progress of the `versionBump()` function.
167
173
  */
168
- progress?(progress: VersionBumpProgress): void;
174
+ progress?: (progress: VersionBumpProgress) => void;
169
175
  /**
170
176
  * Excute additional command after bumping and before commiting
171
177
  */
@@ -263,12 +269,13 @@ interface NormalizedOptions {
263
269
  ignoreScripts: boolean;
264
270
  execute?: string;
265
271
  customVersion?: VersionBumpOptions['customVersion'];
272
+ currentVersion?: string;
266
273
  }
267
274
 
268
275
  interface OperationState {
269
276
  release: ReleaseType | undefined;
270
- oldVersionSource: string;
271
- oldVersion: string;
277
+ currentVersionSource: string;
278
+ currentVersion: string;
272
279
  newVersion: string;
273
280
  commitMessage: string;
274
281
  tagName: string;
@@ -344,4 +351,4 @@ declare const bumpConfigDefaults: VersionBumpOptions;
344
351
  declare function loadBumpConfig(overrides?: Partial<VersionBumpOptions>, cwd?: string): Promise<VersionBumpOptions>;
345
352
  declare function defineConfig(config: Partial<VersionBumpOptions>): Partial<VersionBumpOptions>;
346
353
 
347
- export { type InterfaceOptions, NpmScript, ProgressEvent, type VersionBumpOptions, type VersionBumpProgress, type VersionBumpResults, bumpConfigDefaults, versionBump as default, defineConfig, loadBumpConfig, versionBump, versionBumpInfo };
354
+ export { type InterfaceOptions, NpmScript, ProgressEvent, type ReleaseType, type VersionBumpOptions, type VersionBumpProgress, type VersionBumpResults, bumpConfigDefaults, versionBump as default, defineConfig, loadBumpConfig, versionBump, versionBumpInfo };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import _semver, { ReleaseType } from 'semver';
2
- export { ReleaseType } from 'semver';
1
+ import _semver, { ReleaseType as ReleaseType$1 } from 'semver';
2
+
3
+ type ReleaseType = ReleaseType$1 | 'next';
3
4
 
4
5
  /**
5
6
  * Information about the work that was performed by the `versionBump()` function.
@@ -12,7 +13,7 @@ interface VersionBumpResults {
12
13
  /**
13
14
  * The previous version number in package.json.
14
15
  */
15
- oldVersion: string;
16
+ currentVersion: string;
16
17
  /**
17
18
  * The new version number.
18
19
  */
@@ -82,6 +83,11 @@ interface VersionBumpOptions {
82
83
  * Defaults to "prompt".
83
84
  */
84
85
  release?: string;
86
+ /**
87
+ * The current version number to be bumpped.
88
+ * If not provide, it will be read from the first file in the `files` array.
89
+ */
90
+ currentVersion?: string;
85
91
  /**
86
92
  * The prerelease type (e.g. "alpha", "beta", "next").
87
93
  *
@@ -165,7 +171,7 @@ interface VersionBumpOptions {
165
171
  /**
166
172
  * A callback that is provides information about the progress of the `versionBump()` function.
167
173
  */
168
- progress?(progress: VersionBumpProgress): void;
174
+ progress?: (progress: VersionBumpProgress) => void;
169
175
  /**
170
176
  * Excute additional command after bumping and before commiting
171
177
  */
@@ -263,12 +269,13 @@ interface NormalizedOptions {
263
269
  ignoreScripts: boolean;
264
270
  execute?: string;
265
271
  customVersion?: VersionBumpOptions['customVersion'];
272
+ currentVersion?: string;
266
273
  }
267
274
 
268
275
  interface OperationState {
269
276
  release: ReleaseType | undefined;
270
- oldVersionSource: string;
271
- oldVersion: string;
277
+ currentVersionSource: string;
278
+ currentVersion: string;
272
279
  newVersion: string;
273
280
  commitMessage: string;
274
281
  tagName: string;
@@ -344,4 +351,4 @@ declare const bumpConfigDefaults: VersionBumpOptions;
344
351
  declare function loadBumpConfig(overrides?: Partial<VersionBumpOptions>, cwd?: string): Promise<VersionBumpOptions>;
345
352
  declare function defineConfig(config: Partial<VersionBumpOptions>): Partial<VersionBumpOptions>;
346
353
 
347
- export { type InterfaceOptions, NpmScript, ProgressEvent, type VersionBumpOptions, type VersionBumpProgress, type VersionBumpResults, bumpConfigDefaults, versionBump as default, defineConfig, loadBumpConfig, versionBump, versionBumpInfo };
354
+ export { type InterfaceOptions, NpmScript, ProgressEvent, type ReleaseType, type VersionBumpOptions, type VersionBumpProgress, type VersionBumpResults, bumpConfigDefaults, versionBump as default, defineConfig, loadBumpConfig, versionBump, versionBumpInfo };
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
60
60
 
61
61
  // node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js
62
62
  var require_picocolors = __commonJS({
63
- "node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js"(exports, module2) {
63
+ "node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js"(exports2, module2) {
64
64
  var tty2 = require("tty");
65
65
  var isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty2.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
66
66
  var formatter = (open, close, replace = open) => (input) => {
@@ -649,7 +649,7 @@ var import_semver = __toESM(require("semver"));
649
649
 
650
650
  // src/release-type.ts
651
651
  var prereleaseTypes = ["premajor", "preminor", "prepatch", "prerelease"];
652
- var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch"]);
652
+ var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch", "next"]);
653
653
  function isPrerelease(value) {
654
654
  return prereleaseTypes.includes(value);
655
655
  }
@@ -660,7 +660,7 @@ function isReleaseType(value) {
660
660
  // src/get-new-version.ts
661
661
  async function getNewVersion(operation) {
662
662
  const { release } = operation.options;
663
- const { oldVersion } = operation.state;
663
+ const { currentVersion } = operation.state;
664
664
  switch (release.type) {
665
665
  case "prompt":
666
666
  return promptForNewVersion(operation);
@@ -671,42 +671,41 @@ async function getNewVersion(operation) {
671
671
  default:
672
672
  return operation.update({
673
673
  release: release.type,
674
- newVersion: getNextVersion(oldVersion, release)
674
+ newVersion: getNextVersion(currentVersion, release)
675
675
  });
676
676
  }
677
677
  }
678
- function getNextVersion(oldVersion, bump) {
679
- const oldSemVer = new import_semver.SemVer(oldVersion);
680
- const newSemVer = oldSemVer.inc(bump.type, bump.preid);
678
+ function getNextVersion(currentVersion, bump) {
679
+ const oldSemVer = new import_semver.SemVer(currentVersion);
680
+ const type = bump.type === "next" ? oldSemVer.prerelease.length ? "prerelease" : "patch" : bump.type;
681
+ const newSemVer = oldSemVer.inc(type, bump.preid);
681
682
  if (isPrerelease(bump.type) && newSemVer.prerelease.length === 2 && newSemVer.prerelease[0] === bump.preid && String(newSemVer.prerelease[1]) === "0") {
682
683
  newSemVer.prerelease[1] = "1";
683
684
  newSemVer.format();
684
685
  }
685
686
  return newSemVer.version;
686
687
  }
687
- function getNextVersions(oldVersion, preid) {
688
- var _a;
688
+ function getNextVersions(currentVersion, preid) {
689
689
  const next = {};
690
- const parse = import_semver.default.parse(oldVersion);
690
+ const parse = import_semver.default.parse(currentVersion);
691
691
  if (typeof (parse == null ? void 0 : parse.prerelease[0]) === "string")
692
692
  preid = (parse == null ? void 0 : parse.prerelease[0]) || "preid";
693
693
  for (const type of releaseTypes)
694
- next[type] = import_semver.default.inc(oldVersion, type, preid);
695
- next.next = ((_a = parse == null ? void 0 : parse.prerelease) == null ? void 0 : _a.length) ? import_semver.default.inc(oldVersion, "prerelease", preid) : import_semver.default.inc(oldVersion, "patch");
694
+ next[type] = getNextVersion(currentVersion, { type, preid });
696
695
  return next;
697
696
  }
698
697
  async function promptForNewVersion(operation) {
699
698
  var _a, _b;
700
- const { oldVersion } = operation.state;
699
+ const { currentVersion } = operation.state;
701
700
  const release = operation.options.release;
702
- const next = getNextVersions(oldVersion, release.preid);
703
- const configCustomVersion = await ((_b = (_a = operation.options).customVersion) == null ? void 0 : _b.call(_a, oldVersion, import_semver.default));
701
+ const next = getNextVersions(currentVersion, release.preid);
702
+ const configCustomVersion = await ((_b = (_a = operation.options).customVersion) == null ? void 0 : _b.call(_a, currentVersion, import_semver.default));
704
703
  const PADDING = 13;
705
704
  const answers = await (0, import_prompts.default)([
706
705
  {
707
706
  type: "autocomplete",
708
707
  name: "release",
709
- message: `Current version ${import_picocolors.default.green(oldVersion)}`,
708
+ message: `Current version ${import_picocolors.default.green(currentVersion)}`,
710
709
  initial: configCustomVersion ? "config" : "next",
711
710
  choices: [
712
711
  { value: "major", title: `${"major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.major)}` },
@@ -719,7 +718,7 @@ async function promptForNewVersion(operation) {
719
718
  { value: "prepatch", title: `${"pre-patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.prepatch)}` },
720
719
  { value: "preminor", title: `${"pre-minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.preminor)}` },
721
720
  { value: "premajor", title: `${"pre-major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.premajor)}` },
722
- { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(oldVersion)}` },
721
+ { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(currentVersion)}` },
723
722
  { value: "custom", title: "custom ...".padStart(PADDING + 4, " ") }
724
723
  ]
725
724
  },
@@ -727,13 +726,13 @@ async function promptForNewVersion(operation) {
727
726
  type: (prev) => prev === "custom" ? "text" : null,
728
727
  name: "custom",
729
728
  message: "Enter the new version number:",
730
- initial: oldVersion,
729
+ initial: currentVersion,
731
730
  validate: (custom) => {
732
731
  return (0, import_semver.valid)(custom) ? true : "That's not a valid version number";
733
732
  }
734
733
  }
735
734
  ]);
736
- const newVersion = answers.release === "none" ? oldVersion : answers.release === "custom" ? (0, import_semver.clean)(answers.custom) : answers.release === "config" ? (0, import_semver.clean)(configCustomVersion) : next[answers.release];
735
+ const newVersion = answers.release === "none" ? currentVersion : answers.release === "custom" ? (0, import_semver.clean)(answers.custom) : answers.release === "config" ? (0, import_semver.clean)(configCustomVersion) : next[answers.release];
737
736
  if (!newVersion)
738
737
  import_node_process3.default.exit(1);
739
738
  switch (answers.release) {
@@ -747,7 +746,7 @@ async function promptForNewVersion(operation) {
747
746
  }
748
747
  }
749
748
 
750
- // src/get-old-version.ts
749
+ // src/get-current-version.ts
751
750
  var import_semver2 = require("semver");
752
751
 
753
752
  // src/fs.ts
@@ -921,8 +920,10 @@ function isOptionalString(value) {
921
920
  return value === null || type === "undefined" || type === "string";
922
921
  }
923
922
 
924
- // src/get-old-version.ts
925
- async function getOldVersion(operation) {
923
+ // src/get-current-version.ts
924
+ async function getCurrentVersion(operation) {
925
+ if (operation.state.currentVersion)
926
+ return operation;
926
927
  const { cwd, files } = operation.options;
927
928
  const filesToCheck = files.filter((file) => file.endsWith(".json"));
928
929
  if (!filesToCheck.includes("package.json"))
@@ -931,8 +932,8 @@ async function getOldVersion(operation) {
931
932
  const version = await readVersion(file, cwd);
932
933
  if (version) {
933
934
  return operation.update({
934
- oldVersionSource: file,
935
- oldVersion: version
935
+ currentVersionSource: file,
936
+ currentVersion: version
936
937
  });
937
938
  }
938
939
  }
@@ -1041,7 +1042,7 @@ async function normalizeOptions(raw) {
1041
1042
  let release;
1042
1043
  if (!raw.release || raw.release === "prompt")
1043
1044
  release = { type: "prompt", preid };
1044
- else if (isReleaseType(raw.release))
1045
+ else if (isReleaseType(raw.release) || raw.release === "next")
1045
1046
  release = { type: raw.release, preid };
1046
1047
  else
1047
1048
  release = { type: "version", version: raw.release };
@@ -1090,7 +1091,8 @@ async function normalizeOptions(raw) {
1090
1091
  interface: ui,
1091
1092
  ignoreScripts,
1092
1093
  execute,
1093
- customVersion: raw.customVersion
1094
+ customVersion: raw.customVersion,
1095
+ currentVersion: raw.currentVersion
1094
1096
  };
1095
1097
  }
1096
1098
 
@@ -1105,8 +1107,8 @@ var Operation = class _Operation {
1105
1107
  */
1106
1108
  this.state = {
1107
1109
  release: void 0,
1108
- oldVersion: "",
1109
- oldVersionSource: "",
1110
+ currentVersion: "",
1111
+ currentVersionSource: "",
1110
1112
  newVersion: "",
1111
1113
  commitMessage: "",
1112
1114
  tagName: "",
@@ -1115,6 +1117,12 @@ var Operation = class _Operation {
1115
1117
  };
1116
1118
  this.options = options;
1117
1119
  this._progress = progress;
1120
+ if (options.currentVersion) {
1121
+ this.update({
1122
+ currentVersion: options.currentVersion,
1123
+ currentVersionSource: "user"
1124
+ });
1125
+ }
1118
1126
  }
1119
1127
  /**
1120
1128
  * The results of the operation.
@@ -1124,7 +1132,7 @@ var Operation = class _Operation {
1124
1132
  const state = this.state;
1125
1133
  return {
1126
1134
  release: state.release,
1127
- oldVersion: state.oldVersion,
1135
+ currentVersion: state.currentVersion,
1128
1136
  newVersion: state.newVersion,
1129
1137
  commit: options.commit ? state.commitMessage : false,
1130
1138
  tag: options.tag ? state.tagName : false,
@@ -1212,9 +1220,8 @@ async function updateManifestFile(relPath, operation) {
1212
1220
  const file = await readJsonFile(relPath, cwd);
1213
1221
  if (isManifest(file.data) && file.data.version !== newVersion) {
1214
1222
  file.data.version = newVersion;
1215
- if (isPackageLockManifest(file.data)) {
1223
+ if (isPackageLockManifest(file.data))
1216
1224
  file.data.packages[""].version = newVersion;
1217
- }
1218
1225
  await writeJsonFile(file);
1219
1226
  modified = true;
1220
1227
  }
@@ -1222,11 +1229,11 @@ async function updateManifestFile(relPath, operation) {
1222
1229
  }
1223
1230
  async function updateTextFile(relPath, operation) {
1224
1231
  const { cwd } = operation.options;
1225
- const { oldVersion, newVersion } = operation.state;
1232
+ const { currentVersion, newVersion } = operation.state;
1226
1233
  const modified = false;
1227
1234
  const file = await readTextFile(relPath, cwd);
1228
- if (file.data.includes(oldVersion)) {
1229
- const sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
1235
+ if (file.data.includes(currentVersion)) {
1236
+ const sanitizedVersion = currentVersion.replace(/(\W)/g, "\\$1");
1230
1237
  const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
1231
1238
  file.data = file.data.replace(replacePattern, `$1${newVersion}`);
1232
1239
  await writeTextFile(file);
@@ -1240,7 +1247,7 @@ async function versionBump(arg = {}) {
1240
1247
  if (typeof arg === "string")
1241
1248
  arg = { release: arg };
1242
1249
  const operation = await Operation.start(arg);
1243
- await getOldVersion(operation);
1250
+ await getCurrentVersion(operation);
1244
1251
  await getNewVersion(operation);
1245
1252
  if (arg.confirm) {
1246
1253
  printSummary(operation);
@@ -1278,7 +1285,7 @@ function printSummary(operation) {
1278
1285
  if (operation.options.push)
1279
1286
  console.log(` push ${import_picocolors2.default.cyan(import_picocolors2.default.bold("yes"))}`);
1280
1287
  console.log();
1281
- console.log(` from ${import_picocolors2.default.bold(operation.state.oldVersion)}`);
1288
+ console.log(` from ${import_picocolors2.default.bold(operation.state.currentVersion)}`);
1282
1289
  console.log(` to ${import_picocolors2.default.green(import_picocolors2.default.bold(operation.state.newVersion))}`);
1283
1290
  console.log();
1284
1291
  }
@@ -1286,14 +1293,16 @@ async function versionBumpInfo(arg = {}) {
1286
1293
  if (typeof arg === "string")
1287
1294
  arg = { release: arg };
1288
1295
  const operation = await Operation.start(arg);
1289
- await getOldVersion(operation);
1296
+ await getCurrentVersion(operation);
1290
1297
  await getNewVersion(operation);
1291
1298
  return operation;
1292
1299
  }
1293
1300
 
1294
1301
  // src/config.ts
1295
1302
  var import_node_process6 = __toESM(require("process"));
1303
+ var import_node_path2 = require("path");
1296
1304
  var import_c12 = require("c12");
1305
+ var import_sync = __toESM(require("escalade/sync"));
1297
1306
  var bumpConfigDefaults = {
1298
1307
  commit: true,
1299
1308
  push: true,
@@ -1306,14 +1315,41 @@ var bumpConfigDefaults = {
1306
1315
  files: []
1307
1316
  };
1308
1317
  async function loadBumpConfig(overrides, cwd = import_node_process6.default.cwd()) {
1318
+ const name = "bump";
1319
+ const configFile = findConfigFile(name, cwd);
1309
1320
  const { config } = await (0, import_c12.loadConfig)({
1310
- name: "bump",
1321
+ name,
1311
1322
  defaults: bumpConfigDefaults,
1312
1323
  overrides: __spreadValues({}, overrides),
1313
- cwd
1324
+ cwd: configFile ? (0, import_node_path2.dirname)(configFile) : cwd
1314
1325
  });
1315
1326
  return config;
1316
1327
  }
1328
+ function findConfigFile(name, cwd) {
1329
+ let foundRepositoryRoot = false;
1330
+ try {
1331
+ const candidates = ["js", "mjs", "ts", "mts", "json"].map((ext) => `${name}.config.${ext}`);
1332
+ return (0, import_sync.default)(cwd, (_dir, files) => {
1333
+ const match = files.find((file) => {
1334
+ if (candidates.includes(file))
1335
+ return true;
1336
+ if (file === ".git")
1337
+ foundRepositoryRoot = true;
1338
+ return false;
1339
+ });
1340
+ if (match)
1341
+ return match;
1342
+ if (foundRepositoryRoot) {
1343
+ throw null;
1344
+ }
1345
+ return false;
1346
+ });
1347
+ } catch (error) {
1348
+ if (foundRepositoryRoot)
1349
+ return null;
1350
+ throw error;
1351
+ }
1352
+ }
1317
1353
  function defineConfig(config) {
1318
1354
  return config;
1319
1355
  }
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  loadBumpConfig,
8
8
  versionBump,
9
9
  versionBumpInfo
10
- } from "./chunk-2LHJGPFO.mjs";
10
+ } from "./chunk-OMAU23UL.mjs";
11
11
 
12
12
  // src/index.ts
13
13
  var src_default = versionBump;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bumpp",
3
- "version": "9.3.1",
3
+ "version": "9.4.0",
4
4
  "packageManager": "pnpm@8.15.4",
5
5
  "description": "Bump version, commit changes, tag, and push to Git",
6
6
  "author": {
@@ -51,15 +51,18 @@
51
51
  "build": "tsup src/index.ts src/cli/index.ts --format esm,cjs --dts --clean",
52
52
  "watch": "npm run build -- --watch src",
53
53
  "start": "esno src/cli/run.ts",
54
+ "test": "vitest",
54
55
  "upgrade": "npm-check -u && npm audit fix",
55
56
  "bumpp": "esno src/cli/run.ts",
56
57
  "prepublishOnly": "npm run clean && npm run build",
57
- "release": "npm run bumpp && npm publish"
58
+ "release": "npm run bumpp && npm publish",
59
+ "typecheck": "tsc --noEmit"
58
60
  },
59
61
  "dependencies": {
60
62
  "@jsdevtools/ez-spawn": "^3.0.4",
61
63
  "c12": "^1.9.0",
62
64
  "cac": "^6.7.14",
65
+ "escalade": "^3.1.2",
63
66
  "fast-glob": "^3.3.2",
64
67
  "js-yaml": "^4.1.0",
65
68
  "prompts": "^2.4.2",
@@ -74,12 +77,13 @@
74
77
  "detect-indent": "^7.0.1",
75
78
  "detect-newline": "^4.0.1",
76
79
  "eslint": "^8.57.0",
77
- "esno": "^4.0.0",
80
+ "esno": "^4.7.0",
78
81
  "log-symbols": "^6.0.0",
79
82
  "npm-check": "^6.0.1",
80
83
  "picocolors": "^1.0.0",
81
84
  "rimraf": "^5.0.5",
82
85
  "tsup": "^8.0.2",
83
- "typescript": "^5.3.3"
86
+ "typescript": "^5.3.3",
87
+ "vitest": "^1.3.1"
84
88
  }
85
89
  }