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