版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

1307 строки
44 KiB

  1. var __create = Object.create;
  2. var __defProp = Object.defineProperty;
  3. var __defProps = Object.defineProperties;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  6. var __getOwnPropNames = Object.getOwnPropertyNames;
  7. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  8. var __getProtoOf = Object.getPrototypeOf;
  9. var __hasOwnProp = Object.prototype.hasOwnProperty;
  10. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  11. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  12. var __spreadValues = (a, b) => {
  13. for (var prop in b || (b = {}))
  14. if (__hasOwnProp.call(b, prop))
  15. __defNormalProp(a, prop, b[prop]);
  16. if (__getOwnPropSymbols)
  17. for (var prop of __getOwnPropSymbols(b)) {
  18. if (__propIsEnum.call(b, prop))
  19. __defNormalProp(a, prop, b[prop]);
  20. }
  21. return a;
  22. };
  23. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  24. var __objRest = (source, exclude) => {
  25. var target = {};
  26. for (var prop in source)
  27. if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
  28. target[prop] = source[prop];
  29. if (source != null && __getOwnPropSymbols)
  30. for (var prop of __getOwnPropSymbols(source)) {
  31. if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
  32. target[prop] = source[prop];
  33. }
  34. return target;
  35. };
  36. var __commonJS = (cb, mod) => function __require() {
  37. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  38. };
  39. var __export = (target, all) => {
  40. for (var name in all)
  41. __defProp(target, name, { get: all[name], enumerable: true });
  42. };
  43. var __copyProps = (to, from, except, desc) => {
  44. if (from && typeof from === "object" || typeof from === "function") {
  45. for (let key of __getOwnPropNames(from))
  46. if (!__hasOwnProp.call(to, key) && key !== except)
  47. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  48. }
  49. return to;
  50. };
  51. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  52. // If the importer is in node compatibility mode or this is not an ESM
  53. // file that has been converted to a CommonJS file using a Babel-
  54. // compatible transform (i.e. "__esModule" has not been set), then set
  55. // "default" to the CommonJS "module.exports" for node compatibility.
  56. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  57. mod
  58. ));
  59. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  60. // node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js
  61. var require_picocolors = __commonJS({
  62. "node_modules/.pnpm/picocolors@1.0.0/node_modules/picocolors/picocolors.js"(exports, module2) {
  63. var tty2 = require("tty");
  64. 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);
  65. var formatter = (open, close, replace = open) => (input) => {
  66. let string = "" + input;
  67. let index = string.indexOf(close, open.length);
  68. return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
  69. };
  70. var replaceClose = (string, close, replace, index) => {
  71. let start = string.substring(0, index) + replace;
  72. let end = string.substring(index + close.length);
  73. let nextIndex = end.indexOf(close);
  74. return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
  75. };
  76. var createColors = (enabled = isColorSupported) => ({
  77. isColorSupported: enabled,
  78. reset: enabled ? (s) => `\x1B[0m${s}\x1B[0m` : String,
  79. bold: enabled ? formatter("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m") : String,
  80. dim: enabled ? formatter("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m") : String,
  81. italic: enabled ? formatter("\x1B[3m", "\x1B[23m") : String,
  82. underline: enabled ? formatter("\x1B[4m", "\x1B[24m") : String,
  83. inverse: enabled ? formatter("\x1B[7m", "\x1B[27m") : String,
  84. hidden: enabled ? formatter("\x1B[8m", "\x1B[28m") : String,
  85. strikethrough: enabled ? formatter("\x1B[9m", "\x1B[29m") : String,
  86. black: enabled ? formatter("\x1B[30m", "\x1B[39m") : String,
  87. red: enabled ? formatter("\x1B[31m", "\x1B[39m") : String,
  88. green: enabled ? formatter("\x1B[32m", "\x1B[39m") : String,
  89. yellow: enabled ? formatter("\x1B[33m", "\x1B[39m") : String,
  90. blue: enabled ? formatter("\x1B[34m", "\x1B[39m") : String,
  91. magenta: enabled ? formatter("\x1B[35m", "\x1B[39m") : String,
  92. cyan: enabled ? formatter("\x1B[36m", "\x1B[39m") : String,
  93. white: enabled ? formatter("\x1B[37m", "\x1B[39m") : String,
  94. gray: enabled ? formatter("\x1B[90m", "\x1B[39m") : String,
  95. bgBlack: enabled ? formatter("\x1B[40m", "\x1B[49m") : String,
  96. bgRed: enabled ? formatter("\x1B[41m", "\x1B[49m") : String,
  97. bgGreen: enabled ? formatter("\x1B[42m", "\x1B[49m") : String,
  98. bgYellow: enabled ? formatter("\x1B[43m", "\x1B[49m") : String,
  99. bgBlue: enabled ? formatter("\x1B[44m", "\x1B[49m") : String,
  100. bgMagenta: enabled ? formatter("\x1B[45m", "\x1B[49m") : String,
  101. bgCyan: enabled ? formatter("\x1B[46m", "\x1B[49m") : String,
  102. bgWhite: enabled ? formatter("\x1B[47m", "\x1B[49m") : String
  103. });
  104. module2.exports = createColors();
  105. module2.exports.createColors = createColors;
  106. }
  107. });
  108. // src/index.ts
  109. var src_exports = {};
  110. __export(src_exports, {
  111. NpmScript: () => NpmScript,
  112. ProgressEvent: () => ProgressEvent,
  113. ReleaseType: () => import_semver.ReleaseType,
  114. bumpConfigDefaults: () => bumpConfigDefaults,
  115. default: () => src_default,
  116. defineConfig: () => defineConfig,
  117. loadBumpConfig: () => loadBumpConfig,
  118. versionBump: () => versionBump,
  119. versionBumpInfo: () => versionBumpInfo
  120. });
  121. module.exports = __toCommonJS(src_exports);
  122. // src/version-bump.ts
  123. var ezSpawn3 = __toESM(require("@jsdevtools/ez-spawn"));
  124. var import_picocolors2 = __toESM(require_picocolors());
  125. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/ansi-styles/index.js
  126. var ANSI_BACKGROUND_OFFSET = 10;
  127. var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
  128. var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
  129. var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
  130. var styles = {
  131. modifier: {
  132. reset: [0, 0],
  133. // 21 isn't widely supported and 22 does the same thing
  134. bold: [1, 22],
  135. dim: [2, 22],
  136. italic: [3, 23],
  137. underline: [4, 24],
  138. overline: [53, 55],
  139. inverse: [7, 27],
  140. hidden: [8, 28],
  141. strikethrough: [9, 29]
  142. },
  143. color: {
  144. black: [30, 39],
  145. red: [31, 39],
  146. green: [32, 39],
  147. yellow: [33, 39],
  148. blue: [34, 39],
  149. magenta: [35, 39],
  150. cyan: [36, 39],
  151. white: [37, 39],
  152. // Bright color
  153. blackBright: [90, 39],
  154. gray: [90, 39],
  155. // Alias of `blackBright`
  156. grey: [90, 39],
  157. // Alias of `blackBright`
  158. redBright: [91, 39],
  159. greenBright: [92, 39],
  160. yellowBright: [93, 39],
  161. blueBright: [94, 39],
  162. magentaBright: [95, 39],
  163. cyanBright: [96, 39],
  164. whiteBright: [97, 39]
  165. },
  166. bgColor: {
  167. bgBlack: [40, 49],
  168. bgRed: [41, 49],
  169. bgGreen: [42, 49],
  170. bgYellow: [43, 49],
  171. bgBlue: [44, 49],
  172. bgMagenta: [45, 49],
  173. bgCyan: [46, 49],
  174. bgWhite: [47, 49],
  175. // Bright color
  176. bgBlackBright: [100, 49],
  177. bgGray: [100, 49],
  178. // Alias of `bgBlackBright`
  179. bgGrey: [100, 49],
  180. // Alias of `bgBlackBright`
  181. bgRedBright: [101, 49],
  182. bgGreenBright: [102, 49],
  183. bgYellowBright: [103, 49],
  184. bgBlueBright: [104, 49],
  185. bgMagentaBright: [105, 49],
  186. bgCyanBright: [106, 49],
  187. bgWhiteBright: [107, 49]
  188. }
  189. };
  190. var modifierNames = Object.keys(styles.modifier);
  191. var foregroundColorNames = Object.keys(styles.color);
  192. var backgroundColorNames = Object.keys(styles.bgColor);
  193. var colorNames = [...foregroundColorNames, ...backgroundColorNames];
  194. function assembleStyles() {
  195. const codes = /* @__PURE__ */ new Map();
  196. for (const [groupName, group] of Object.entries(styles)) {
  197. for (const [styleName, style] of Object.entries(group)) {
  198. styles[styleName] = {
  199. open: `\x1B[${style[0]}m`,
  200. close: `\x1B[${style[1]}m`
  201. };
  202. group[styleName] = styles[styleName];
  203. codes.set(style[0], style[1]);
  204. }
  205. Object.defineProperty(styles, groupName, {
  206. value: group,
  207. enumerable: false
  208. });
  209. }
  210. Object.defineProperty(styles, "codes", {
  211. value: codes,
  212. enumerable: false
  213. });
  214. styles.color.close = "\x1B[39m";
  215. styles.bgColor.close = "\x1B[49m";
  216. styles.color.ansi = wrapAnsi16();
  217. styles.color.ansi256 = wrapAnsi256();
  218. styles.color.ansi16m = wrapAnsi16m();
  219. styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
  220. styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
  221. styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
  222. Object.defineProperties(styles, {
  223. rgbToAnsi256: {
  224. value(red, green, blue) {
  225. if (red === green && green === blue) {
  226. if (red < 8) {
  227. return 16;
  228. }
  229. if (red > 248) {
  230. return 231;
  231. }
  232. return Math.round((red - 8) / 247 * 24) + 232;
  233. }
  234. return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
  235. },
  236. enumerable: false
  237. },
  238. hexToRgb: {
  239. value(hex) {
  240. const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
  241. if (!matches) {
  242. return [0, 0, 0];
  243. }
  244. let [colorString] = matches;
  245. if (colorString.length === 3) {
  246. colorString = [...colorString].map((character) => character + character).join("");
  247. }
  248. const integer = Number.parseInt(colorString, 16);
  249. return [
  250. /* eslint-disable no-bitwise */
  251. integer >> 16 & 255,
  252. integer >> 8 & 255,
  253. integer & 255
  254. /* eslint-enable no-bitwise */
  255. ];
  256. },
  257. enumerable: false
  258. },
  259. hexToAnsi256: {
  260. value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
  261. enumerable: false
  262. },
  263. ansi256ToAnsi: {
  264. value(code) {
  265. if (code < 8) {
  266. return 30 + code;
  267. }
  268. if (code < 16) {
  269. return 90 + (code - 8);
  270. }
  271. let red;
  272. let green;
  273. let blue;
  274. if (code >= 232) {
  275. red = ((code - 232) * 10 + 8) / 255;
  276. green = red;
  277. blue = red;
  278. } else {
  279. code -= 16;
  280. const remainder = code % 36;
  281. red = Math.floor(code / 36) / 5;
  282. green = Math.floor(remainder / 6) / 5;
  283. blue = remainder % 6 / 5;
  284. }
  285. const value = Math.max(red, green, blue) * 2;
  286. if (value === 0) {
  287. return 30;
  288. }
  289. let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
  290. if (value === 2) {
  291. result += 60;
  292. }
  293. return result;
  294. },
  295. enumerable: false
  296. },
  297. rgbToAnsi: {
  298. value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
  299. enumerable: false
  300. },
  301. hexToAnsi: {
  302. value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
  303. enumerable: false
  304. }
  305. });
  306. return styles;
  307. }
  308. var ansiStyles = assembleStyles();
  309. var ansi_styles_default = ansiStyles;
  310. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/supports-color/index.js
  311. var import_node_process = __toESM(require("process"), 1);
  312. var import_node_os = __toESM(require("os"), 1);
  313. var import_node_tty = __toESM(require("tty"), 1);
  314. function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
  315. const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
  316. const position = argv.indexOf(prefix + flag);
  317. const terminatorPosition = argv.indexOf("--");
  318. return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
  319. }
  320. var { env } = import_node_process.default;
  321. var flagForceColor;
  322. if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
  323. flagForceColor = 0;
  324. } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
  325. flagForceColor = 1;
  326. }
  327. function envForceColor() {
  328. if ("FORCE_COLOR" in env) {
  329. if (env.FORCE_COLOR === "true") {
  330. return 1;
  331. }
  332. if (env.FORCE_COLOR === "false") {
  333. return 0;
  334. }
  335. return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
  336. }
  337. }
  338. function translateLevel(level) {
  339. if (level === 0) {
  340. return false;
  341. }
  342. return {
  343. level,
  344. hasBasic: true,
  345. has256: level >= 2,
  346. has16m: level >= 3
  347. };
  348. }
  349. function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
  350. const noFlagForceColor = envForceColor();
  351. if (noFlagForceColor !== void 0) {
  352. flagForceColor = noFlagForceColor;
  353. }
  354. const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
  355. if (forceColor === 0) {
  356. return 0;
  357. }
  358. if (sniffFlags) {
  359. if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
  360. return 3;
  361. }
  362. if (hasFlag("color=256")) {
  363. return 2;
  364. }
  365. }
  366. if ("TF_BUILD" in env && "AGENT_NAME" in env) {
  367. return 1;
  368. }
  369. if (haveStream && !streamIsTTY && forceColor === void 0) {
  370. return 0;
  371. }
  372. const min = forceColor || 0;
  373. if (env.TERM === "dumb") {
  374. return min;
  375. }
  376. if (import_node_process.default.platform === "win32") {
  377. const osRelease = import_node_os.default.release().split(".");
  378. if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  379. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  380. }
  381. return 1;
  382. }
  383. if ("CI" in env) {
  384. if ("GITHUB_ACTIONS" in env) {
  385. return 3;
  386. }
  387. if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
  388. return 1;
  389. }
  390. return min;
  391. }
  392. if ("TEAMCITY_VERSION" in env) {
  393. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  394. }
  395. if (env.COLORTERM === "truecolor") {
  396. return 3;
  397. }
  398. if (env.TERM === "xterm-kitty") {
  399. return 3;
  400. }
  401. if ("TERM_PROGRAM" in env) {
  402. const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
  403. switch (env.TERM_PROGRAM) {
  404. case "iTerm.app": {
  405. return version >= 3 ? 3 : 2;
  406. }
  407. case "Apple_Terminal": {
  408. return 2;
  409. }
  410. }
  411. }
  412. if (/-256(color)?$/i.test(env.TERM)) {
  413. return 2;
  414. }
  415. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  416. return 1;
  417. }
  418. if ("COLORTERM" in env) {
  419. return 1;
  420. }
  421. return min;
  422. }
  423. function createSupportsColor(stream, options = {}) {
  424. const level = _supportsColor(stream, __spreadValues({
  425. streamIsTTY: stream && stream.isTTY
  426. }, options));
  427. return translateLevel(level);
  428. }
  429. var supportsColor = {
  430. stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
  431. stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
  432. };
  433. var supports_color_default = supportsColor;
  434. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/utilities.js
  435. function stringReplaceAll(string, substring, replacer) {
  436. let index = string.indexOf(substring);
  437. if (index === -1) {
  438. return string;
  439. }
  440. const substringLength = substring.length;
  441. let endIndex = 0;
  442. let returnValue = "";
  443. do {
  444. returnValue += string.slice(endIndex, index) + substring + replacer;
  445. endIndex = index + substringLength;
  446. index = string.indexOf(substring, endIndex);
  447. } while (index !== -1);
  448. returnValue += string.slice(endIndex);
  449. return returnValue;
  450. }
  451. function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
  452. let endIndex = 0;
  453. let returnValue = "";
  454. do {
  455. const gotCR = string[index - 1] === "\r";
  456. returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
  457. endIndex = index + 1;
  458. index = string.indexOf("\n", endIndex);
  459. } while (index !== -1);
  460. returnValue += string.slice(endIndex);
  461. return returnValue;
  462. }
  463. // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/index.js
  464. var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
  465. var GENERATOR = Symbol("GENERATOR");
  466. var STYLER = Symbol("STYLER");
  467. var IS_EMPTY = Symbol("IS_EMPTY");
  468. var levelMapping = [
  469. "ansi",
  470. "ansi",
  471. "ansi256",
  472. "ansi16m"
  473. ];
  474. var styles2 = /* @__PURE__ */ Object.create(null);
  475. var applyOptions = (object, options = {}) => {
  476. if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
  477. throw new Error("The `level` option should be an integer from 0 to 3");
  478. }
  479. const colorLevel = stdoutColor ? stdoutColor.level : 0;
  480. object.level = options.level === void 0 ? colorLevel : options.level;
  481. };
  482. var chalkFactory = (options) => {
  483. const chalk2 = (...strings) => strings.join(" ");
  484. applyOptions(chalk2, options);
  485. Object.setPrototypeOf(chalk2, createChalk.prototype);
  486. return chalk2;
  487. };
  488. function createChalk(options) {
  489. return chalkFactory(options);
  490. }
  491. Object.setPrototypeOf(createChalk.prototype, Function.prototype);
  492. for (const [styleName, style] of Object.entries(ansi_styles_default)) {
  493. styles2[styleName] = {
  494. get() {
  495. const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
  496. Object.defineProperty(this, styleName, { value: builder });
  497. return builder;
  498. }
  499. };
  500. }
  501. styles2.visible = {
  502. get() {
  503. const builder = createBuilder(this, this[STYLER], true);
  504. Object.defineProperty(this, "visible", { value: builder });
  505. return builder;
  506. }
  507. };
  508. var getModelAnsi = (model, level, type, ...arguments_) => {
  509. if (model === "rgb") {
  510. if (level === "ansi16m") {
  511. return ansi_styles_default[type].ansi16m(...arguments_);
  512. }
  513. if (level === "ansi256") {
  514. return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
  515. }
  516. return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
  517. }
  518. if (model === "hex") {
  519. return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
  520. }
  521. return ansi_styles_default[type][model](...arguments_);
  522. };
  523. var usedModels = ["rgb", "hex", "ansi256"];
  524. for (const model of usedModels) {
  525. styles2[model] = {
  526. get() {
  527. const { level } = this;
  528. return function(...arguments_) {
  529. const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
  530. return createBuilder(this, styler, this[IS_EMPTY]);
  531. };
  532. }
  533. };
  534. const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
  535. styles2[bgModel] = {
  536. get() {
  537. const { level } = this;
  538. return function(...arguments_) {
  539. const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
  540. return createBuilder(this, styler, this[IS_EMPTY]);
  541. };
  542. }
  543. };
  544. }
  545. var proto = Object.defineProperties(() => {
  546. }, __spreadProps(__spreadValues({}, styles2), {
  547. level: {
  548. enumerable: true,
  549. get() {
  550. return this[GENERATOR].level;
  551. },
  552. set(level) {
  553. this[GENERATOR].level = level;
  554. }
  555. }
  556. }));
  557. var createStyler = (open, close, parent) => {
  558. let openAll;
  559. let closeAll;
  560. if (parent === void 0) {
  561. openAll = open;
  562. closeAll = close;
  563. } else {
  564. openAll = parent.openAll + open;
  565. closeAll = close + parent.closeAll;
  566. }
  567. return {
  568. open,
  569. close,
  570. openAll,
  571. closeAll,
  572. parent
  573. };
  574. };
  575. var createBuilder = (self, _styler, _isEmpty) => {
  576. const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
  577. Object.setPrototypeOf(builder, proto);
  578. builder[GENERATOR] = self;
  579. builder[STYLER] = _styler;
  580. builder[IS_EMPTY] = _isEmpty;
  581. return builder;
  582. };
  583. var applyStyle = (self, string) => {
  584. if (self.level <= 0 || !string) {
  585. return self[IS_EMPTY] ? "" : string;
  586. }
  587. let styler = self[STYLER];
  588. if (styler === void 0) {
  589. return string;
  590. }
  591. const { openAll, closeAll } = styler;
  592. if (string.includes("\x1B")) {
  593. while (styler !== void 0) {
  594. string = stringReplaceAll(string, styler.close, styler.open);
  595. styler = styler.parent;
  596. }
  597. }
  598. const lfIndex = string.indexOf("\n");
  599. if (lfIndex !== -1) {
  600. string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
  601. }
  602. return openAll + string + closeAll;
  603. };
  604. Object.defineProperties(createChalk.prototype, styles2);
  605. var chalk = createChalk();
  606. var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
  607. var source_default = chalk;
  608. // node_modules/.pnpm/is-unicode-supported@1.3.0/node_modules/is-unicode-supported/index.js
  609. var import_node_process2 = __toESM(require("process"), 1);
  610. function isUnicodeSupported() {
  611. if (import_node_process2.default.platform !== "win32") {
  612. return import_node_process2.default.env.TERM !== "linux";
  613. }
  614. return Boolean(import_node_process2.default.env.CI) || Boolean(import_node_process2.default.env.WT_SESSION) || Boolean(import_node_process2.default.env.TERMINUS_SUBLIME) || import_node_process2.default.env.ConEmuTask === "{cmd::Cmder}" || import_node_process2.default.env.TERM_PROGRAM === "Terminus-Sublime" || import_node_process2.default.env.TERM_PROGRAM === "vscode" || import_node_process2.default.env.TERM === "xterm-256color" || import_node_process2.default.env.TERM === "alacritty" || import_node_process2.default.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
  615. }
  616. // node_modules/.pnpm/log-symbols@5.1.0/node_modules/log-symbols/index.js
  617. var main = {
  618. info: source_default.blue("\u2139"),
  619. success: source_default.green("\u2714"),
  620. warning: source_default.yellow("\u26A0"),
  621. error: source_default.red("\u2716")
  622. };
  623. var fallback = {
  624. info: source_default.blue("i"),
  625. success: source_default.green("\u221A"),
  626. warning: source_default.yellow("\u203C"),
  627. error: source_default.red("\xD7")
  628. };
  629. var logSymbols = isUnicodeSupported() ? main : fallback;
  630. var log_symbols_default = logSymbols;
  631. // src/version-bump.ts
  632. var import_prompts2 = __toESM(require("prompts"));
  633. // src/get-new-version.ts
  634. var import_picocolors = __toESM(require_picocolors());
  635. var import_prompts = __toESM(require("prompts"));
  636. var import_semver2 = __toESM(require("semver"));
  637. // src/release-type.ts
  638. var import_semver = require("semver");
  639. var prereleaseTypes = ["premajor", "preminor", "prepatch", "prerelease"];
  640. var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch"]);
  641. function isPrerelease(value) {
  642. return prereleaseTypes.includes(value);
  643. }
  644. function isReleaseType(value) {
  645. return releaseTypes.includes(value);
  646. }
  647. // src/get-new-version.ts
  648. async function getNewVersion(operation) {
  649. const { release } = operation.options;
  650. const { oldVersion } = operation.state;
  651. switch (release.type) {
  652. case "prompt":
  653. return promptForNewVersion(operation);
  654. case "version":
  655. return operation.update({
  656. newVersion: new import_semver2.SemVer(release.version, true).version
  657. });
  658. default:
  659. return operation.update({
  660. release: release.type,
  661. newVersion: getNextVersion(oldVersion, release)
  662. });
  663. }
  664. }
  665. function getNextVersion(oldVersion, bump) {
  666. const oldSemVer = new import_semver2.SemVer(oldVersion);
  667. const newSemVer = oldSemVer.inc(bump.type, bump.preid);
  668. if (isPrerelease(bump.type) && newSemVer.prerelease.length === 2 && newSemVer.prerelease[0] === bump.preid && String(newSemVer.prerelease[1]) === "0") {
  669. newSemVer.prerelease[1] = "1";
  670. newSemVer.format();
  671. }
  672. return newSemVer.version;
  673. }
  674. function getNextVersions(oldVersion, preid) {
  675. var _a;
  676. const next = {};
  677. const parse = import_semver2.default.parse(oldVersion);
  678. if (typeof (parse == null ? void 0 : parse.prerelease[0]) === "string")
  679. preid = (parse == null ? void 0 : parse.prerelease[0]) || "preid";
  680. for (const type of releaseTypes)
  681. next[type] = import_semver2.default.inc(oldVersion, type, preid);
  682. next.next = ((_a = parse == null ? void 0 : parse.prerelease) == null ? void 0 : _a.length) ? import_semver2.default.inc(oldVersion, "prerelease", preid) : import_semver2.default.inc(oldVersion, "patch");
  683. return next;
  684. }
  685. async function promptForNewVersion(operation) {
  686. const { oldVersion } = operation.state;
  687. const release = operation.options.release;
  688. const next = getNextVersions(oldVersion, release.preid);
  689. const PADDING = 13;
  690. const answers = await (0, import_prompts.default)([
  691. {
  692. type: "autocomplete",
  693. name: "release",
  694. message: `Current version ${import_picocolors.default.green(oldVersion)}`,
  695. initial: "next",
  696. choices: [
  697. { value: "major", title: `${"major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.major)}` },
  698. { value: "minor", title: `${"minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.minor)}` },
  699. { value: "patch", title: `${"patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.patch)}` },
  700. { value: "next", title: `${"next".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.next)}` },
  701. { value: "prepatch", title: `${"pre-patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.prepatch)}` },
  702. { value: "preminor", title: `${"pre-minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.preminor)}` },
  703. { value: "premajor", title: `${"pre-major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.premajor)}` },
  704. { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(oldVersion)}` },
  705. { value: "custom", title: "custom ...".padStart(PADDING + 4, " ") }
  706. ]
  707. },
  708. {
  709. type: (prev) => prev === "custom" ? "text" : null,
  710. name: "custom",
  711. message: "Enter the new version number:",
  712. initial: oldVersion,
  713. validate: (custom) => {
  714. return (0, import_semver2.valid)(custom) ? true : "That's not a valid version number";
  715. }
  716. }
  717. ]);
  718. const newVersion = answers.release === "none" ? oldVersion : answers.release === "custom" ? (0, import_semver2.clean)(answers.custom) : next[answers.release];
  719. if (!newVersion)
  720. process.exit(1);
  721. switch (answers.release) {
  722. case "custom":
  723. case "next":
  724. case "none":
  725. return operation.update({ newVersion });
  726. default:
  727. return operation.update({ release: answers.release, newVersion });
  728. }
  729. }
  730. // src/get-old-version.ts
  731. var import_semver3 = require("semver");
  732. // src/fs.ts
  733. var import_node_fs = __toESM(require("fs"));
  734. var import_node_path = __toESM(require("path"));
  735. // node_modules/.pnpm/detect-indent@7.0.1/node_modules/detect-indent/index.js
  736. var INDENT_REGEX = /^(?:( )+|\t+)/;
  737. var INDENT_TYPE_SPACE = "space";
  738. var INDENT_TYPE_TAB = "tab";
  739. function makeIndentsMap(string, ignoreSingleSpaces) {
  740. const indents = /* @__PURE__ */ new Map();
  741. let previousSize = 0;
  742. let previousIndentType;
  743. let key;
  744. for (const line of string.split(/\n/g)) {
  745. if (!line) {
  746. continue;
  747. }
  748. let indent;
  749. let indentType;
  750. let use;
  751. let weight;
  752. let entry;
  753. const matches = line.match(INDENT_REGEX);
  754. if (matches === null) {
  755. previousSize = 0;
  756. previousIndentType = "";
  757. } else {
  758. indent = matches[0].length;
  759. indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
  760. if (ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) {
  761. continue;
  762. }
  763. if (indentType !== previousIndentType) {
  764. previousSize = 0;
  765. }
  766. previousIndentType = indentType;
  767. use = 1;
  768. weight = 0;
  769. const indentDifference = indent - previousSize;
  770. previousSize = indent;
  771. if (indentDifference === 0) {
  772. use = 0;
  773. weight = 1;
  774. } else {
  775. const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
  776. key = encodeIndentsKey(indentType, absoluteIndentDifference);
  777. }
  778. entry = indents.get(key);
  779. entry = entry === void 0 ? [1, 0] : [entry[0] + use, entry[1] + weight];
  780. indents.set(key, entry);
  781. }
  782. }
  783. return indents;
  784. }
  785. function encodeIndentsKey(indentType, indentAmount) {
  786. const typeCharacter = indentType === INDENT_TYPE_SPACE ? "s" : "t";
  787. return typeCharacter + String(indentAmount);
  788. }
  789. function decodeIndentsKey(indentsKey) {
  790. const keyHasTypeSpace = indentsKey[0] === "s";
  791. const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
  792. const amount = Number(indentsKey.slice(1));
  793. return { type, amount };
  794. }
  795. function getMostUsedKey(indents) {
  796. let result;
  797. let maxUsed = 0;
  798. let maxWeight = 0;
  799. for (const [key, [usedCount, weight]] of indents) {
  800. if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
  801. maxUsed = usedCount;
  802. maxWeight = weight;
  803. result = key;
  804. }
  805. }
  806. return result;
  807. }
  808. function makeIndentString(type, amount) {
  809. const indentCharacter = type === INDENT_TYPE_SPACE ? " " : " ";
  810. return indentCharacter.repeat(amount);
  811. }
  812. function detectIndent(string) {
  813. if (typeof string !== "string") {
  814. throw new TypeError("Expected a string");
  815. }
  816. let indents = makeIndentsMap(string, true);
  817. if (indents.size === 0) {
  818. indents = makeIndentsMap(string, false);
  819. }
  820. const keyOfMostUsedIndent = getMostUsedKey(indents);
  821. let type;
  822. let amount = 0;
  823. let indent = "";
  824. if (keyOfMostUsedIndent !== void 0) {
  825. ({ type, amount } = decodeIndentsKey(keyOfMostUsedIndent));
  826. indent = makeIndentString(type, amount);
  827. }
  828. return {
  829. amount,
  830. type,
  831. indent
  832. };
  833. }
  834. // node_modules/.pnpm/detect-newline@4.0.0/node_modules/detect-newline/index.js
  835. function detectNewline(string) {
  836. if (typeof string !== "string") {
  837. throw new TypeError("Expected a string");
  838. }
  839. const newlines = string.match(/(?:\r?\n)/g) || [];
  840. if (newlines.length === 0) {
  841. return;
  842. }
  843. const crlf = newlines.filter((newline) => newline === "\r\n").length;
  844. const lf = newlines.length - crlf;
  845. return crlf > lf ? "\r\n" : "\n";
  846. }
  847. // src/fs.ts
  848. async function readJsonFile(name, cwd) {
  849. const file = await readTextFile(name, cwd);
  850. const data = JSON.parse(file.data);
  851. const indent = detectIndent(file.data).indent;
  852. const newline = detectNewline(file.data);
  853. return __spreadProps(__spreadValues({}, file), { data, indent, newline });
  854. }
  855. async function writeJsonFile(file) {
  856. let json = JSON.stringify(file.data, void 0, file.indent);
  857. if (file.newline)
  858. json += file.newline;
  859. return writeTextFile(__spreadProps(__spreadValues({}, file), { data: json }));
  860. }
  861. function readTextFile(name, cwd) {
  862. return new Promise((resolve, reject) => {
  863. const filePath = import_node_path.default.join(cwd, name);
  864. import_node_fs.default.readFile(filePath, "utf8", (err, text) => {
  865. if (err) {
  866. reject(err);
  867. } else {
  868. resolve({
  869. path: filePath,
  870. data: text
  871. });
  872. }
  873. });
  874. });
  875. }
  876. function writeTextFile(file) {
  877. return new Promise((resolve, reject) => {
  878. import_node_fs.default.writeFile(file.path, file.data, (err) => {
  879. if (err)
  880. reject(err);
  881. else
  882. resolve();
  883. });
  884. });
  885. }
  886. // src/manifest.ts
  887. function isManifest(obj) {
  888. return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
  889. }
  890. function isOptionalString(value) {
  891. const type = typeof value;
  892. return value === null || type === "undefined" || type === "string";
  893. }
  894. // src/get-old-version.ts
  895. async function getOldVersion(operation) {
  896. const { cwd, files } = operation.options;
  897. const filesToCheck = files.filter((file) => file.endsWith(".json"));
  898. if (!filesToCheck.includes("package.json"))
  899. filesToCheck.push("package.json");
  900. for (const file of filesToCheck) {
  901. const version = await readVersion(file, cwd);
  902. if (version) {
  903. return operation.update({
  904. oldVersionSource: file,
  905. oldVersion: version
  906. });
  907. }
  908. }
  909. throw new Error(
  910. `Unable to determine the current version number. Checked ${filesToCheck.join(", ")}.`
  911. );
  912. }
  913. async function readVersion(file, cwd) {
  914. try {
  915. const { data: manifest } = await readJsonFile(file, cwd);
  916. if (isManifest(manifest)) {
  917. if ((0, import_semver3.valid)(manifest.version))
  918. return manifest.version;
  919. }
  920. } catch (error) {
  921. return void 0;
  922. }
  923. }
  924. // src/git.ts
  925. var ezSpawn = __toESM(require("@jsdevtools/ez-spawn"));
  926. // src/types/version-bump-progress.ts
  927. var ProgressEvent = /* @__PURE__ */ ((ProgressEvent2) => {
  928. ProgressEvent2["FileUpdated"] = "file updated";
  929. ProgressEvent2["FileSkipped"] = "file skipped";
  930. ProgressEvent2["GitCommit"] = "git commit";
  931. ProgressEvent2["GitTag"] = "git tag";
  932. ProgressEvent2["GitPush"] = "git push";
  933. ProgressEvent2["NpmScript"] = "npm script";
  934. return ProgressEvent2;
  935. })(ProgressEvent || {});
  936. var NpmScript = /* @__PURE__ */ ((NpmScript2) => {
  937. NpmScript2["PreVersion"] = "preversion";
  938. NpmScript2["Version"] = "version";
  939. NpmScript2["PostVersion"] = "postversion";
  940. return NpmScript2;
  941. })(NpmScript || {});
  942. // src/git.ts
  943. async function gitCommit(operation) {
  944. if (!operation.options.commit)
  945. return operation;
  946. const { all, noVerify, message } = operation.options.commit;
  947. const { updatedFiles, newVersion } = operation.state;
  948. let args = [];
  949. if (all) {
  950. args.push("--all");
  951. }
  952. if (noVerify) {
  953. args.push("--no-verify");
  954. }
  955. const commitMessage = formatVersionString(message, newVersion);
  956. args.push("--message", commitMessage);
  957. if (!all)
  958. args = args.concat(updatedFiles);
  959. await ezSpawn.async("git", ["commit", ...args]);
  960. return operation.update({ event: "git commit" /* GitCommit */, commitMessage });
  961. }
  962. async function gitTag(operation) {
  963. if (!operation.options.tag)
  964. return operation;
  965. const { commit, tag } = operation.options;
  966. const { newVersion } = operation.state;
  967. const args = [
  968. // Create an annotated tag, which is recommended for releases.
  969. // See https://git-scm.com/docs/git-tag
  970. "--annotate",
  971. // Use the same commit message for the tag
  972. "--message",
  973. formatVersionString(commit.message, newVersion)
  974. ];
  975. const tagName = formatVersionString(tag.name, newVersion);
  976. args.push(tagName);
  977. await ezSpawn.async("git", ["tag", ...args]);
  978. return operation.update({ event: "git tag" /* GitTag */, tagName });
  979. }
  980. async function gitPush(operation) {
  981. if (!operation.options.push)
  982. return operation;
  983. await ezSpawn.async("git", "push");
  984. if (operation.options.tag) {
  985. await ezSpawn.async("git", ["push", "--tags"]);
  986. }
  987. return operation.update({ event: "git push" /* GitPush */ });
  988. }
  989. function formatVersionString(template, newVersion) {
  990. if (template.includes("%s"))
  991. return template.replace(/%s/g, newVersion);
  992. else
  993. return template + newVersion;
  994. }
  995. // src/normalize-options.ts
  996. var import_fast_glob = __toESM(require("fast-glob"));
  997. async function normalizeOptions(raw) {
  998. var _a;
  999. const preid = typeof raw.preid === "string" ? raw.preid : "beta";
  1000. const push = Boolean(raw.push);
  1001. const all = Boolean(raw.all);
  1002. const noVerify = Boolean(raw.noVerify);
  1003. const cwd = raw.cwd || process.cwd();
  1004. const ignoreScripts = Boolean(raw.ignoreScripts);
  1005. const execute = raw.execute;
  1006. let release;
  1007. if (!raw.release || raw.release === "prompt")
  1008. release = { type: "prompt", preid };
  1009. else if (isReleaseType(raw.release))
  1010. release = { type: raw.release, preid };
  1011. else
  1012. release = { type: "version", version: raw.release };
  1013. let tag;
  1014. if (typeof raw.tag === "string")
  1015. tag = { name: raw.tag };
  1016. else if (raw.tag)
  1017. tag = { name: "v" };
  1018. let commit;
  1019. if (typeof raw.commit === "string")
  1020. commit = { all, noVerify, message: raw.commit };
  1021. else if (raw.commit || tag || push)
  1022. commit = { all, noVerify, message: "chore: release v" };
  1023. const files = await (0, import_fast_glob.default)(
  1024. ((_a = raw.files) == null ? void 0 : _a.length) ? raw.files : ["package.json", "package-lock.json"],
  1025. {
  1026. cwd,
  1027. onlyFiles: true,
  1028. ignore: [
  1029. "**/{.git,node_modules,bower_components,__tests__,fixtures,fixture}/**"
  1030. ]
  1031. }
  1032. );
  1033. let ui;
  1034. if (raw.interface === false) {
  1035. ui = { input: false, output: false };
  1036. } else if (raw.interface === true || !raw.interface) {
  1037. ui = { input: process.stdin, output: process.stdout };
  1038. } else {
  1039. let _b = raw.interface, { input, output } = _b, other = __objRest(_b, ["input", "output"]);
  1040. if (input === true || input !== false && !input)
  1041. input = process.stdin;
  1042. if (output === true || output !== false && !output)
  1043. output = process.stdout;
  1044. ui = __spreadValues({ input, output }, other);
  1045. }
  1046. if (release.type === "prompt" && !(ui.input && ui.output))
  1047. throw new Error("Cannot prompt for the version number because input or output has been disabled.");
  1048. return { release, commit, tag, push, files, cwd, interface: ui, ignoreScripts, execute };
  1049. }
  1050. // src/operation.ts
  1051. var Operation = class {
  1052. /**
  1053. * Private constructor. Use the `Operation.start()` static method instead.
  1054. */
  1055. constructor(options, progress) {
  1056. /**
  1057. * The current state of the operation.
  1058. */
  1059. this.state = {
  1060. release: void 0,
  1061. oldVersion: "",
  1062. oldVersionSource: "",
  1063. newVersion: "",
  1064. commitMessage: "",
  1065. tagName: "",
  1066. updatedFiles: [],
  1067. skippedFiles: []
  1068. };
  1069. this.options = options;
  1070. this._progress = progress;
  1071. }
  1072. /**
  1073. * The results of the operation.
  1074. */
  1075. get results() {
  1076. const options = this.options;
  1077. const state = this.state;
  1078. return {
  1079. release: state.release,
  1080. oldVersion: state.oldVersion,
  1081. newVersion: state.newVersion,
  1082. commit: options.commit ? state.commitMessage : false,
  1083. tag: options.tag ? state.tagName : false,
  1084. updatedFiles: state.updatedFiles.slice(),
  1085. skippedFiles: state.skippedFiles.slice()
  1086. };
  1087. }
  1088. /**
  1089. * Starts a new `versionBump()` operation.
  1090. */
  1091. static async start(input) {
  1092. const options = await normalizeOptions(input);
  1093. return new Operation(options, input.progress);
  1094. }
  1095. /**
  1096. * Updates the operation state and results, and reports the updated progress to the user.
  1097. */
  1098. update(_a) {
  1099. var _b = _a, { event, script } = _b, newState = __objRest(_b, ["event", "script"]);
  1100. Object.assign(this.state, newState);
  1101. if (event && this._progress) {
  1102. this._progress(__spreadValues({ event, script }, this.results));
  1103. }
  1104. return this;
  1105. }
  1106. };
  1107. // src/run-npm-script.ts
  1108. var ezSpawn2 = __toESM(require("@jsdevtools/ez-spawn"));
  1109. async function runNpmScript(script, operation) {
  1110. const { cwd, ignoreScripts } = operation.options;
  1111. if (!ignoreScripts) {
  1112. const { data: manifest } = await readJsonFile("package.json", cwd);
  1113. if (isManifest(manifest) && hasScript(manifest, script)) {
  1114. await ezSpawn2.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
  1115. operation.update({ event: "npm script" /* NpmScript */, script });
  1116. }
  1117. }
  1118. return operation;
  1119. }
  1120. function hasScript(manifest, script) {
  1121. const scripts = manifest.scripts;
  1122. if (scripts && typeof scripts === "object")
  1123. return Boolean(scripts[script]);
  1124. return false;
  1125. }
  1126. // src/update-files.ts
  1127. var path2 = __toESM(require("path"));
  1128. async function updateFiles(operation) {
  1129. const { files } = operation.options;
  1130. for (const relPath of files) {
  1131. const modified = await updateFile(relPath, operation);
  1132. if (modified) {
  1133. operation.update({
  1134. event: "file updated" /* FileUpdated */,
  1135. updatedFiles: operation.state.updatedFiles.concat(relPath)
  1136. });
  1137. } else {
  1138. operation.update({
  1139. event: "file skipped" /* FileSkipped */,
  1140. skippedFiles: operation.state.skippedFiles.concat(relPath)
  1141. });
  1142. }
  1143. }
  1144. return operation;
  1145. }
  1146. async function updateFile(relPath, operation) {
  1147. const name = path2.basename(relPath).trim().toLowerCase();
  1148. switch (name) {
  1149. case "package.json":
  1150. case "package-lock.json":
  1151. case "bower.json":
  1152. case "component.json":
  1153. return updateManifestFile(relPath, operation);
  1154. default:
  1155. return updateTextFile(relPath, operation);
  1156. }
  1157. }
  1158. async function updateManifestFile(relPath, operation) {
  1159. const { cwd } = operation.options;
  1160. const { newVersion } = operation.state;
  1161. let modified = false;
  1162. const file = await readJsonFile(relPath, cwd);
  1163. if (isManifest(file.data) && file.data.version !== newVersion) {
  1164. file.data.version = newVersion;
  1165. await writeJsonFile(file);
  1166. modified = true;
  1167. }
  1168. return modified;
  1169. }
  1170. async function updateTextFile(relPath, operation) {
  1171. const { cwd } = operation.options;
  1172. const { oldVersion, newVersion } = operation.state;
  1173. const modified = false;
  1174. const file = await readTextFile(relPath, cwd);
  1175. if (file.data.includes(oldVersion)) {
  1176. const sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
  1177. const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
  1178. file.data = file.data.replace(replacePattern, `$1${newVersion}`);
  1179. await writeTextFile(file);
  1180. return true;
  1181. }
  1182. return modified;
  1183. }
  1184. // src/version-bump.ts
  1185. async function versionBump(arg = {}) {
  1186. if (typeof arg === "string")
  1187. arg = { release: arg };
  1188. const operation = await Operation.start(arg);
  1189. await getOldVersion(operation);
  1190. await getNewVersion(operation);
  1191. if (arg.confirm) {
  1192. printSummary(operation);
  1193. if (!await (0, import_prompts2.default)({
  1194. name: "yes",
  1195. type: "confirm",
  1196. message: "Bump?",
  1197. initial: true
  1198. }).then((r) => r.yes))
  1199. process.exit(1);
  1200. }
  1201. await runNpmScript("preversion" /* PreVersion */, operation);
  1202. await updateFiles(operation);
  1203. if (operation.options.execute) {
  1204. console.log(log_symbols_default.info, "Executing script", operation.options.execute);
  1205. await ezSpawn3.async(operation.options.execute, { stdio: "inherit" });
  1206. console.log(log_symbols_default.success, "Script finished");
  1207. }
  1208. await runNpmScript("version" /* Version */, operation);
  1209. await gitCommit(operation);
  1210. await gitTag(operation);
  1211. await runNpmScript("postversion" /* PostVersion */, operation);
  1212. await gitPush(operation);
  1213. return operation.results;
  1214. }
  1215. function printSummary(operation) {
  1216. console.log();
  1217. console.log(` files ${operation.options.files.map((i) => import_picocolors2.default.bold(i)).join("\n ")}`);
  1218. if (operation.options.commit)
  1219. console.log(` commit ${import_picocolors2.default.bold(formatVersionString(operation.options.commit.message, operation.state.newVersion))}`);
  1220. if (operation.options.tag)
  1221. console.log(` tag ${import_picocolors2.default.bold(formatVersionString(operation.options.tag.name, operation.state.newVersion))}`);
  1222. if (operation.options.execute)
  1223. console.log(` execute ${import_picocolors2.default.bold(operation.options.execute)}`);
  1224. if (operation.options.push)
  1225. console.log(` push ${import_picocolors2.default.cyan(import_picocolors2.default.bold("yes"))}`);
  1226. console.log();
  1227. console.log(` from ${import_picocolors2.default.bold(operation.state.oldVersion)}`);
  1228. console.log(` to ${import_picocolors2.default.green(import_picocolors2.default.bold(operation.state.newVersion))}`);
  1229. console.log();
  1230. }
  1231. async function versionBumpInfo(arg = {}) {
  1232. if (typeof arg === "string")
  1233. arg = { release: arg };
  1234. const operation = await Operation.start(arg);
  1235. await getOldVersion(operation);
  1236. await getNewVersion(operation);
  1237. return operation;
  1238. }
  1239. // src/config.ts
  1240. var import_c12 = require("c12");
  1241. var bumpConfigDefaults = {
  1242. commit: true,
  1243. push: true,
  1244. tag: true,
  1245. recursive: false,
  1246. noVerify: false,
  1247. confirm: true,
  1248. ignoreScripts: false,
  1249. all: false,
  1250. files: []
  1251. };
  1252. async function loadBumpConfig(overrides, cwd = process.cwd()) {
  1253. const { config } = await (0, import_c12.loadConfig)({
  1254. name: "bump",
  1255. defaults: bumpConfigDefaults,
  1256. overrides: __spreadValues({}, overrides),
  1257. cwd
  1258. });
  1259. return config;
  1260. }
  1261. function defineConfig(config) {
  1262. return config;
  1263. }
  1264. // src/index.ts
  1265. var src_default = versionBump;
  1266. // Annotate the CommonJS export names for ESM import in node:
  1267. 0 && (module.exports = {
  1268. NpmScript,
  1269. ProgressEvent,
  1270. ReleaseType,
  1271. bumpConfigDefaults,
  1272. defineConfig,
  1273. loadBumpConfig,
  1274. versionBump,
  1275. versionBumpInfo
  1276. });