bumpp 9.10.1 → 9.11.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1070 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
33
+ var require_picocolors = __commonJS({
34
+ "node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports2, module2) {
35
+ var p = process || {};
36
+ var argv = p.argv || [];
37
+ var env = p.env || {};
38
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
39
+ var formatter = (open, close, replace = open) => (input) => {
40
+ let string = "" + input, index = string.indexOf(close, open.length);
41
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
42
+ };
43
+ var replaceClose = (string, close, replace, index) => {
44
+ let result = "", cursor = 0;
45
+ do {
46
+ result += string.substring(cursor, index) + replace;
47
+ cursor = index + close.length;
48
+ index = string.indexOf(close, cursor);
49
+ } while (~index);
50
+ return result + string.substring(cursor);
51
+ };
52
+ var createColors = (enabled = isColorSupported) => {
53
+ let f = enabled ? formatter : () => String;
54
+ return {
55
+ isColorSupported: enabled,
56
+ reset: f("\x1B[0m", "\x1B[0m"),
57
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
58
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
59
+ italic: f("\x1B[3m", "\x1B[23m"),
60
+ underline: f("\x1B[4m", "\x1B[24m"),
61
+ inverse: f("\x1B[7m", "\x1B[27m"),
62
+ hidden: f("\x1B[8m", "\x1B[28m"),
63
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
64
+ black: f("\x1B[30m", "\x1B[39m"),
65
+ red: f("\x1B[31m", "\x1B[39m"),
66
+ green: f("\x1B[32m", "\x1B[39m"),
67
+ yellow: f("\x1B[33m", "\x1B[39m"),
68
+ blue: f("\x1B[34m", "\x1B[39m"),
69
+ magenta: f("\x1B[35m", "\x1B[39m"),
70
+ cyan: f("\x1B[36m", "\x1B[39m"),
71
+ white: f("\x1B[37m", "\x1B[39m"),
72
+ gray: f("\x1B[90m", "\x1B[39m"),
73
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
74
+ bgRed: f("\x1B[41m", "\x1B[49m"),
75
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
76
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
77
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
78
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
79
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
80
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
81
+ blackBright: f("\x1B[90m", "\x1B[39m"),
82
+ redBright: f("\x1B[91m", "\x1B[39m"),
83
+ greenBright: f("\x1B[92m", "\x1B[39m"),
84
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
85
+ blueBright: f("\x1B[94m", "\x1B[39m"),
86
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
87
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
88
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
89
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
90
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
91
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
92
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
93
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
94
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
95
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
96
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
97
+ };
98
+ };
99
+ module2.exports = createColors();
100
+ module2.exports.createColors = createColors;
101
+ }
102
+ });
103
+
104
+ // src/index.ts
105
+ var src_exports = {};
106
+ __export(src_exports, {
107
+ NpmScript: () => NpmScript,
108
+ ProgressEvent: () => ProgressEvent,
109
+ bumpConfigDefaults: () => bumpConfigDefaults,
110
+ default: () => src_default,
111
+ defineConfig: () => defineConfig,
112
+ loadBumpConfig: () => loadBumpConfig,
113
+ versionBump: () => versionBump,
114
+ versionBumpInfo: () => versionBumpInfo
115
+ });
116
+ module.exports = __toCommonJS(src_exports);
117
+
118
+ // src/version-bump.ts
119
+ var import_node_process4 = __toESM(require("process"), 1);
120
+
121
+ // node_modules/.pnpm/args-tokenizer@0.3.0/node_modules/args-tokenizer/dist/args-tokenizer.js
122
+ var spaceRegex = /\s/;
123
+ var tokenizeArgs = (argsString, options) => {
124
+ const tokens = [];
125
+ let currentToken = "";
126
+ let openningQuote;
127
+ let escaped = false;
128
+ for (let index = 0; index < argsString.length; index += 1) {
129
+ const char = argsString[index];
130
+ if (escaped) {
131
+ escaped = false;
132
+ if (openningQuote || char !== "\n") {
133
+ currentToken += char;
134
+ }
135
+ continue;
136
+ }
137
+ if (char === "\\") {
138
+ escaped = true;
139
+ continue;
140
+ }
141
+ if (openningQuote === void 0 && spaceRegex.test(char)) {
142
+ if (currentToken.length > 0) {
143
+ tokens.push(currentToken);
144
+ currentToken = "";
145
+ }
146
+ continue;
147
+ }
148
+ if (char === "'" || char === '"') {
149
+ if (openningQuote === void 0) {
150
+ openningQuote = char;
151
+ continue;
152
+ }
153
+ if (openningQuote === char) {
154
+ openningQuote = void 0;
155
+ continue;
156
+ }
157
+ }
158
+ currentToken += char;
159
+ }
160
+ if (currentToken.length > 0) {
161
+ tokens.push(currentToken);
162
+ }
163
+ if (options?.loose) {
164
+ return tokens;
165
+ }
166
+ if (openningQuote) {
167
+ throw Error("Unexpected end of string. Closing quote is missing.");
168
+ }
169
+ return tokens;
170
+ };
171
+
172
+ // node_modules/.pnpm/log-symbols@7.0.0/node_modules/log-symbols/symbols.js
173
+ var symbols_exports = {};
174
+ __export(symbols_exports, {
175
+ error: () => error,
176
+ info: () => info,
177
+ success: () => success,
178
+ warning: () => warning
179
+ });
180
+
181
+ // node_modules/.pnpm/yoctocolors@2.1.1/node_modules/yoctocolors/base.js
182
+ var import_node_tty = __toESM(require("tty"), 1);
183
+ var hasColors = import_node_tty.default?.WriteStream?.prototype?.hasColors?.() ?? false;
184
+ var format = (open, close) => {
185
+ if (!hasColors) {
186
+ return (input) => input;
187
+ }
188
+ const openCode = `\x1B[${open}m`;
189
+ const closeCode = `\x1B[${close}m`;
190
+ return (input) => {
191
+ const string = input + "";
192
+ let index = string.indexOf(closeCode);
193
+ if (index === -1) {
194
+ return openCode + string + closeCode;
195
+ }
196
+ let result = openCode;
197
+ let lastIndex = 0;
198
+ while (index !== -1) {
199
+ result += string.slice(lastIndex, index) + openCode;
200
+ lastIndex = index + closeCode.length;
201
+ index = string.indexOf(closeCode, lastIndex);
202
+ }
203
+ result += string.slice(lastIndex) + closeCode;
204
+ return result;
205
+ };
206
+ };
207
+ var reset = format(0, 0);
208
+ var bold = format(1, 22);
209
+ var dim = format(2, 22);
210
+ var italic = format(3, 23);
211
+ var underline = format(4, 24);
212
+ var overline = format(53, 55);
213
+ var inverse = format(7, 27);
214
+ var hidden = format(8, 28);
215
+ var strikethrough = format(9, 29);
216
+ var black = format(30, 39);
217
+ var red = format(31, 39);
218
+ var green = format(32, 39);
219
+ var yellow = format(33, 39);
220
+ var blue = format(34, 39);
221
+ var magenta = format(35, 39);
222
+ var cyan = format(36, 39);
223
+ var white = format(37, 39);
224
+ var gray = format(90, 39);
225
+ var bgBlack = format(40, 49);
226
+ var bgRed = format(41, 49);
227
+ var bgGreen = format(42, 49);
228
+ var bgYellow = format(43, 49);
229
+ var bgBlue = format(44, 49);
230
+ var bgMagenta = format(45, 49);
231
+ var bgCyan = format(46, 49);
232
+ var bgWhite = format(47, 49);
233
+ var bgGray = format(100, 49);
234
+ var redBright = format(91, 39);
235
+ var greenBright = format(92, 39);
236
+ var yellowBright = format(93, 39);
237
+ var blueBright = format(94, 39);
238
+ var magentaBright = format(95, 39);
239
+ var cyanBright = format(96, 39);
240
+ var whiteBright = format(97, 39);
241
+ var bgRedBright = format(101, 49);
242
+ var bgGreenBright = format(102, 49);
243
+ var bgYellowBright = format(103, 49);
244
+ var bgBlueBright = format(104, 49);
245
+ var bgMagentaBright = format(105, 49);
246
+ var bgCyanBright = format(106, 49);
247
+ var bgWhiteBright = format(107, 49);
248
+
249
+ // node_modules/.pnpm/is-unicode-supported@2.1.0/node_modules/is-unicode-supported/index.js
250
+ var import_node_process = __toESM(require("process"), 1);
251
+ function isUnicodeSupported() {
252
+ const { env } = import_node_process.default;
253
+ const { TERM, TERM_PROGRAM } = env;
254
+ if (import_node_process.default.platform !== "win32") {
255
+ return TERM !== "linux";
256
+ }
257
+ return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
258
+ }
259
+
260
+ // node_modules/.pnpm/log-symbols@7.0.0/node_modules/log-symbols/symbols.js
261
+ var _isUnicodeSupported = isUnicodeSupported();
262
+ var info = blue(_isUnicodeSupported ? "\u2139" : "i");
263
+ var success = green(_isUnicodeSupported ? "\u2714" : "\u221A");
264
+ var warning = yellow(_isUnicodeSupported ? "\u26A0" : "\u203C");
265
+ var error = red(_isUnicodeSupported ? "\u2716\uFE0F" : "\xD7");
266
+
267
+ // src/version-bump.ts
268
+ var import_picocolors3 = __toESM(require_picocolors(), 1);
269
+ var import_prompts2 = __toESM(require("prompts"), 1);
270
+ var import_tiny_conventional_commits_parser = require("tiny-conventional-commits-parser");
271
+ var import_tinyexec3 = require("tinyexec");
272
+
273
+ // src/get-current-version.ts
274
+ var import_semver = require("semver");
275
+
276
+ // src/fs.ts
277
+ var import_node_fs = __toESM(require("fs"), 1);
278
+ var import_node_path = __toESM(require("path"), 1);
279
+ var jsonc = __toESM(require("jsonc-parser"), 1);
280
+ async function readJsoncFile(name, cwd) {
281
+ const file = await readTextFile(name, cwd);
282
+ const data = jsonc.parse(file.data);
283
+ const modified = [];
284
+ return { ...file, data, modified, text: file.data };
285
+ }
286
+ async function writeJsoncFile(file) {
287
+ let newJSON = file.text;
288
+ for (const [key, value] of file.modified) {
289
+ const edit = jsonc.modify(newJSON, key, value, {});
290
+ newJSON = jsonc.applyEdits(newJSON, edit);
291
+ }
292
+ return writeTextFile({ ...file, data: newJSON });
293
+ }
294
+ function readTextFile(name, cwd) {
295
+ return new Promise((resolve, reject) => {
296
+ const filePath = import_node_path.default.join(cwd, name);
297
+ import_node_fs.default.readFile(filePath, "utf8", (err, text) => {
298
+ if (err) {
299
+ reject(err);
300
+ } else {
301
+ resolve({
302
+ path: filePath,
303
+ data: text
304
+ });
305
+ }
306
+ });
307
+ });
308
+ }
309
+ function writeTextFile(file) {
310
+ return new Promise((resolve, reject) => {
311
+ import_node_fs.default.writeFile(file.path, file.data, (err) => {
312
+ if (err)
313
+ reject(err);
314
+ else
315
+ resolve();
316
+ });
317
+ });
318
+ }
319
+
320
+ // src/manifest.ts
321
+ function isManifest(obj) {
322
+ return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
323
+ }
324
+ function isPackageLockManifest(manifest) {
325
+ return typeof manifest.packages?.[""]?.version === "string";
326
+ }
327
+ function isOptionalString(value) {
328
+ const type = typeof value;
329
+ return value === null || type === "undefined" || type === "string";
330
+ }
331
+
332
+ // src/get-current-version.ts
333
+ async function getCurrentVersion(operation) {
334
+ if (operation.state.currentVersion)
335
+ return operation;
336
+ const { cwd, files } = operation.options;
337
+ const filesToCheck = files.filter((file) => file.endsWith(".json"));
338
+ if (!filesToCheck.includes("package.json"))
339
+ filesToCheck.push("package.json");
340
+ if (!filesToCheck.includes("deno.json"))
341
+ filesToCheck.push("deno.json");
342
+ if (!filesToCheck.includes("deno.jsonc"))
343
+ filesToCheck.push("deno.jsonc");
344
+ for (const file of filesToCheck) {
345
+ const version = await readVersion(file, cwd);
346
+ if (version) {
347
+ return operation.update({
348
+ currentVersionSource: file,
349
+ currentVersion: version
350
+ });
351
+ }
352
+ }
353
+ throw new Error(
354
+ `Unable to determine the current version number. Checked ${filesToCheck.join(", ")}.`
355
+ );
356
+ }
357
+ async function readVersion(file, cwd) {
358
+ try {
359
+ const { data: manifest } = await readJsoncFile(file, cwd);
360
+ if (isManifest(manifest)) {
361
+ if ((0, import_semver.valid)(manifest.version))
362
+ return manifest.version;
363
+ }
364
+ } catch {
365
+ return void 0;
366
+ }
367
+ }
368
+
369
+ // src/get-new-version.ts
370
+ var import_node_process2 = __toESM(require("process"), 1);
371
+ var import_picocolors = __toESM(require_picocolors(), 1);
372
+ var import_prompts = __toESM(require("prompts"), 1);
373
+ var import_semver2 = __toESM(require("semver"), 1);
374
+
375
+ // src/release-type.ts
376
+ var prereleaseTypes = ["premajor", "preminor", "prepatch", "prerelease"];
377
+ var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch", "next", "conventional"]);
378
+ function isPrerelease(value) {
379
+ return prereleaseTypes.includes(value);
380
+ }
381
+ function isReleaseType(value) {
382
+ return releaseTypes.includes(value);
383
+ }
384
+
385
+ // src/get-new-version.ts
386
+ async function getNewVersion(operation, commits) {
387
+ const { release } = operation.options;
388
+ const { currentVersion } = operation.state;
389
+ switch (release.type) {
390
+ case "prompt":
391
+ return promptForNewVersion(operation, commits);
392
+ case "version":
393
+ return operation.update({
394
+ newVersion: new import_semver2.SemVer(release.version, true).version
395
+ });
396
+ default:
397
+ return operation.update({
398
+ release: release.type,
399
+ newVersion: getNextVersion(currentVersion, release, commits)
400
+ });
401
+ }
402
+ }
403
+ function getNextVersion(currentVersion, bump, commits) {
404
+ const oldSemVer = new import_semver2.SemVer(currentVersion);
405
+ let type;
406
+ if (bump.type === "next") {
407
+ type = oldSemVer.prerelease.length ? "prerelease" : "patch";
408
+ } else if (bump.type === "conventional") {
409
+ type = oldSemVer.prerelease.length ? "prerelease" : determineSemverChange(commits);
410
+ } else {
411
+ type = bump.type;
412
+ }
413
+ const newSemVer = oldSemVer.inc(type, bump.preid);
414
+ if (isPrerelease(bump.type) && newSemVer.prerelease.length === 2 && newSemVer.prerelease[0] === bump.preid && String(newSemVer.prerelease[1]) === "0") {
415
+ newSemVer.prerelease[1] = "1";
416
+ newSemVer.format();
417
+ }
418
+ return newSemVer.version;
419
+ }
420
+ function determineSemverChange(commits) {
421
+ let [hasMajor, hasMinor] = [false, false];
422
+ for (const commit of commits) {
423
+ if (commit.isBreaking) {
424
+ hasMajor = true;
425
+ } else if (commit.type === "feat") {
426
+ hasMinor = true;
427
+ }
428
+ }
429
+ return hasMajor ? "major" : hasMinor ? "minor" : "patch";
430
+ }
431
+ function getNextVersions(currentVersion, preid, commits) {
432
+ const next = {};
433
+ const parse2 = import_semver2.default.parse(currentVersion);
434
+ if (typeof parse2?.prerelease[0] === "string")
435
+ preid = parse2?.prerelease[0] || "preid";
436
+ for (const type of releaseTypes)
437
+ next[type] = getNextVersion(currentVersion, { type, preid }, commits);
438
+ return next;
439
+ }
440
+ async function promptForNewVersion(operation, commits) {
441
+ const { currentVersion } = operation.state;
442
+ const release = operation.options.release;
443
+ const next = getNextVersions(currentVersion, release.preid, commits);
444
+ const configCustomVersion = await operation.options.customVersion?.(currentVersion, import_semver2.default);
445
+ const PADDING = 13;
446
+ const answers = await (0, import_prompts.default)([
447
+ {
448
+ type: "autocomplete",
449
+ name: "release",
450
+ message: `Current version ${import_picocolors.default.green(currentVersion)}`,
451
+ initial: configCustomVersion ? "config" : "next",
452
+ choices: [
453
+ { value: "major", title: `${"major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.major)}` },
454
+ { value: "minor", title: `${"minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.minor)}` },
455
+ { value: "patch", title: `${"patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.patch)}` },
456
+ { value: "next", title: `${"next".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.next)}` },
457
+ { value: "conventional", title: `${"conventional".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.conventional)}` },
458
+ ...configCustomVersion ? [
459
+ { value: "config", title: `${"from config".padStart(PADDING, " ")} ${import_picocolors.default.bold(configCustomVersion)}` }
460
+ ] : [],
461
+ { value: "prepatch", title: `${"pre-patch".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.prepatch)}` },
462
+ { value: "preminor", title: `${"pre-minor".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.preminor)}` },
463
+ { value: "premajor", title: `${"pre-major".padStart(PADDING, " ")} ${import_picocolors.default.bold(next.premajor)}` },
464
+ { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${import_picocolors.default.bold(currentVersion)}` },
465
+ { value: "custom", title: "custom ...".padStart(PADDING + 4, " ") }
466
+ ]
467
+ },
468
+ {
469
+ type: (prev) => prev === "custom" ? "text" : null,
470
+ name: "custom",
471
+ message: "Enter the new version number:",
472
+ initial: currentVersion,
473
+ validate: (custom) => {
474
+ return (0, import_semver2.valid)(custom) ? true : "That's not a valid version number";
475
+ }
476
+ }
477
+ ]);
478
+ const newVersion = answers.release === "none" ? currentVersion : answers.release === "custom" ? (0, import_semver2.clean)(answers.custom) : answers.release === "config" ? (0, import_semver2.clean)(configCustomVersion) : next[answers.release];
479
+ if (!newVersion)
480
+ import_node_process2.default.exit(1);
481
+ switch (answers.release) {
482
+ case "custom":
483
+ case "config":
484
+ case "next":
485
+ case "conventional":
486
+ case "none":
487
+ return operation.update({ newVersion });
488
+ default:
489
+ return operation.update({ release: answers.release, newVersion });
490
+ }
491
+ }
492
+
493
+ // src/git.ts
494
+ var import_tinyexec = require("tinyexec");
495
+
496
+ // src/types/version-bump-progress.ts
497
+ var ProgressEvent = /* @__PURE__ */ ((ProgressEvent2) => {
498
+ ProgressEvent2["FileUpdated"] = "file updated";
499
+ ProgressEvent2["FileSkipped"] = "file skipped";
500
+ ProgressEvent2["GitCommit"] = "git commit";
501
+ ProgressEvent2["GitTag"] = "git tag";
502
+ ProgressEvent2["GitPush"] = "git push";
503
+ ProgressEvent2["NpmScript"] = "npm script";
504
+ return ProgressEvent2;
505
+ })(ProgressEvent || {});
506
+ var NpmScript = /* @__PURE__ */ ((NpmScript2) => {
507
+ NpmScript2["PreVersion"] = "preversion";
508
+ NpmScript2["Version"] = "version";
509
+ NpmScript2["PostVersion"] = "postversion";
510
+ return NpmScript2;
511
+ })(NpmScript || {});
512
+
513
+ // src/git.ts
514
+ async function gitCommit(operation) {
515
+ if (!operation.options.commit)
516
+ return operation;
517
+ const { all, noVerify, message } = operation.options.commit;
518
+ const { updatedFiles, newVersion } = operation.state;
519
+ let args = ["--allow-empty"];
520
+ if (all) {
521
+ args.push("--all");
522
+ }
523
+ if (noVerify) {
524
+ args.push("--no-verify");
525
+ }
526
+ if (operation.options.sign) {
527
+ args.push("--gpg-sign");
528
+ }
529
+ const commitMessage = formatVersionString(message, newVersion);
530
+ args.push("--message", commitMessage);
531
+ if (!all)
532
+ args = args.concat(updatedFiles);
533
+ await (0, import_tinyexec.x)("git", ["commit", ...args], { throwOnError: true });
534
+ return operation.update({ event: "git commit" /* GitCommit */, commitMessage });
535
+ }
536
+ async function gitTag(operation) {
537
+ if (!operation.options.tag)
538
+ return operation;
539
+ const { commit, tag } = operation.options;
540
+ const { newVersion } = operation.state;
541
+ const args = [
542
+ // Create an annotated tag, which is recommended for releases.
543
+ // See https://git-scm.com/docs/git-tag
544
+ "--annotate",
545
+ // Use the same commit message for the tag
546
+ "--message",
547
+ formatVersionString(commit.message, newVersion)
548
+ ];
549
+ const tagName = formatVersionString(tag.name, newVersion);
550
+ args.push(tagName);
551
+ if (operation.options.sign) {
552
+ args.push("--sign");
553
+ }
554
+ await (0, import_tinyexec.x)("git", ["tag", ...args], { throwOnError: true });
555
+ return operation.update({ event: "git tag" /* GitTag */, tagName });
556
+ }
557
+ async function gitPush(operation) {
558
+ if (!operation.options.push)
559
+ return operation;
560
+ await (0, import_tinyexec.x)("git", ["push"], { throwOnError: true });
561
+ if (operation.options.tag) {
562
+ await (0, import_tinyexec.x)("git", ["push", "--tags"], { throwOnError: true });
563
+ }
564
+ return operation.update({ event: "git push" /* GitPush */ });
565
+ }
566
+ function formatVersionString(template, newVersion) {
567
+ if (template.includes("%s"))
568
+ return template.replace(/%s/g, newVersion);
569
+ else
570
+ return template + newVersion;
571
+ }
572
+
573
+ // src/normalize-options.ts
574
+ var import_node_fs2 = __toESM(require("fs"), 1);
575
+ var import_promises = __toESM(require("fs/promises"), 1);
576
+ var import_node_process3 = __toESM(require("process"), 1);
577
+ var import_js_yaml = __toESM(require("js-yaml"), 1);
578
+ var import_tinyglobby = require("tinyglobby");
579
+ async function normalizeOptions(raw) {
580
+ const preid = typeof raw.preid === "string" ? raw.preid : "beta";
581
+ const sign = Boolean(raw.sign);
582
+ const push = Boolean(raw.push);
583
+ const all = Boolean(raw.all);
584
+ const install = Boolean(raw.install);
585
+ const noVerify = Boolean(raw.noVerify);
586
+ const cwd = raw.cwd || import_node_process3.default.cwd();
587
+ const ignoreScripts = Boolean(raw.ignoreScripts);
588
+ const execute = raw.execute;
589
+ const recursive = Boolean(raw.recursive);
590
+ let release;
591
+ if (!raw.release || raw.release === "prompt")
592
+ release = { type: "prompt", preid };
593
+ else if (isReleaseType(raw.release) || raw.release === "next")
594
+ release = { type: raw.release, preid };
595
+ else
596
+ release = { type: "version", version: raw.release };
597
+ let tag;
598
+ if (typeof raw.tag === "string")
599
+ tag = { name: raw.tag };
600
+ else if (raw.tag)
601
+ tag = { name: "v" };
602
+ let commit;
603
+ if (typeof raw.commit === "string")
604
+ commit = { all, noVerify, message: raw.commit };
605
+ else if (raw.commit || tag || push)
606
+ commit = { all, noVerify, message: "chore: release v" };
607
+ if (recursive && !raw.files?.length) {
608
+ raw.files = [
609
+ "package.json",
610
+ "package-lock.json",
611
+ "packages/**/package.json",
612
+ "jsr.json",
613
+ "jsr.jsonc",
614
+ "deno.json",
615
+ "deno.jsonc"
616
+ ];
617
+ if (import_node_fs2.default.existsSync("pnpm-workspace.yaml")) {
618
+ const pnpmWorkspace = await import_promises.default.readFile("pnpm-workspace.yaml", "utf8");
619
+ const workspaces = import_js_yaml.default.load(pnpmWorkspace);
620
+ const workspacesWithPackageJson = workspaces.packages.map((workspace) => `${workspace}/package.json`);
621
+ const withoutExcludedWorkspaces = workspacesWithPackageJson.filter((workspace) => !workspace.startsWith("!") && !raw.files?.includes(workspace));
622
+ raw.files = raw.files.concat(withoutExcludedWorkspaces);
623
+ }
624
+ } else {
625
+ raw.files = raw.files?.length ? raw.files : ["package.json", "package-lock.json", "jsr.json", "jsr.jsonc", "deno.json", "deno.jsonc"];
626
+ }
627
+ const files = await (0, import_tinyglobby.glob)(
628
+ raw.files,
629
+ {
630
+ cwd,
631
+ onlyFiles: true,
632
+ expandDirectories: false,
633
+ ignore: [
634
+ "**/{.git,node_modules,bower_components,__tests__,fixtures,fixture}/**"
635
+ ]
636
+ }
637
+ );
638
+ let ui;
639
+ if (raw.interface === false) {
640
+ ui = { input: false, output: false };
641
+ } else if (raw.interface === true || !raw.interface) {
642
+ ui = { input: import_node_process3.default.stdin, output: import_node_process3.default.stdout };
643
+ } else {
644
+ let { input, output, ...other } = raw.interface;
645
+ if (input === true || input !== false && !input)
646
+ input = import_node_process3.default.stdin;
647
+ if (output === true || output !== false && !output)
648
+ output = import_node_process3.default.stdout;
649
+ ui = { input, output, ...other };
650
+ }
651
+ if (release.type === "prompt" && !(ui.input && ui.output))
652
+ throw new Error("Cannot prompt for the version number because input or output has been disabled.");
653
+ return {
654
+ release,
655
+ commit,
656
+ tag,
657
+ sign,
658
+ push,
659
+ files,
660
+ cwd,
661
+ install,
662
+ interface: ui,
663
+ ignoreScripts,
664
+ execute,
665
+ printCommits: raw.printCommits ?? true,
666
+ customVersion: raw.customVersion,
667
+ currentVersion: raw.currentVersion
668
+ };
669
+ }
670
+
671
+ // src/operation.ts
672
+ var Operation = class _Operation {
673
+ /**
674
+ * The options for this operation.
675
+ */
676
+ options;
677
+ /**
678
+ * The current state of the operation.
679
+ */
680
+ state = {
681
+ release: void 0,
682
+ currentVersion: "",
683
+ currentVersionSource: "",
684
+ newVersion: "",
685
+ commitMessage: "",
686
+ tagName: "",
687
+ updatedFiles: [],
688
+ skippedFiles: []
689
+ };
690
+ /**
691
+ * The results of the operation.
692
+ */
693
+ get results() {
694
+ const options = this.options;
695
+ const state = this.state;
696
+ return {
697
+ release: state.release,
698
+ currentVersion: state.currentVersion,
699
+ newVersion: state.newVersion,
700
+ commit: options.commit ? state.commitMessage : false,
701
+ tag: options.tag ? state.tagName : false,
702
+ updatedFiles: state.updatedFiles.slice(),
703
+ skippedFiles: state.skippedFiles.slice()
704
+ };
705
+ }
706
+ /**
707
+ * The callback that's used to report the progress of the operation.
708
+ */
709
+ _progress;
710
+ /**
711
+ * Private constructor. Use the `Operation.start()` static method instead.
712
+ */
713
+ constructor(options, progress) {
714
+ this.options = options;
715
+ this._progress = progress;
716
+ if (options.currentVersion) {
717
+ this.update({
718
+ currentVersion: options.currentVersion,
719
+ currentVersionSource: "user"
720
+ });
721
+ }
722
+ }
723
+ /**
724
+ * Starts a new `versionBump()` operation.
725
+ */
726
+ static async start(input) {
727
+ const options = await normalizeOptions(input);
728
+ return new _Operation(options, input.progress);
729
+ }
730
+ /**
731
+ * Updates the operation state and results, and reports the updated progress to the user.
732
+ */
733
+ update({ event, script, ...newState }) {
734
+ Object.assign(this.state, newState);
735
+ if (event && this._progress) {
736
+ this._progress({ event, script, ...this.results });
737
+ }
738
+ return this;
739
+ }
740
+ };
741
+
742
+ // src/print-commits.ts
743
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
744
+ var messageColorMap = {
745
+ feat: import_picocolors2.default.green,
746
+ feature: import_picocolors2.default.green,
747
+ refactor: import_picocolors2.default.cyan,
748
+ style: import_picocolors2.default.cyan,
749
+ docs: import_picocolors2.default.blue,
750
+ doc: import_picocolors2.default.blue,
751
+ types: import_picocolors2.default.blue,
752
+ type: import_picocolors2.default.blue,
753
+ chore: import_picocolors2.default.gray,
754
+ ci: import_picocolors2.default.gray,
755
+ build: import_picocolors2.default.gray,
756
+ deps: import_picocolors2.default.gray,
757
+ dev: import_picocolors2.default.gray,
758
+ fix: import_picocolors2.default.yellow,
759
+ test: import_picocolors2.default.yellow,
760
+ perf: import_picocolors2.default.magenta,
761
+ revert: import_picocolors2.default.red,
762
+ breaking: import_picocolors2.default.red
763
+ };
764
+ function formatParsedCommits(commits) {
765
+ const typeLength = commits.map(({ type }) => type.length).reduce((a, b) => Math.max(a, b), 0);
766
+ const scopeLength = commits.map(({ scope }) => scope.length).reduce((a, b) => Math.max(a, b), 0);
767
+ return commits.map((commit) => {
768
+ let color = messageColorMap[commit.type] || ((c4) => c4);
769
+ if (commit.isBreaking) {
770
+ color = (s) => import_picocolors2.default.inverse(import_picocolors2.default.red(s));
771
+ }
772
+ const paddedType = commit.type.padStart(typeLength + 1, " ");
773
+ const paddedScope = !commit.scope ? " ".repeat(scopeLength ? scopeLength + 2 : 0) : import_picocolors2.default.dim("(") + commit.scope + import_picocolors2.default.dim(")") + " ".repeat(scopeLength - commit.scope.length);
774
+ return [
775
+ import_picocolors2.default.dim(commit.shortHash),
776
+ " ",
777
+ color === import_picocolors2.default.gray ? color(paddedType) : import_picocolors2.default.bold(color(paddedType)),
778
+ " ",
779
+ paddedScope,
780
+ import_picocolors2.default.dim(":"),
781
+ " ",
782
+ color === import_picocolors2.default.gray ? color(commit.description) : commit.description
783
+ ].join("");
784
+ });
785
+ }
786
+ function printRecentCommits(commits) {
787
+ if (!commits.length) {
788
+ console.log();
789
+ console.log(import_picocolors2.default.blue(`i`) + import_picocolors2.default.gray(` No commits since the last version`));
790
+ console.log();
791
+ return;
792
+ }
793
+ const prettified = formatParsedCommits(commits);
794
+ console.log();
795
+ console.log(
796
+ import_picocolors2.default.bold(
797
+ `${import_picocolors2.default.green(commits.length)} Commits since the last version:`
798
+ )
799
+ );
800
+ console.log();
801
+ console.log(prettified.join("\n"));
802
+ console.log();
803
+ }
804
+
805
+ // src/run-npm-script.ts
806
+ var import_tinyexec2 = require("tinyexec");
807
+ async function runNpmScript(script, operation) {
808
+ const { cwd, ignoreScripts } = operation.options;
809
+ if (!ignoreScripts) {
810
+ const { data: manifest } = await readJsoncFile("package.json", cwd);
811
+ if (isManifest(manifest) && hasScript(manifest, script)) {
812
+ await (0, import_tinyexec2.x)("npm", ["run", script, "--silent"], {
813
+ nodeOptions: { stdio: "inherit" }
814
+ });
815
+ operation.update({ event: "npm script" /* NpmScript */, script });
816
+ }
817
+ }
818
+ return operation;
819
+ }
820
+ function hasScript(manifest, script) {
821
+ const scripts = manifest.scripts;
822
+ if (scripts && typeof scripts === "object")
823
+ return Boolean(scripts[script]);
824
+ return false;
825
+ }
826
+
827
+ // src/update-files.ts
828
+ var import_node_fs3 = require("fs");
829
+ var path2 = __toESM(require("path"), 1);
830
+ async function updateFiles(operation) {
831
+ const { files } = operation.options;
832
+ for (const relPath of files) {
833
+ const modified = await updateFile(relPath, operation);
834
+ if (modified) {
835
+ operation.update({
836
+ event: "file updated" /* FileUpdated */,
837
+ updatedFiles: operation.state.updatedFiles.concat(relPath)
838
+ });
839
+ } else {
840
+ operation.update({
841
+ event: "file skipped" /* FileSkipped */,
842
+ skippedFiles: operation.state.skippedFiles.concat(relPath)
843
+ });
844
+ }
845
+ }
846
+ return operation;
847
+ }
848
+ async function updateFile(relPath, operation) {
849
+ if (!(0, import_node_fs3.existsSync)(path2.join(operation.options.cwd, relPath))) {
850
+ return false;
851
+ }
852
+ const name = path2.basename(relPath).trim().toLowerCase();
853
+ switch (name) {
854
+ case "package.json":
855
+ case "package-lock.json":
856
+ case "bower.json":
857
+ case "component.json":
858
+ case "jsr.json":
859
+ case "jsr.jsonc":
860
+ case "deno.json":
861
+ case "deno.jsonc":
862
+ return updateManifestFile(relPath, operation);
863
+ default:
864
+ return updateTextFile(relPath, operation);
865
+ }
866
+ }
867
+ async function updateManifestFile(relPath, operation) {
868
+ const { cwd } = operation.options;
869
+ const { newVersion } = operation.state;
870
+ let modified = false;
871
+ const file = await readJsoncFile(relPath, cwd);
872
+ if (!isManifest(file.data)) {
873
+ return modified;
874
+ }
875
+ if (file.data.version == null) {
876
+ return modified;
877
+ }
878
+ if (file.data.version !== newVersion) {
879
+ file.modified.push([["version"], newVersion]);
880
+ if (isPackageLockManifest(file.data))
881
+ file.modified.push([["packages", "", "version"], newVersion]);
882
+ await writeJsoncFile(file);
883
+ modified = true;
884
+ }
885
+ return modified;
886
+ }
887
+ async function updateTextFile(relPath, operation) {
888
+ const { cwd } = operation.options;
889
+ const { currentVersion, newVersion } = operation.state;
890
+ const modified = false;
891
+ const file = await readTextFile(relPath, cwd);
892
+ if (file.data.includes(currentVersion)) {
893
+ const sanitizedVersion = currentVersion.replace(/(\W)/g, "\\$1");
894
+ const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
895
+ file.data = file.data.replace(replacePattern, `$1${newVersion}`);
896
+ await writeTextFile(file);
897
+ return true;
898
+ }
899
+ return modified;
900
+ }
901
+
902
+ // src/version-bump.ts
903
+ async function versionBump(arg = {}) {
904
+ if (typeof arg === "string")
905
+ arg = { release: arg };
906
+ const operation = await Operation.start(arg);
907
+ const commits = (0, import_tiny_conventional_commits_parser.getRecentCommits)();
908
+ if (operation.options.printCommits) {
909
+ printRecentCommits(commits);
910
+ }
911
+ await getCurrentVersion(operation);
912
+ await getNewVersion(operation, commits);
913
+ if (arg.confirm) {
914
+ printSummary(operation);
915
+ if (!await (0, import_prompts2.default)({
916
+ name: "yes",
917
+ type: "confirm",
918
+ message: "Bump?",
919
+ initial: true
920
+ }).then((r) => r.yes)) {
921
+ import_node_process4.default.exit(1);
922
+ }
923
+ }
924
+ await runNpmScript("preversion" /* PreVersion */, operation);
925
+ await updateFiles(operation);
926
+ if (operation.options.install) {
927
+ const { detect } = await import("package-manager-detector/detect");
928
+ const pm = await detect();
929
+ if (!pm?.name) {
930
+ throw new Error("Could not detect package manager, failed to run npm install");
931
+ }
932
+ const { COMMANDS, constructCommand } = await import("package-manager-detector/commands");
933
+ const command = constructCommand(COMMANDS[pm.name].install, []);
934
+ if (!command) {
935
+ throw new Error("Could not find install command for package manager");
936
+ }
937
+ console.log(symbols_exports.info, "Installing dependencies with", `${command.command} ${command.args.join(" ")}`);
938
+ await (0, import_tinyexec3.x)(command.command, command.args, {
939
+ throwOnError: true,
940
+ nodeOptions: {
941
+ stdio: "inherit",
942
+ cwd: operation.options.cwd
943
+ }
944
+ });
945
+ console.log(symbols_exports.success, "Dependencies installed");
946
+ }
947
+ if (operation.options.execute) {
948
+ if (typeof operation.options.execute === "function") {
949
+ await operation.options.execute(operation);
950
+ } else {
951
+ const [command, ...args] = tokenizeArgs(operation.options.execute);
952
+ console.log(symbols_exports.info, "Executing script", command, ...args);
953
+ await (0, import_tinyexec3.x)(command, args, {
954
+ throwOnError: true,
955
+ nodeOptions: {
956
+ stdio: "inherit",
957
+ cwd: operation.options.cwd
958
+ }
959
+ });
960
+ console.log(symbols_exports.success, "Script finished");
961
+ }
962
+ }
963
+ await runNpmScript("version" /* Version */, operation);
964
+ await gitCommit(operation);
965
+ await gitTag(operation);
966
+ await runNpmScript("postversion" /* PostVersion */, operation);
967
+ await gitPush(operation);
968
+ return operation.results;
969
+ }
970
+ function printSummary(operation) {
971
+ console.log();
972
+ console.log(` files ${operation.options.files.map((i) => import_picocolors3.default.bold(i)).join("\n ")}`);
973
+ if (operation.options.commit)
974
+ console.log(` commit ${import_picocolors3.default.bold(formatVersionString(operation.options.commit.message, operation.state.newVersion))}`);
975
+ if (operation.options.tag)
976
+ console.log(` tag ${import_picocolors3.default.bold(formatVersionString(operation.options.tag.name, operation.state.newVersion))}`);
977
+ if (operation.options.execute)
978
+ console.log(` execute ${import_picocolors3.default.bold(typeof operation.options.execute === "function" ? "function" : operation.options.execute)}`);
979
+ if (operation.options.push)
980
+ console.log(` push ${import_picocolors3.default.cyan(import_picocolors3.default.bold("yes"))}`);
981
+ if (operation.options.install)
982
+ console.log(` install ${import_picocolors3.default.cyan(import_picocolors3.default.bold("yes"))}`);
983
+ console.log();
984
+ console.log(` from ${import_picocolors3.default.bold(operation.state.currentVersion)}`);
985
+ console.log(` to ${import_picocolors3.default.green(import_picocolors3.default.bold(operation.state.newVersion))}`);
986
+ console.log();
987
+ }
988
+ async function versionBumpInfo(arg = {}) {
989
+ if (typeof arg === "string")
990
+ arg = { release: arg };
991
+ const operation = await Operation.start(arg);
992
+ const commits = (0, import_tiny_conventional_commits_parser.getRecentCommits)();
993
+ await getCurrentVersion(operation);
994
+ await getNewVersion(operation, commits);
995
+ return operation;
996
+ }
997
+
998
+ // src/config.ts
999
+ var import_node_path2 = require("path");
1000
+ var import_node_process5 = __toESM(require("process"), 1);
1001
+ var import_c12 = require("c12");
1002
+ var import_sync = __toESM(require("escalade/sync"), 1);
1003
+ var bumpConfigDefaults = {
1004
+ commit: true,
1005
+ push: true,
1006
+ tag: true,
1007
+ sign: false,
1008
+ install: false,
1009
+ recursive: false,
1010
+ noVerify: false,
1011
+ confirm: true,
1012
+ ignoreScripts: false,
1013
+ all: false,
1014
+ noGitCheck: true,
1015
+ files: []
1016
+ };
1017
+ async function loadBumpConfig(overrides, cwd = import_node_process5.default.cwd()) {
1018
+ const name = "bump";
1019
+ const configFile = findConfigFile(name, cwd);
1020
+ const { config } = await (0, import_c12.loadConfig)({
1021
+ name,
1022
+ defaults: bumpConfigDefaults,
1023
+ overrides: {
1024
+ ...overrides
1025
+ },
1026
+ cwd: configFile ? (0, import_node_path2.dirname)(configFile) : cwd
1027
+ });
1028
+ return config;
1029
+ }
1030
+ function findConfigFile(name, cwd) {
1031
+ let foundRepositoryRoot = false;
1032
+ try {
1033
+ const candidates = ["js", "mjs", "ts", "mts", "json"].map((ext) => `${name}.config.${ext}`);
1034
+ return (0, import_sync.default)(cwd, (_dir, files) => {
1035
+ const match = files.find((file) => {
1036
+ if (candidates.includes(file))
1037
+ return true;
1038
+ if (file === ".git")
1039
+ foundRepositoryRoot = true;
1040
+ return false;
1041
+ });
1042
+ if (match)
1043
+ return match;
1044
+ if (foundRepositoryRoot) {
1045
+ throw null;
1046
+ }
1047
+ return false;
1048
+ });
1049
+ } catch (error2) {
1050
+ if (foundRepositoryRoot)
1051
+ return null;
1052
+ throw error2;
1053
+ }
1054
+ }
1055
+ function defineConfig(config) {
1056
+ return config;
1057
+ }
1058
+
1059
+ // src/index.ts
1060
+ var src_default = versionBump;
1061
+ // Annotate the CommonJS export names for ESM import in node:
1062
+ 0 && (module.exports = {
1063
+ NpmScript,
1064
+ ProgressEvent,
1065
+ bumpConfigDefaults,
1066
+ defineConfig,
1067
+ loadBumpConfig,
1068
+ versionBump,
1069
+ versionBumpInfo
1070
+ });