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