@releasekit/release 0.3.0 → 0.4.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/README.md +22 -1
- package/dist/chunk-I5CGC253.js +438 -0
- package/dist/chunk-WNKYXS62.js +46 -0
- package/dist/chunk-YZHGXRG6.js +651 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +58 -0
- package/dist/dispatcher.d.ts +6 -0
- package/dist/dispatcher.js +92 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +10 -0
- package/docs/ci-setup.md +266 -0
- package/package.json +7 -6
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
// ../core/dist/index.js
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
function readPackageVersion(importMetaUrl) {
|
|
7
|
+
try {
|
|
8
|
+
const dir = path.dirname(fileURLToPath(importMetaUrl));
|
|
9
|
+
const packageJsonPath = path.resolve(dir, "../package.json");
|
|
10
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
11
|
+
return packageJson.version ?? "0.0.0";
|
|
12
|
+
} catch {
|
|
13
|
+
return "0.0.0";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var LOG_LEVELS = {
|
|
17
|
+
error: 0,
|
|
18
|
+
warn: 1,
|
|
19
|
+
info: 2,
|
|
20
|
+
debug: 3,
|
|
21
|
+
trace: 4
|
|
22
|
+
};
|
|
23
|
+
var PREFIXES = {
|
|
24
|
+
error: "[ERROR]",
|
|
25
|
+
warn: "[WARN]",
|
|
26
|
+
info: "[INFO]",
|
|
27
|
+
debug: "[DEBUG]",
|
|
28
|
+
trace: "[TRACE]"
|
|
29
|
+
};
|
|
30
|
+
var COLORS = {
|
|
31
|
+
error: chalk.red,
|
|
32
|
+
warn: chalk.yellow,
|
|
33
|
+
info: chalk.blue,
|
|
34
|
+
debug: chalk.gray,
|
|
35
|
+
trace: chalk.dim
|
|
36
|
+
};
|
|
37
|
+
var currentLevel = "info";
|
|
38
|
+
var quietMode = false;
|
|
39
|
+
function setLogLevel(level) {
|
|
40
|
+
currentLevel = level;
|
|
41
|
+
}
|
|
42
|
+
function setQuietMode(quiet) {
|
|
43
|
+
quietMode = quiet;
|
|
44
|
+
}
|
|
45
|
+
function setJsonMode(_json) {
|
|
46
|
+
}
|
|
47
|
+
function shouldLog(level) {
|
|
48
|
+
if (quietMode && level !== "error") return false;
|
|
49
|
+
return LOG_LEVELS[level] <= LOG_LEVELS[currentLevel];
|
|
50
|
+
}
|
|
51
|
+
function log(message, level = "info") {
|
|
52
|
+
if (!shouldLog(level)) return;
|
|
53
|
+
const formatted = COLORS[level](`${PREFIXES[level]} ${message}`);
|
|
54
|
+
console.error(formatted);
|
|
55
|
+
}
|
|
56
|
+
function error(message) {
|
|
57
|
+
log(message, "error");
|
|
58
|
+
}
|
|
59
|
+
function warn(message) {
|
|
60
|
+
log(message, "warn");
|
|
61
|
+
}
|
|
62
|
+
function info(message) {
|
|
63
|
+
log(message, "info");
|
|
64
|
+
}
|
|
65
|
+
function success(message) {
|
|
66
|
+
if (!shouldLog("info")) return;
|
|
67
|
+
console.error(chalk.green(`[SUCCESS] ${message}`));
|
|
68
|
+
}
|
|
69
|
+
var ReleaseKitError = class _ReleaseKitError extends Error {
|
|
70
|
+
constructor(message) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.name = this.constructor.name;
|
|
73
|
+
}
|
|
74
|
+
logError() {
|
|
75
|
+
log(this.message, "error");
|
|
76
|
+
if (this.suggestions.length > 0) {
|
|
77
|
+
log("\nSuggested solutions:", "info");
|
|
78
|
+
for (const [i, suggestion] of this.suggestions.entries()) {
|
|
79
|
+
log(`${i + 1}. ${suggestion}`, "info");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
static isReleaseKitError(error2) {
|
|
84
|
+
return error2 instanceof _ReleaseKitError;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var EXIT_CODES = {
|
|
88
|
+
SUCCESS: 0,
|
|
89
|
+
GENERAL_ERROR: 1,
|
|
90
|
+
CONFIG_ERROR: 2,
|
|
91
|
+
INPUT_ERROR: 3,
|
|
92
|
+
TEMPLATE_ERROR: 4,
|
|
93
|
+
LLM_ERROR: 5,
|
|
94
|
+
GITHUB_ERROR: 6,
|
|
95
|
+
GIT_ERROR: 7,
|
|
96
|
+
VERSION_ERROR: 8,
|
|
97
|
+
PUBLISH_ERROR: 9
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/release.ts
|
|
101
|
+
import { execSync } from "child_process";
|
|
102
|
+
|
|
103
|
+
// ../config/dist/index.js
|
|
104
|
+
import * as fs2 from "fs";
|
|
105
|
+
import * as path2 from "path";
|
|
106
|
+
import * as TOML from "smol-toml";
|
|
107
|
+
import * as fs3 from "fs";
|
|
108
|
+
import * as path3 from "path";
|
|
109
|
+
import { z as z2 } from "zod";
|
|
110
|
+
import { z } from "zod";
|
|
111
|
+
import * as fs22 from "fs";
|
|
112
|
+
import * as os from "os";
|
|
113
|
+
import * as path22 from "path";
|
|
114
|
+
var ConfigError = class extends ReleaseKitError {
|
|
115
|
+
code = "CONFIG_ERROR";
|
|
116
|
+
suggestions;
|
|
117
|
+
constructor(message, suggestions) {
|
|
118
|
+
super(message);
|
|
119
|
+
this.suggestions = suggestions ?? [
|
|
120
|
+
"Check that releasekit.config.json exists and is valid JSON",
|
|
121
|
+
"Run with --verbose for more details"
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var MAX_JSONC_LENGTH = 1e5;
|
|
126
|
+
function parseJsonc(content) {
|
|
127
|
+
if (content.length > MAX_JSONC_LENGTH) {
|
|
128
|
+
throw new Error(`JSONC content too long: ${content.length} characters (max ${MAX_JSONC_LENGTH})`);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(content);
|
|
132
|
+
} catch {
|
|
133
|
+
const cleaned = content.replace(/\/\/[^\r\n]{0,10000}$/gm, "").replace(/\/\*[\s\S]{0,50000}?\*\//g, "").trim();
|
|
134
|
+
return JSON.parse(cleaned);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
var GitConfigSchema = z.object({
|
|
138
|
+
remote: z.string().default("origin"),
|
|
139
|
+
branch: z.string().default("main"),
|
|
140
|
+
pushMethod: z.enum(["auto", "ssh", "https"]).default("auto"),
|
|
141
|
+
/**
|
|
142
|
+
* Optional env var name containing a GitHub token for HTTPS pushes.
|
|
143
|
+
* When set, publish steps can use this token without mutating git remotes.
|
|
144
|
+
*/
|
|
145
|
+
httpsTokenEnv: z.string().optional(),
|
|
146
|
+
push: z.boolean().optional(),
|
|
147
|
+
skipHooks: z.boolean().optional()
|
|
148
|
+
});
|
|
149
|
+
var MonorepoConfigSchema = z.object({
|
|
150
|
+
mode: z.enum(["root", "packages", "both"]).optional(),
|
|
151
|
+
rootPath: z.string().optional(),
|
|
152
|
+
packagesPath: z.string().optional(),
|
|
153
|
+
mainPackage: z.string().optional()
|
|
154
|
+
});
|
|
155
|
+
var BranchPatternSchema = z.object({
|
|
156
|
+
pattern: z.string(),
|
|
157
|
+
releaseType: z.enum(["major", "minor", "patch", "prerelease"])
|
|
158
|
+
});
|
|
159
|
+
var VersionCargoConfigSchema = z.object({
|
|
160
|
+
enabled: z.boolean().default(true),
|
|
161
|
+
paths: z.array(z.string()).optional()
|
|
162
|
+
});
|
|
163
|
+
var VersionConfigSchema = z.object({
|
|
164
|
+
tagTemplate: z.string().default("v{version}"),
|
|
165
|
+
packageSpecificTags: z.boolean().default(false),
|
|
166
|
+
preset: z.string().default("conventional"),
|
|
167
|
+
sync: z.boolean().default(true),
|
|
168
|
+
packages: z.array(z.string()).default([]),
|
|
169
|
+
mainPackage: z.string().optional(),
|
|
170
|
+
updateInternalDependencies: z.enum(["major", "minor", "patch", "no-internal-update"]).default("minor"),
|
|
171
|
+
skip: z.array(z.string()).optional(),
|
|
172
|
+
commitMessage: z.string().optional(),
|
|
173
|
+
versionStrategy: z.enum(["branchPattern", "commitMessage"]).default("commitMessage"),
|
|
174
|
+
branchPatterns: z.array(BranchPatternSchema).optional(),
|
|
175
|
+
defaultReleaseType: z.enum(["major", "minor", "patch", "prerelease"]).optional(),
|
|
176
|
+
mismatchStrategy: z.enum(["error", "warn", "ignore", "prefer-package", "prefer-git"]).default("warn"),
|
|
177
|
+
versionPrefix: z.string().default(""),
|
|
178
|
+
prereleaseIdentifier: z.string().optional(),
|
|
179
|
+
strictReachable: z.boolean().default(false),
|
|
180
|
+
cargo: VersionCargoConfigSchema.optional()
|
|
181
|
+
});
|
|
182
|
+
var NpmConfigSchema = z.object({
|
|
183
|
+
enabled: z.boolean().default(true),
|
|
184
|
+
auth: z.enum(["auto", "oidc", "token"]).default("auto"),
|
|
185
|
+
provenance: z.boolean().default(true),
|
|
186
|
+
access: z.enum(["public", "restricted"]).default("public"),
|
|
187
|
+
registry: z.string().default("https://registry.npmjs.org"),
|
|
188
|
+
copyFiles: z.array(z.string()).default(["LICENSE"]),
|
|
189
|
+
tag: z.string().default("latest")
|
|
190
|
+
});
|
|
191
|
+
var CargoPublishConfigSchema = z.object({
|
|
192
|
+
enabled: z.boolean().default(false),
|
|
193
|
+
noVerify: z.boolean().default(false),
|
|
194
|
+
publishOrder: z.array(z.string()).default([]),
|
|
195
|
+
clean: z.boolean().default(false)
|
|
196
|
+
});
|
|
197
|
+
var PublishGitConfigSchema = z.object({
|
|
198
|
+
push: z.boolean().default(true),
|
|
199
|
+
pushMethod: z.enum(["auto", "ssh", "https"]).optional(),
|
|
200
|
+
remote: z.string().optional(),
|
|
201
|
+
branch: z.string().optional(),
|
|
202
|
+
httpsTokenEnv: z.string().optional(),
|
|
203
|
+
skipHooks: z.boolean().optional()
|
|
204
|
+
});
|
|
205
|
+
var GitHubReleaseConfigSchema = z.object({
|
|
206
|
+
enabled: z.boolean().default(true),
|
|
207
|
+
draft: z.boolean().default(true),
|
|
208
|
+
perPackage: z.boolean().default(true),
|
|
209
|
+
prerelease: z.union([z.literal("auto"), z.boolean()]).default("auto"),
|
|
210
|
+
/**
|
|
211
|
+
* Controls the source for the GitHub release body.
|
|
212
|
+
* - 'auto': Use release notes if enabled, else changelog, else GitHub auto-generated.
|
|
213
|
+
* - 'releaseNotes': Use LLM-generated release notes (requires notes.releaseNotes.enabled: true).
|
|
214
|
+
* - 'changelog': Use formatted changelog entries.
|
|
215
|
+
* - 'generated': Use GitHub's auto-generated notes.
|
|
216
|
+
* - 'none': No body.
|
|
217
|
+
*/
|
|
218
|
+
body: z.enum(["auto", "releaseNotes", "changelog", "generated", "none"]).default("auto")
|
|
219
|
+
});
|
|
220
|
+
var VerifyRegistryConfigSchema = z.object({
|
|
221
|
+
enabled: z.boolean().default(true),
|
|
222
|
+
maxAttempts: z.number().int().positive().default(5),
|
|
223
|
+
initialDelay: z.number().int().positive().default(15e3),
|
|
224
|
+
backoffMultiplier: z.number().positive().default(2)
|
|
225
|
+
});
|
|
226
|
+
var VerifyConfigSchema = z.object({
|
|
227
|
+
npm: VerifyRegistryConfigSchema.default({
|
|
228
|
+
enabled: true,
|
|
229
|
+
maxAttempts: 5,
|
|
230
|
+
initialDelay: 15e3,
|
|
231
|
+
backoffMultiplier: 2
|
|
232
|
+
}),
|
|
233
|
+
cargo: VerifyRegistryConfigSchema.default({
|
|
234
|
+
enabled: true,
|
|
235
|
+
maxAttempts: 10,
|
|
236
|
+
initialDelay: 3e4,
|
|
237
|
+
backoffMultiplier: 2
|
|
238
|
+
})
|
|
239
|
+
});
|
|
240
|
+
var PublishConfigSchema = z.object({
|
|
241
|
+
git: PublishGitConfigSchema.optional(),
|
|
242
|
+
npm: NpmConfigSchema.default({
|
|
243
|
+
enabled: true,
|
|
244
|
+
auth: "auto",
|
|
245
|
+
provenance: true,
|
|
246
|
+
access: "public",
|
|
247
|
+
registry: "https://registry.npmjs.org",
|
|
248
|
+
copyFiles: ["LICENSE"],
|
|
249
|
+
tag: "latest"
|
|
250
|
+
}),
|
|
251
|
+
cargo: CargoPublishConfigSchema.default({
|
|
252
|
+
enabled: false,
|
|
253
|
+
noVerify: false,
|
|
254
|
+
publishOrder: [],
|
|
255
|
+
clean: false
|
|
256
|
+
}),
|
|
257
|
+
githubRelease: GitHubReleaseConfigSchema.default({
|
|
258
|
+
enabled: true,
|
|
259
|
+
draft: true,
|
|
260
|
+
perPackage: true,
|
|
261
|
+
prerelease: "auto",
|
|
262
|
+
body: "auto"
|
|
263
|
+
}),
|
|
264
|
+
verify: VerifyConfigSchema.default({
|
|
265
|
+
npm: {
|
|
266
|
+
enabled: true,
|
|
267
|
+
maxAttempts: 5,
|
|
268
|
+
initialDelay: 15e3,
|
|
269
|
+
backoffMultiplier: 2
|
|
270
|
+
},
|
|
271
|
+
cargo: {
|
|
272
|
+
enabled: true,
|
|
273
|
+
maxAttempts: 10,
|
|
274
|
+
initialDelay: 3e4,
|
|
275
|
+
backoffMultiplier: 2
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
});
|
|
279
|
+
var TemplateConfigSchema = z.object({
|
|
280
|
+
path: z.string().optional(),
|
|
281
|
+
engine: z.enum(["handlebars", "liquid", "ejs"]).optional()
|
|
282
|
+
});
|
|
283
|
+
var LocationModeSchema = z.enum(["root", "packages", "both"]);
|
|
284
|
+
var ChangelogConfigSchema = z.object({
|
|
285
|
+
mode: LocationModeSchema.optional(),
|
|
286
|
+
file: z.string().optional(),
|
|
287
|
+
templates: TemplateConfigSchema.optional()
|
|
288
|
+
});
|
|
289
|
+
var LLMOptionsSchema = z.object({
|
|
290
|
+
timeout: z.number().optional(),
|
|
291
|
+
maxTokens: z.number().optional(),
|
|
292
|
+
temperature: z.number().optional()
|
|
293
|
+
});
|
|
294
|
+
var LLMRetryConfigSchema = z.object({
|
|
295
|
+
maxAttempts: z.number().int().positive().optional(),
|
|
296
|
+
initialDelay: z.number().nonnegative().optional(),
|
|
297
|
+
maxDelay: z.number().positive().optional(),
|
|
298
|
+
backoffFactor: z.number().positive().optional()
|
|
299
|
+
});
|
|
300
|
+
var LLMTasksConfigSchema = z.object({
|
|
301
|
+
summarize: z.boolean().optional(),
|
|
302
|
+
enhance: z.boolean().optional(),
|
|
303
|
+
categorize: z.boolean().optional(),
|
|
304
|
+
releaseNotes: z.boolean().optional()
|
|
305
|
+
});
|
|
306
|
+
var LLMCategorySchema = z.object({
|
|
307
|
+
name: z.string(),
|
|
308
|
+
description: z.string(),
|
|
309
|
+
scopes: z.array(z.string()).optional()
|
|
310
|
+
});
|
|
311
|
+
var ScopeRulesSchema = z.object({
|
|
312
|
+
allowed: z.array(z.string()).optional(),
|
|
313
|
+
caseSensitive: z.boolean().default(false),
|
|
314
|
+
invalidScopeAction: z.enum(["remove", "keep", "fallback"]).default("remove"),
|
|
315
|
+
fallbackScope: z.string().optional()
|
|
316
|
+
});
|
|
317
|
+
var ScopeConfigSchema = z.object({
|
|
318
|
+
mode: z.enum(["restricted", "packages", "none", "unrestricted"]).default("unrestricted"),
|
|
319
|
+
rules: ScopeRulesSchema.optional()
|
|
320
|
+
});
|
|
321
|
+
var LLMPromptOverridesSchema = z.object({
|
|
322
|
+
enhance: z.string().optional(),
|
|
323
|
+
categorize: z.string().optional(),
|
|
324
|
+
enhanceAndCategorize: z.string().optional(),
|
|
325
|
+
summarize: z.string().optional(),
|
|
326
|
+
releaseNotes: z.string().optional()
|
|
327
|
+
});
|
|
328
|
+
var LLMPromptsConfigSchema = z.object({
|
|
329
|
+
instructions: LLMPromptOverridesSchema.optional(),
|
|
330
|
+
templates: LLMPromptOverridesSchema.optional()
|
|
331
|
+
});
|
|
332
|
+
var LLMConfigSchema = z.object({
|
|
333
|
+
provider: z.string(),
|
|
334
|
+
model: z.string(),
|
|
335
|
+
baseURL: z.string().optional(),
|
|
336
|
+
apiKey: z.string().optional(),
|
|
337
|
+
options: LLMOptionsSchema.optional(),
|
|
338
|
+
concurrency: z.number().int().positive().optional(),
|
|
339
|
+
retry: LLMRetryConfigSchema.optional(),
|
|
340
|
+
tasks: LLMTasksConfigSchema.optional(),
|
|
341
|
+
categories: z.array(LLMCategorySchema).optional(),
|
|
342
|
+
style: z.string().optional(),
|
|
343
|
+
scopes: ScopeConfigSchema.optional(),
|
|
344
|
+
prompts: LLMPromptsConfigSchema.optional()
|
|
345
|
+
});
|
|
346
|
+
var ReleaseNotesConfigSchema = z.object({
|
|
347
|
+
mode: LocationModeSchema.optional(),
|
|
348
|
+
file: z.string().optional(),
|
|
349
|
+
templates: TemplateConfigSchema.optional(),
|
|
350
|
+
llm: LLMConfigSchema.optional()
|
|
351
|
+
});
|
|
352
|
+
var NotesInputConfigSchema = z.object({
|
|
353
|
+
source: z.string().optional(),
|
|
354
|
+
file: z.string().optional()
|
|
355
|
+
});
|
|
356
|
+
var NotesConfigSchema = z.object({
|
|
357
|
+
changelog: z.union([z.literal(false), ChangelogConfigSchema]).optional(),
|
|
358
|
+
releaseNotes: z.union([z.literal(false), ReleaseNotesConfigSchema]).optional(),
|
|
359
|
+
updateStrategy: z.enum(["prepend", "regenerate"]).optional()
|
|
360
|
+
});
|
|
361
|
+
var CILabelsConfigSchema = z.object({
|
|
362
|
+
stable: z.string().default("release:stable"),
|
|
363
|
+
prerelease: z.string().default("release:prerelease"),
|
|
364
|
+
skip: z.string().default("release:skip"),
|
|
365
|
+
major: z.string().default("release:major"),
|
|
366
|
+
minor: z.string().default("release:minor"),
|
|
367
|
+
patch: z.string().default("release:patch")
|
|
368
|
+
});
|
|
369
|
+
var CIConfigSchema = z.object({
|
|
370
|
+
releaseStrategy: z.enum(["manual", "direct", "standing-pr", "scheduled"]).default("direct"),
|
|
371
|
+
releaseTrigger: z.enum(["commit", "label"]).default("label"),
|
|
372
|
+
prPreview: z.boolean().default(true),
|
|
373
|
+
autoRelease: z.boolean().default(false),
|
|
374
|
+
/**
|
|
375
|
+
* Commit message prefixes that should not trigger a release.
|
|
376
|
+
* Defaults to `['chore: release ']` to match the release commit template
|
|
377
|
+
* (`chore: release ${packageName} v${version}`) and provide a
|
|
378
|
+
* secondary loop-prevention guard alongside `[skip ci]`.
|
|
379
|
+
*/
|
|
380
|
+
skipPatterns: z.array(z.string()).default(["chore: release "]),
|
|
381
|
+
minChanges: z.number().int().positive().default(1),
|
|
382
|
+
labels: CILabelsConfigSchema.default({
|
|
383
|
+
stable: "release:stable",
|
|
384
|
+
prerelease: "release:prerelease",
|
|
385
|
+
skip: "release:skip",
|
|
386
|
+
major: "release:major",
|
|
387
|
+
minor: "release:minor",
|
|
388
|
+
patch: "release:patch"
|
|
389
|
+
})
|
|
390
|
+
});
|
|
391
|
+
var ReleaseCIConfigSchema = z.object({
|
|
392
|
+
skipPatterns: z.array(z.string().min(1)).optional(),
|
|
393
|
+
minChanges: z.number().int().positive().optional(),
|
|
394
|
+
/** Set to `false` to disable GitHub release creation in CI. */
|
|
395
|
+
githubRelease: z.literal(false).optional(),
|
|
396
|
+
/** Set to `false` to disable changelog generation in CI. */
|
|
397
|
+
notes: z.literal(false).optional()
|
|
398
|
+
});
|
|
399
|
+
var ReleaseConfigSchema = z.object({
|
|
400
|
+
/**
|
|
401
|
+
* Optional steps to enable. The version step always runs; only 'notes' and
|
|
402
|
+
* 'publish' can be opted out. Omitting a step is equivalent to --skip-<step>.
|
|
403
|
+
*/
|
|
404
|
+
steps: z.array(z.enum(["notes", "publish"])).min(1).optional(),
|
|
405
|
+
ci: ReleaseCIConfigSchema.optional()
|
|
406
|
+
});
|
|
407
|
+
var ReleaseKitConfigSchema = z.object({
|
|
408
|
+
git: GitConfigSchema.optional(),
|
|
409
|
+
monorepo: MonorepoConfigSchema.optional(),
|
|
410
|
+
version: VersionConfigSchema.optional(),
|
|
411
|
+
publish: PublishConfigSchema.optional(),
|
|
412
|
+
notes: NotesConfigSchema.optional(),
|
|
413
|
+
ci: CIConfigSchema.optional(),
|
|
414
|
+
release: ReleaseConfigSchema.optional()
|
|
415
|
+
});
|
|
416
|
+
var MAX_INPUT_LENGTH = 1e4;
|
|
417
|
+
function substituteVariables(value) {
|
|
418
|
+
if (value.length > MAX_INPUT_LENGTH) {
|
|
419
|
+
throw new Error(`Input too long: ${value.length} characters (max ${MAX_INPUT_LENGTH})`);
|
|
420
|
+
}
|
|
421
|
+
const envPattern = /\{env:([^}]{1,1000})\}/g;
|
|
422
|
+
const filePattern = /\{file:([^}]{1,1000})\}/g;
|
|
423
|
+
let result = value;
|
|
424
|
+
result = result.replace(envPattern, (_, varName) => {
|
|
425
|
+
return process.env[varName] ?? "";
|
|
426
|
+
});
|
|
427
|
+
result = result.replace(filePattern, (_, filePath) => {
|
|
428
|
+
const expandedPath = filePath.startsWith("~") ? path22.join(os.homedir(), filePath.slice(1)) : filePath;
|
|
429
|
+
try {
|
|
430
|
+
return fs22.readFileSync(expandedPath, "utf-8").trim();
|
|
431
|
+
} catch {
|
|
432
|
+
return "";
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
var SOLE_REFERENCE_PATTERN = /^\{(?:env|file):[^}]+\}$/;
|
|
438
|
+
function substituteInObject(obj) {
|
|
439
|
+
if (typeof obj === "string") {
|
|
440
|
+
const result = substituteVariables(obj);
|
|
441
|
+
if (result === "" && SOLE_REFERENCE_PATTERN.test(obj)) {
|
|
442
|
+
return void 0;
|
|
443
|
+
}
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
if (Array.isArray(obj)) {
|
|
447
|
+
return obj.map((item) => substituteInObject(item));
|
|
448
|
+
}
|
|
449
|
+
if (obj && typeof obj === "object") {
|
|
450
|
+
const result = {};
|
|
451
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
452
|
+
result[key] = substituteInObject(value);
|
|
453
|
+
}
|
|
454
|
+
return result;
|
|
455
|
+
}
|
|
456
|
+
return obj;
|
|
457
|
+
}
|
|
458
|
+
var AUTH_DIR = path22.join(os.homedir(), ".config", "releasekit");
|
|
459
|
+
var AUTH_FILE = path22.join(AUTH_DIR, "auth.json");
|
|
460
|
+
var CONFIG_FILE = "releasekit.config.json";
|
|
461
|
+
function loadConfigFile(configPath) {
|
|
462
|
+
if (!fs3.existsSync(configPath)) {
|
|
463
|
+
return {};
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
const content = fs3.readFileSync(configPath, "utf-8");
|
|
467
|
+
const parsed = parseJsonc(content);
|
|
468
|
+
const substituted = substituteInObject(parsed);
|
|
469
|
+
return ReleaseKitConfigSchema.parse(substituted);
|
|
470
|
+
} catch (error2) {
|
|
471
|
+
if (error2 instanceof z2.ZodError) {
|
|
472
|
+
const issues = error2.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
473
|
+
throw new ConfigError(`Config validation errors:
|
|
474
|
+
${issues}`);
|
|
475
|
+
}
|
|
476
|
+
if (error2 instanceof SyntaxError) {
|
|
477
|
+
throw new ConfigError(`Invalid JSON in config file: ${error2.message}`);
|
|
478
|
+
}
|
|
479
|
+
throw error2;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function loadConfig(options) {
|
|
483
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
484
|
+
const configPath = options?.configPath ?? path3.join(cwd, CONFIG_FILE);
|
|
485
|
+
return loadConfigFile(configPath);
|
|
486
|
+
}
|
|
487
|
+
function loadCIConfig(options) {
|
|
488
|
+
const config = loadConfig(options);
|
|
489
|
+
return config.ci;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// src/release.ts
|
|
493
|
+
function getHeadCommitMessage(cwd) {
|
|
494
|
+
try {
|
|
495
|
+
return execSync("git log -1 --pretty=%s", { encoding: "utf-8", cwd }).trim();
|
|
496
|
+
} catch {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async function runRelease(inputOptions) {
|
|
501
|
+
const options = { ...inputOptions };
|
|
502
|
+
if (options.verbose) setLogLevel("debug");
|
|
503
|
+
if (options.quiet) setQuietMode(true);
|
|
504
|
+
if (options.json) setJsonMode(true);
|
|
505
|
+
let releaseKitConfig;
|
|
506
|
+
try {
|
|
507
|
+
releaseKitConfig = loadConfig({ cwd: options.projectDir, configPath: options.config });
|
|
508
|
+
} catch (err) {
|
|
509
|
+
error(`Failed to load release config: ${err instanceof Error ? err.message : String(err)}`);
|
|
510
|
+
throw err;
|
|
511
|
+
}
|
|
512
|
+
const releaseConfig = releaseKitConfig.release;
|
|
513
|
+
if (releaseConfig?.ci?.skipPatterns?.length) {
|
|
514
|
+
const headCommit = getHeadCommitMessage(options.projectDir);
|
|
515
|
+
if (headCommit) {
|
|
516
|
+
const matchedPattern = releaseConfig.ci.skipPatterns.find((p) => headCommit.startsWith(p));
|
|
517
|
+
if (matchedPattern) {
|
|
518
|
+
info(`Skipping release: commit message matches skip pattern "${matchedPattern}"`);
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (releaseConfig?.steps) {
|
|
524
|
+
if (!releaseConfig.steps.includes("notes") && !options.skipNotes) {
|
|
525
|
+
options.skipNotes = true;
|
|
526
|
+
}
|
|
527
|
+
if (!releaseConfig.steps.includes("publish") && !options.skipPublish) {
|
|
528
|
+
options.skipPublish = true;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (releaseConfig?.ci?.notes === false && !options.skipNotes) {
|
|
532
|
+
options.skipNotes = true;
|
|
533
|
+
}
|
|
534
|
+
if (releaseConfig?.ci?.githubRelease === false && !options.skipGithubRelease) {
|
|
535
|
+
options.skipGithubRelease = true;
|
|
536
|
+
}
|
|
537
|
+
info("Running version analysis...");
|
|
538
|
+
const versionOutput = await runVersionStep({ ...options, dryRun: true });
|
|
539
|
+
versionOutput.dryRun = options.dryRun ?? false;
|
|
540
|
+
if (versionOutput.updates.length === 0) {
|
|
541
|
+
info("No releasable changes found");
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
if (releaseConfig?.ci?.minChanges !== void 0 && versionOutput.updates.length < releaseConfig.ci.minChanges) {
|
|
545
|
+
info(
|
|
546
|
+
`Skipping release: ${versionOutput.updates.length} package(s) to update, minimum is ${releaseConfig.ci.minChanges}`
|
|
547
|
+
);
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
if (!options.dryRun) {
|
|
551
|
+
const { flushPendingWrites } = await import("@releasekit/version");
|
|
552
|
+
flushPendingWrites();
|
|
553
|
+
}
|
|
554
|
+
info(`Found ${versionOutput.updates.length} package update(s)`);
|
|
555
|
+
for (const update of versionOutput.updates) {
|
|
556
|
+
info(` ${update.packageName} \u2192 ${update.newVersion}`);
|
|
557
|
+
}
|
|
558
|
+
let notesGenerated = false;
|
|
559
|
+
let packageNotes;
|
|
560
|
+
let releaseNotes;
|
|
561
|
+
let notesFiles = [];
|
|
562
|
+
if (!options.skipNotes) {
|
|
563
|
+
info("Generating release notes...");
|
|
564
|
+
const notesResult = await runNotesStep(versionOutput, options);
|
|
565
|
+
packageNotes = notesResult.packageNotes;
|
|
566
|
+
releaseNotes = notesResult.releaseNotes;
|
|
567
|
+
notesFiles = notesResult.files;
|
|
568
|
+
notesGenerated = true;
|
|
569
|
+
success("Release notes generated");
|
|
570
|
+
}
|
|
571
|
+
let publishOutput;
|
|
572
|
+
if (!options.skipPublish) {
|
|
573
|
+
info("Publishing...");
|
|
574
|
+
publishOutput = await runPublishStep(versionOutput, options, releaseNotes ?? packageNotes, notesFiles);
|
|
575
|
+
success("Publish complete");
|
|
576
|
+
}
|
|
577
|
+
return { versionOutput, notesGenerated, packageNotes, releaseNotes, publishOutput };
|
|
578
|
+
}
|
|
579
|
+
async function runVersionStep(options) {
|
|
580
|
+
const { loadConfig: loadConfig2, VersionEngine, enableJsonOutput, getJsonData } = await import("@releasekit/version");
|
|
581
|
+
enableJsonOutput(options.dryRun);
|
|
582
|
+
const config = loadConfig2({ cwd: options.projectDir, configPath: options.config });
|
|
583
|
+
if (options.dryRun) config.dryRun = true;
|
|
584
|
+
if (options.sync) config.sync = true;
|
|
585
|
+
if (options.bump) config.type = options.bump;
|
|
586
|
+
if (options.prerelease) {
|
|
587
|
+
config.prereleaseIdentifier = options.prerelease === true ? "next" : options.prerelease;
|
|
588
|
+
config.isPrerelease = true;
|
|
589
|
+
}
|
|
590
|
+
const cliTargets = options.target ? options.target.split(",").map((t) => t.trim()) : [];
|
|
591
|
+
if (cliTargets.length > 0) {
|
|
592
|
+
config.packages = cliTargets;
|
|
593
|
+
}
|
|
594
|
+
const engine = new VersionEngine(config);
|
|
595
|
+
const pkgsResult = await engine.getWorkspacePackages();
|
|
596
|
+
const resolvedCount = pkgsResult.packages.length;
|
|
597
|
+
if (resolvedCount === 0) {
|
|
598
|
+
throw new Error("No packages found in workspace");
|
|
599
|
+
}
|
|
600
|
+
if (config.sync) {
|
|
601
|
+
engine.setStrategy("sync");
|
|
602
|
+
await engine.run(pkgsResult);
|
|
603
|
+
} else if (resolvedCount === 1) {
|
|
604
|
+
engine.setStrategy("single");
|
|
605
|
+
await engine.run(pkgsResult);
|
|
606
|
+
} else {
|
|
607
|
+
engine.setStrategy("async");
|
|
608
|
+
await engine.run(pkgsResult, cliTargets);
|
|
609
|
+
}
|
|
610
|
+
return getJsonData();
|
|
611
|
+
}
|
|
612
|
+
async function runNotesStep(versionOutput, options) {
|
|
613
|
+
const { parseVersionOutput, runPipeline, loadConfig: loadConfig2 } = await import("@releasekit/notes");
|
|
614
|
+
const config = loadConfig2(options.projectDir, options.config);
|
|
615
|
+
const input = parseVersionOutput(JSON.stringify(versionOutput));
|
|
616
|
+
const result = await runPipeline(input, config, options.dryRun);
|
|
617
|
+
return { packageNotes: result.packageNotes, releaseNotes: result.releaseNotes, files: result.files };
|
|
618
|
+
}
|
|
619
|
+
async function runPublishStep(versionOutput, options, releaseNotes, additionalFiles) {
|
|
620
|
+
const { runPipeline, loadConfig: loadConfig2 } = await import("@releasekit/publish");
|
|
621
|
+
const config = loadConfig2({ configPath: options.config });
|
|
622
|
+
if (options.branch) {
|
|
623
|
+
config.git.branch = options.branch;
|
|
624
|
+
}
|
|
625
|
+
const publishOptions = {
|
|
626
|
+
dryRun: options.dryRun,
|
|
627
|
+
registry: "all",
|
|
628
|
+
npmAuth: options.npmAuth ?? "auto",
|
|
629
|
+
skipGit: options.skipGit,
|
|
630
|
+
skipPublish: false,
|
|
631
|
+
skipGithubRelease: options.skipGithubRelease,
|
|
632
|
+
skipVerification: options.skipVerification,
|
|
633
|
+
json: options.json,
|
|
634
|
+
verbose: options.verbose,
|
|
635
|
+
releaseNotes,
|
|
636
|
+
additionalFiles
|
|
637
|
+
};
|
|
638
|
+
return runPipeline(versionOutput, config, publishOptions);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export {
|
|
642
|
+
readPackageVersion,
|
|
643
|
+
error,
|
|
644
|
+
warn,
|
|
645
|
+
info,
|
|
646
|
+
success,
|
|
647
|
+
EXIT_CODES,
|
|
648
|
+
loadConfig,
|
|
649
|
+
loadCIConfig,
|
|
650
|
+
runRelease
|
|
651
|
+
};
|