bumpp 7.1.0 → 8.0.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/cli/index.js CHANGED
@@ -1,28 +1,762 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __esm = (fn, res) => function __init() {
38
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
39
+ };
40
+ var __commonJS = (cb, mod) => function __require() {
41
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
42
+ };
43
+ var __export = (target, all) => {
44
+ for (var name2 in all)
45
+ __defProp(target, name2, { get: all[name2], enumerable: true });
46
+ };
47
+ var __reExport = (target, module2, copyDefault, desc) => {
48
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
49
+ for (let key of __getOwnPropNames(module2))
50
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
51
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
52
+ }
53
+ return target;
54
+ };
55
+ var __toESM = (module2, isNodeMode) => {
56
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
57
+ };
58
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
59
+ return (module2, temp) => {
60
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
61
+ };
62
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
63
+
64
+ // node_modules/.pnpm/tsup@5.11.9_typescript@4.5.4/node_modules/tsup/assets/cjs_shims.js
65
+ var init_cjs_shims = __esm({
66
+ "node_modules/.pnpm/tsup@5.11.9_typescript@4.5.4/node_modules/tsup/assets/cjs_shims.js"() {
67
+ }
68
+ });
69
+
70
+ // node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js
71
+ var require_is_unicode_supported = __commonJS({
72
+ "node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js"(exports, module2) {
73
+ "use strict";
74
+ init_cjs_shims();
75
+ module2.exports = () => {
76
+ if (process.platform !== "win32") {
77
+ return true;
78
+ }
79
+ return Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) || process.env.TERM_PROGRAM === "vscode" || process.env.TERM === "xterm-256color" || process.env.TERM === "alacritty";
80
+ };
81
+ }
82
+ });
83
+
84
+ // node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js
85
+ var require_log_symbols = __commonJS({
86
+ "node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js"(exports, module2) {
87
+ "use strict";
88
+ init_cjs_shims();
89
+ var chalk = require("chalk");
90
+ var isUnicodeSupported = require_is_unicode_supported();
91
+ var main2 = {
92
+ info: chalk.blue("\u2139"),
93
+ success: chalk.green("\u2714"),
94
+ warning: chalk.yellow("\u26A0"),
95
+ error: chalk.red("\u2716")
96
+ };
97
+ var fallback = {
98
+ info: chalk.blue("i"),
99
+ success: chalk.green("\u221A"),
100
+ warning: chalk.yellow("\u203C"),
101
+ error: chalk.red("\xD7")
102
+ };
103
+ module2.exports = isUnicodeSupported() ? main2 : fallback;
104
+ }
105
+ });
106
+
107
+ // node_modules/.pnpm/detect-newline@3.1.0/node_modules/detect-newline/index.js
108
+ var require_detect_newline = __commonJS({
109
+ "node_modules/.pnpm/detect-newline@3.1.0/node_modules/detect-newline/index.js"(exports, module2) {
110
+ "use strict";
111
+ init_cjs_shims();
112
+ var detectNewline2 = (string) => {
113
+ if (typeof string !== "string") {
114
+ throw new TypeError("Expected a string");
115
+ }
116
+ const newlines = string.match(/(?:\r?\n)/g) || [];
117
+ if (newlines.length === 0) {
118
+ return;
119
+ }
120
+ const crlf = newlines.filter((newline) => newline === "\r\n").length;
121
+ const lf = newlines.length - crlf;
122
+ return crlf > lf ? "\r\n" : "\n";
123
+ };
124
+ module2.exports = detectNewline2;
125
+ module2.exports.graceful = (string) => typeof string === "string" && detectNewline2(string) || "\n";
126
+ }
127
+ });
2
128
 
129
+ // src/cli/index.ts
130
+ var cli_exports = {};
131
+ __export(cli_exports, {
132
+ main: () => main
133
+ });
134
+ init_cjs_shims();
135
+ var import_log_symbols2 = __toESM(require_log_symbols());
3
136
 
137
+ // package.json
138
+ var name = "bumpp";
139
+ var version = "8.0.0";
140
+ var description = "Automatically (or with prompts) bump your version number, commit changes, tag, and push to Git";
4
141
 
142
+ // src/types/version-bump-progress.ts
143
+ init_cjs_shims();
144
+ var ProgressEvent = /* @__PURE__ */ ((ProgressEvent2) => {
145
+ ProgressEvent2["FileUpdated"] = "file updated";
146
+ ProgressEvent2["FileSkipped"] = "file skipped";
147
+ ProgressEvent2["GitCommit"] = "git commit";
148
+ ProgressEvent2["GitTag"] = "git tag";
149
+ ProgressEvent2["GitPush"] = "git push";
150
+ ProgressEvent2["NpmScript"] = "npm script";
151
+ return ProgressEvent2;
152
+ })(ProgressEvent || {});
153
+ var NpmScript = /* @__PURE__ */ ((NpmScript2) => {
154
+ NpmScript2["PreVersion"] = "preversion";
155
+ NpmScript2["Version"] = "version";
156
+ NpmScript2["PostVersion"] = "postversion";
157
+ return NpmScript2;
158
+ })(NpmScript || {});
159
+
160
+ // src/version-bump.ts
161
+ init_cjs_shims();
162
+ var ezSpawn3 = __toESM(require("@jsdevtools/ez-spawn"));
163
+ var import_chalk2 = require("chalk");
164
+ var import_log_symbols = __toESM(require_log_symbols());
165
+ var import_prompts2 = __toESM(require("prompts"));
166
+
167
+ // src/get-new-version.ts
168
+ init_cjs_shims();
169
+ var import_chalk = require("chalk");
170
+ var import_prompts = __toESM(require("prompts"));
171
+ var import_semver2 = __toESM(require("semver"));
172
+
173
+ // src/release-type.ts
174
+ init_cjs_shims();
175
+ var import_semver = require("semver");
176
+ var prereleaseTypes = ["premajor", "preminor", "prepatch", "prerelease"];
177
+ var releaseTypes = prereleaseTypes.concat(["major", "minor", "patch"]);
178
+ function isPrerelease(value) {
179
+ return prereleaseTypes.includes(value);
180
+ }
181
+ function isReleaseType(value) {
182
+ return releaseTypes.includes(value);
183
+ }
5
184
 
185
+ // src/get-new-version.ts
186
+ async function getNewVersion(operation) {
187
+ const { release } = operation.options;
188
+ const { oldVersion } = operation.state;
189
+ switch (release.type) {
190
+ case "prompt":
191
+ return promptForNewVersion(operation);
192
+ case "version":
193
+ return operation.update({
194
+ newVersion: new import_semver2.SemVer(release.version, true).version
195
+ });
196
+ default:
197
+ return operation.update({
198
+ release: release.type,
199
+ newVersion: getNextVersion(oldVersion, release)
200
+ });
201
+ }
202
+ }
203
+ function getNextVersion(oldVersion, bump) {
204
+ const oldSemVer = new import_semver2.SemVer(oldVersion);
205
+ const newSemVer = oldSemVer.inc(bump.type, bump.preid);
206
+ if (isPrerelease(bump.type) && newSemVer.prerelease.length === 2 && newSemVer.prerelease[0] === bump.preid && String(newSemVer.prerelease[1]) === "0") {
207
+ newSemVer.prerelease[1] = "1";
208
+ newSemVer.format();
209
+ }
210
+ return newSemVer.version;
211
+ }
212
+ function getNextVersions(oldVersion, preid) {
213
+ var _a;
214
+ const next = {};
215
+ const parse = import_semver2.default.parse(oldVersion);
216
+ if (typeof (parse == null ? void 0 : parse.prerelease[0]) === "string")
217
+ preid = (parse == null ? void 0 : parse.prerelease[0]) || "preid";
218
+ for (const type of releaseTypes)
219
+ next[type] = import_semver2.default.inc(oldVersion, type, preid);
220
+ 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");
221
+ return next;
222
+ }
223
+ async function promptForNewVersion(operation) {
224
+ const { oldVersion } = operation.state;
225
+ const release = operation.options.release;
226
+ const next = getNextVersions(oldVersion, release.preid);
227
+ const PADDING = 13;
228
+ const answers = await (0, import_prompts.default)([
229
+ {
230
+ type: "autocomplete",
231
+ name: "release",
232
+ message: `Current version ${(0, import_chalk.green)(oldVersion)}`,
233
+ initial: "next",
234
+ choices: [
235
+ { value: "major", title: `${"major".padStart(PADDING, " ")} ${(0, import_chalk.bold)(next.major)}` },
236
+ { value: "minor", title: `${"minor".padStart(PADDING, " ")} ${(0, import_chalk.bold)(next.minor)}` },
237
+ { value: "patch", title: `${"patch".padStart(PADDING, " ")} ${(0, import_chalk.bold)(next.patch)}` },
238
+ { value: "next", title: `${"next".padStart(PADDING, " ")} ${(0, import_chalk.bold)(next.next)}` },
239
+ { value: "prerelease", title: `${"pre-release".padStart(PADDING, " ")} ${(0, import_chalk.bold)(next.prerelease)}` },
240
+ { value: "none", title: `${"as-is".padStart(PADDING, " ")} ${(0, import_chalk.bold)(oldVersion)}` },
241
+ { value: "custom", title: "custom ...".padStart(PADDING + 4, " ") }
242
+ ]
243
+ },
244
+ {
245
+ type: (prev) => prev === "custom" ? "text" : null,
246
+ name: "custom",
247
+ message: "Enter the new version number:",
248
+ initial: oldVersion,
249
+ validate: (custom) => {
250
+ return (0, import_semver2.valid)(custom) ? true : "That's not a valid version number";
251
+ }
252
+ }
253
+ ]);
254
+ const newVersion = answers.release === "none" ? oldVersion : answers.release === "custom" ? (0, import_semver2.clean)(answers.custom) : next[answers.release];
255
+ if (!newVersion)
256
+ process.exit(1);
257
+ switch (answers.release) {
258
+ case "custom":
259
+ case "next":
260
+ case "none":
261
+ return operation.update({ newVersion });
262
+ default:
263
+ return operation.update({ release: answers.release, newVersion });
264
+ }
265
+ }
6
266
 
7
- var _chunkXF5JTHA6js = require('../chunk-XF5JTHA6.js');
267
+ // src/get-old-version.ts
268
+ init_cjs_shims();
269
+ var import_semver3 = require("semver");
270
+
271
+ // src/fs.ts
272
+ init_cjs_shims();
273
+ var import_fs = __toESM(require("fs"));
274
+ var import_path = __toESM(require("path"));
275
+
276
+ // node_modules/.pnpm/detect-indent@7.0.0/node_modules/detect-indent/index.js
277
+ init_cjs_shims();
278
+ var INDENT_REGEX = /^(?:( )+|\t+)/;
279
+ var INDENT_TYPE_SPACE = "space";
280
+ var INDENT_TYPE_TAB = "tab";
281
+ function makeIndentsMap(string, ignoreSingleSpaces) {
282
+ const indents = /* @__PURE__ */ new Map();
283
+ let previousSize = 0;
284
+ let previousIndentType;
285
+ let key;
286
+ for (const line of string.split(/\n/g)) {
287
+ if (!line) {
288
+ continue;
289
+ }
290
+ let indent;
291
+ let indentType;
292
+ let weight;
293
+ let entry;
294
+ const matches = line.match(INDENT_REGEX);
295
+ if (matches === null) {
296
+ previousSize = 0;
297
+ previousIndentType = "";
298
+ } else {
299
+ indent = matches[0].length;
300
+ indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
301
+ if (ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && indent === 1) {
302
+ continue;
303
+ }
304
+ if (indentType !== previousIndentType) {
305
+ previousSize = 0;
306
+ }
307
+ previousIndentType = indentType;
308
+ weight = 0;
309
+ const indentDifference = indent - previousSize;
310
+ previousSize = indent;
311
+ if (indentDifference === 0) {
312
+ weight++;
313
+ } else {
314
+ const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
315
+ key = encodeIndentsKey(indentType, absoluteIndentDifference);
316
+ }
317
+ entry = indents.get(key);
318
+ entry = entry === void 0 ? [1, 0] : [++entry[0], entry[1] + weight];
319
+ indents.set(key, entry);
320
+ }
321
+ }
322
+ return indents;
323
+ }
324
+ function encodeIndentsKey(indentType, indentAmount) {
325
+ const typeCharacter = indentType === INDENT_TYPE_SPACE ? "s" : "t";
326
+ return typeCharacter + String(indentAmount);
327
+ }
328
+ function decodeIndentsKey(indentsKey) {
329
+ const keyHasTypeSpace = indentsKey[0] === "s";
330
+ const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
331
+ const amount = Number(indentsKey.slice(1));
332
+ return { type, amount };
333
+ }
334
+ function getMostUsedKey(indents) {
335
+ let result;
336
+ let maxUsed = 0;
337
+ let maxWeight = 0;
338
+ for (const [key, [usedCount, weight]] of indents) {
339
+ if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
340
+ maxUsed = usedCount;
341
+ maxWeight = weight;
342
+ result = key;
343
+ }
344
+ }
345
+ return result;
346
+ }
347
+ function makeIndentString(type, amount) {
348
+ const indentCharacter = type === INDENT_TYPE_SPACE ? " " : " ";
349
+ return indentCharacter.repeat(amount);
350
+ }
351
+ function detectIndent(string) {
352
+ if (typeof string !== "string") {
353
+ throw new TypeError("Expected a string");
354
+ }
355
+ let indents = makeIndentsMap(string, true);
356
+ if (indents.size === 0) {
357
+ indents = makeIndentsMap(string, false);
358
+ }
359
+ const keyOfMostUsedIndent = getMostUsedKey(indents);
360
+ let type;
361
+ let amount = 0;
362
+ let indent = "";
363
+ if (keyOfMostUsedIndent !== void 0) {
364
+ ({ type, amount } = decodeIndentsKey(keyOfMostUsedIndent));
365
+ indent = makeIndentString(type, amount);
366
+ }
367
+ return {
368
+ amount,
369
+ type,
370
+ indent
371
+ };
372
+ }
8
373
 
9
- // src/cli/index.ts
10
- var import_log_symbols = _chunkXF5JTHA6js.__toModule.call(void 0, _chunkXF5JTHA6js.require_log_symbols.call(void 0, ));
374
+ // src/fs.ts
375
+ var import_detect_newline = __toESM(require_detect_newline());
376
+ async function readJsonFile(name2, cwd) {
377
+ const file = await readTextFile(name2, cwd);
378
+ const data = JSON.parse(file.data);
379
+ const indent = detectIndent(file.data).indent;
380
+ const newline = (0, import_detect_newline.default)(file.data);
381
+ return __spreadProps(__spreadValues({}, file), { data, indent, newline });
382
+ }
383
+ async function writeJsonFile(file) {
384
+ let json = JSON.stringify(file.data, void 0, file.indent);
385
+ if (file.newline)
386
+ json += file.newline;
387
+ return writeTextFile(__spreadProps(__spreadValues({}, file), { data: json }));
388
+ }
389
+ function readTextFile(name2, cwd) {
390
+ return new Promise((resolve, reject) => {
391
+ const filePath = import_path.default.join(cwd, name2);
392
+ import_fs.default.readFile(filePath, "utf8", (err, text) => {
393
+ if (err) {
394
+ reject(err);
395
+ } else {
396
+ resolve({
397
+ path: filePath,
398
+ data: text
399
+ });
400
+ }
401
+ });
402
+ });
403
+ }
404
+ function writeTextFile(file) {
405
+ return new Promise((resolve, reject) => {
406
+ import_fs.default.writeFile(file.path, file.data, (err) => {
407
+ if (err)
408
+ reject(err);
409
+ else
410
+ resolve();
411
+ });
412
+ });
413
+ }
11
414
 
12
- // package.json
13
- var name = "bumpp";
14
- var version = "7.1.0";
15
- var description = "Automatically (or with prompts) bump your version number, commit changes, tag, and push to Git";
415
+ // src/manifest.ts
416
+ init_cjs_shims();
417
+ function isManifest(obj) {
418
+ return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
419
+ }
420
+ function isOptionalString(value) {
421
+ const type = typeof value;
422
+ return value === null || type === "undefined" || type === "string";
423
+ }
424
+
425
+ // src/get-old-version.ts
426
+ async function getOldVersion(operation) {
427
+ const { cwd, files } = operation.options;
428
+ const filesToCheck = files.filter((file) => file.endsWith(".json"));
429
+ if (!filesToCheck.includes("package.json"))
430
+ filesToCheck.push("package.json");
431
+ for (const file of filesToCheck) {
432
+ const version2 = await readVersion(file, cwd);
433
+ if (version2) {
434
+ return operation.update({
435
+ oldVersionSource: file,
436
+ oldVersion: version2
437
+ });
438
+ }
439
+ }
440
+ throw new Error(`Unable to determine the current version number. Checked ${filesToCheck.join(", ")}.`);
441
+ }
442
+ async function readVersion(file, cwd) {
443
+ try {
444
+ const { data: manifest } = await readJsonFile(file, cwd);
445
+ if (isManifest(manifest)) {
446
+ if ((0, import_semver3.valid)(manifest.version))
447
+ return manifest.version;
448
+ }
449
+ } catch (error) {
450
+ return void 0;
451
+ }
452
+ }
453
+
454
+ // src/git.ts
455
+ init_cjs_shims();
456
+ var ezSpawn = __toESM(require("@jsdevtools/ez-spawn"));
457
+ async function gitCommit(operation) {
458
+ if (!operation.options.commit)
459
+ return operation;
460
+ const { all, noVerify, message } = operation.options.commit;
461
+ const { updatedFiles, newVersion } = operation.state;
462
+ let args = [];
463
+ if (all) {
464
+ args.push("--all");
465
+ }
466
+ if (noVerify) {
467
+ args.push("--no-verify");
468
+ }
469
+ const commitMessage = formatVersionString(message, newVersion);
470
+ args.push("--message", commitMessage);
471
+ if (!all)
472
+ args = args.concat(updatedFiles);
473
+ await ezSpawn.async("git", ["commit", ...args]);
474
+ return operation.update({ event: "git commit" /* GitCommit */, commitMessage });
475
+ }
476
+ async function gitTag(operation) {
477
+ if (!operation.options.tag)
478
+ return operation;
479
+ const { commit, tag } = operation.options;
480
+ const { newVersion } = operation.state;
481
+ const args = [
482
+ "--annotate",
483
+ "--message",
484
+ formatVersionString(commit.message, newVersion)
485
+ ];
486
+ const tagName = formatVersionString(tag.name, newVersion);
487
+ args.push(tagName);
488
+ await ezSpawn.async("git", ["tag", ...args]);
489
+ return operation.update({ event: "git tag" /* GitTag */, tagName });
490
+ }
491
+ async function gitPush(operation) {
492
+ if (!operation.options.push)
493
+ return operation;
494
+ await ezSpawn.async("git", "push");
495
+ if (operation.options.tag) {
496
+ await ezSpawn.async("git", ["push", "--tags"]);
497
+ }
498
+ return operation.update({ event: "git push" /* GitPush */ });
499
+ }
500
+ function formatVersionString(template, newVersion) {
501
+ if (template.includes("%s"))
502
+ return template.replace(/%s/g, newVersion);
503
+ else
504
+ return template + newVersion;
505
+ }
506
+
507
+ // src/operation.ts
508
+ init_cjs_shims();
509
+
510
+ // src/normalize-options.ts
511
+ init_cjs_shims();
512
+ var import_globby = __toESM(require("globby"));
513
+ async function normalizeOptions(raw) {
514
+ const preid = typeof raw.preid === "string" ? raw.preid : "beta";
515
+ const push = Boolean(raw.push);
516
+ const all = Boolean(raw.all);
517
+ const noVerify = Boolean(raw.noVerify);
518
+ const cwd = raw.cwd || process.cwd();
519
+ const ignoreScripts = Boolean(raw.ignoreScripts);
520
+ const execute = raw.execute;
521
+ let release;
522
+ if (!raw.release || raw.release === "prompt")
523
+ release = { type: "prompt", preid };
524
+ else if (isReleaseType(raw.release))
525
+ release = { type: raw.release, preid };
526
+ else
527
+ release = { type: "version", version: raw.release };
528
+ let tag;
529
+ if (typeof raw.tag === "string")
530
+ tag = { name: raw.tag };
531
+ else if (raw.tag)
532
+ tag = { name: "v" };
533
+ let commit;
534
+ if (typeof raw.commit === "string")
535
+ commit = { all, noVerify, message: raw.commit };
536
+ else if (raw.commit || tag || push)
537
+ commit = { all, noVerify, message: "chore: release v" };
538
+ let files;
539
+ if (Array.isArray(raw.files) && raw.files.length > 0) {
540
+ files = await strictGlobMatches(raw.files, { cwd });
541
+ } else {
542
+ files = await (0, import_globby.default)(["package.json", "package-lock.json"], { cwd });
543
+ }
544
+ let ui;
545
+ if (raw.interface === false) {
546
+ ui = { input: false, outut: false };
547
+ } else if (raw.interface === true || !raw.interface) {
548
+ ui = { input: process.stdin, output: process.stdout };
549
+ } else {
550
+ let _a = raw.interface, { input, output } = _a, other = __objRest(_a, ["input", "output"]);
551
+ if (input === true || input !== false && !input)
552
+ input = process.stdin;
553
+ if (output === true || output !== false && !output)
554
+ output = process.stdout;
555
+ ui = __spreadValues({ input, output }, other);
556
+ }
557
+ if (release.type === "prompt" && !(ui.input && ui.output))
558
+ throw new Error("Cannot prompt for the version number because input or output has been disabled.");
559
+ return { release, commit, tag, push, files, cwd, interface: ui, ignoreScripts, execute };
560
+ }
561
+ async function strictGlobMatches(files, options) {
562
+ const matches = await Promise.all(files.map((file) => strictGlobMatch(file, options)));
563
+ const matchedFiles = /* @__PURE__ */ new Set();
564
+ for (const match of matches) {
565
+ for (const file of match)
566
+ matchedFiles.add(file);
567
+ }
568
+ return [...matchedFiles];
569
+ }
570
+ async function strictGlobMatch(file, options) {
571
+ const matches = await (0, import_globby.default)(file, options);
572
+ if (matches.length === 0) {
573
+ if ((0, import_globby.hasMagic)(file))
574
+ throw new Error(`Could not find any files matching "${file}".`);
575
+ else
576
+ throw new Error(`Could not find file: ${file}.`);
577
+ }
578
+ return matches.sort();
579
+ }
580
+
581
+ // src/operation.ts
582
+ var Operation = class {
583
+ constructor(options, progress2) {
584
+ this.state = {
585
+ release: void 0,
586
+ oldVersion: "",
587
+ oldVersionSource: "",
588
+ newVersion: "",
589
+ commitMessage: "",
590
+ tagName: "",
591
+ updatedFiles: [],
592
+ skippedFiles: []
593
+ };
594
+ this.options = options;
595
+ this._progress = progress2;
596
+ }
597
+ get results() {
598
+ const options = this.options;
599
+ const state = this.state;
600
+ return {
601
+ release: state.release,
602
+ oldVersion: state.oldVersion,
603
+ newVersion: state.newVersion,
604
+ commit: options.commit ? state.commitMessage : false,
605
+ tag: options.tag ? state.tagName : false,
606
+ updatedFiles: state.updatedFiles.slice(),
607
+ skippedFiles: state.skippedFiles.slice()
608
+ };
609
+ }
610
+ static async start(input) {
611
+ const options = await normalizeOptions(input);
612
+ return new Operation(options, input.progress);
613
+ }
614
+ update(_a) {
615
+ var _b = _a, { event, script } = _b, newState = __objRest(_b, ["event", "script"]);
616
+ Object.assign(this.state, newState);
617
+ if (event && this._progress) {
618
+ this._progress(__spreadValues({ event, script }, this.results));
619
+ }
620
+ return this;
621
+ }
622
+ };
623
+
624
+ // src/run-npm-script.ts
625
+ init_cjs_shims();
626
+ var ezSpawn2 = __toESM(require("@jsdevtools/ez-spawn"));
627
+ async function runNpmScript(script, operation) {
628
+ const { cwd, ignoreScripts } = operation.options;
629
+ if (!ignoreScripts) {
630
+ const { data: manifest } = await readJsonFile("package.json", cwd);
631
+ if (isManifest(manifest) && hasScript(manifest, script)) {
632
+ await ezSpawn2.async("npm", ["run", script, "--silent"], { stdio: "inherit" });
633
+ operation.update({ event: "npm script" /* NpmScript */, script });
634
+ }
635
+ }
636
+ return operation;
637
+ }
638
+ function hasScript(manifest, script) {
639
+ const scripts = manifest.scripts;
640
+ if (scripts && typeof scripts === "object")
641
+ return Boolean(scripts[script]);
642
+ return false;
643
+ }
644
+
645
+ // src/update-files.ts
646
+ init_cjs_shims();
647
+ var path2 = __toESM(require("path"));
648
+ async function updateFiles(operation) {
649
+ const { files } = operation.options;
650
+ for (const relPath of files) {
651
+ const modified = await updateFile(relPath, operation);
652
+ if (modified) {
653
+ operation.update({
654
+ event: "file updated" /* FileUpdated */,
655
+ updatedFiles: operation.state.updatedFiles.concat(relPath)
656
+ });
657
+ } else {
658
+ operation.update({
659
+ event: "file skipped" /* FileSkipped */,
660
+ skippedFiles: operation.state.skippedFiles.concat(relPath)
661
+ });
662
+ }
663
+ }
664
+ return operation;
665
+ }
666
+ async function updateFile(relPath, operation) {
667
+ const name2 = path2.basename(relPath).trim().toLowerCase();
668
+ switch (name2) {
669
+ case "package.json":
670
+ case "package-lock.json":
671
+ case "bower.json":
672
+ case "component.json":
673
+ return updateManifestFile(relPath, operation);
674
+ default:
675
+ return updateTextFile(relPath, operation);
676
+ }
677
+ }
678
+ async function updateManifestFile(relPath, operation) {
679
+ const { cwd } = operation.options;
680
+ const { newVersion } = operation.state;
681
+ let modified = false;
682
+ const file = await readJsonFile(relPath, cwd);
683
+ if (isManifest(file.data) && file.data.version !== newVersion) {
684
+ file.data.version = newVersion;
685
+ await writeJsonFile(file);
686
+ modified = true;
687
+ }
688
+ return modified;
689
+ }
690
+ async function updateTextFile(relPath, operation) {
691
+ const { cwd } = operation.options;
692
+ const { oldVersion, newVersion } = operation.state;
693
+ const modified = false;
694
+ const file = await readTextFile(relPath, cwd);
695
+ if (file.data.includes(oldVersion)) {
696
+ const sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
697
+ const replacePattern = new RegExp(`(\\b|v)${sanitizedVersion}\\b`, "g");
698
+ file.data = file.data.replace(replacePattern, `$1${newVersion}`);
699
+ await writeTextFile(file);
700
+ return true;
701
+ }
702
+ return modified;
703
+ }
704
+
705
+ // src/version-bump.ts
706
+ async function versionBump(arg = {}) {
707
+ if (typeof arg === "string")
708
+ arg = { release: arg };
709
+ const operation = await Operation.start(arg);
710
+ await getOldVersion(operation);
711
+ await getNewVersion(operation);
712
+ if (arg.confirm) {
713
+ console.log();
714
+ console.log(` files ${operation.options.files.map((i) => (0, import_chalk2.bold)(i)).join(", ")}`);
715
+ if (operation.options.commit)
716
+ console.log(` commit ${(0, import_chalk2.bold)(formatVersionString(operation.options.commit.message, operation.state.newVersion))}`);
717
+ if (operation.options.tag)
718
+ console.log(` tag ${(0, import_chalk2.bold)(formatVersionString(operation.options.tag.name, operation.state.newVersion))}`);
719
+ if (operation.options.execute)
720
+ console.log(` execute ${(0, import_chalk2.bold)(operation.options.execute)}`);
721
+ if (operation.options.push)
722
+ console.log(` push ${(0, import_chalk2.cyan)((0, import_chalk2.bold)("yes"))}`);
723
+ console.log();
724
+ console.log(` from ${(0, import_chalk2.bold)(operation.state.oldVersion)}`);
725
+ console.log(` to ${(0, import_chalk2.green)((0, import_chalk2.bold)(operation.state.newVersion))}`);
726
+ console.log();
727
+ if (!await (0, import_prompts2.default)({
728
+ name: "yes",
729
+ type: "confirm",
730
+ message: "Bump"
731
+ }).then((r) => r.yes))
732
+ return;
733
+ }
734
+ await runNpmScript("preversion" /* PreVersion */, operation);
735
+ await updateFiles(operation);
736
+ if (operation.options.execute) {
737
+ console.log(import_log_symbols.info, "Executing script", operation.options.execute);
738
+ await ezSpawn3.async(operation.options.execute, { stdio: "inherit" });
739
+ console.log(import_log_symbols.success, "Script finished");
740
+ }
741
+ await runNpmScript("version" /* Version */, operation);
742
+ await gitCommit(operation);
743
+ await gitTag(operation);
744
+ await runNpmScript("postversion" /* PostVersion */, operation);
745
+ await gitPush(operation);
746
+ return operation.results;
747
+ }
16
748
 
17
749
  // src/cli/exit-code.ts
18
- var ExitCode;
19
- (function(ExitCode2) {
750
+ init_cjs_shims();
751
+ var ExitCode = /* @__PURE__ */ ((ExitCode2) => {
20
752
  ExitCode2[ExitCode2["Success"] = 0] = "Success";
21
753
  ExitCode2[ExitCode2["FatalError"] = 1] = "FatalError";
22
754
  ExitCode2[ExitCode2["InvalidArgument"] = 9] = "InvalidArgument";
23
- })(ExitCode || (ExitCode = {}));
755
+ return ExitCode2;
756
+ })(ExitCode || {});
24
757
 
25
758
  // src/cli/help.ts
759
+ init_cjs_shims();
26
760
  var usageText = `
27
761
  Usage: bumpp [release] [options] [files...]
28
762
 
@@ -99,25 +833,15 @@ ${name} v${version} - ${description}
99
833
  ${usageText}`;
100
834
 
101
835
  // src/cli/parse-args.ts
102
- var _commandlineargs = require('command-line-args'); var _commandlineargs2 = _interopRequireDefault(_commandlineargs);
103
- var _semver = require('semver');
836
+ init_cjs_shims();
837
+ var import_semver4 = require("semver");
838
+ var import_cac = __toESM(require("cac"));
104
839
  function parseArgs(argv) {
105
840
  try {
106
- let args = _commandlineargs2.default.call(void 0, [
107
- { name: "preid", type: String },
108
- { name: "commit", alias: "c", type: String },
109
- { name: "tag", alias: "t", type: String },
110
- { name: "push", alias: "p", type: Boolean },
111
- { name: "all", alias: "a", type: Boolean },
112
- { name: "no-verify", type: Boolean },
113
- { name: "quiet", alias: "q", type: Boolean },
114
- { name: "version", alias: "v", type: Boolean },
115
- { name: "help", alias: "h", type: Boolean },
116
- { name: "ignore-scripts", type: Boolean },
117
- { name: "execute", alias: "x", type: String },
118
- { name: "files", type: String, multiple: true, defaultOption: true }
119
- ], { argv });
120
- let parsedArgs = {
841
+ const cli = (0, import_cac.default)("bumpp");
842
+ cli.version(version).usage("[...files]").option("--preid <preid>", "ID for prerelease").option("--all", "Include all files").option("-c, --commit [msg]", "Commit message", { default: true }).option("-t, --tag [tag]", "Tag name", { default: true }).option("-p, --push", "Push to remote", { default: true }).option("-y, --yes", "Skip confirmation").option("--no-verify", "Skip git verification").option("--ignore-scripts", "Ignore scripts", { default: false }).option("-q, --quiet", "Quiet mode").option("-v, --version <version>", "Tagert version").option("-x, --execute <command>", "Commands to execute after version bumps").help();
843
+ const args = cli.parse(argv).options;
844
+ const parsedArgs = {
121
845
  help: args.help,
122
846
  version: args.version,
123
847
  quiet: args.quiet,
@@ -127,24 +851,16 @@ function parseArgs(argv) {
127
851
  tag: args.tag,
128
852
  push: args.push,
129
853
  all: args.all,
130
- noVerify: args["no-verify"],
131
- files: args.files,
132
- ignoreScripts: args["ignore-scripts"],
854
+ confirm: !args.yes,
855
+ noVerify: !args.verify,
856
+ files: args["--"],
857
+ ignoreScripts: args.ignoreScripts,
133
858
  execute: args.execute
134
859
  }
135
860
  };
136
- if (args.preid === null) {
137
- throw new Error('The --preid option requires a value, such as "alpha", "beta", etc.');
138
- }
139
- if (args.commit === null) {
140
- parsedArgs.options.commit = true;
141
- }
142
- if (args.tag === null) {
143
- parsedArgs.options.tag = true;
144
- }
145
861
  if (parsedArgs.options.files && parsedArgs.options.files.length > 0) {
146
- let firstArg = parsedArgs.options.files[0];
147
- if (firstArg === "prompt" || _chunkXF5JTHA6js.isReleaseType.call(void 0, firstArg) || _semver.valid.call(void 0, firstArg)) {
862
+ const firstArg = parsedArgs.options.files[0];
863
+ if (firstArg === "prompt" || isReleaseType(firstArg) || (0, import_semver4.valid)(firstArg)) {
148
864
  parsedArgs.options.release = firstArg;
149
865
  parsedArgs.options.files.shift();
150
866
  }
@@ -157,7 +873,7 @@ function parseArgs(argv) {
157
873
  function errorHandler(error) {
158
874
  console.error(error.message);
159
875
  console.error(usageText);
160
- return process.exit(ExitCode.InvalidArgument);
876
+ return process.exit(9 /* InvalidArgument */);
161
877
  }
162
878
 
163
879
  // src/cli/index.ts
@@ -165,18 +881,17 @@ async function main(args) {
165
881
  try {
166
882
  process.on("uncaughtException", errorHandler2);
167
883
  process.on("unhandledRejection", errorHandler2);
168
- let { help, version: version2, quiet, options } = parseArgs(args);
884
+ const { help, version: version2, quiet, options } = parseArgs(args);
169
885
  if (help) {
170
886
  console.log(helpText);
171
- process.exit(ExitCode.Success);
887
+ process.exit(0 /* Success */);
172
888
  } else if (version2) {
173
889
  console.log(version);
174
- process.exit(ExitCode.Success);
890
+ process.exit(0 /* Success */);
175
891
  } else {
176
- if (!quiet) {
892
+ if (!quiet)
177
893
  options.progress = progress;
178
- }
179
- await _chunkXF5JTHA6js.versionBump.call(void 0, options);
894
+ await versionBump(options);
180
895
  }
181
896
  } catch (error) {
182
897
  errorHandler2(error);
@@ -184,34 +899,35 @@ async function main(args) {
184
899
  }
185
900
  function progress({ event, script, updatedFiles, skippedFiles, newVersion }) {
186
901
  switch (event) {
187
- case _chunkXF5JTHA6js.ProgressEvent.FileUpdated:
188
- console.log(import_log_symbols.success, `Updated ${updatedFiles.pop()} to ${newVersion}`);
902
+ case "file updated" /* FileUpdated */:
903
+ console.log(import_log_symbols2.success, `Updated ${updatedFiles.pop()} to ${newVersion}`);
189
904
  break;
190
- case _chunkXF5JTHA6js.ProgressEvent.FileSkipped:
191
- console.log(import_log_symbols.info, `${skippedFiles.pop()} did not need to be updated`);
905
+ case "file skipped" /* FileSkipped */:
906
+ console.log(import_log_symbols2.info, `${skippedFiles.pop()} did not need to be updated`);
192
907
  break;
193
- case _chunkXF5JTHA6js.ProgressEvent.GitCommit:
194
- console.log(import_log_symbols.success, "Git commit");
908
+ case "git commit" /* GitCommit */:
909
+ console.log(import_log_symbols2.success, "Git commit");
195
910
  break;
196
- case _chunkXF5JTHA6js.ProgressEvent.GitTag:
197
- console.log(import_log_symbols.success, "Git tag");
911
+ case "git tag" /* GitTag */:
912
+ console.log(import_log_symbols2.success, "Git tag");
198
913
  break;
199
- case _chunkXF5JTHA6js.ProgressEvent.GitPush:
200
- console.log(import_log_symbols.success, "Git push");
914
+ case "git push" /* GitPush */:
915
+ console.log(import_log_symbols2.success, "Git push");
201
916
  break;
202
- case _chunkXF5JTHA6js.ProgressEvent.NpmScript:
203
- console.log(import_log_symbols.success, `Npm run ${script}`);
917
+ case "npm script" /* NpmScript */:
918
+ console.log(import_log_symbols2.success, `Npm run ${script}`);
204
919
  break;
205
920
  }
206
921
  }
207
922
  function errorHandler2(error) {
208
923
  let message = error.message || String(error);
209
- if (process.env.DEBUG || process.env.NODE_ENV === "development") {
924
+ if (process.env.DEBUG || process.env.NODE_ENV === "development")
210
925
  message = error.stack || message;
211
- }
212
926
  console.error(message);
213
- process.exit(ExitCode.FatalError);
927
+ process.exit(1 /* FatalError */);
214
928
  }
215
-
216
-
217
- exports.main = main;
929
+ module.exports = __toCommonJS(cli_exports);
930
+ // Annotate the CommonJS export names for ESM import in node:
931
+ 0 && (module.exports = {
932
+ main
933
+ });