@icebreakers/monorepo 5.0.3 → 5.1.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.mjs +64 -38
- package/dist/{commands-KNarzvFs.mjs → commands-BD9u8I6D.mjs} +1086 -96
- package/dist/{create-flow-D2KdMg-m.mjs → create-flow-D_SecUxo.mjs} +2 -2
- package/dist/{index-Ltm2Ry5E.d.mts → index-cBqxgIwY.d.mts} +7 -2
- package/dist/index.d.mts +152 -13
- package/dist/index.mjs +3 -3
- package/dist/tooling-entry.d.mts +1 -1
- package/dist/{types-DYEKpMcN.mjs → types-S6igCe0w.mjs} +4 -4
- package/package.json +6 -6
- package/resources/skills/icebreakers-monorepo-cli/references/commands.md +21 -1
- package/resources/skills/icebreakers-monorepo-cli/references/config.md +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
2
2
|
import { i as getWorkspacePackages, n as getWorkspaceData, r as getWorkspacePackageSummaries } from "./workspace-MCKewElu.mjs";
|
|
3
|
-
import { _ as isIgnorableFsError, c as devDependencies$1, d as logger, g as fs$1, i as packageDir, n as assetsDir, o as templatesDir, s as dependencies, t as initToolingTargets, u as version$1 } from "./types-
|
|
3
|
+
import { _ as isIgnorableFsError, c as devDependencies$1, d as logger, g as fs$1, i as packageDir, n as assetsDir, o as templatesDir, s as dependencies, t as initToolingTargets, u as version$1 } from "./types-S6igCe0w.mjs";
|
|
4
4
|
import { a as loadMonorepoConfig, c as resolveToolingConfig, i as getRepoctlConfigCandidates, o as loadMonorepoConfigDetails, s as resolveCommandConfig } from "./config-p842Knhq.mjs";
|
|
5
5
|
import { f as defineTsconfigConfig } from "./tooling-Bn3XOfO0.mjs";
|
|
6
6
|
import gitUrlParse from "git-url-parse";
|
|
@@ -8,7 +8,7 @@ import { simpleGit } from "simple-git";
|
|
|
8
8
|
import { findWorkspaceDir } from "@pnpm/find-workspace-dir";
|
|
9
9
|
import path from "pathe";
|
|
10
10
|
import process from "node:process";
|
|
11
|
-
import { readFile, readdir } from "node:fs/promises";
|
|
11
|
+
import { access, readFile, readdir } from "node:fs/promises";
|
|
12
12
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
13
13
|
import fs from "node:fs";
|
|
14
14
|
import path$1 from "node:path";
|
|
@@ -1206,6 +1206,94 @@ async function createNewProject(options) {
|
|
|
1206
1206
|
logger.success(`${pc.bgGreenBright(pc.white(`[${plan.template}]`))} ${plan.targetName} 项目创建成功!`);
|
|
1207
1207
|
}
|
|
1208
1208
|
//#endregion
|
|
1209
|
+
//#region src/commands/upgrade/release-migration.ts
|
|
1210
|
+
const releaseWorkflowMarker = "# repoctl-managed: release/v2";
|
|
1211
|
+
function isLegacyReleaseWorkflow(content) {
|
|
1212
|
+
if (!content.includes("changesets/action")) return false;
|
|
1213
|
+
return content.includes("publish-script:") || content.includes("changeset publish") || content.includes("changeset version") || content.includes("pnpm exec repo release");
|
|
1214
|
+
}
|
|
1215
|
+
async function classifyReleaseWorkflow(workspaceDir) {
|
|
1216
|
+
const workflowPath = path.join(workspaceDir, ".github/workflows/release.yml");
|
|
1217
|
+
if (!await fs$1.pathExists(workflowPath)) return "missing";
|
|
1218
|
+
const content = await fs$1.readFile(workflowPath, "utf8");
|
|
1219
|
+
if (content.includes("# repoctl-managed: release/v2")) return "managed";
|
|
1220
|
+
if (isLegacyReleaseWorkflow(content)) return "legacy";
|
|
1221
|
+
return "custom";
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* 将 Changesets prerelease 状态迁移到 pnpm lanes,并移除只属于旧 CLI 的元数据。
|
|
1225
|
+
* 未识别的 pre.json 会保留,避免静默丢失用户状态。
|
|
1226
|
+
*/
|
|
1227
|
+
async function migrateLegacyVersioning(workspaceDir) {
|
|
1228
|
+
const changesetDir = path.join(workspaceDir, ".changeset");
|
|
1229
|
+
const configPath = path.join(changesetDir, "config.json");
|
|
1230
|
+
const prePath = path.join(changesetDir, "pre.json");
|
|
1231
|
+
let migratedLane = false;
|
|
1232
|
+
if (await fs$1.pathExists(prePath)) try {
|
|
1233
|
+
const state = JSON.parse(await readFile(prePath, "utf8"));
|
|
1234
|
+
if (state.mode === "pre" && typeof state.tag === "string" && state.tag.length > 0) {
|
|
1235
|
+
const workspacePath = path.join(workspaceDir, "pnpm-workspace.yaml");
|
|
1236
|
+
const manifest = YAML.parse(await readFile(workspacePath, "utf8"));
|
|
1237
|
+
const versioningValue = manifest["versioning"];
|
|
1238
|
+
const versioning = versioningValue && typeof versioningValue === "object" && !Array.isArray(versioningValue) ? versioningValue : {};
|
|
1239
|
+
const lanesValue = versioning["lanes"];
|
|
1240
|
+
const lanes = lanesValue && typeof lanesValue === "object" && !Array.isArray(lanesValue) ? lanesValue : {};
|
|
1241
|
+
const packages = await getWorkspacePackages(workspaceDir);
|
|
1242
|
+
for (const pkg of packages) if (pkg.manifest.name) lanes[pkg.manifest.name] = state.tag;
|
|
1243
|
+
versioning["lanes"] = lanes;
|
|
1244
|
+
manifest["versioning"] = versioning;
|
|
1245
|
+
await fs$1.writeFile(workspacePath, YAML.stringify(manifest, { singleQuote: true }), "utf8");
|
|
1246
|
+
await fs$1.remove(prePath);
|
|
1247
|
+
migratedLane = true;
|
|
1248
|
+
}
|
|
1249
|
+
} catch {}
|
|
1250
|
+
if (await fs$1.pathExists(configPath)) await fs$1.remove(configPath);
|
|
1251
|
+
return { migratedLane };
|
|
1252
|
+
}
|
|
1253
|
+
//#endregion
|
|
1254
|
+
//#region src/commands/doctor/release.ts
|
|
1255
|
+
const releaseCiMinimumVersion = "5.1.0";
|
|
1256
|
+
function check(id, title, status, detail, fix) {
|
|
1257
|
+
return {
|
|
1258
|
+
id,
|
|
1259
|
+
title,
|
|
1260
|
+
status,
|
|
1261
|
+
detail,
|
|
1262
|
+
...fix ? { fix } : {}
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
async function collectReleaseChecks(workspaceDir, pkgJson) {
|
|
1266
|
+
const workflowPath = path.join(workspaceDir, ".github/workflows/release.yml");
|
|
1267
|
+
const [hasWorkflow, hasPreState, hasChangesetConfig] = await Promise.all([
|
|
1268
|
+
fs$1.pathExists(workflowPath),
|
|
1269
|
+
fs$1.pathExists(path.join(workspaceDir, ".changeset/pre.json")),
|
|
1270
|
+
fs$1.pathExists(path.join(workspaceDir, ".changeset/config.json"))
|
|
1271
|
+
]);
|
|
1272
|
+
if (!hasWorkflow && !hasPreState && !hasChangesetConfig) return [];
|
|
1273
|
+
const checks = [];
|
|
1274
|
+
const workflowStatus = await classifyReleaseWorkflow(workspaceDir);
|
|
1275
|
+
if (workflowStatus === "managed") checks.push(check("release-workflow", "release workflow", "pass", `release workflow 已由 ${releaseWorkflowMarker} 管理。`));
|
|
1276
|
+
else if (workflowStatus === "legacy") checks.push(check("release-workflow", "release workflow", "warn", "检测到旧的 Changesets release workflow。", "首次迁移运行 pnpm dlx repoctl@latest upgrade --yes。"));
|
|
1277
|
+
else if (workflowStatus === "custom") checks.push(check("release-workflow", "release workflow", "warn", "release workflow 未包含 repoctl managed marker,可能存在自定义发布逻辑。", "确认内容后运行 repo upgrade --overwrite-release,或手动加入 repoctl-managed: release/v2。"));
|
|
1278
|
+
if (hasPreState) checks.push(check("release-prerelease-state", "prerelease state", "warn", "检测到旧的 .changeset/pre.json。", "运行 pnpm dlx repoctl@latest upgrade --yes 将其迁移为 pnpm versioning.lanes。"));
|
|
1279
|
+
if (hasChangesetConfig) checks.push(check("release-changeset-config", "changeset config", "warn", "检测到只属于 Changesets CLI 的 .changeset/config.json。", "运行 pnpm dlx repoctl@latest upgrade --yes 清理旧配置。"));
|
|
1280
|
+
if (hasWorkflow) {
|
|
1281
|
+
const packageVersion = pkgJson.devDependencies?.["repoctl"] ?? pkgJson.dependencies?.["repoctl"];
|
|
1282
|
+
const parsed = minVersion(packageVersion ?? "");
|
|
1283
|
+
if (!parsed || !gte(parsed, "5.1.0")) checks.push(check("release-cli-version", "release CLI version", "warn", `repoctl 版本 ${packageVersion ?? "missing"} 不保证支持 release ci。`, `运行 pnpm dlx repoctl@latest upgrade --yes,或将 repoctl 升级到 >=${releaseCiMinimumVersion}。`));
|
|
1284
|
+
else checks.push(check("release-cli-version", "release CLI version", "pass", `repoctl 版本 ${packageVersion} 支持 release ci。`));
|
|
1285
|
+
try {
|
|
1286
|
+
const workspace = YAML.parse(await readFile(path.join(workspaceDir, "pnpm-workspace.yaml"), "utf8"));
|
|
1287
|
+
const hasFixed = Array.isArray(workspace.versioning?.fixed) && workspace.versioning.fixed.length > 0;
|
|
1288
|
+
const hasRepositoryChangelog = workspace.versioning?.changelog?.storage === "repository";
|
|
1289
|
+
checks.push(hasFixed && hasRepositoryChangelog ? check("release-versioning-config", "release versioning config", "pass", "pnpm fixed group 与 repository changelog 配置完整。") : check("release-versioning-config", "release versioning config", "warn", "pnpm-workspace.yaml 缺少 release 所需的 fixed 或 repository changelog 配置。", "运行 repo upgrade --yes 同步 pnpm versioning 配置。"));
|
|
1290
|
+
} catch {
|
|
1291
|
+
checks.push(check("release-versioning-config", "release versioning config", "warn", "无法读取 pnpm-workspace.yaml 的 versioning 配置。", "运行 repo upgrade --yes 同步 pnpm versioning 配置。"));
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return checks;
|
|
1295
|
+
}
|
|
1296
|
+
//#endregion
|
|
1209
1297
|
//#region src/commands/doctor.ts
|
|
1210
1298
|
const recommendedRepoScripts = {
|
|
1211
1299
|
"repo:init": "repo init",
|
|
@@ -1491,6 +1579,7 @@ async function runDoctor(cwd) {
|
|
|
1491
1579
|
detail: `以下 package.json 未被 pnpm-workspace.yaml 覆盖:${uncoveredWorkspacePackages.join(", ")}。`,
|
|
1492
1580
|
fix: "运行 repo init --yes 追加缺失 workspace patterns。"
|
|
1493
1581
|
}));
|
|
1582
|
+
checks.push(...await collectReleaseChecks(workspaceDir, pkgJson));
|
|
1494
1583
|
return {
|
|
1495
1584
|
cwd,
|
|
1496
1585
|
workspaceDir,
|
|
@@ -1618,20 +1707,10 @@ async function createContext(cwd) {
|
|
|
1618
1707
|
//#endregion
|
|
1619
1708
|
//#region src/commands/init/setChangeset.ts
|
|
1620
1709
|
/**
|
|
1621
|
-
*
|
|
1710
|
+
* 保留兼容的初始化入口,并确保 pnpm change 有可写入的 intent 目录。
|
|
1622
1711
|
*/
|
|
1623
1712
|
async function setChangeset_default(ctx) {
|
|
1624
|
-
|
|
1625
|
-
if (gitUrl && await fs$1.exists(workspaceFilepath)) {
|
|
1626
|
-
const changesetConfigPath = path.resolve(path.dirname(workspaceFilepath), ".changeset/config.json");
|
|
1627
|
-
if (await fs$1.exists(changesetConfigPath)) {
|
|
1628
|
-
const changesetConfig = await fs$1.readJson(changesetConfigPath);
|
|
1629
|
-
if (gitUrl.full_name) {
|
|
1630
|
-
setByPath(changesetConfig, "changelog.1.repo", gitUrl.full_name);
|
|
1631
|
-
await fs$1.outputJson(changesetConfigPath, changesetConfig, { spaces: 2 });
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1713
|
+
if (await fs$1.exists(ctx.workspaceDir)) await fs$1.ensureDir(path.join(ctx.workspaceDir, ".changeset"));
|
|
1635
1714
|
}
|
|
1636
1715
|
//#endregion
|
|
1637
1716
|
//#region src/commands/init/setIssueTemplateConfig.ts
|
|
@@ -1722,9 +1801,7 @@ async function setReadme_default(ctx, options = {}) {
|
|
|
1722
1801
|
//#endregion
|
|
1723
1802
|
//#region ../../package.json
|
|
1724
1803
|
var devDependencies = {
|
|
1725
|
-
"@
|
|
1726
|
-
"@commitlint/cli": "^21.2.1",
|
|
1727
|
-
"@icebreakers/changelog-github": "^2.0.0",
|
|
1804
|
+
"@commitlint/cli": "^21.2.2",
|
|
1728
1805
|
"@icebreakers/monorepo": "workspace:*",
|
|
1729
1806
|
"@types/node": "^26.2.0",
|
|
1730
1807
|
"@types/semver": "^7.8.0",
|
|
@@ -1746,7 +1823,7 @@ var devDependencies = {
|
|
|
1746
1823
|
"tsdown": "0.22.14",
|
|
1747
1824
|
"tslib": "^2.8.1",
|
|
1748
1825
|
"tsx": "^4.23.12",
|
|
1749
|
-
"turbo": "^2.10.
|
|
1826
|
+
"turbo": "^2.10.10",
|
|
1750
1827
|
"type-fest": "^5.8.0",
|
|
1751
1828
|
"typescript": "^6.0.3",
|
|
1752
1829
|
"vitest": "~4.1.10",
|
|
@@ -1783,8 +1860,9 @@ const packageDependencies = {
|
|
|
1783
1860
|
"typecheck": "turbo run typecheck",
|
|
1784
1861
|
"format": "eslint . --fix",
|
|
1785
1862
|
"validate": "pnpm run build && pnpm run lint && pnpm run typecheck && pnpm run tsd && pnpm run test",
|
|
1786
|
-
"release": "
|
|
1787
|
-
"
|
|
1863
|
+
"release": "pnpm change",
|
|
1864
|
+
"version-packages": "pnpm version -r",
|
|
1865
|
+
"publish-packages": "repo release stable publish",
|
|
1788
1866
|
"release:pre": "repo release pre publish",
|
|
1789
1867
|
"------": "--------------",
|
|
1790
1868
|
"preinstall": "npx only-allow pnpm",
|
|
@@ -2131,13 +2209,306 @@ async function setVscodeBinaryMirror(cwd) {
|
|
|
2131
2209
|
await fs$1.writeFile(targetJsonPath, `${stringify(json, void 0, 2)}\n`, "utf8");
|
|
2132
2210
|
}
|
|
2133
2211
|
//#endregion
|
|
2134
|
-
//#region src/commands/release.ts
|
|
2135
|
-
const
|
|
2136
|
-
"
|
|
2137
|
-
"
|
|
2138
|
-
"
|
|
2139
|
-
"
|
|
2140
|
-
|
|
2212
|
+
//#region src/commands/release/notes/model.ts
|
|
2213
|
+
const categoryOrder = [
|
|
2214
|
+
"breaking",
|
|
2215
|
+
"features",
|
|
2216
|
+
"fixes",
|
|
2217
|
+
"performance",
|
|
2218
|
+
"docs",
|
|
2219
|
+
"other",
|
|
2220
|
+
"maintenance"
|
|
2221
|
+
];
|
|
2222
|
+
const categoryTitles = {
|
|
2223
|
+
breaking: "🚨 Breaking Changes",
|
|
2224
|
+
features: "🚀 Features",
|
|
2225
|
+
fixes: "🐞 Bug Fixes",
|
|
2226
|
+
performance: "🏎 Performance",
|
|
2227
|
+
docs: "📚 Documentation",
|
|
2228
|
+
maintenance: "🧰 Maintenance",
|
|
2229
|
+
other: "🧩 Other Changes"
|
|
2230
|
+
};
|
|
2231
|
+
function readVersionSection(changelog, version) {
|
|
2232
|
+
const versions = [...changelog.matchAll(/^## ([^\n]+)$/gm)];
|
|
2233
|
+
const index = versions.findIndex((match) => match[1] === version);
|
|
2234
|
+
const current = versions[index];
|
|
2235
|
+
if (index < 0 || !current || current.index === void 0) return;
|
|
2236
|
+
const end = versions[index + 1]?.index ?? changelog.length;
|
|
2237
|
+
return {
|
|
2238
|
+
content: changelog.slice(current.index, end).trim().slice(current[0].length).trim() || void 0,
|
|
2239
|
+
previousVersion: versions[index + 1]?.[1]
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
function readIntentSections(content) {
|
|
2243
|
+
const lines = content.split(/\r?\n/);
|
|
2244
|
+
if (lines[0]?.trim() !== "---") return;
|
|
2245
|
+
const end = lines.findIndex((line, index) => index > 0 && line.trim() === "---");
|
|
2246
|
+
if (end < 0) return;
|
|
2247
|
+
return {
|
|
2248
|
+
frontmatter: lines.slice(1, end).join("\n"),
|
|
2249
|
+
summary: lines.slice(end + 1).join("\n").trim()
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
function parseIntentPackages(content) {
|
|
2253
|
+
const sections = readIntentSections(content);
|
|
2254
|
+
if (!sections) return [];
|
|
2255
|
+
try {
|
|
2256
|
+
const frontmatter = YAML.parse(sections.frontmatter);
|
|
2257
|
+
if (!frontmatter || typeof frontmatter !== "object" || Array.isArray(frontmatter)) return [];
|
|
2258
|
+
return Object.keys(frontmatter).filter((key) => key !== "summary" && key !== "type");
|
|
2259
|
+
} catch {
|
|
2260
|
+
return [];
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
function parseIntentSummary(content) {
|
|
2264
|
+
return readIntentSections(content)?.summary ?? content.trim();
|
|
2265
|
+
}
|
|
2266
|
+
function uniqueCommits(commits) {
|
|
2267
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2268
|
+
for (const commit of commits) {
|
|
2269
|
+
const existing = merged.get(commit.sha);
|
|
2270
|
+
if (!existing) {
|
|
2271
|
+
merged.set(commit.sha, commit);
|
|
2272
|
+
continue;
|
|
2273
|
+
}
|
|
2274
|
+
merged.set(commit.sha, {
|
|
2275
|
+
...existing,
|
|
2276
|
+
packages: [.../* @__PURE__ */ new Set([...existing.packages ?? [], ...commit.packages ?? []])],
|
|
2277
|
+
summaries: [...new Set([
|
|
2278
|
+
existing.summary,
|
|
2279
|
+
...existing.summaries ?? [],
|
|
2280
|
+
commit.summary,
|
|
2281
|
+
...commit.summaries ?? []
|
|
2282
|
+
].filter((summary) => Boolean(summary)))]
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
return [...merged.values()];
|
|
2286
|
+
}
|
|
2287
|
+
function buildPackageCompareUrl(release, metadata) {
|
|
2288
|
+
if (!release.previousVersion || !metadata.repository || !/^[^/]+\/[^/]+$/.test(metadata.repository)) return;
|
|
2289
|
+
const serverUrl = (metadata.serverUrl || "https://github.com").replace(/\/$/, "");
|
|
2290
|
+
const previousTag = encodeURIComponent([release.name, release.previousVersion].join("@"));
|
|
2291
|
+
const currentTag = encodeURIComponent([release.name, release.version].join("@"));
|
|
2292
|
+
return [
|
|
2293
|
+
serverUrl,
|
|
2294
|
+
metadata.repository,
|
|
2295
|
+
"compare",
|
|
2296
|
+
`${previousTag}...${currentTag}`
|
|
2297
|
+
].join("/");
|
|
2298
|
+
}
|
|
2299
|
+
function buildNpmPackageUrl(name, version) {
|
|
2300
|
+
return `https://www.npmjs.com/package/${name.startsWith("@") ? name : encodeURIComponent(name)}/v/${encodeURIComponent(version)}`;
|
|
2301
|
+
}
|
|
2302
|
+
//#endregion
|
|
2303
|
+
//#region src/commands/release/notes/entries.ts
|
|
2304
|
+
function parseReferences(commits, content) {
|
|
2305
|
+
const pullRequests = /* @__PURE__ */ new Set();
|
|
2306
|
+
const issues = /* @__PURE__ */ new Set();
|
|
2307
|
+
for (const message of [...commits.map((commit) => [commit.subject, commit.body ?? ""].join("\n")), content]) {
|
|
2308
|
+
for (const match of message.matchAll(/\(#(\d+)\)/g)) pullRequests.add(Number(match[1]));
|
|
2309
|
+
for (const match of message.matchAll(/(?:^|\W)#(\d+)\b/g)) {
|
|
2310
|
+
const number = Number(match[1]);
|
|
2311
|
+
if (!pullRequests.has(number)) issues.add(number);
|
|
2312
|
+
}
|
|
2313
|
+
for (const match of message.matchAll(/\bGH[- ]?(\d+)\b/gi)) issues.add(Number(match[1]));
|
|
2314
|
+
}
|
|
2315
|
+
for (const number of pullRequests) issues.delete(number);
|
|
2316
|
+
return {
|
|
2317
|
+
issues: [...issues].sort((a, b) => a - b),
|
|
2318
|
+
pullRequests: [...pullRequests].sort((a, b) => a - b)
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
function sourceCategory(commits) {
|
|
2322
|
+
for (const commit of commits) {
|
|
2323
|
+
const subject = commit.subject.toLowerCase();
|
|
2324
|
+
const conventional = /^([a-z]+)(?:\([^)]*\))?(!)?:/.exec(subject);
|
|
2325
|
+
if (conventional?.[2] || subject.startsWith("breaking")) return "breaking";
|
|
2326
|
+
if (conventional?.[1] === "feat" || conventional?.[1] === "feature" || subject.includes("🚀")) return "features";
|
|
2327
|
+
if (conventional?.[1] === "fix" || subject.includes("🐛") || subject.includes("🐞")) return "fixes";
|
|
2328
|
+
if (conventional?.[1] === "perf" || subject.includes("🏎")) return "performance";
|
|
2329
|
+
if ([
|
|
2330
|
+
"doc",
|
|
2331
|
+
"docs",
|
|
2332
|
+
"documentation"
|
|
2333
|
+
].includes(conventional?.[1] ?? "") || subject.includes("📚")) return "docs";
|
|
2334
|
+
if ([
|
|
2335
|
+
"chore",
|
|
2336
|
+
"ci",
|
|
2337
|
+
"test",
|
|
2338
|
+
"refactor",
|
|
2339
|
+
"dep",
|
|
2340
|
+
"deps"
|
|
2341
|
+
].includes(conventional?.[1] ?? "") || /dependencies|maintenance/i.test(subject)) return "maintenance";
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
function classifyChange(heading, summary, commits) {
|
|
2345
|
+
const fromCommit = sourceCategory(commits);
|
|
2346
|
+
if (fromCommit) return fromCommit;
|
|
2347
|
+
const categoryHint = [heading, summary].join(" ").toLowerCase();
|
|
2348
|
+
if (/major|breaking|重大|破坏/.test(categoryHint)) return "breaking";
|
|
2349
|
+
if (/minor|feature|🚀|新增|功能/.test(categoryHint)) return "features";
|
|
2350
|
+
if (/fix|bug|🐛|🐞|修复|错误|问题/.test(categoryHint)) return "fixes";
|
|
2351
|
+
if (/perf|🏎|性能/.test(categoryHint)) return "performance";
|
|
2352
|
+
if (/doc|📚|文档/.test(categoryHint)) return "docs";
|
|
2353
|
+
if (/dependenc|chore|ci|test|refactor|maintenance|📦|依赖|维护/.test(categoryHint)) return "maintenance";
|
|
2354
|
+
return "other";
|
|
2355
|
+
}
|
|
2356
|
+
function readMarkdownEntries(content) {
|
|
2357
|
+
const headings = [...content.matchAll(/^### ([^\n]+)$/gm)];
|
|
2358
|
+
if (!headings.length) return [{
|
|
2359
|
+
heading: "Patch Changes",
|
|
2360
|
+
summary: content.trim()
|
|
2361
|
+
}];
|
|
2362
|
+
const entries = [];
|
|
2363
|
+
for (let index = 0; index < headings.length; index++) {
|
|
2364
|
+
const heading = headings[index];
|
|
2365
|
+
if (!heading || heading.index === void 0) continue;
|
|
2366
|
+
const start = heading.index + heading[0].length;
|
|
2367
|
+
const end = headings[index + 1]?.index ?? content.length;
|
|
2368
|
+
const lines = content.slice(start, end).trim().split("\n");
|
|
2369
|
+
let current = "";
|
|
2370
|
+
for (const line of lines) if (line.startsWith("- ")) {
|
|
2371
|
+
if (current) entries.push({
|
|
2372
|
+
heading: heading[1],
|
|
2373
|
+
summary: current.trim()
|
|
2374
|
+
});
|
|
2375
|
+
current = line.slice(2).trim();
|
|
2376
|
+
} else if (line.trim()) current = current ? [current, line.trim()].join("\n") : line.trim();
|
|
2377
|
+
if (current) entries.push({
|
|
2378
|
+
heading: heading[1],
|
|
2379
|
+
summary: current.trim()
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
return entries.length ? entries : [{
|
|
2383
|
+
heading: "Patch Changes",
|
|
2384
|
+
summary: content.trim()
|
|
2385
|
+
}];
|
|
2386
|
+
}
|
|
2387
|
+
function commitsForPackage(commits, packageName) {
|
|
2388
|
+
return uniqueCommits(commits.filter((commit) => !commit.packages?.length || commit.packages.includes(packageName)));
|
|
2389
|
+
}
|
|
2390
|
+
function normalizeForMatch(value) {
|
|
2391
|
+
return value.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/[*_`]/g, "").replace(/[^\p{L}\p{N}]+/gu, " ").trim().toLowerCase();
|
|
2392
|
+
}
|
|
2393
|
+
function commitsForEntry(commits, summary) {
|
|
2394
|
+
const normalizedSummary = normalizeForMatch(summary);
|
|
2395
|
+
const matched = commits.filter((commit) => {
|
|
2396
|
+
const summaries = [commit.summary, ...commit.summaries ?? []].filter((value) => Boolean(value));
|
|
2397
|
+
if (!summaries.length) return false;
|
|
2398
|
+
return summaries.some((summary) => {
|
|
2399
|
+
const normalizedIntent = normalizeForMatch(summary);
|
|
2400
|
+
return normalizedIntent === normalizedSummary || normalizedSummary.includes(normalizedIntent) || normalizedIntent.includes(normalizedSummary);
|
|
2401
|
+
});
|
|
2402
|
+
});
|
|
2403
|
+
if (matched.length) return matched;
|
|
2404
|
+
return commits.length === 1 ? commits : [];
|
|
2405
|
+
}
|
|
2406
|
+
function buildEntries(release, commits) {
|
|
2407
|
+
const packageCommits = commitsForPackage(commits, release.name);
|
|
2408
|
+
return readMarkdownEntries(release.content).flatMap((item) => {
|
|
2409
|
+
const summary = item.summary.replace(/^[-*]\s+/, "").replace(/\n+/g, " ").trim();
|
|
2410
|
+
if (!summary) return [];
|
|
2411
|
+
const entryCommits = commitsForEntry(packageCommits, summary);
|
|
2412
|
+
const refs = parseReferences(entryCommits, summary);
|
|
2413
|
+
return [{
|
|
2414
|
+
packageName: release.name,
|
|
2415
|
+
version: release.version,
|
|
2416
|
+
...release.npmUrl ? { npmUrl: release.npmUrl } : {},
|
|
2417
|
+
category: classifyChange(item.heading, summary, entryCommits),
|
|
2418
|
+
summary,
|
|
2419
|
+
commits: entryCommits,
|
|
2420
|
+
pullRequests: refs.pullRequests,
|
|
2421
|
+
issues: refs.issues,
|
|
2422
|
+
authors: entryCommits.map((commit) => commit.author).filter((author) => Boolean(author))
|
|
2423
|
+
}];
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
//#endregion
|
|
2427
|
+
//#region src/commands/release/notes/render.ts
|
|
2428
|
+
function formatReferenceLinks(entry, metadata) {
|
|
2429
|
+
const repository = metadata.repository && /^[^/]+\/[^/]+$/.test(metadata.repository) ? metadata.repository : void 0;
|
|
2430
|
+
const serverUrl = (metadata.serverUrl || "https://github.com").replace(/\/$/, "");
|
|
2431
|
+
const baseUrl = repository ? `${serverUrl}/${repository}` : void 0;
|
|
2432
|
+
const links = [];
|
|
2433
|
+
for (const commit of entry.commits) {
|
|
2434
|
+
const label = commit.sha.slice(0, 7);
|
|
2435
|
+
links.push(baseUrl ? `[\`${label}\`](${baseUrl}/commit/${commit.sha})` : `\`${label}\``);
|
|
2436
|
+
}
|
|
2437
|
+
for (const number of entry.pullRequests) links.push(baseUrl ? `[#${number}](${baseUrl}/pull/${number})` : `#${number}`);
|
|
2438
|
+
for (const number of entry.issues) links.push(baseUrl ? `[#${number}](${baseUrl}/issues/${number})` : `#${number}`);
|
|
2439
|
+
return links.length ? ` ${links.join(" · ")}` : "";
|
|
2440
|
+
}
|
|
2441
|
+
function formatEntry(entry, metadata, linkNpmVersion) {
|
|
2442
|
+
return `- **${linkNpmVersion && entry.npmUrl ? `[${entry.packageName}@${entry.version}](${entry.npmUrl})` : `${entry.packageName}@${entry.version}`}**: ${entry.summary}${formatReferenceLinks(entry, metadata)}`;
|
|
2443
|
+
}
|
|
2444
|
+
function formatCategoryEntries(entries, category, metadata, headingLevel, linkNpmVersion) {
|
|
2445
|
+
const matching = entries.filter((entry) => entry.category === category);
|
|
2446
|
+
if (!matching.length) return [];
|
|
2447
|
+
return [
|
|
2448
|
+
`${"#".repeat(headingLevel)} ${categoryTitles[category]}`,
|
|
2449
|
+
"",
|
|
2450
|
+
...matching.map((entry) => formatEntry(entry, metadata, linkNpmVersion))
|
|
2451
|
+
];
|
|
2452
|
+
}
|
|
2453
|
+
function formatContributor(value) {
|
|
2454
|
+
if (value.startsWith("@")) return value;
|
|
2455
|
+
return /^[\w-]+$/.test(value) ? `@${value}` : value;
|
|
2456
|
+
}
|
|
2457
|
+
function formatContributors(contributors) {
|
|
2458
|
+
const unique = [...new Set(contributors.map((value) => value.trim()).filter(Boolean))].sort((a, b) => a.localeCompare(b));
|
|
2459
|
+
return unique.length ? [
|
|
2460
|
+
"## ❤️ Contributors",
|
|
2461
|
+
"",
|
|
2462
|
+
`Thanks to ${unique.map(formatContributor).join(" · ")}`
|
|
2463
|
+
] : [];
|
|
2464
|
+
}
|
|
2465
|
+
function formatVersion(version, npmUrl) {
|
|
2466
|
+
return npmUrl ? `[\`${version}\`](${npmUrl})` : `\`${version}\``;
|
|
2467
|
+
}
|
|
2468
|
+
function formatPackages(packages, linkNpmVersion) {
|
|
2469
|
+
if (!packages.length) return [];
|
|
2470
|
+
return [
|
|
2471
|
+
"## Packages",
|
|
2472
|
+
"",
|
|
2473
|
+
"| Package | From | To |",
|
|
2474
|
+
"| --- | --- | --- |",
|
|
2475
|
+
...packages.map((pkg) => {
|
|
2476
|
+
const previous = pkg.previousVersion ? formatVersion(pkg.previousVersion, pkg.previousNpmUrl) : "—";
|
|
2477
|
+
const current = formatVersion(pkg.version, linkNpmVersion ? pkg.npmUrl : void 0);
|
|
2478
|
+
return `| \`${pkg.name}\` | ${previous} | ${current} |`;
|
|
2479
|
+
})
|
|
2480
|
+
];
|
|
2481
|
+
}
|
|
2482
|
+
function renderReleasePullRequest(document, metadata = {}) {
|
|
2483
|
+
const sections = [
|
|
2484
|
+
"# Release Notes",
|
|
2485
|
+
"",
|
|
2486
|
+
`> ${`${document.packages.length} package${document.packages.length === 1 ? "" : "s"}`} updated · ${`${document.entries.length} change${document.entries.length === 1 ? "" : "s"}`}`
|
|
2487
|
+
];
|
|
2488
|
+
for (const category of categoryOrder.filter((category) => category !== "maintenance")) {
|
|
2489
|
+
const section = formatCategoryEntries(document.entries, category, metadata, 2, false);
|
|
2490
|
+
if (section.length) sections.push("", "", ...section);
|
|
2491
|
+
}
|
|
2492
|
+
const maintenance = formatCategoryEntries(document.entries, "maintenance", metadata, 2, false);
|
|
2493
|
+
if (maintenance.length) sections.push("", "", "<details>", "<summary>🧰 Maintenance</summary>", "", ...maintenance.slice(2), "", "</details>");
|
|
2494
|
+
sections.push("", "", ...formatPackages(document.packages, false));
|
|
2495
|
+
sections.push("", "", ...formatContributors(document.contributors));
|
|
2496
|
+
return sections.join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
2497
|
+
}
|
|
2498
|
+
function renderGitHubRelease(document, metadata = {}) {
|
|
2499
|
+
if (!document.entries.length) return "No significant changes.";
|
|
2500
|
+
const sections = [];
|
|
2501
|
+
for (const category of categoryOrder) {
|
|
2502
|
+
const section = formatCategoryEntries(document.entries, category, metadata, 3, true);
|
|
2503
|
+
if (section.length) sections.push(...sections.length ? ["", ...section] : section);
|
|
2504
|
+
}
|
|
2505
|
+
const contributors = [...new Set(document.contributors)].sort((a, b) => a.localeCompare(b));
|
|
2506
|
+
if (contributors.length) sections.push("", "### ❤️ Contributors", "", `Thanks to ${contributors.map(formatContributor).join(" · ")}`);
|
|
2507
|
+
if (document.compareUrls.length) sections.push("", `##### [View changes on GitHub](${document.compareUrls[0]})`);
|
|
2508
|
+
return sections.join("\n");
|
|
2509
|
+
}
|
|
2510
|
+
//#endregion
|
|
2511
|
+
//#region src/commands/release/errors.ts
|
|
2141
2512
|
var ReleaseCommandError = class extends Error {
|
|
2142
2513
|
exitCode;
|
|
2143
2514
|
constructor(message, exitCode = 1) {
|
|
@@ -2146,6 +2517,8 @@ var ReleaseCommandError = class extends Error {
|
|
|
2146
2517
|
this.name = "ReleaseCommandError";
|
|
2147
2518
|
}
|
|
2148
2519
|
};
|
|
2520
|
+
//#endregion
|
|
2521
|
+
//#region src/commands/release/shared.ts
|
|
2149
2522
|
function run(command, args, options) {
|
|
2150
2523
|
const result = (options.spawn ?? spawnSync)(command, args, {
|
|
2151
2524
|
cwd: options.cwd,
|
|
@@ -2169,15 +2542,22 @@ function capture(command, args, options) {
|
|
|
2169
2542
|
if (result.status !== 0) throw new ReleaseCommandError(`command failed: ${command} ${args.join(" ")}`, result.status ?? 1);
|
|
2170
2543
|
return result.stdout?.toString().trim() ?? "";
|
|
2171
2544
|
}
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2545
|
+
function getReleaseEnv(options) {
|
|
2546
|
+
return options.env ?? process.env;
|
|
2547
|
+
}
|
|
2548
|
+
function hasGitChanges(options) {
|
|
2549
|
+
return (options.spawn ?? spawnSync)("git", [
|
|
2550
|
+
"diff",
|
|
2551
|
+
"--quiet",
|
|
2552
|
+
"--exit-code"
|
|
2553
|
+
], {
|
|
2554
|
+
cwd: options.cwd,
|
|
2555
|
+
encoding: "utf8",
|
|
2556
|
+
shell: false,
|
|
2557
|
+
stdio: "ignore"
|
|
2558
|
+
}).status !== 0;
|
|
2179
2559
|
}
|
|
2180
|
-
async function
|
|
2560
|
+
async function hasPendingIntents(cwd) {
|
|
2181
2561
|
try {
|
|
2182
2562
|
return (await readdir(path.join(cwd, ".changeset"), { withFileTypes: true })).some((entry) => entry.isFile() && entry.name.endsWith(".md"));
|
|
2183
2563
|
} catch {
|
|
@@ -2185,49 +2565,413 @@ async function hasPendingChangesets(cwd) {
|
|
|
2185
2565
|
}
|
|
2186
2566
|
}
|
|
2187
2567
|
function resolveBranch(options) {
|
|
2188
|
-
return options.branch?.trim() ||
|
|
2568
|
+
return options.branch?.trim() || getReleaseEnv(options)["GITHUB_REF_NAME"]?.trim() || capture("git", [
|
|
2189
2569
|
"rev-parse",
|
|
2190
2570
|
"--abbrev-ref",
|
|
2191
2571
|
"HEAD"
|
|
2192
2572
|
], options);
|
|
2193
2573
|
}
|
|
2194
|
-
async function
|
|
2195
|
-
const
|
|
2196
|
-
|
|
2197
|
-
if (
|
|
2574
|
+
async function getPublishablePackageNames(cwd) {
|
|
2575
|
+
const { packages } = await getWorkspaceData(cwd);
|
|
2576
|
+
const names = packages.map((pkg) => pkg.manifest.name).filter((name) => Boolean(name));
|
|
2577
|
+
if (!names.length) throw new ReleaseCommandError("no publishable workspace packages were found");
|
|
2578
|
+
return names;
|
|
2579
|
+
}
|
|
2580
|
+
function packageFilters(names) {
|
|
2581
|
+
return names.flatMap((name) => ["--filter", name]);
|
|
2582
|
+
}
|
|
2583
|
+
async function runLane(lane, options) {
|
|
2584
|
+
run("pnpm", [
|
|
2585
|
+
"lane",
|
|
2586
|
+
lane,
|
|
2587
|
+
...packageFilters(await getPublishablePackageNames(options.cwd))
|
|
2588
|
+
], options);
|
|
2589
|
+
}
|
|
2590
|
+
async function readLaneAssignments(cwd) {
|
|
2591
|
+
try {
|
|
2592
|
+
const workspaceFile = await readFile(path.join(cwd, "pnpm-workspace.yaml"), "utf8");
|
|
2593
|
+
return YAML.parse(workspaceFile).versioning?.lanes ?? {};
|
|
2594
|
+
} catch {
|
|
2595
|
+
return {};
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
async function assertLaneAssignments(lane, options) {
|
|
2599
|
+
const names = await getPublishablePackageNames(options.cwd);
|
|
2600
|
+
const assignments = await readLaneAssignments(options.cwd);
|
|
2601
|
+
const mismatched = names.filter((name) => assignments[name] !== lane);
|
|
2602
|
+
if (mismatched.length) throw new ReleaseCommandError([
|
|
2603
|
+
`all publishable packages must be on the ${lane} lane before prerelease publishing`,
|
|
2604
|
+
`mismatched packages: ${mismatched.join(", ")}`,
|
|
2605
|
+
`Run \`repo release pre enter ${lane}\`, commit pnpm-workspace.yaml, and push again.`
|
|
2606
|
+
].join("\n"));
|
|
2607
|
+
}
|
|
2608
|
+
async function assertStableLaneAssignments(options) {
|
|
2609
|
+
const assignments = await readLaneAssignments(options.cwd);
|
|
2610
|
+
const active = Object.entries(assignments).filter(([, lane]) => lane !== "main");
|
|
2611
|
+
if (active.length) throw new ReleaseCommandError(`stable releases require all packages on the main lane, found ${active.map(([name, lane]) => `${name}:${lane}`).join(", ")}`);
|
|
2612
|
+
}
|
|
2613
|
+
function runQualityChecks(options) {
|
|
2198
2614
|
run("pnpm", ["run", "build"], options);
|
|
2199
2615
|
run("pnpm", ["run", "lint"], options);
|
|
2200
2616
|
run("pnpm", ["run", "test"], options);
|
|
2201
|
-
run("pnpm", [
|
|
2202
|
-
"exec",
|
|
2203
|
-
"changeset",
|
|
2204
|
-
"publish"
|
|
2205
|
-
], options);
|
|
2206
2617
|
}
|
|
2618
|
+
function parsePublishSummary(content) {
|
|
2619
|
+
let parsed;
|
|
2620
|
+
try {
|
|
2621
|
+
parsed = JSON.parse(content);
|
|
2622
|
+
} catch {
|
|
2623
|
+
throw new ReleaseCommandError("pnpm-publish-summary.json is not valid JSON");
|
|
2624
|
+
}
|
|
2625
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.publishedPackages)) throw new ReleaseCommandError("pnpm-publish-summary.json does not contain publishedPackages");
|
|
2626
|
+
return parsed.publishedPackages.map((item) => {
|
|
2627
|
+
if (!item || typeof item !== "object" || typeof item.name !== "string" || typeof item.version !== "string") throw new ReleaseCommandError("pnpm-publish-summary.json contains an invalid package entry");
|
|
2628
|
+
return {
|
|
2629
|
+
name: item.name,
|
|
2630
|
+
version: item.version
|
|
2631
|
+
};
|
|
2632
|
+
});
|
|
2633
|
+
}
|
|
2634
|
+
async function readPublishSummary(cwd) {
|
|
2635
|
+
const summaryPath = path.join(cwd, "pnpm-publish-summary.json");
|
|
2636
|
+
try {
|
|
2637
|
+
await access(summaryPath);
|
|
2638
|
+
return parsePublishSummary(await readFile(summaryPath, "utf8"));
|
|
2639
|
+
} catch (error) {
|
|
2640
|
+
if (error instanceof ReleaseCommandError) throw error;
|
|
2641
|
+
return [];
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
//#endregion
|
|
2645
|
+
//#region src/commands/release/body.ts
|
|
2646
|
+
async function readPackageRelease(name, version, rootDir) {
|
|
2647
|
+
let changelog;
|
|
2648
|
+
try {
|
|
2649
|
+
changelog = await readFile(path.join(rootDir, "CHANGELOG.md"), "utf8");
|
|
2650
|
+
} catch {
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
const section = readVersionSection(changelog, version);
|
|
2654
|
+
if (!section?.content) return;
|
|
2655
|
+
return {
|
|
2656
|
+
name,
|
|
2657
|
+
version,
|
|
2658
|
+
...section.previousVersion ? { previousVersion: section.previousVersion } : {},
|
|
2659
|
+
content: section.content
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
/** Captures source commits and package ownership before pnpm consumes intents. */
|
|
2663
|
+
async function readPendingIntentCommits(options) {
|
|
2664
|
+
let entries;
|
|
2665
|
+
try {
|
|
2666
|
+
entries = await readdir(path.join(options.cwd, ".changeset"), { withFileTypes: true });
|
|
2667
|
+
} catch {
|
|
2668
|
+
return [];
|
|
2669
|
+
}
|
|
2670
|
+
const commits = [];
|
|
2671
|
+
for (const entry of entries) {
|
|
2672
|
+
if (!entry.isFile() || entry.name === "README.md" || !entry.name.endsWith(".md")) continue;
|
|
2673
|
+
try {
|
|
2674
|
+
const intentPath = `.changeset/${entry.name}`;
|
|
2675
|
+
const intentContent = await readFile(path.join(options.cwd, intentPath), "utf8");
|
|
2676
|
+
const packages = parseIntentPackages(intentContent);
|
|
2677
|
+
const summary = parseIntentSummary(intentContent);
|
|
2678
|
+
const sha = capture("git", [
|
|
2679
|
+
"log",
|
|
2680
|
+
"-1",
|
|
2681
|
+
"--format=%H",
|
|
2682
|
+
"--",
|
|
2683
|
+
intentPath
|
|
2684
|
+
], options);
|
|
2685
|
+
if (!sha) continue;
|
|
2686
|
+
const [fullSha, subject, body, author] = capture("git", [
|
|
2687
|
+
"show",
|
|
2688
|
+
"-s",
|
|
2689
|
+
"--format=%H%x1F%s%x1F%b%x1F%an",
|
|
2690
|
+
sha
|
|
2691
|
+
], options).split("");
|
|
2692
|
+
if (fullSha) commits.push({
|
|
2693
|
+
sha: fullSha,
|
|
2694
|
+
subject: subject ?? "",
|
|
2695
|
+
body: body ?? "",
|
|
2696
|
+
...author ? { author } : {},
|
|
2697
|
+
...packages.length ? { packages } : {},
|
|
2698
|
+
...summary ? { summary } : {}
|
|
2699
|
+
});
|
|
2700
|
+
} catch {}
|
|
2701
|
+
}
|
|
2702
|
+
return uniqueCommits(commits);
|
|
2703
|
+
}
|
|
2704
|
+
async function readWorkspaceVersions(cwd) {
|
|
2705
|
+
const packages = await getWorkspacePackages(cwd);
|
|
2706
|
+
const versions = /* @__PURE__ */ new Map();
|
|
2707
|
+
for (const pkg of packages) try {
|
|
2708
|
+
const manifest = JSON.parse(await readFile(pkg.pkgJsonPath, "utf8"));
|
|
2709
|
+
if (typeof manifest.name === "string" && typeof manifest.version === "string") versions.set(manifest.name, manifest.version);
|
|
2710
|
+
} catch {}
|
|
2711
|
+
return versions;
|
|
2712
|
+
}
|
|
2713
|
+
function buildReleasePackage(release) {
|
|
2714
|
+
const packageLinks = {};
|
|
2715
|
+
if (!release.private) {
|
|
2716
|
+
packageLinks.npmUrl = release.npmUrl ?? buildNpmPackageUrl(release.name, release.version);
|
|
2717
|
+
if (release.previousVersion) packageLinks.previousNpmUrl = buildNpmPackageUrl(release.name, release.previousVersion);
|
|
2718
|
+
}
|
|
2719
|
+
return {
|
|
2720
|
+
name: release.name,
|
|
2721
|
+
version: release.version,
|
|
2722
|
+
...release.previousVersion ? { previousVersion: release.previousVersion } : {},
|
|
2723
|
+
...packageLinks
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
async function buildReleaseNoteDocument(cwd, previousVersions, metadata = {}) {
|
|
2727
|
+
const workspacePackages = await getWorkspacePackages(cwd);
|
|
2728
|
+
const releases = [];
|
|
2729
|
+
for (const pkg of workspacePackages) {
|
|
2730
|
+
let manifest;
|
|
2731
|
+
try {
|
|
2732
|
+
manifest = JSON.parse(await readFile(pkg.pkgJsonPath, "utf8"));
|
|
2733
|
+
} catch {
|
|
2734
|
+
continue;
|
|
2735
|
+
}
|
|
2736
|
+
if (typeof manifest.name !== "string" || typeof manifest.version !== "string") continue;
|
|
2737
|
+
if (previousVersions?.get(manifest.name) === manifest.version) continue;
|
|
2738
|
+
const release = await readPackageRelease(manifest.name, manifest.version, pkg.rootDir);
|
|
2739
|
+
if (release) {
|
|
2740
|
+
const previousVersion = previousVersions?.get(manifest.name) || release.previousVersion;
|
|
2741
|
+
releases.push({
|
|
2742
|
+
...release,
|
|
2743
|
+
...manifest.private === true ? { private: true } : { npmUrl: buildNpmPackageUrl(manifest.name, manifest.version) },
|
|
2744
|
+
...previousVersion ? { previousVersion } : {}
|
|
2745
|
+
});
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
const entries = releases.flatMap((release) => buildEntries(release, metadata.commits ?? []));
|
|
2749
|
+
const contributors = [.../* @__PURE__ */ new Set([...metadata.contributors ?? [], ...entries.flatMap((entry) => entry.authors)])].filter((value) => !/github-actions|dependabot|\[bot\]$/i.test(value));
|
|
2750
|
+
const compareUrls = releases.map((release) => buildPackageCompareUrl(release, metadata)).filter((url) => Boolean(url));
|
|
2751
|
+
return {
|
|
2752
|
+
packages: releases.map(buildReleasePackage),
|
|
2753
|
+
entries,
|
|
2754
|
+
contributors,
|
|
2755
|
+
compareUrls
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2758
|
+
//#endregion
|
|
2759
|
+
//#region src/commands/release/github.ts
|
|
2760
|
+
var GitHubApiError = class extends ReleaseCommandError {
|
|
2761
|
+
status;
|
|
2762
|
+
responseBody;
|
|
2763
|
+
constructor(message, status, responseBody) {
|
|
2764
|
+
super(message);
|
|
2765
|
+
this.status = status;
|
|
2766
|
+
this.responseBody = responseBody;
|
|
2767
|
+
this.name = "GitHubApiError";
|
|
2768
|
+
}
|
|
2769
|
+
};
|
|
2770
|
+
var GitHubClient = class {
|
|
2771
|
+
token;
|
|
2772
|
+
repository;
|
|
2773
|
+
apiUrl;
|
|
2774
|
+
requestFetch;
|
|
2775
|
+
constructor(options = {}) {
|
|
2776
|
+
this.token = options.token ?? process.env["GITHUB_TOKEN"];
|
|
2777
|
+
this.repository = options.repository ?? process.env["GITHUB_REPOSITORY"];
|
|
2778
|
+
this.apiUrl = (options.apiUrl ?? process.env["GITHUB_API_URL"] ?? "https://api.github.com").replace(/\/$/, "");
|
|
2779
|
+
this.requestFetch = options.fetch ?? globalThis.fetch;
|
|
2780
|
+
}
|
|
2781
|
+
getRepository() {
|
|
2782
|
+
if (!this.token) throw new GitHubApiError("GITHUB_TOKEN is required for GitHub release orchestration", 0);
|
|
2783
|
+
if (!this.repository || !/^[^/]+\/[^/]+$/.test(this.repository)) throw new GitHubApiError("GITHUB_REPOSITORY must be in owner/name format", 0);
|
|
2784
|
+
return this.repository;
|
|
2785
|
+
}
|
|
2786
|
+
async request(method, endpoint, body) {
|
|
2787
|
+
const repository = this.getRepository();
|
|
2788
|
+
let response;
|
|
2789
|
+
try {
|
|
2790
|
+
response = await this.requestFetch(`${this.apiUrl}/repos/${repository}${endpoint}`, {
|
|
2791
|
+
method,
|
|
2792
|
+
headers: {
|
|
2793
|
+
"Accept": "application/vnd.github+json",
|
|
2794
|
+
"Authorization": `Bearer ${this.token}`,
|
|
2795
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
2796
|
+
...body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
2797
|
+
},
|
|
2798
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
2799
|
+
});
|
|
2800
|
+
} catch (error) {
|
|
2801
|
+
throw new GitHubApiError(`GitHub API request ${method} ${endpoint} failed: ${error instanceof Error ? error.message : String(error)}. Check network access and GITHUB_API_URL.`, 0);
|
|
2802
|
+
}
|
|
2803
|
+
const text = await response.text();
|
|
2804
|
+
let data;
|
|
2805
|
+
if (text) try {
|
|
2806
|
+
data = JSON.parse(text);
|
|
2807
|
+
} catch {
|
|
2808
|
+
throw new GitHubApiError(`GitHub API returned invalid JSON for ${method} ${endpoint}`, response.status, text);
|
|
2809
|
+
}
|
|
2810
|
+
if (!response.ok) {
|
|
2811
|
+
const message = typeof data === "object" && data !== null && "message" in data ? String(data.message) : text || response.statusText;
|
|
2812
|
+
throw new GitHubApiError(`GitHub API ${method} ${endpoint} failed (${response.status}): ${message}`, response.status, text);
|
|
2813
|
+
}
|
|
2814
|
+
return {
|
|
2815
|
+
status: response.status,
|
|
2816
|
+
data
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
async ensurePullRequest(options) {
|
|
2820
|
+
const [owner] = this.getRepository().split("/");
|
|
2821
|
+
const head = options.head.includes(":") ? options.head : `${owner}:${options.head}`;
|
|
2822
|
+
const query = new URLSearchParams({
|
|
2823
|
+
state: "open",
|
|
2824
|
+
head,
|
|
2825
|
+
base: options.base,
|
|
2826
|
+
per_page: "10"
|
|
2827
|
+
});
|
|
2828
|
+
const existing = (await this.request("GET", `/pulls?${query.toString()}`)).data?.[0];
|
|
2829
|
+
if (existing) {
|
|
2830
|
+
await this.request("PATCH", `/pulls/${existing.number}`, {
|
|
2831
|
+
title: options.title,
|
|
2832
|
+
body: options.body,
|
|
2833
|
+
base: options.base
|
|
2834
|
+
});
|
|
2835
|
+
return existing;
|
|
2836
|
+
}
|
|
2837
|
+
try {
|
|
2838
|
+
const created = await this.request("POST", "/pulls", {
|
|
2839
|
+
title: options.title,
|
|
2840
|
+
body: options.body,
|
|
2841
|
+
head: options.head,
|
|
2842
|
+
base: options.base
|
|
2843
|
+
});
|
|
2844
|
+
if (!created.data) throw new GitHubApiError("GitHub did not return the created pull request", created.status);
|
|
2845
|
+
return created.data;
|
|
2846
|
+
} catch (error) {
|
|
2847
|
+
if (!(error instanceof GitHubApiError) || error.status !== 422) throw error;
|
|
2848
|
+
const recovered = await this.request("GET", `/pulls?${query.toString()}`);
|
|
2849
|
+
if (recovered.data?.[0]) return recovered.data[0];
|
|
2850
|
+
throw error;
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
async closeLegacyReleasePullRequests(options) {
|
|
2854
|
+
const [owner] = this.getRepository().split("/");
|
|
2855
|
+
const head = options.head.includes(":") ? options.head : `${owner}:${options.head}`;
|
|
2856
|
+
const query = new URLSearchParams({
|
|
2857
|
+
state: "open",
|
|
2858
|
+
head,
|
|
2859
|
+
base: options.base,
|
|
2860
|
+
per_page: "100"
|
|
2861
|
+
});
|
|
2862
|
+
const listed = await this.request("GET", `/pulls?${query.toString()}`);
|
|
2863
|
+
for (const pullRequest of listed.data ?? []) if (pullRequest.head?.ref === options.head && (pullRequest.title === "Version Packages" || pullRequest.body?.includes("changesets/action") === true)) await this.request("PATCH", `/pulls/${pullRequest.number}`, { state: "closed" });
|
|
2864
|
+
}
|
|
2865
|
+
async ensureRelease(options) {
|
|
2866
|
+
let existing;
|
|
2867
|
+
try {
|
|
2868
|
+
existing = (await this.request("GET", `/releases/tags/${encodeURIComponent(options.tag)}`)).data;
|
|
2869
|
+
} catch (error) {
|
|
2870
|
+
if (!(error instanceof GitHubApiError) || error.status !== 404) throw error;
|
|
2871
|
+
}
|
|
2872
|
+
if (existing) {
|
|
2873
|
+
if (options.body !== void 0 || options.name !== void 0) return (await this.request("PATCH", `/releases/${existing.id}`, {
|
|
2874
|
+
...options.name === void 0 ? {} : { name: options.name },
|
|
2875
|
+
...options.body === void 0 ? {} : { body: options.body },
|
|
2876
|
+
prerelease: options.prerelease ?? false
|
|
2877
|
+
})).data ?? existing;
|
|
2878
|
+
return existing;
|
|
2879
|
+
}
|
|
2880
|
+
try {
|
|
2881
|
+
const created = await this.request("POST", "/releases", {
|
|
2882
|
+
tag_name: options.tag,
|
|
2883
|
+
target_commitish: options.target,
|
|
2884
|
+
name: options.name ?? options.tag,
|
|
2885
|
+
...options.body === void 0 ? { generate_release_notes: true } : { body: options.body },
|
|
2886
|
+
prerelease: options.prerelease ?? false
|
|
2887
|
+
});
|
|
2888
|
+
if (!created.data) throw new GitHubApiError("GitHub did not return the created release", created.status);
|
|
2889
|
+
return created.data;
|
|
2890
|
+
} catch (error) {
|
|
2891
|
+
if (!(error instanceof GitHubApiError) || error.status !== 422) throw error;
|
|
2892
|
+
const recovered = await this.request("GET", `/releases/tags/${encodeURIComponent(options.tag)}`);
|
|
2893
|
+
if (!recovered.data) throw error;
|
|
2894
|
+
return recovered.data;
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
async enrichReleaseNote(document) {
|
|
2898
|
+
try {
|
|
2899
|
+
const commitAuthors = /* @__PURE__ */ new Map();
|
|
2900
|
+
const commitShas = [...new Set(document.entries.flatMap((entry) => entry.commits.map((commit) => commit.sha)))];
|
|
2901
|
+
for (const sha of commitShas) {
|
|
2902
|
+
const response = await this.request("GET", `/commits/${encodeURIComponent(sha)}`);
|
|
2903
|
+
const author = response.data?.author?.login || response.data?.commit?.author?.name;
|
|
2904
|
+
if (author) commitAuthors.set(sha, author);
|
|
2905
|
+
}
|
|
2906
|
+
const referenceNumbers = [...new Set(document.entries.flatMap((entry) => [...entry.pullRequests, ...entry.issues]))];
|
|
2907
|
+
const referenceAuthors = /* @__PURE__ */ new Set();
|
|
2908
|
+
for (const number of referenceNumbers) {
|
|
2909
|
+
const author = (await this.request("GET", `/issues/${number}`)).data?.user?.login;
|
|
2910
|
+
if (author) referenceAuthors.add(author);
|
|
2911
|
+
}
|
|
2912
|
+
const entries = document.entries.map((entry) => {
|
|
2913
|
+
const authors = [.../* @__PURE__ */ new Set([...entry.authors, ...entry.commits.map((commit) => commitAuthors.get(commit.sha)).filter((author) => Boolean(author))])];
|
|
2914
|
+
return authors.length ? {
|
|
2915
|
+
...entry,
|
|
2916
|
+
authors
|
|
2917
|
+
} : entry;
|
|
2918
|
+
});
|
|
2919
|
+
return {
|
|
2920
|
+
...document,
|
|
2921
|
+
entries,
|
|
2922
|
+
contributors: [.../* @__PURE__ */ new Set([
|
|
2923
|
+
...document.contributors,
|
|
2924
|
+
...commitAuthors.values(),
|
|
2925
|
+
...referenceAuthors
|
|
2926
|
+
])]
|
|
2927
|
+
};
|
|
2928
|
+
} catch (error) {
|
|
2929
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2930
|
+
logger.warn(`GitHub release note metadata enrichment skipped: ${message}`);
|
|
2931
|
+
return document;
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
async ensureTag(options) {
|
|
2935
|
+
const endpoint = `/git/ref/tags/${encodeURIComponent(options.tag)}`;
|
|
2936
|
+
try {
|
|
2937
|
+
await this.request("GET", endpoint);
|
|
2938
|
+
return;
|
|
2939
|
+
} catch (error) {
|
|
2940
|
+
if (!(error instanceof GitHubApiError) || error.status !== 404) throw error;
|
|
2941
|
+
}
|
|
2942
|
+
try {
|
|
2943
|
+
await this.request("POST", "/git/refs", {
|
|
2944
|
+
ref: `refs/tags/${options.tag}`,
|
|
2945
|
+
sha: options.target
|
|
2946
|
+
});
|
|
2947
|
+
} catch (error) {
|
|
2948
|
+
if (!(error instanceof GitHubApiError) || error.status !== 422) throw error;
|
|
2949
|
+
await this.request("GET", endpoint);
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
};
|
|
2953
|
+
//#endregion
|
|
2954
|
+
//#region src/commands/release/types.ts
|
|
2955
|
+
const prereleaseBranches = /* @__PURE__ */ new Set([
|
|
2956
|
+
"alpha",
|
|
2957
|
+
"beta",
|
|
2958
|
+
"rc",
|
|
2959
|
+
"next"
|
|
2960
|
+
]);
|
|
2961
|
+
//#endregion
|
|
2962
|
+
//#region src/commands/release/prerelease.ts
|
|
2207
2963
|
async function releasePrerelease(options) {
|
|
2208
2964
|
const branch = resolveBranch(options);
|
|
2209
2965
|
if (!prereleaseBranches.has(branch)) throw new ReleaseCommandError(`repo release pre is only allowed on alpha, beta, rc, or next branches, got ${branch}`);
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
run("pnpm", ["run", "lint"], options);
|
|
2214
|
-
run("pnpm", ["run", "test"], options);
|
|
2215
|
-
if (!await hasPendingChangesets(options.cwd)) return;
|
|
2966
|
+
await assertLaneAssignments(branch, options);
|
|
2967
|
+
runQualityChecks(options);
|
|
2968
|
+
if (!await hasPendingIntents(options.cwd)) return;
|
|
2216
2969
|
run("pnpm", [
|
|
2217
|
-
"
|
|
2218
|
-
"
|
|
2219
|
-
"
|
|
2970
|
+
"version",
|
|
2971
|
+
"-r",
|
|
2972
|
+
"--no-git-checks"
|
|
2220
2973
|
], options);
|
|
2221
|
-
if (!(
|
|
2222
|
-
"diff",
|
|
2223
|
-
"--quiet",
|
|
2224
|
-
"--exit-code"
|
|
2225
|
-
], {
|
|
2226
|
-
cwd: options.cwd,
|
|
2227
|
-
encoding: "utf8",
|
|
2228
|
-
shell: false,
|
|
2229
|
-
stdio: "ignore"
|
|
2230
|
-
}).status !== 0)) return;
|
|
2974
|
+
if (!hasGitChanges(options)) return;
|
|
2231
2975
|
run("git", ["add", "-A"], options);
|
|
2232
2976
|
run("git", [
|
|
2233
2977
|
"commit",
|
|
@@ -2235,9 +2979,13 @@ async function releasePrerelease(options) {
|
|
|
2235
2979
|
`chore(release): ${branch} [skip ci]`
|
|
2236
2980
|
], options);
|
|
2237
2981
|
run("pnpm", [
|
|
2238
|
-
"
|
|
2239
|
-
"
|
|
2240
|
-
"
|
|
2982
|
+
"publish",
|
|
2983
|
+
"-r",
|
|
2984
|
+
"--tag",
|
|
2985
|
+
branch,
|
|
2986
|
+
"--report-summary",
|
|
2987
|
+
"--provenance",
|
|
2988
|
+
"--no-git-checks"
|
|
2241
2989
|
], options);
|
|
2242
2990
|
run("git", [
|
|
2243
2991
|
"push",
|
|
@@ -2246,23 +2994,262 @@ async function releasePrerelease(options) {
|
|
|
2246
2994
|
`HEAD:${branch}`
|
|
2247
2995
|
], options);
|
|
2248
2996
|
}
|
|
2249
|
-
function enterPrerelease(tag, options) {
|
|
2250
|
-
if (!prereleaseBranches.has(tag)) throw new ReleaseCommandError(`unknown prerelease
|
|
2997
|
+
async function enterPrerelease(tag, options) {
|
|
2998
|
+
if (!prereleaseBranches.has(tag)) throw new ReleaseCommandError(`unknown prerelease lane ${tag}; expected alpha, beta, rc, or next`);
|
|
2999
|
+
await runLane(tag, options);
|
|
3000
|
+
}
|
|
3001
|
+
async function exitPrerelease(options) {
|
|
3002
|
+
await runLane("main", options);
|
|
3003
|
+
}
|
|
3004
|
+
//#endregion
|
|
3005
|
+
//#region src/commands/release/stable.ts
|
|
3006
|
+
async function prepareStable(options) {
|
|
3007
|
+
const branch = resolveBranch(options);
|
|
3008
|
+
if (branch !== "main") throw new ReleaseCommandError(`repo release stable prepare is only allowed on main, got ${branch}`);
|
|
3009
|
+
await assertStableLaneAssignments(options);
|
|
3010
|
+
runQualityChecks(options);
|
|
3011
|
+
if (!await hasPendingIntents(options.cwd)) return false;
|
|
2251
3012
|
run("pnpm", [
|
|
2252
|
-
"
|
|
2253
|
-
"
|
|
2254
|
-
"
|
|
2255
|
-
"enter",
|
|
2256
|
-
tag
|
|
3013
|
+
"version",
|
|
3014
|
+
"-r",
|
|
3015
|
+
"--no-git-checks"
|
|
2257
3016
|
], options);
|
|
3017
|
+
return hasGitChanges(options);
|
|
2258
3018
|
}
|
|
2259
|
-
function
|
|
3019
|
+
async function publishStable(options) {
|
|
3020
|
+
const branch = resolveBranch(options);
|
|
3021
|
+
if (branch !== "main") throw new ReleaseCommandError(`repo release stable publish is only allowed on main, got ${branch}`);
|
|
3022
|
+
await assertStableLaneAssignments(options);
|
|
3023
|
+
runQualityChecks(options);
|
|
2260
3024
|
run("pnpm", [
|
|
3025
|
+
"publish",
|
|
3026
|
+
"-r",
|
|
3027
|
+
"--report-summary",
|
|
3028
|
+
"--provenance",
|
|
3029
|
+
"--no-git-checks"
|
|
3030
|
+
], options);
|
|
3031
|
+
}
|
|
3032
|
+
/** Compatibility entry point retained for existing generated repositories. */
|
|
3033
|
+
async function releaseStable(options) {
|
|
3034
|
+
await publishStable(options);
|
|
3035
|
+
}
|
|
3036
|
+
//#endregion
|
|
3037
|
+
//#region src/commands/release/ci.ts
|
|
3038
|
+
const releaseBranch = "release/pnpm-version";
|
|
3039
|
+
function gitRefExists(ref, options) {
|
|
3040
|
+
return (options.spawn ?? spawnSync)("git", [
|
|
3041
|
+
"rev-parse",
|
|
3042
|
+
"--verify",
|
|
3043
|
+
"--quiet",
|
|
3044
|
+
ref
|
|
3045
|
+
], {
|
|
3046
|
+
cwd: options.cwd,
|
|
3047
|
+
encoding: "utf8",
|
|
3048
|
+
shell: false,
|
|
3049
|
+
stdio: "ignore"
|
|
3050
|
+
}).status === 0;
|
|
3051
|
+
}
|
|
3052
|
+
function remoteTagExists(tag, options) {
|
|
3053
|
+
return (options.spawn ?? spawnSync)("git", [
|
|
3054
|
+
"ls-remote",
|
|
3055
|
+
"--exit-code",
|
|
3056
|
+
"--refs",
|
|
3057
|
+
"origin",
|
|
3058
|
+
`refs/tags/${tag}`
|
|
3059
|
+
], {
|
|
3060
|
+
cwd: options.cwd,
|
|
3061
|
+
encoding: "utf8",
|
|
3062
|
+
shell: false,
|
|
3063
|
+
stdio: "ignore"
|
|
3064
|
+
}).status === 0;
|
|
3065
|
+
}
|
|
3066
|
+
function resolveGitHub(options) {
|
|
3067
|
+
return options.github ?? new GitHubClient();
|
|
3068
|
+
}
|
|
3069
|
+
function resolveTarget(options) {
|
|
3070
|
+
return getReleaseEnv(options)["GITHUB_SHA"]?.trim() || capture("git", ["rev-parse", "HEAD"], options);
|
|
3071
|
+
}
|
|
3072
|
+
async function publishMetadata(packages, options, prerelease = false) {
|
|
3073
|
+
if (!packages.length) return;
|
|
3074
|
+
const github = resolveGitHub(options);
|
|
3075
|
+
const target = resolveTarget(options);
|
|
3076
|
+
const releaseEnv = getReleaseEnv(options);
|
|
3077
|
+
const metadata = {
|
|
3078
|
+
...releaseEnv["GITHUB_REPOSITORY"] ? { repository: releaseEnv["GITHUB_REPOSITORY"] } : {},
|
|
3079
|
+
...releaseEnv["GITHUB_SERVER_URL"] ? { serverUrl: releaseEnv["GITHUB_SERVER_URL"] } : {}
|
|
3080
|
+
};
|
|
3081
|
+
let noteDocument = await buildReleaseNoteDocument(options.cwd, void 0, metadata);
|
|
3082
|
+
if (github.enrichReleaseNote) noteDocument = await github.enrichReleaseNote(noteDocument);
|
|
3083
|
+
for (const pkg of packages) {
|
|
3084
|
+
const tag = `${pkg.name}@${pkg.version}`;
|
|
3085
|
+
const body = renderGitHubRelease({
|
|
3086
|
+
...noteDocument,
|
|
3087
|
+
packages: noteDocument.packages.filter((item) => item.name === pkg.name && item.version === pkg.version),
|
|
3088
|
+
entries: noteDocument.entries.filter((entry) => entry.packageName === pkg.name && entry.version === pkg.version),
|
|
3089
|
+
compareUrls: noteDocument.compareUrls.filter((url) => url.includes(encodeURIComponent(`${pkg.name}@`)))
|
|
3090
|
+
}, metadata);
|
|
3091
|
+
if (github.ensureTag) {
|
|
3092
|
+
await github.ensureTag({
|
|
3093
|
+
tag,
|
|
3094
|
+
target
|
|
3095
|
+
});
|
|
3096
|
+
await github.ensureRelease({
|
|
3097
|
+
tag,
|
|
3098
|
+
target,
|
|
3099
|
+
prerelease,
|
|
3100
|
+
name: tag,
|
|
3101
|
+
body
|
|
3102
|
+
});
|
|
3103
|
+
continue;
|
|
3104
|
+
}
|
|
3105
|
+
if (remoteTagExists(tag, options)) {
|
|
3106
|
+
await github.ensureRelease({
|
|
3107
|
+
tag,
|
|
3108
|
+
target,
|
|
3109
|
+
prerelease,
|
|
3110
|
+
name: tag,
|
|
3111
|
+
body
|
|
3112
|
+
});
|
|
3113
|
+
continue;
|
|
3114
|
+
}
|
|
3115
|
+
if (!gitRefExists(tag, options)) run("git", [
|
|
3116
|
+
"tag",
|
|
3117
|
+
"-a",
|
|
3118
|
+
tag,
|
|
3119
|
+
"-m",
|
|
3120
|
+
tag
|
|
3121
|
+
], options);
|
|
3122
|
+
run("git", [
|
|
3123
|
+
"push",
|
|
3124
|
+
"origin",
|
|
3125
|
+
`refs/tags/${tag}`
|
|
3126
|
+
], options);
|
|
3127
|
+
await github.ensureRelease({
|
|
3128
|
+
tag,
|
|
3129
|
+
target,
|
|
3130
|
+
prerelease,
|
|
3131
|
+
name: tag,
|
|
3132
|
+
body
|
|
3133
|
+
});
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
async function createReleasePullRequest(options) {
|
|
3137
|
+
const branch = resolveBranch(options);
|
|
3138
|
+
if (branch !== "main") throw new ReleaseCommandError(`repo release stable prepare is only allowed on main, got ${branch}`);
|
|
3139
|
+
const previousVersions = await readWorkspaceVersions(options.cwd);
|
|
3140
|
+
const sourceCommits = await readPendingIntentCommits(options);
|
|
3141
|
+
if (!await prepareStable(options)) return false;
|
|
3142
|
+
run("git", [
|
|
3143
|
+
"config",
|
|
3144
|
+
"user.name",
|
|
3145
|
+
"github-actions[bot]"
|
|
3146
|
+
], options);
|
|
3147
|
+
run("git", [
|
|
3148
|
+
"config",
|
|
3149
|
+
"user.email",
|
|
3150
|
+
"41898282+github-actions[bot]@users.noreply.github.com"
|
|
3151
|
+
], options);
|
|
3152
|
+
run("git", [
|
|
3153
|
+
"checkout",
|
|
3154
|
+
"-B",
|
|
3155
|
+
releaseBranch
|
|
3156
|
+
], options);
|
|
3157
|
+
run("git", ["add", "-A"], options);
|
|
3158
|
+
run("git", [
|
|
3159
|
+
"commit",
|
|
3160
|
+
"-m",
|
|
3161
|
+
"chore(release): version packages"
|
|
3162
|
+
], options);
|
|
3163
|
+
run("git", [
|
|
3164
|
+
"push",
|
|
3165
|
+
"--force",
|
|
3166
|
+
"origin",
|
|
3167
|
+
`HEAD:${releaseBranch}`
|
|
3168
|
+
], options);
|
|
3169
|
+
const github = resolveGitHub(options);
|
|
3170
|
+
const releaseEnv = getReleaseEnv(options);
|
|
3171
|
+
const metadata = {
|
|
3172
|
+
commits: sourceCommits,
|
|
3173
|
+
...releaseEnv["GITHUB_REPOSITORY"] ? { repository: releaseEnv["GITHUB_REPOSITORY"] } : {},
|
|
3174
|
+
...releaseEnv["GITHUB_SERVER_URL"] ? { serverUrl: releaseEnv["GITHUB_SERVER_URL"] } : {}
|
|
3175
|
+
};
|
|
3176
|
+
let noteDocument = await buildReleaseNoteDocument(options.cwd, previousVersions, metadata);
|
|
3177
|
+
if (github.enrichReleaseNote) noteDocument = await github.enrichReleaseNote(noteDocument);
|
|
3178
|
+
await github.ensurePullRequest({
|
|
3179
|
+
head: releaseBranch,
|
|
3180
|
+
base: "main",
|
|
3181
|
+
title: "chore(release): version packages",
|
|
3182
|
+
body: renderReleasePullRequest(noteDocument, metadata)
|
|
3183
|
+
});
|
|
3184
|
+
await github.closeLegacyReleasePullRequests?.({
|
|
3185
|
+
head: "changeset-release/main",
|
|
3186
|
+
base: "main"
|
|
3187
|
+
});
|
|
3188
|
+
return true;
|
|
3189
|
+
}
|
|
3190
|
+
async function recoverUnpublished(options) {
|
|
3191
|
+
const packageName = options.packageName || getReleaseEnv(options)["REPO_RELEASE_PACKAGE"]?.trim();
|
|
3192
|
+
const packageVersion = options.packageVersion || getReleaseEnv(options)["REPO_RELEASE_VERSION"]?.trim();
|
|
3193
|
+
if (!packageName || !packageVersion) throw new ReleaseCommandError("publish-unpublished requires REPO_RELEASE_PACKAGE and REPO_RELEASE_VERSION");
|
|
3194
|
+
const actualVersion = capture("pnpm", [
|
|
3195
|
+
"--filter",
|
|
3196
|
+
packageName,
|
|
2261
3197
|
"exec",
|
|
2262
|
-
"
|
|
2263
|
-
"
|
|
2264
|
-
"
|
|
3198
|
+
"node",
|
|
3199
|
+
"-p",
|
|
3200
|
+
"require('./package.json').version"
|
|
3201
|
+
], options);
|
|
3202
|
+
if (actualVersion !== packageVersion) throw new ReleaseCommandError(`expected ${packageName}@${packageVersion} in the workspace, found ${actualVersion}`);
|
|
3203
|
+
run("pnpm", [
|
|
3204
|
+
"publish",
|
|
3205
|
+
"-r",
|
|
3206
|
+
"--filter",
|
|
3207
|
+
packageName,
|
|
3208
|
+
"--report-summary",
|
|
3209
|
+
"--provenance",
|
|
3210
|
+
"--no-git-checks"
|
|
2265
3211
|
], options);
|
|
3212
|
+
if (capture("npm", [
|
|
3213
|
+
"view",
|
|
3214
|
+
`${packageName}@${packageVersion}`,
|
|
3215
|
+
"version"
|
|
3216
|
+
], options) !== packageVersion) throw new ReleaseCommandError(`npm did not report ${packageName}@${packageVersion} after recovery`);
|
|
3217
|
+
await publishMetadata(await readPublishSummary(options.cwd), options);
|
|
3218
|
+
}
|
|
3219
|
+
function resolveMode(options) {
|
|
3220
|
+
const requested = options.mode || getReleaseEnv(options)["REPO_RELEASE_MODE"]?.trim();
|
|
3221
|
+
if (requested && requested !== "auto") return requested;
|
|
3222
|
+
return "auto";
|
|
3223
|
+
}
|
|
3224
|
+
async function releaseCi(options) {
|
|
3225
|
+
const mode = resolveMode(options);
|
|
3226
|
+
if (mode === "prepare") {
|
|
3227
|
+
await createReleasePullRequest(options);
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3230
|
+
if (mode === "publish") {
|
|
3231
|
+
await publishStable(options);
|
|
3232
|
+
await publishMetadata(await readPublishSummary(options.cwd), options);
|
|
3233
|
+
return;
|
|
3234
|
+
}
|
|
3235
|
+
if (mode === "publish-unpublished") {
|
|
3236
|
+
await recoverUnpublished(options);
|
|
3237
|
+
return;
|
|
3238
|
+
}
|
|
3239
|
+
if (mode !== "auto") throw new ReleaseCommandError(`unknown release CI mode ${mode}; expected auto, prepare, publish, or publish-unpublished`);
|
|
3240
|
+
const branch = resolveBranch(options);
|
|
3241
|
+
if (prereleaseBranches.has(branch)) {
|
|
3242
|
+
await releasePrerelease(options);
|
|
3243
|
+
await publishMetadata(await readPublishSummary(options.cwd), options, true);
|
|
3244
|
+
return;
|
|
3245
|
+
}
|
|
3246
|
+
if (branch !== "main") throw new ReleaseCommandError(`repo release ci only supports main, alpha, beta, rc, or next branches, got ${branch}`);
|
|
3247
|
+
if (await hasPendingIntents(options.cwd)) {
|
|
3248
|
+
await createReleasePullRequest(options);
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
await publishStable(options);
|
|
3252
|
+
await publishMetadata(await readPublishSummary(options.cwd), options);
|
|
2266
3253
|
}
|
|
2267
3254
|
//#endregion
|
|
2268
3255
|
//#region src/commands/templates.ts
|
|
@@ -2596,6 +3583,7 @@ const scriptsEntries = Object.entries({
|
|
|
2596
3583
|
//#region src/commands/upgrade/pkg-json.ts
|
|
2597
3584
|
const NON_OVERRIDABLE_PREFIXES = ["workspace:", "catalog:"];
|
|
2598
3585
|
const legacyToolPackageName = "@icebreakers/monorepo";
|
|
3586
|
+
const legacyReleaseDependencies = ["@changesets/cli", "@icebreakers/changelog-github"];
|
|
2599
3587
|
function parseVersion(input) {
|
|
2600
3588
|
if (typeof input !== "string" || input.trim().length === 0) return null;
|
|
2601
3589
|
try {
|
|
@@ -2651,6 +3639,10 @@ function setPkgJson(sourcePkgJson, targetPkgJson, options) {
|
|
|
2651
3639
|
}
|
|
2652
3640
|
}
|
|
2653
3641
|
if (legacyToolPackageName in targetDevDeps && "repoctl" in targetDevDeps) delete targetDevDeps[legacyToolPackageName];
|
|
3642
|
+
for (const dependency of legacyReleaseDependencies) {
|
|
3643
|
+
delete targetDeps[dependency];
|
|
3644
|
+
delete targetDevDeps[dependency];
|
|
3645
|
+
}
|
|
2654
3646
|
if (shouldEnsureRepoctl) {
|
|
2655
3647
|
const nextVersion = `^${version$1}`;
|
|
2656
3648
|
const targetVersion = targetDevDeps["repoctl"];
|
|
@@ -2804,6 +3796,12 @@ async function upgradeMonorepo(opts) {
|
|
|
2804
3796
|
const relPath = toWorkspaceGitignorePath(path.relative(assetsDir, file.path));
|
|
2805
3797
|
if (skipChangesetMarkdown && relPath.startsWith(".changeset/") && relPath.endsWith(".md")) continue;
|
|
2806
3798
|
const targetPath = path.resolve(absOutDir, relPath);
|
|
3799
|
+
if (relPath === ".github/workflows/release.yml" && await fs$1.pathExists(targetPath)) {
|
|
3800
|
+
if (await classifyReleaseWorkflow(absOutDir) === "custom" && !merged.overwriteRelease) {
|
|
3801
|
+
logger.warn("skip custom release workflow; use repo upgrade --overwrite-release to replace it");
|
|
3802
|
+
continue;
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
2807
3805
|
try {
|
|
2808
3806
|
if (relPath === "package.json") {
|
|
2809
3807
|
if (!await fs$1.pathExists(targetPath)) continue;
|
|
@@ -2881,23 +3879,6 @@ async function upgradeMonorepo(opts) {
|
|
|
2881
3879
|
});
|
|
2882
3880
|
continue;
|
|
2883
3881
|
}
|
|
2884
|
-
if (relPath === ".changeset/config.json" && repoName) {
|
|
2885
|
-
const changesetJson = await fs$1.readJson(file.path);
|
|
2886
|
-
setByPath(changesetJson, "changelog.1.repo", repoName);
|
|
2887
|
-
const data = `${JSON.stringify(changesetJson, void 0, 2)}\n`;
|
|
2888
|
-
const intent = await evaluateWriteIntent(targetPath, buildWriteIntentOptions(data));
|
|
2889
|
-
const action = async () => {
|
|
2890
|
-
await fs$1.outputFile(targetPath, data, "utf8");
|
|
2891
|
-
logger.success(targetPath);
|
|
2892
|
-
};
|
|
2893
|
-
await scheduleOverwrite(intent, {
|
|
2894
|
-
relPath,
|
|
2895
|
-
targetPath,
|
|
2896
|
-
action,
|
|
2897
|
-
pending: pendingOverwrites
|
|
2898
|
-
});
|
|
2899
|
-
continue;
|
|
2900
|
-
}
|
|
2901
3882
|
if (relPath === "LICENSE") {
|
|
2902
3883
|
const source = await fs$1.readFile(file.path);
|
|
2903
3884
|
const intent = await evaluateWriteIntent(targetPath, {
|
|
@@ -2958,11 +3939,14 @@ async function upgradeMonorepo(opts) {
|
|
|
2958
3939
|
...merged.overwrite !== void 0 ? { overwrite: merged.overwrite } : {},
|
|
2959
3940
|
...merged.noOverwrite !== void 0 ? { noOverwrite: merged.noOverwrite } : {}
|
|
2960
3941
|
});
|
|
3942
|
+
await migrateLegacyVersioning(absOutDir);
|
|
2961
3943
|
}
|
|
2962
3944
|
//#endregion
|
|
2963
3945
|
//#region src/commands/index.ts
|
|
2964
3946
|
var commands_exports = /* @__PURE__ */ __exportAll({
|
|
2965
3947
|
GitClient: () => GitClient,
|
|
3948
|
+
GitHubApiError: () => GitHubApiError,
|
|
3949
|
+
GitHubClient: () => GitHubClient,
|
|
2966
3950
|
checkTemplates: () => checkTemplates,
|
|
2967
3951
|
cleanProjects: () => cleanProjects,
|
|
2968
3952
|
collectEnvInfo: () => collectEnvInfo,
|
|
@@ -2970,6 +3954,7 @@ var commands_exports = /* @__PURE__ */ __exportAll({
|
|
|
2970
3954
|
collectEnvSnapshot: () => collectEnvSnapshot,
|
|
2971
3955
|
collectEnvSupportBundle: () => collectEnvSupportBundle,
|
|
2972
3956
|
createNewProject: () => createNewProject,
|
|
3957
|
+
createReleasePullRequest: () => createReleasePullRequest,
|
|
2973
3958
|
createTimestampFolderName: () => createTimestampFolderName,
|
|
2974
3959
|
defaultAgenticBaseDir: () => defaultAgenticBaseDir,
|
|
2975
3960
|
enterPrerelease: () => enterPrerelease,
|
|
@@ -2989,6 +3974,11 @@ var commands_exports = /* @__PURE__ */ __exportAll({
|
|
|
2989
3974
|
inspectMonorepoConfig: () => inspectMonorepoConfig,
|
|
2990
3975
|
loadAgenticTasks: () => loadAgenticTasks,
|
|
2991
3976
|
normalizeInitToolingTargets: () => normalizeInitToolingTargets,
|
|
3977
|
+
parsePublishSummary: () => parsePublishSummary,
|
|
3978
|
+
prepareStable: () => prepareStable,
|
|
3979
|
+
publishStable: () => publishStable,
|
|
3980
|
+
recoverUnpublished: () => recoverUnpublished,
|
|
3981
|
+
releaseCi: () => releaseCi,
|
|
2992
3982
|
releasePrerelease: () => releasePrerelease,
|
|
2993
3983
|
releaseStable: () => releaseStable,
|
|
2994
3984
|
resolveCreateNewProjectPlan: () => resolveCreateNewProjectPlan,
|
|
@@ -3007,4 +3997,4 @@ var commands_exports = /* @__PURE__ */ __exportAll({
|
|
|
3007
3997
|
verifyStagedTypecheck: () => verifyStagedTypecheck
|
|
3008
3998
|
});
|
|
3009
3999
|
//#endregion
|
|
3010
|
-
export {
|
|
4000
|
+
export { verifyPrePush as $, getTemplateMap as A, setByPath as B, collectEnvPaths as C, createNewProject as D, runDoctor as E, getSkillTargetPaths as F, toWorkspaceGitignorePath as G, isFileChanged as H, skillTargets as I, resolveFullWorkspaceCheckPlan as J, updateIssueTemplateConfig as K, syncSkills as L, templateMap as M, inspectMonorepoConfig as N, defaultTemplate as O, cleanProjects as P, verifyPreCommit as Q, escapeStringRegexp as R, collectEnvInfo as S, collectEnvSupportBundle as T, isGitignoreFile as U, getFileHash as V, toPublishGitignorePath as W, runRecommendedCheck as X, resolveRecommendedCheckPlan as Y, verifyCommitMsg as Z, init as _, recoverUnpublished as a, loadAgenticTasks as at, normalizeInitToolingTargets as b, publishStable as c, exitPrerelease as d, verifyStagedTypecheck as et, releasePrerelease as f, setVscodeBinaryMirror as g, parsePublishSummary as h, createReleasePullRequest as i, generateAgenticTemplates as it, resolveCreateNewProjectPlan as j, getCreateChoices as k, releaseStable as l, GitHubClient as m, upgradeMonorepo as n, defaultAgenticBaseDir as nt, releaseCi as o, GitClient as ot, GitHubApiError as p, getKnownRepoCheckCommands as q, checkTemplates as r, generateAgenticTemplate as rt, prepareStable as s, commands_exports as t, createTimestampFolderName as tt, enterPrerelease as u, initMetadata as v, collectEnvSnapshot as w, createContext as x, initTooling as y, isMatch as z };
|