@icebreakers/monorepo 4.0.5 → 4.0.6

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.
@@ -1,8 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-twds-ZHy.mjs";
2
2
  import { i as getWorkspacePackages, n as getWorkspaceData, r as getWorkspacePackageSummaries } from "./workspace-BVfGk4Av.mjs";
3
- import { _ as isIgnorableFsError, c as devDependencies$1, d as logger, g as fs$1, i as packageDir, l as name$1, n as assetsDir, o as templatesDir, s as dependencies, t as initToolingTargets, u as version$1 } from "./types-l72Q1OXu.mjs";
4
- import { a as loadMonorepoConfig, c as resolveToolingConfig, i as getMonorepoConfigCandidates, o as loadMonorepoConfigDetails, s as resolveCommandConfig } from "./config-itCaAICn.mjs";
5
- import { f as defineTsconfigConfig } from "./tooling-cxnXmQex.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-dLzSmmdf.mjs";
4
+ import { a as loadMonorepoConfig, c as resolveToolingConfig, i as getRepoctlConfigCandidates, o as loadMonorepoConfigDetails, s as resolveCommandConfig } from "./config-BrLDFwAH.mjs";
5
+ import { f as defineTsconfigConfig } from "./tooling-D1Bjw6xy.mjs";
6
6
  import gitUrlParse from "git-url-parse";
7
7
  import { simpleGit } from "simple-git";
8
8
  import { findWorkspaceDir } from "@pnpm/find-workspace-dir";
@@ -736,13 +736,6 @@ async function syncSkills(options = {}) {
736
736
  }
737
737
  //#endregion
738
738
  //#region src/commands/clean.ts
739
- const preferredPackageNames = ["repoctl", "@icebreakers/monorepo"];
740
- function resolvePreferredToolPackageName$1(pkgJson) {
741
- const devDependencies = pkgJson["devDependencies"];
742
- if (!devDependencies || typeof devDependencies !== "object") return "repoctl";
743
- for (const packageName of preferredPackageNames) if (Object.hasOwn(devDependencies, packageName)) return packageName;
744
- return "repoctl";
745
- }
746
739
  function mergeCleanConfig(base, overrides) {
747
740
  const normalizedBase = base ?? {};
748
741
  if (!overrides) return normalizedBase;
@@ -753,7 +746,7 @@ function mergeCleanConfig(base, overrides) {
753
746
  };
754
747
  }
755
748
  /**
756
- * 交互式清理被选中的包目录,同时重写根 package.json 中的 @icebreakers/monorepo 版本。
749
+ * 交互式清理被选中的包目录,同时重写根 package.json 中的 repoctl 版本。
757
750
  */
758
751
  async function cleanProjects(cwd, overrides) {
759
752
  const cleanConfig = mergeCleanConfig(await resolveCommandConfig("clean", cwd), overrides);
@@ -796,7 +789,8 @@ async function cleanProjects(cwd, overrides) {
796
789
  }));
797
790
  const name = path.resolve(workspaceDir, "package.json");
798
791
  const pkgJson = await fs$1.readJson(name);
799
- setByPath(pkgJson, `devDependencies.${resolvePreferredToolPackageName$1(pkgJson).replaceAll(".", "\\.")}`, cleanConfig?.pinnedVersion ?? "latest");
792
+ if (pkgJson.devDependencies && typeof pkgJson.devDependencies === "object") delete pkgJson.devDependencies["@icebreakers/monorepo"];
793
+ setByPath(pkgJson, "devDependencies.repoctl", cleanConfig?.pinnedVersion ?? "latest");
800
794
  await fs$1.outputJson(name, pkgJson, { spaces: 2 });
801
795
  }
802
796
  //#endregion
@@ -814,11 +808,162 @@ async function inspectMonorepoConfig(cwd) {
814
808
  const legacyToolingLoaderImportPattern = /import\s+\{\s*load(?:Repoctl|Monorepo)ToolingModule\s*\}\s+from\s+['"][^'"]*tooling\/load-tooling-module\.mjs['"]\s*;?\n?/g;
815
809
  const legacyToolingLoaderCallPattern = /const\s+\{\s*([\w$]+(?:\s*,\s*[\w$]+)*)\s*\}\s*=\s*await\s+load(?:Repoctl|Monorepo)ToolingModule\(\)\s*;?\n?/g;
816
810
  const legacyToolingEntryPattern = /packages\/(?:monorepo|repoctl)\/dist\/tooling-entry\.mjs/;
811
+ const directToolingPackages = [
812
+ {
813
+ source: "@icebreakers/commitlint-config",
814
+ importName: "defineCommitlintConfig",
815
+ wrapSingleArgument: true
816
+ },
817
+ {
818
+ source: "@icebreakers/eslint-config",
819
+ importName: "defineEslintConfig",
820
+ wrapSingleArgument: false
821
+ },
822
+ {
823
+ source: "@icebreakers/stylelint-config",
824
+ importName: "defineStylelintConfig",
825
+ wrapSingleArgument: true
826
+ }
827
+ ];
817
828
  function normalizeNamedImports(input) {
818
829
  return [...new Set(input.split(",").map((item) => item.trim()).filter(Boolean))].sort((left, right) => left.localeCompare(right));
819
830
  }
820
831
  function hasLegacyToolingReference(content) {
821
- return content.includes("tooling/load-tooling-module.mjs") || content.includes("loadRepoctlToolingModule") || content.includes("loadMonorepoToolingModule") || legacyToolingEntryPattern.test(content);
832
+ return content.includes("tooling/load-tooling-module.mjs") || content.includes("loadRepoctlToolingModule") || content.includes("loadMonorepoToolingModule") || legacyToolingEntryPattern.test(content) || directToolingPackages.some((pkg) => content.includes(pkg.source));
833
+ }
834
+ function escapeRegExp(input) {
835
+ return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
836
+ }
837
+ function findMatchingCloseParen(content, openParenIndex) {
838
+ let depth = 0;
839
+ let quote = null;
840
+ let escaped = false;
841
+ let lineComment = false;
842
+ let blockComment = false;
843
+ for (let index = openParenIndex; index < content.length; index++) {
844
+ const char = content[index];
845
+ const next = content[index + 1];
846
+ if (lineComment) {
847
+ if (char === "\n") lineComment = false;
848
+ continue;
849
+ }
850
+ if (blockComment) {
851
+ if (char === "*" && next === "/") {
852
+ blockComment = false;
853
+ index++;
854
+ }
855
+ continue;
856
+ }
857
+ if (quote) {
858
+ if (escaped) {
859
+ escaped = false;
860
+ continue;
861
+ }
862
+ if (char === "\\") {
863
+ escaped = true;
864
+ continue;
865
+ }
866
+ if (char === quote) quote = null;
867
+ continue;
868
+ }
869
+ if (char === "/" && next === "/") {
870
+ lineComment = true;
871
+ index++;
872
+ continue;
873
+ }
874
+ if (char === "/" && next === "*") {
875
+ blockComment = true;
876
+ index++;
877
+ continue;
878
+ }
879
+ if (char === "'" || char === "\"" || char === "`") {
880
+ quote = char;
881
+ continue;
882
+ }
883
+ if (char === "(") {
884
+ depth++;
885
+ continue;
886
+ }
887
+ if (char === ")") {
888
+ depth--;
889
+ if (depth === 0) return index;
890
+ }
891
+ }
892
+ return -1;
893
+ }
894
+ function hasTopLevelComma(content) {
895
+ if (findMatchingCloseParen(`(${content})`, 0) === -1) return true;
896
+ let depth = 0;
897
+ let quote = null;
898
+ let escaped = false;
899
+ for (let index = 0; index < content.length; index++) {
900
+ const char = content[index];
901
+ if (quote) {
902
+ if (escaped) {
903
+ escaped = false;
904
+ continue;
905
+ }
906
+ if (char === "\\") {
907
+ escaped = true;
908
+ continue;
909
+ }
910
+ if (char === quote) quote = null;
911
+ continue;
912
+ }
913
+ if (char === "'" || char === "\"" || char === "`") {
914
+ quote = char;
915
+ continue;
916
+ }
917
+ if ("([{".includes(char)) {
918
+ depth++;
919
+ continue;
920
+ }
921
+ if (")]}".includes(char)) {
922
+ depth--;
923
+ continue;
924
+ }
925
+ if (char === "," && depth === 0) return true;
926
+ }
927
+ return false;
928
+ }
929
+ function removeSimpleNamedImport(content, source) {
930
+ const pattern = new RegExp(`import\\s+\\{\\s*icebreaker(?:\\s+as\\s+([\\w$]+))?\\s*\\}\\s+from\\s+['"]${escapeRegExp(source)}['"]\\s*;?\\n?`);
931
+ const match = pattern.exec(content);
932
+ if (!match) return null;
933
+ return {
934
+ localName: match[1] ?? "icebreaker",
935
+ content: content.replace(pattern, "")
936
+ };
937
+ }
938
+ function replaceExportDefaultCall(content, localName, importName, wrapSingleArgument) {
939
+ const match = new RegExp(`export\\s+default\\s+(?:await\\s+)?${escapeRegExp(localName)}\\s*\\(`).exec(content);
940
+ if (!match) return null;
941
+ const openParenIndex = match.index + match[0].length - 1;
942
+ const closeParenIndex = findMatchingCloseParen(content, openParenIndex);
943
+ if (closeParenIndex === -1) return null;
944
+ const args = content.slice(openParenIndex + 1, closeParenIndex).trim();
945
+ if (wrapSingleArgument && args && hasTopLevelComma(args)) return null;
946
+ const defineArgs = wrapSingleArgument && args ? `{ options: ${args} }` : args;
947
+ return [
948
+ content.slice(0, match.index),
949
+ `export default await ${importName}(${defineArgs})`,
950
+ content.slice(closeParenIndex + 1)
951
+ ].join("");
952
+ }
953
+ function migrateDirectToolingReferences(content, importSource = "repoctl/tooling") {
954
+ let nextContent = content;
955
+ const importNames = [];
956
+ for (const pkg of directToolingPackages) {
957
+ if (!nextContent.includes(pkg.source)) continue;
958
+ const removed = removeSimpleNamedImport(nextContent, pkg.source);
959
+ if (!removed) continue;
960
+ const replaced = replaceExportDefaultCall(removed.content, removed.localName, pkg.importName, pkg.wrapSingleArgument);
961
+ if (!replaced) continue;
962
+ nextContent = replaced;
963
+ importNames.push(pkg.importName);
964
+ }
965
+ if (importNames.length === 0) return content;
966
+ return `${`import { ${normalizeNamedImports(importNames.join(",")).join(", ")} } from '${importSource}'\n\n`}${nextContent}`.replace(/\n{3,}/g, "\n\n").trimStart();
822
967
  }
823
968
  function migrateLegacyToolingReferences(content, importSource = "repoctl/tooling") {
824
969
  if (!hasLegacyToolingReference(content)) return content;
@@ -827,9 +972,9 @@ function migrateLegacyToolingReferences(content, importSource = "repoctl/tooling
827
972
  importNames.push(...normalizeNamedImports(imports));
828
973
  return "";
829
974
  });
830
- if (importNames.length === 0) return nextContent.replace(legacyToolingLoaderImportPattern, "").replace(/\n{3,}/g, "\n\n");
975
+ if (importNames.length === 0) return migrateDirectToolingReferences(nextContent, importSource).replace(legacyToolingLoaderImportPattern, "").replace(/\n{3,}/g, "\n\n");
831
976
  nextContent = nextContent.replace(legacyToolingLoaderImportPattern, "");
832
- return `${`import { ${normalizeNamedImports(importNames.join(",")).join(", ")} } from '${importSource}'\n`}${nextContent}`.replace(/\n{3,}/g, "\n\n").trimStart();
977
+ return migrateDirectToolingReferences(`${`import { ${normalizeNamedImports(importNames.join(",")).join(", ")} } from '${importSource}'\n`}${nextContent}`, importSource).replace(/\n{3,}/g, "\n\n").trimStart();
833
978
  }
834
979
  //#endregion
835
980
  //#region src/commands/create/plan.ts
@@ -909,7 +1054,7 @@ async function resolveCreateNewProjectPlan(options) {
909
1054
  if (!templateDefinitions[requestedTemplateName]) throw new Error(formatUnknownTemplateError(requestedTemplateName, availableTemplates));
910
1055
  const template = requestedTemplateName;
911
1056
  const templateDefinition = templateDefinitions[template];
912
- if (!templateDefinition) throw new Error(`未找到名为 ${template} 的模板,请检查 repoctl.config.ts 或 monorepo.config.ts`);
1057
+ if (!templateDefinition) throw new Error(`未找到名为 ${template} 的模板,请检查 repoctl.config.ts`);
913
1058
  const sourceDir = path.join(templatesRoot, templateDefinition.source);
914
1059
  const targetName = name && name.length > 0 ? name : templateDefinition.target;
915
1060
  const targetDir = path.join(cwd, targetName);
@@ -1024,7 +1169,7 @@ async function updateWorkspaceManifest(workspaceDir, targetName) {
1024
1169
  * 根据模板生成一个新项目目录,并自动补写 `package.json` 常用字段。
1025
1170
  *
1026
1171
  * 默认行为:
1027
- * - 优先读取 `repoctl.config.ts -> commands.create`,兼容 `monorepo.config.ts`
1172
+ * - 读取 `repoctl.config.ts -> commands.create`
1028
1173
  * - 模板类型默认回退到 `'tsdown'`
1029
1174
  * - 若目标目录已存在则直接抛错
1030
1175
  * - 若模板包含 `package.json`,会自动写入 `name`、`version` 与 Git 仓库信息
@@ -1055,6 +1200,12 @@ async function createNewProject(options) {
1055
1200
  }
1056
1201
  //#endregion
1057
1202
  //#region src/commands/doctor.ts
1203
+ const recommendedRepoScripts = {
1204
+ "repo:init": "repo init",
1205
+ "repo:new": "repo new",
1206
+ "repo:check": "repo check",
1207
+ "repo:doctor": "repo doctor"
1208
+ };
1058
1209
  function createCheck(check) {
1059
1210
  return check;
1060
1211
  }
@@ -1069,28 +1220,23 @@ function summarizeChecks(checks) {
1069
1220
  });
1070
1221
  }
1071
1222
  function resolveToolPackageName(pkgJson) {
1072
- return [
1073
- typeof pkgJson.devDependencies?.["repoctl"] === "string" ? {
1074
- name: "repoctl",
1075
- version: pkgJson.devDependencies["repoctl"]
1076
- } : null,
1077
- typeof pkgJson.devDependencies?.["@icebreakers/monorepo"] === "string" ? {
1078
- name: "@icebreakers/monorepo",
1079
- version: pkgJson.devDependencies["@icebreakers/monorepo"]
1080
- } : null,
1081
- typeof pkgJson.dependencies?.["repoctl"] === "string" ? {
1082
- name: "repoctl",
1083
- version: pkgJson.dependencies["repoctl"]
1084
- } : null,
1085
- typeof pkgJson.dependencies?.["@icebreakers/monorepo"] === "string" ? {
1086
- name: "@icebreakers/monorepo",
1087
- version: pkgJson.dependencies["@icebreakers/monorepo"]
1088
- } : null
1089
- ].find((value) => value !== null) ?? null;
1223
+ return [typeof pkgJson.devDependencies?.["repoctl"] === "string" ? {
1224
+ name: "repoctl",
1225
+ version: pkgJson.devDependencies["repoctl"]
1226
+ } : null, typeof pkgJson.dependencies?.["repoctl"] === "string" ? {
1227
+ name: "repoctl",
1228
+ version: pkgJson.dependencies["repoctl"]
1229
+ } : null].find((value) => value !== null) ?? null;
1090
1230
  }
1091
1231
  function hasScript(pkgJson, name) {
1092
1232
  return typeof pkgJson.scripts?.[name] === "string" && pkgJson.scripts[name].length > 0;
1093
1233
  }
1234
+ function getMissingScripts(pkgJson, expected) {
1235
+ return Object.keys(expected).filter((scriptName) => !hasScript(pkgJson, scriptName));
1236
+ }
1237
+ function getUnexpectedScripts(pkgJson, expected) {
1238
+ return Object.entries(expected).filter(([scriptName, expectedCommand]) => hasScript(pkgJson, scriptName) && pkgJson.scripts?.[scriptName] !== expectedCommand).map(([scriptName]) => scriptName);
1239
+ }
1094
1240
  function getWorkspacePatterns(manifest) {
1095
1241
  if (typeof manifest !== "object" || manifest === null) return [];
1096
1242
  const packages = manifest.packages;
@@ -1134,14 +1280,14 @@ async function runDoctor(cwd) {
1134
1280
  const packageJsonPath = `${workspaceDir}/package.json`;
1135
1281
  const workspaceManifestPath = `${workspaceDir}/pnpm-workspace.yaml`;
1136
1282
  const repoctlConfigPath = `${workspaceDir}/repoctl.config.ts`;
1137
- const monorepoConfigPath = `${workspaceDir}/monorepo.config.ts`;
1283
+ const legacyMonorepoConfigPath = `${workspaceDir}/monorepo.config.ts`;
1138
1284
  const huskyPreCommitPath = `${workspaceDir}/.husky/pre-commit`;
1139
1285
  const lintStagedConfigPath = `${workspaceDir}/lint-staged.config.js`;
1140
- const [hasPackageJson, hasWorkspaceManifest, hasRepoctlConfig, hasMonorepoConfig, hasHuskyPreCommit, hasLintStagedConfig] = await Promise.all([
1286
+ const [hasPackageJson, hasWorkspaceManifest, hasRepoctlConfig, hasLegacyMonorepoConfig, hasHuskyPreCommit, hasLintStagedConfig] = await Promise.all([
1141
1287
  fs$1.pathExists(packageJsonPath),
1142
1288
  fs$1.pathExists(workspaceManifestPath),
1143
1289
  fs$1.pathExists(repoctlConfigPath),
1144
- fs$1.pathExists(monorepoConfigPath),
1290
+ fs$1.pathExists(legacyMonorepoConfigPath),
1145
1291
  fs$1.pathExists(huskyPreCommitPath),
1146
1292
  fs$1.pathExists(lintStagedConfigPath)
1147
1293
  ]);
@@ -1171,7 +1317,7 @@ async function runDoctor(cwd) {
1171
1317
  title: "pnpm workspace",
1172
1318
  status: "fail",
1173
1319
  detail: "缺少 pnpm-workspace.yaml,当前目录不像一个完整的 pnpm monorepo 根目录。",
1174
- fix: "运行 repo setup --yes 补充 pnpm-workspace.yaml,或确认你当前就在仓库根目录。"
1320
+ fix: "运行 repo init --yes 补充 pnpm-workspace.yaml,或确认你当前就在仓库根目录。"
1175
1321
  })];
1176
1322
  const nodeRange = pkgJson.engines?.node;
1177
1323
  if (typeof nodeRange === "string" && nodeRange.length > 0) checks.push(satisfies(process.version, nodeRange) ? createCheck({
@@ -1203,46 +1349,39 @@ async function runDoctor(cwd) {
1203
1349
  id: "tool-package",
1204
1350
  title: "repo CLI 依赖",
1205
1351
  status: "fail",
1206
- detail: "根 package.json 中未发现 repoctl 或 @icebreakers/monorepo 依赖。",
1207
- fix: "运行 repo setup --yes 添加 repoctl devDependency,或手动执行 pnpm add -D repoctl。"
1352
+ detail: "根 package.json 中未发现 repoctl 依赖。",
1353
+ fix: "运行 repo init --yes 添加 repoctl devDependency,或手动执行 pnpm add -D repoctl。"
1208
1354
  }));
1209
- const hasSetup = hasScript(pkgJson, "setup");
1210
- const hasNew = hasScript(pkgJson, "new");
1211
- const hasCheck = hasScript(pkgJson, "check");
1212
- const hasDoctor = hasScript(pkgJson, "doctor");
1213
- if (hasSetup && hasNew && hasCheck && hasDoctor) checks.push(createCheck({
1355
+ const missingRepoScripts = getMissingScripts(pkgJson, recommendedRepoScripts);
1356
+ const unexpectedRepoScripts = getUnexpectedScripts(pkgJson, recommendedRepoScripts);
1357
+ if (missingRepoScripts.length === 0 && unexpectedRepoScripts.length === 0) checks.push(createCheck({
1214
1358
  id: "root-scripts",
1215
- title: "根快捷脚本",
1359
+ title: "repo:* 根脚本",
1216
1360
  status: "pass",
1217
- detail: "已检测到 setup / new / check / doctor 根脚本,可以直接使用 pnpm setup / pnpm new / pnpm check / pnpm doctor。"
1361
+ detail: "已检测到 repo:init / repo:new / repo:check / repo:doctor,推荐使用 pnpm run repo:doctor -- --json 这类无冲突入口。"
1218
1362
  }));
1219
1363
  else {
1220
- const missing = [
1221
- !hasSetup ? "setup" : null,
1222
- !hasNew ? "new" : null,
1223
- !hasCheck ? "check" : null,
1224
- !hasDoctor ? "doctor" : null
1225
- ].filter(Boolean).join(", ");
1364
+ const details = [missingRepoScripts.length ? `缺少:${missingRepoScripts.join(", ")}` : null, unexpectedRepoScripts.length ? `命令不一致:${unexpectedRepoScripts.join(", ")}` : null].filter(Boolean).join(";");
1226
1365
  checks.push(createCheck({
1227
1366
  id: "root-scripts",
1228
- title: "根快捷脚本",
1367
+ title: "repo:* 根脚本",
1229
1368
  status: "warn",
1230
- detail: `缺少推荐的根脚本:${missing}。`,
1231
- fix: "运行 repo setup --yes 同步推荐根脚本,或手动在 package.json 中补齐 setup / new / check / doctor。"
1369
+ detail: `推荐的 repo:* 根脚本未完全就绪。${details}。`,
1370
+ fix: "运行 repo init --yes 同步推荐根脚本,或手动在 package.json 中补齐 repo:init / repo:new / repo:check / repo:doctor。"
1232
1371
  }));
1233
1372
  }
1234
- if (hasRepoctlConfig && hasMonorepoConfig) checks.push(createCheck({
1373
+ if (hasLegacyMonorepoConfig) checks.push(createCheck({
1235
1374
  id: "config-file",
1236
1375
  title: "配置文件",
1237
1376
  status: "fail",
1238
- detail: "同时存在 repoctl.config.ts 和 monorepo.config.ts,CLI 会拒绝加载。",
1239
- fix: "保留一个配置文件即可,推荐只保留 repoctl.config.ts。"
1377
+ detail: "检测到已废弃的 monorepo.config.ts,repoctl 不再加载该文件。",
1378
+ fix: "将 monorepo.config.ts 改名为 repoctl.config.ts,并确认根配置只保留 repoctl.config.ts。"
1240
1379
  }));
1241
- else if (hasRepoctlConfig || hasMonorepoConfig) checks.push(createCheck({
1380
+ else if (hasRepoctlConfig) checks.push(createCheck({
1242
1381
  id: "config-file",
1243
1382
  title: "配置文件",
1244
1383
  status: "pass",
1245
- detail: `已检测到配置文件:${hasRepoctlConfig ? "repoctl.config.ts" : "monorepo.config.ts"}`
1384
+ detail: "已检测到配置文件:repoctl.config.ts"
1246
1385
  }));
1247
1386
  else checks.push(createCheck({
1248
1387
  id: "config-file",
@@ -1301,14 +1440,14 @@ async function runDoctor(cwd) {
1301
1440
  id: "tooling-imports",
1302
1441
  title: "tooling imports",
1303
1442
  status: "pass",
1304
- detail: "tooling 配置未引用本地源码仓库 loader。"
1443
+ detail: "tooling 配置未引用本地源码仓库 loader 或旧 @icebreakers/*-config wrapper。"
1305
1444
  }));
1306
1445
  else checks.push(createCheck({
1307
1446
  id: "tooling-imports",
1308
1447
  title: "tooling imports",
1309
1448
  status: "warn",
1310
- detail: `以下配置引用了本地源码仓库 tooling loader:${legacyToolingFiles.join(", ")}。`,
1311
- fix: "运行 repo upgrade --yes 迁移为直接 import repoctl/tooling。"
1449
+ detail: `以下配置引用了旧 tooling 入口:${legacyToolingFiles.join(", ")}。`,
1450
+ fix: "运行 repo upgrade --yes 迁移为直接 import repoctl/tooling,并保留现有配置语义。"
1312
1451
  }));
1313
1452
  const missingCommonPatterns = (await Promise.all([
1314
1453
  "apps",
@@ -1329,7 +1468,7 @@ async function runDoctor(cwd) {
1329
1468
  title: "workspace patterns",
1330
1469
  status: "warn",
1331
1470
  detail: `pnpm-workspace.yaml 缺少常见目录:${missingCommonPatterns.join(", ")}。`,
1332
- fix: "运行 repo setup --yes 追加缺失 workspace patterns。"
1471
+ fix: "运行 repo init --yes 追加缺失 workspace patterns。"
1333
1472
  }));
1334
1473
  const uncoveredWorkspacePackages = workspacePackageDirs.filter((dir) => !isWorkspacePatternCovered(dir, workspacePatterns));
1335
1474
  if (hasWorkspaceManifest && uncoveredWorkspacePackages.length === 0) checks.push(createCheck({
@@ -1343,7 +1482,7 @@ async function runDoctor(cwd) {
1343
1482
  title: "workspace package coverage",
1344
1483
  status: "warn",
1345
1484
  detail: `以下 package.json 未被 pnpm-workspace.yaml 覆盖:${uncoveredWorkspacePackages.join(", ")}。`,
1346
- fix: "运行 repo setup --yes 追加缺失 workspace patterns。"
1485
+ fix: "运行 repo init --yes 追加缺失 workspace patterns。"
1347
1486
  }));
1348
1487
  return {
1349
1488
  cwd,
@@ -1395,12 +1534,11 @@ async function collectEnvInfo(cwd) {
1395
1534
  }
1396
1535
  async function collectEnvPaths(cwd) {
1397
1536
  const workspaceDir = await findWorkspaceDir(cwd) ?? cwd;
1398
- const configCandidates = getMonorepoConfigCandidates(workspaceDir);
1537
+ const configCandidates = getRepoctlConfigCandidates(workspaceDir);
1399
1538
  const paths = {
1400
1539
  packageJson: path.join(workspaceDir, "package.json"),
1401
1540
  workspaceManifest: path.join(workspaceDir, "pnpm-workspace.yaml"),
1402
1541
  repoctlConfig: path.join(workspaceDir, "repoctl.config.ts"),
1403
- legacyConfig: path.join(workspaceDir, "monorepo.config.ts"),
1404
1542
  toolingDir: path.join(workspaceDir, "tooling"),
1405
1543
  reportsDir: path.join(workspaceDir, "reports"),
1406
1544
  doctorReport: path.join(workspaceDir, "reports/doctor.json"),
@@ -1415,9 +1553,7 @@ async function collectEnvPaths(cwd) {
1415
1553
  packageJson: await createEnvPathEntry(workspaceDir, paths.packageJson),
1416
1554
  workspaceManifest: await createEnvPathEntry(workspaceDir, paths.workspaceManifest),
1417
1555
  repoctlConfig: await createEnvPathEntry(workspaceDir, paths.repoctlConfig),
1418
- repoctlConfigs: await Promise.all(configCandidates.repoctl.map((file) => createEnvPathEntry(workspaceDir, file))),
1419
- legacyConfig: await createEnvPathEntry(workspaceDir, paths.legacyConfig),
1420
- legacyConfigs: await Promise.all(configCandidates.monorepo.map((file) => createEnvPathEntry(workspaceDir, file))),
1556
+ repoctlConfigs: await Promise.all(configCandidates.map((file) => createEnvPathEntry(workspaceDir, file))),
1421
1557
  toolingDir: await createEnvPathEntry(workspaceDir, paths.toolingDir),
1422
1558
  reportsDir: await createEnvPathEntry(workspaceDir, paths.reportsDir),
1423
1559
  doctorReport: await createEnvPathEntry(workspaceDir, paths.doctorReport),
@@ -1582,10 +1718,7 @@ var devDependencies = {
1582
1718
  "@changesets/cli": "^2.31.0",
1583
1719
  "@commitlint/cli": "^20.5.3",
1584
1720
  "@icebreakers/changelog-github": "^1.0.2",
1585
- "@icebreakers/commitlint-config": "^2.0.0",
1586
- "@icebreakers/eslint-config": "^4.0.10",
1587
1721
  "@icebreakers/monorepo": "workspace:*",
1588
- "@icebreakers/stylelint-config": "^3.0.6",
1589
1722
  "@types/node": "^25.6.0",
1590
1723
  "@types/semver": "^7.7.1",
1591
1724
  "@vitest/coverage-v8": "~4.1.5",
@@ -1603,7 +1736,7 @@ var devDependencies = {
1603
1736
  "stylelint": "^17.11.0",
1604
1737
  "tailwindcss": "^4.2.4",
1605
1738
  "tsd": "^0.33.0",
1606
- "tsdown": "0.21.10",
1739
+ "tsdown": "0.22.0",
1607
1740
  "tslib": "^2.8.1",
1608
1741
  "tsx": "^4.21.0",
1609
1742
  "turbo": "^2.9.9",
@@ -1650,24 +1783,17 @@ const packageDependencies = {
1650
1783
  "commit": "commit",
1651
1784
  "commitlint": "commitlint --edit",
1652
1785
  "-------": "---------------",
1653
- "setup": "repo setup",
1654
- "new": "repo new",
1655
- "check": "repo check",
1656
- "doctor": "repo doctor",
1657
- "sync": "repo sync",
1658
- "clean:repo": "repo clean",
1659
- "mirror": "repo mirror",
1786
+ "repo:init": "repo init",
1787
+ "repo:new": "repo new",
1788
+ "repo:check": "repo check",
1789
+ "repo:doctor": "repo doctor",
1660
1790
  "------simple": "--------------",
1661
1791
  "pr:alpha": "repo release pre enter alpha",
1662
1792
  "pr:beta": "repo release pre enter beta",
1663
1793
  "pr:rc": "repo release pre enter rc",
1664
1794
  "pr:next": "repo release pre enter next",
1665
1795
  "pr:exit": "repo release pre exit",
1666
- "--------": "----------------",
1667
- "script:init": "repo init",
1668
- "script:sync": "repo sync",
1669
- "script:clean": "repo clean",
1670
- "script:mirror": "repo mirror"
1796
+ "--------": "----------------"
1671
1797
  },
1672
1798
  devDependencies,
1673
1799
  publishConfig: {
@@ -1698,20 +1824,11 @@ function createConfigModule(functionName, source) {
1698
1824
  function getToolingPackageDependency(toolingPackageName) {
1699
1825
  return { [toolingPackageName]: getToolingPackageVersion() };
1700
1826
  }
1701
- function getRootDeps(pkgJson) {
1702
- return {
1703
- ...pkgJson.dependencies ?? {},
1704
- ...pkgJson.devDependencies ?? {}
1705
- };
1706
- }
1707
- function resolveToolingPackageName(pkgJson) {
1708
- const deps = getRootDeps(pkgJson);
1709
- if (typeof deps["repoctl"] === "string" && deps["repoctl"].length > 0) return "repoctl";
1710
- if (typeof deps["@icebreakers/monorepo"] === "string" && deps["@icebreakers/monorepo"].length > 0) return "@icebreakers/monorepo";
1827
+ function resolveToolingPackageName() {
1711
1828
  return "repoctl";
1712
1829
  }
1713
- function resolveToolingImportSource(toolingPackageName) {
1714
- return toolingPackageName === "repoctl" ? "repoctl/tooling" : "@icebreakers/monorepo/tooling";
1830
+ function resolveToolingImportSource() {
1831
+ return "repoctl/tooling";
1715
1832
  }
1716
1833
  const initToolingPresets = {
1717
1834
  "commitlint": {
@@ -1720,8 +1837,7 @@ const initToolingPresets = {
1720
1837
  getContent: ({ toolingImportSource }) => createConfigModule("defineCommitlintConfig", toolingImportSource),
1721
1838
  getDependencies: ({ toolingPackageName }) => ({
1722
1839
  ...getToolingPackageDependency(toolingPackageName),
1723
- "@commitlint/cli": getDependencyVersion("@commitlint/cli"),
1724
- "@icebreakers/commitlint-config": getDependencyVersion("@icebreakers/commitlint-config")
1840
+ "@commitlint/cli": getDependencyVersion("@commitlint/cli")
1725
1841
  })
1726
1842
  },
1727
1843
  "eslint": {
@@ -1730,8 +1846,7 @@ const initToolingPresets = {
1730
1846
  getContent: ({ toolingImportSource }) => createConfigModule("defineEslintConfig", toolingImportSource),
1731
1847
  getDependencies: ({ toolingPackageName }) => ({
1732
1848
  ...getToolingPackageDependency(toolingPackageName),
1733
- "@icebreakers/eslint-config": getDependencyVersion("@icebreakers/eslint-config"),
1734
- "eslint": getDependencyVersion("eslint")
1849
+ eslint: getDependencyVersion("eslint")
1735
1850
  })
1736
1851
  },
1737
1852
  "stylelint": {
@@ -1740,8 +1855,7 @@ const initToolingPresets = {
1740
1855
  getContent: ({ toolingImportSource }) => createConfigModule("defineStylelintConfig", toolingImportSource),
1741
1856
  getDependencies: ({ toolingPackageName }) => ({
1742
1857
  ...getToolingPackageDependency(toolingPackageName),
1743
- "@icebreakers/stylelint-config": getDependencyVersion("@icebreakers/stylelint-config"),
1744
- "stylelint": getDependencyVersion("stylelint")
1858
+ stylelint: getDependencyVersion("stylelint")
1745
1859
  })
1746
1860
  },
1747
1861
  "lint-staged": {
@@ -1796,6 +1910,10 @@ function mergeDevDependencies(pkgJson, additions) {
1796
1910
  current[name] = version;
1797
1911
  changed = true;
1798
1912
  }
1913
+ if ("repoctl" in current && "@icebreakers/monorepo" in current) {
1914
+ delete current["@icebreakers/monorepo"];
1915
+ changed = true;
1916
+ }
1799
1917
  if (!changed && pkgJson.devDependencies) return false;
1800
1918
  pkgJson.devDependencies = sortRecord(current);
1801
1919
  return true;
@@ -1823,8 +1941,8 @@ async function initTooling(cwd, options = {}) {
1823
1941
  const pkgJsonPath = path.resolve(cwd, "package.json");
1824
1942
  if (!await fs$1.pathExists(pkgJsonPath)) throw new Error(`未找到 package.json,无法初始化 tooling: ${pkgJsonPath}`);
1825
1943
  const packageJson = await fs$1.readJson(pkgJsonPath);
1826
- const toolingPackageName = resolveToolingPackageName(packageJson);
1827
- const toolingImportSource = resolveToolingImportSource(toolingPackageName);
1944
+ const toolingPackageName = resolveToolingPackageName();
1945
+ const toolingImportSource = resolveToolingImportSource();
1828
1946
  const additions = {};
1829
1947
  const writtenFiles = [];
1830
1948
  const skippedFiles = [];
@@ -2012,6 +2130,7 @@ const prereleaseBranches = new Set([
2012
2130
  "next"
2013
2131
  ]);
2014
2132
  var ReleaseCommandError = class extends Error {
2133
+ exitCode;
2015
2134
  constructor(message, exitCode = 1) {
2016
2135
  super(message);
2017
2136
  this.exitCode = exitCode;
@@ -2455,23 +2574,16 @@ async function flushPendingOverwrites(pending, options = {}) {
2455
2574
  for (const item of pending) if (selectedSet.has(item.targetPath)) await item.action();
2456
2575
  }
2457
2576
  const scriptsEntries = Object.entries({
2458
- "setup": "repo setup",
2459
- "new": "repo new",
2460
- "check": "repo check",
2461
- "doctor": "repo doctor",
2462
- "sync": "repo sync",
2463
- "clean:repo": "repo clean",
2464
- "mirror": "repo mirror",
2465
- "script:init": "repo init",
2466
- "script:sync": "repo sync",
2467
- "script:clean": "repo clean",
2468
- "script:mirror": "repo mirror",
2577
+ "repo:init": "repo init",
2578
+ "repo:new": "repo new",
2579
+ "repo:check": "repo check",
2580
+ "repo:doctor": "repo doctor",
2469
2581
  "commitlint": "commitlint --edit"
2470
2582
  });
2471
2583
  //#endregion
2472
2584
  //#region src/commands/upgrade/pkg-json.ts
2473
2585
  const NON_OVERRIDABLE_PREFIXES = ["workspace:", "catalog:"];
2474
- const toolPackageNames = ["repoctl", name$1];
2586
+ const legacyToolPackageName = "@icebreakers/monorepo";
2475
2587
  function parseVersion(input) {
2476
2588
  if (typeof input !== "string" || input.trim().length === 0) return null;
2477
2589
  try {
@@ -2492,15 +2604,10 @@ function shouldAssignVersion(currentVersion, nextVersion) {
2492
2604
  if (!current || !next) return true;
2493
2605
  return !gte(current, next);
2494
2606
  }
2495
- function resolvePreferredToolPackageName(sourceDevDeps, targetDevDeps) {
2496
- for (const depName of toolPackageNames) if (typeof targetDevDeps[depName] === "string" && targetDevDeps[depName].length > 0) return depName;
2497
- for (const depName of toolPackageNames) if (typeof sourceDevDeps[depName] === "string" && sourceDevDeps[depName].length > 0) return depName;
2498
- return "repoctl";
2499
- }
2500
2607
  /**
2501
2608
  * 将内置 package.json 内容合并进目标工程:
2502
2609
  * - 同步依赖(保留 workspace: 前缀的版本)
2503
- * - 确保 @icebreakers/monorepo 使用最新版本
2610
+ * - 确保 repoctl 使用最新版本
2504
2611
  * - 写入预置脚本
2505
2612
  */
2506
2613
  function setPkgJson(sourcePkgJson, targetPkgJson, options) {
@@ -2509,7 +2616,7 @@ function setPkgJson(sourcePkgJson, targetPkgJson, options) {
2509
2616
  const sourceDevDeps = sourcePkgJson.devDependencies ?? {};
2510
2617
  const targetDeps = { ...targetPkgJson.dependencies ?? {} };
2511
2618
  const targetDevDeps = { ...targetPkgJson.devDependencies ?? {} };
2512
- const preferredToolPackageName = resolvePreferredToolPackageName(sourceDevDeps, targetDevDeps);
2619
+ const shouldEnsureRepoctl = Boolean(sourceDevDeps["repoctl"] || sourceDevDeps[legacyToolPackageName] || targetDevDeps["repoctl"] || targetDevDeps[legacyToolPackageName]);
2513
2620
  if (packageManager && !targetPkgJson.packageManager) targetPkgJson.packageManager = packageManager;
2514
2621
  for (const [depName, depVersion] of Object.entries(sourceDeps)) {
2515
2622
  if (typeof depVersion !== "string") continue;
@@ -2520,18 +2627,24 @@ function setPkgJson(sourcePkgJson, targetPkgJson, options) {
2520
2627
  if (Object.keys(targetDeps).length) targetPkgJson.dependencies = targetDeps;
2521
2628
  for (const [depName, depVersion] of Object.entries(sourceDevDeps)) {
2522
2629
  if (typeof depVersion !== "string") continue;
2523
- if (toolPackageNames.includes(depName)) {
2524
- if (depName !== preferredToolPackageName) continue;
2630
+ if (depName === "repoctl") {
2525
2631
  const nextVersion = `^${version$1}`;
2526
2632
  const targetVersion = targetDevDeps[depName];
2527
2633
  if (!hasNonOverridablePrefix(targetVersion) && shouldAssignVersion(targetVersion, nextVersion)) targetDevDeps[depName] = nextVersion;
2528
- } else {
2634
+ } else if (depName === legacyToolPackageName) delete targetDevDeps[legacyToolPackageName];
2635
+ else {
2529
2636
  const targetVersion = targetDevDeps[depName];
2530
2637
  if (hasNonOverridablePrefix(targetVersion)) continue;
2531
2638
  if (shouldAssignVersion(targetVersion, depVersion)) targetDevDeps[depName] = depVersion;
2532
2639
  }
2533
2640
  }
2534
- for (const depName of toolPackageNames) if (depName !== preferredToolPackageName && depName in targetDevDeps && preferredToolPackageName in targetDevDeps) delete targetDevDeps[depName];
2641
+ if (legacyToolPackageName in targetDevDeps && "repoctl" in targetDevDeps) delete targetDevDeps[legacyToolPackageName];
2642
+ if (shouldEnsureRepoctl) {
2643
+ const nextVersion = `^${version$1}`;
2644
+ const targetVersion = targetDevDeps["repoctl"];
2645
+ if (!hasNonOverridablePrefix(targetVersion) && shouldAssignVersion(targetVersion, nextVersion)) targetDevDeps["repoctl"] = nextVersion;
2646
+ delete targetDevDeps[legacyToolPackageName];
2647
+ }
2535
2648
  if (Object.keys(targetDevDeps).length) targetPkgJson.devDependencies = targetDevDeps;
2536
2649
  const scriptPairs = options?.scripts ? Object.entries(options.scripts) : scriptsEntries;
2537
2650
  if (scriptPairs.length) {
@@ -2807,7 +2920,11 @@ async function upgradeMonorepo(opts) {
2807
2920
  continue;
2808
2921
  }
2809
2922
  let source = await fs$1.readFile(file.path);
2810
- if (/\.(?:js|mjs|ts|mts|cjs|cts)$/.test(relPath)) source = Buffer.from(migrateLegacyToolingReferences(source.toString("utf8"), "repoctl/tooling"));
2923
+ if (/\.(?:js|mjs|ts|mts|cjs|cts)$/.test(relPath)) {
2924
+ const textSource = await fs$1.pathExists(targetPath) ? await fs$1.readFile(targetPath, "utf8") : source.toString("utf8");
2925
+ const migrated = migrateLegacyToolingReferences(textSource, "repoctl/tooling");
2926
+ source = Buffer.from(migrated === textSource ? migrateLegacyToolingReferences(source.toString("utf8"), "repoctl/tooling") : migrated);
2927
+ }
2811
2928
  const intent = await evaluateWriteIntent(targetPath, buildWriteIntentOptions(source));
2812
2929
  const action = async () => {
2813
2930
  await fs$1.outputFile(targetPath, source);