@icebreakers/monorepo 3.2.18 → 4.0.1

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/index.mjs CHANGED
@@ -1,2 +1,6 @@
1
- import { $ as getWorkspaceData, A as toPublishGitignorePath, B as ensureDir, C as resolveCommandConfig, D as getFileHash, E as setByPath, F as generateAgenticTemplate, G as outputJSON, H as exists, I as generateAgenticTemplates, J as readJSON, K as outputJson, L as loadAgenticTasks, M as updateIssueTemplateConfig, N as createTimestampFolderName, O as isFileChanged, P as defaultAgenticBaseDir, Q as writeJson, R as logger, S as loadMonorepoConfig, T as isMatch, U as isIgnorableFsError, V as ensureFile, W as outputFile, X as remove, Y as readJson, Z as writeJSON, _ as rootDir, a as createContext, b as version, c as getCreateChoices, d as cleanProjects, et as getWorkspacePackages, f as getSkillTargetPaths, g as packageDir, h as assetsDir, i as init, j as toWorkspaceGitignorePath, k as isGitignoreFile, l as getTemplateMap, m as syncSkills, n as syncNpmMirror, o as createNewProject, p as skillTargets, q as pathExists, r as setVscodeBinaryMirror, t as upgradeMonorepo, tt as GitClient, u as templateMap, v as templatesDir, w as escapeStringRegexp, x as defineMonorepoConfig, y as name, z as copy } from "./upgrade-tD-PPMpL.mjs";
2
- export { GitClient, assetsDir, cleanProjects, copy, createContext, createNewProject, createTimestampFolderName, defaultAgenticBaseDir, defineMonorepoConfig, ensureDir, ensureFile, escapeStringRegexp, exists, generateAgenticTemplate, generateAgenticTemplates, getCreateChoices, getFileHash, getSkillTargetPaths, getTemplateMap, getWorkspaceData, getWorkspacePackages, init, isFileChanged, isGitignoreFile, isIgnorableFsError, isMatch, loadAgenticTasks, loadMonorepoConfig, logger, name, outputFile, outputJSON, outputJson, packageDir, pathExists, readJSON, readJson, remove, resolveCommandConfig, rootDir, setByPath, setVscodeBinaryMirror, skillTargets, syncNpmMirror, syncSkills, templateMap, templatesDir, toPublishGitignorePath, toWorkspaceGitignorePath, updateIssueTemplateConfig, upgradeMonorepo, version, writeJSON, writeJson };
1
+ import { A as isFileChanged, B as verifyPreCommit, C as getSkillTargetPaths, D as isMatch, E as escapeStringRegexp, F as getKnownRepoCheckCommands, G as generateAgenticTemplate, H as verifyStagedTypecheck, I as resolveFullWorkspaceCheckPlan, J as GitClient, K as generateAgenticTemplates, L as resolveRecommendedCheckPlan, M as toPublishGitignorePath, N as toWorkspaceGitignorePath, O as setByPath, P as updateIssueTemplateConfig, R as runRecommendedCheck, S as cleanProjects, T as syncSkills, U as createTimestampFolderName, V as verifyPrePush, W as defaultAgenticBaseDir, _ as getCreateChoices, a as init, b as templateMap, c as normalizeInitToolingTargets, d as collectEnvPaths, f as collectEnvSnapshot, h as createNewProject, i as setVscodeBinaryMirror, j as isGitignoreFile, k as getFileHash, l as createContext, m as runDoctor, n as upgradeMonorepo, o as initMetadata, p as collectEnvSupportBundle, q as loadAgenticTasks, r as checkTemplates, s as initTooling, u as collectEnvInfo, v as getTemplateMap, w as skillTargets, x as inspectMonorepoConfig, y as resolveCreateNewProjectPlan, z as verifyCommitMsg } from "./commands-ikcXv_mG.mjs";
2
+ import { i as getWorkspacePackages, n as getWorkspaceData, r as getWorkspacePackageSummaries, t as clearWorkspaceCache } from "./workspace-DS6LAL71.mjs";
3
+ import { C as readJson, E as writeJson, S as readJSON, T as writeJSON, _ as isIgnorableFsError, a as rootDir, b as outputJson, d as logger, f as copy, h as exists, i as packageDir, l as name, m as ensureFile, n as assetsDir, o as templatesDir, p as ensureDir, r as cliName, t as initToolingTargets, u as version, v as outputFile, w as remove, x as pathExists, y as outputJSON } from "./types-CveZChKu.mjs";
4
+ import { a as loadMonorepoConfig, c as resolveToolingConfig, i as getMonorepoConfigCandidates, o as loadMonorepoConfigDetails, r as defineMonorepoConfig, s as resolveCommandConfig, t as configExtensions } from "./config-BGCo7USv.mjs";
5
+ import { a as createMonorepoTsconfig, c as defineCommitlintConfig, d as defineStylelintConfig, f as defineTsconfigConfig, h as loadMonorepoToolingConfig, i as createMonorepoStylelintConfig, l as defineEslintConfig, m as defineVitestProjectConfig, n as createMonorepoEslintConfig, o as createMonorepoVitestConfig, p as defineVitestConfig, r as createMonorepoLintStagedConfig, s as createMonorepoVitestProjectConfig, t as createMonorepoCommitlintConfig, u as defineLintStagedConfig } from "./tooling-DyUe-eiv.mjs";
6
+ export { GitClient, assetsDir, checkTemplates, cleanProjects, clearWorkspaceCache, cliName, collectEnvInfo, collectEnvPaths, collectEnvSnapshot, collectEnvSupportBundle, configExtensions, copy, createContext, createMonorepoCommitlintConfig, createMonorepoEslintConfig, createMonorepoLintStagedConfig, createMonorepoStylelintConfig, createMonorepoTsconfig, createMonorepoVitestConfig, createMonorepoVitestProjectConfig, createNewProject, createTimestampFolderName, defaultAgenticBaseDir, defineCommitlintConfig, defineEslintConfig, defineLintStagedConfig, defineMonorepoConfig, defineStylelintConfig, defineTsconfigConfig, defineVitestConfig, defineVitestProjectConfig, ensureDir, ensureFile, escapeStringRegexp, exists, generateAgenticTemplate, generateAgenticTemplates, getCreateChoices, getFileHash, getKnownRepoCheckCommands, getMonorepoConfigCandidates, getSkillTargetPaths, getTemplateMap, getWorkspaceData, getWorkspacePackageSummaries, getWorkspacePackages, init, initMetadata, initTooling, initToolingTargets, inspectMonorepoConfig, isFileChanged, isGitignoreFile, isIgnorableFsError, isMatch, loadAgenticTasks, loadMonorepoConfig, loadMonorepoConfigDetails, loadMonorepoToolingConfig, logger, normalizeInitToolingTargets, outputFile, outputJSON, outputJson, packageDir, name as packageName, pathExists, readJSON, readJson, remove, resolveCommandConfig, resolveCreateNewProjectPlan, resolveFullWorkspaceCheckPlan, resolveRecommendedCheckPlan, resolveToolingConfig, rootDir, runDoctor, runRecommendedCheck, setByPath, setVscodeBinaryMirror, skillTargets, syncSkills, templateMap, templatesDir, toPublishGitignorePath, toWorkspaceGitignorePath, updateIssueTemplateConfig, upgradeMonorepo, verifyCommitMsg, verifyPreCommit, verifyPrePush, verifyStagedTypecheck, version, writeJSON, writeJson };
@@ -0,0 +1,14 @@
1
+ import "node:module";
2
+ //#region \0rolldown/runtime.js
3
+ var __defProp = Object.defineProperty;
4
+ var __exportAll = (all, no_symbols) => {
5
+ let target = {};
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
+ return target;
12
+ };
13
+ //#endregion
14
+ export { __exportAll as t };
@@ -0,0 +1,427 @@
1
+ import { a as loadMonorepoConfig } from "./config-BGCo7USv.mjs";
2
+ import process from "node:process";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import YAML from "yaml";
6
+ import { fileURLToPath } from "node:url";
7
+ import { icebreaker } from "@icebreakers/commitlint-config";
8
+ import { icebreaker as icebreaker$1 } from "@icebreakers/eslint-config";
9
+ import { icebreaker as icebreaker$2 } from "@icebreakers/stylelint-config";
10
+ import { parse } from "comment-json";
11
+ import { mergeConfig } from "vitest/config";
12
+ //#region src/tooling/index.ts
13
+ const defaultProjectRoots = ["packages", "apps"];
14
+ const defaultConfigCandidates = [
15
+ "vitest.config.ts",
16
+ "vitest.config.mts",
17
+ "vitest.config.js",
18
+ "vitest.config.cjs",
19
+ "vitest.workspace.ts",
20
+ "vitest.workspace.mts"
21
+ ];
22
+ const defaultWorkspaceConfigCandidates = [
23
+ "vitest.config.ts",
24
+ "vitest.config.mts",
25
+ "vitest.config.cts",
26
+ "vitest.config.js",
27
+ "vitest.config.cjs",
28
+ "vitest.config.mjs"
29
+ ];
30
+ const windowsPathSeparatorPattern = /\\/g;
31
+ const relativeCurrentDirPattern = /^\.\//;
32
+ const globTokenPattern = /[*?[{]/;
33
+ const trailingSlashPattern = /\/+$/;
34
+ const monorepoTsconfigPath = fileURLToPath(new URL("../../tsconfig.base.json", import.meta.url));
35
+ function escapeForShell(value) {
36
+ return `'${value.replaceAll("'", "'\\''")}'`;
37
+ }
38
+ function resolveProjects(rootDir, projectRoots, configCandidates) {
39
+ const projects = [];
40
+ for (const folder of projectRoots) {
41
+ const rootPath = path.resolve(rootDir, folder);
42
+ if (!fs.existsSync(rootPath)) continue;
43
+ const entries = fs.readdirSync(rootPath, { withFileTypes: true });
44
+ for (const entry of entries) {
45
+ if (!entry.isDirectory()) continue;
46
+ const projectDir = path.join(rootPath, entry.name);
47
+ const configPath = configCandidates.map((candidate) => path.join(projectDir, candidate)).find(fs.existsSync);
48
+ if (configPath) projects.push(path.relative(rootDir, configPath));
49
+ }
50
+ }
51
+ return projects;
52
+ }
53
+ function extractBaseDirFromGlob(pattern) {
54
+ if (!pattern) return null;
55
+ const normalized = pattern.replace(windowsPathSeparatorPattern, "/").replace(relativeCurrentDirPattern, "");
56
+ const globIndex = normalized.search(globTokenPattern);
57
+ return (globIndex === -1 ? normalized : normalized.slice(0, globIndex)).replace(trailingSlashPattern, "") || null;
58
+ }
59
+ function loadProjectRootsFromWorkspace(rootDir, workspaceFile) {
60
+ const workspacePath = path.resolve(rootDir, workspaceFile);
61
+ if (!fs.existsSync(workspacePath)) return [];
62
+ try {
63
+ const workspaceContent = fs.readFileSync(workspacePath, "utf8");
64
+ const workspace = YAML.parse(workspaceContent) ?? {};
65
+ const roots = (Array.isArray(workspace.packages) ? workspace.packages : []).map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry && !entry.startsWith("!")).map(extractBaseDirFromGlob).filter((entry) => Boolean(entry));
66
+ return roots.length ? [...new Set(roots)] : [];
67
+ } catch {
68
+ return [];
69
+ }
70
+ }
71
+ function findConfig(basePath, configCandidates) {
72
+ for (const filename of configCandidates) {
73
+ const candidate = path.join(basePath, filename);
74
+ if (fs.existsSync(candidate)) return candidate;
75
+ }
76
+ return null;
77
+ }
78
+ /**
79
+ * 读取当前工作目录下的 `monorepo.config.*` 中 `tooling` 配置块。
80
+ *
81
+ * @param cwd 配置文件解析起点。默认使用 `process.cwd()`
82
+ * @returns 标准化后的 tooling 配置;未配置时返回空对象
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * import { loadMonorepoToolingConfig } from '@icebreakers/monorepo/tooling'
87
+ *
88
+ * const tooling = await loadMonorepoToolingConfig()
89
+ * console.log(tooling.vitest?.includeWorkspaceRootConfig)
90
+ * ```
91
+ */
92
+ async function loadMonorepoToolingConfig(cwd = process.cwd()) {
93
+ return (await loadMonorepoConfig(cwd)).tooling ?? {};
94
+ }
95
+ async function loadToolingSection(key, cwd = process.cwd()) {
96
+ return (await loadMonorepoToolingConfig(cwd))[key];
97
+ }
98
+ function resolveConfigInput(input) {
99
+ return {
100
+ cwd: input?.cwd ?? process.cwd(),
101
+ options: input?.options ?? input?.config
102
+ };
103
+ }
104
+ function mergeTsconfig(base, override) {
105
+ if (!override) return base;
106
+ return {
107
+ ...base,
108
+ ...override,
109
+ ...base.compilerOptions || override.compilerOptions ? { compilerOptions: {
110
+ ...base.compilerOptions ?? {},
111
+ ...override.compilerOptions ?? {}
112
+ } } : {}
113
+ };
114
+ }
115
+ function loadBundledTsconfig() {
116
+ return parse(fs.readFileSync(monorepoTsconfigPath, "utf8"));
117
+ }
118
+ /**
119
+ * 基于 `@icebreakers/commitlint-config` 创建 commitlint 配置。
120
+ *
121
+ * 适合在需要手动传入覆盖项时使用;如果只想读取 `repoctl.config.ts` / `monorepo.config.ts` 默认值,
122
+ * 优先使用 `defineCommitlintConfig()`。
123
+ *
124
+ * @param options 额外合并到默认 commitlint 配置上的字段
125
+ * @returns 可直接作为 `commitlint.config.ts` 默认导出的配置对象
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * import { createMonorepoCommitlintConfig } from '@icebreakers/monorepo/tooling'
130
+ *
131
+ * export default createMonorepoCommitlintConfig({
132
+ * rules: {
133
+ * 'subject-case': [0],
134
+ * },
135
+ * })
136
+ * ```
137
+ */
138
+ function createMonorepoCommitlintConfig(options = {}) {
139
+ return icebreaker(options);
140
+ }
141
+ /**
142
+ * 从 `repoctl.config.ts` / `monorepo.config.ts` 读取 `tooling.commitlint`,并生成 commitlint 配置。
143
+ *
144
+ * @param input `cwd` 用于指定配置文件解析起点,`config` 用于追加运行时覆盖项
145
+ * @returns 可直接导出的 commitlint 配置对象
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import { defineCommitlintConfig } from '@icebreakers/monorepo/tooling'
150
+ *
151
+ * export default await defineCommitlintConfig()
152
+ * ```
153
+ */
154
+ async function defineCommitlintConfig(input = {}) {
155
+ const resolved = resolveConfigInput(input);
156
+ return createMonorepoCommitlintConfig({
157
+ ...await loadToolingSection("commitlint", resolved.cwd),
158
+ ...resolved.options
159
+ });
160
+ }
161
+ /**
162
+ * 基于 `@icebreakers/eslint-config` 创建 ESLint 配置。
163
+ *
164
+ * 默认会追加一个用于忽略 `fixtures` 目录的 glob,除非显式传入其他 `ignores`。
165
+ *
166
+ * @param options 额外 ESLint 配置;`ignores` 默认会忽略 `fixtures` 目录
167
+ * @returns 可直接作为 `eslint.config.js` 默认导出的 flat config
168
+ */
169
+ function createMonorepoEslintConfig(options = {}) {
170
+ const { configs = [], ...rest } = options;
171
+ return icebreaker$1(rest, ...configs);
172
+ }
173
+ /**
174
+ * 从 `repoctl.config.ts` / `monorepo.config.ts` 读取 `tooling.eslint`,并生成 ESLint 配置。
175
+ *
176
+ * @param input `cwd` 用于指定配置文件解析起点,`config` 用于追加运行时覆盖项
177
+ * @returns 可直接导出的 ESLint flat config
178
+ *
179
+ * @example
180
+ * ```js
181
+ * import { defineEslintConfig } from '@icebreakers/monorepo/tooling'
182
+ *
183
+ * export default await defineEslintConfig()
184
+ * ```
185
+ */
186
+ async function defineEslintConfig(input = {}) {
187
+ const resolved = resolveConfigInput(input);
188
+ return createMonorepoEslintConfig({
189
+ ...await loadToolingSection("eslint", resolved.cwd),
190
+ ...resolved.options
191
+ });
192
+ }
193
+ /**
194
+ * 基于 `@icebreakers/stylelint-config` 创建 Stylelint 配置。
195
+ *
196
+ * @param options 额外合并到默认 stylelint 配置上的字段
197
+ * @returns 可直接作为 `stylelint.config.js` 默认导出的配置对象
198
+ */
199
+ function createMonorepoStylelintConfig(options = {}) {
200
+ return icebreaker$2(options);
201
+ }
202
+ /**
203
+ * 从 `repoctl.config.ts` / `monorepo.config.ts` 读取 `tooling.stylelint`,并生成 Stylelint 配置。
204
+ *
205
+ * @param input `cwd` 用于指定配置文件解析起点,`config` 用于追加运行时覆盖项
206
+ * @returns 可直接导出的 Stylelint 配置对象
207
+ */
208
+ async function defineStylelintConfig(input = {}) {
209
+ const resolved = resolveConfigInput(input);
210
+ return createMonorepoStylelintConfig({
211
+ ...await loadToolingSection("stylelint", resolved.cwd),
212
+ ...resolved.options
213
+ });
214
+ }
215
+ /**
216
+ * 创建 monorepo 内置的 TypeScript 基线配置。
217
+ *
218
+ * @param options 额外覆盖项,会与包内置 `tsconfig.base.json` 合并
219
+ * @returns 可直接写入或二次扩展的 `tsconfig.json` 配置对象
220
+ */
221
+ function createMonorepoTsconfig(options = {}) {
222
+ return mergeTsconfig(loadBundledTsconfig(), options);
223
+ }
224
+ /**
225
+ * 从 `repoctl.config.ts` / `monorepo.config.ts` 读取 `tooling.tsconfig`,并生成最终的 TypeScript 配置对象。
226
+ *
227
+ * @param input `cwd` 用于指定配置文件解析起点,`config` 用于追加运行时覆盖项
228
+ * @returns 可直接写入或导出的 `tsconfig.json` 配置对象
229
+ */
230
+ async function defineTsconfigConfig(input = {}) {
231
+ const resolved = resolveConfigInput(input);
232
+ return createMonorepoTsconfig(mergeTsconfig(await loadToolingSection("tsconfig", resolved.cwd) ?? {}, resolved.options));
233
+ }
234
+ /**
235
+ * 创建适用于当前仓库约定的 `lint-staged` 配置。
236
+ *
237
+ * 默认行为:
238
+ * - `*.{js,jsx,mjs,ts,tsx,mts,cts}` 运行 `eslint --fix`
239
+ * - `*.vue` 同时运行 `eslint --fix` 与 `stylelint --fix --allow-empty-input`
240
+ * - `*.{ts,tsx,mts,cts,vue}` 调用 `pnpm exec repo verify staged-typecheck`
241
+ * - 样式文件运行 `stylelint --fix --allow-empty-input`
242
+ *
243
+ * @param options 仅支持 `monorepoCommand`,默认值为 `pnpm exec repo`
244
+ * @returns 可直接导出的 `lint-staged` 配置对象
245
+ *
246
+ * @example
247
+ * ```js
248
+ * import { createMonorepoLintStagedConfig } from '@icebreakers/monorepo/tooling'
249
+ *
250
+ * export default createMonorepoLintStagedConfig({
251
+ * monorepoCommand: 'pnpm exec repo',
252
+ * })
253
+ * ```
254
+ */
255
+ function createMonorepoLintStagedConfig(options = {}) {
256
+ if (options.config) return options.config;
257
+ const monorepoCommand = options.monorepoCommand ?? "pnpm exec repo";
258
+ return {
259
+ "*.{js,jsx,mjs,ts,tsx,mts,cts}": ["eslint --fix"],
260
+ "*.vue": ["eslint --fix", "stylelint --fix --allow-empty-input"],
261
+ "*.{ts,tsx,mts,cts,vue}": (files) => {
262
+ const uniqueFiles = [...new Set(files)];
263
+ if (uniqueFiles.length === 0) return [];
264
+ return `${monorepoCommand} verify staged-typecheck ${uniqueFiles.map(escapeForShell).join(" ")}`;
265
+ },
266
+ "*.{json,md,mdx,html,yml,yaml}": ["eslint --fix"],
267
+ "*.{css,scss,sass,less}": ["stylelint --fix --allow-empty-input"]
268
+ };
269
+ }
270
+ /**
271
+ * 从 `repoctl.config.ts` / `monorepo.config.ts` 读取 `tooling.lintStaged`,并生成 `lint-staged` 配置。
272
+ *
273
+ * @param input `cwd` 用于指定配置文件解析起点,`config` 用于追加运行时覆盖项
274
+ * @returns 可直接导出的 `lint-staged` 配置对象
275
+ */
276
+ async function defineLintStagedConfig(input = {}) {
277
+ const resolved = resolveConfigInput(input);
278
+ return createMonorepoLintStagedConfig({
279
+ ...await loadToolingSection("lintStaged", resolved.cwd),
280
+ ...resolved.options
281
+ });
282
+ }
283
+ /**
284
+ * 创建 monorepo 根级 Vitest 配置。
285
+ *
286
+ * 默认值:
287
+ * - `rootDir`: `process.cwd()`
288
+ * - `workspaceFile`: `'pnpm-workspace.yaml'`
289
+ * - `projectRoots`: 自动从 workspace packages 推导,失败时回退到 `['packages', 'apps']`
290
+ * - `includeWorkspaceRootConfig`: `false`
291
+ * - `coverageEnabled`: `true`
292
+ * - `coverageAll`: `false`
293
+ * - `coverageSkipFull`: `true`
294
+ *
295
+ * @param options Vitest 默认配置生成参数
296
+ * @returns 仅包含 `test` 字段的 Vitest 配置片段
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * import { createMonorepoVitestConfig } from '@icebreakers/monorepo/tooling'
301
+ *
302
+ * export default {
303
+ * ...createMonorepoVitestConfig({
304
+ * includeWorkspaceRootConfig: false,
305
+ * coverageExclude: ['dist output glob'],
306
+ * }),
307
+ * }
308
+ * ```
309
+ */
310
+ function createMonorepoVitestConfig(options = {}) {
311
+ const rootDir = options.rootDir ?? process.cwd();
312
+ const workspaceProjectRoots = loadProjectRootsFromWorkspace(rootDir, options.workspaceFile ?? "pnpm-workspace.yaml");
313
+ const projectRoots = options.projectRoots ?? (workspaceProjectRoots.length ? workspaceProjectRoots : defaultProjectRoots);
314
+ const configCandidates = options.configCandidates ?? defaultConfigCandidates;
315
+ const includeWorkspaceRootConfig = options.includeWorkspaceRootConfig ?? false;
316
+ const projects = resolveProjects(rootDir, projectRoots, configCandidates);
317
+ if (includeWorkspaceRootConfig) {
318
+ const rootConfig = findConfig(rootDir, defaultWorkspaceConfigCandidates);
319
+ if (rootConfig) projects.unshift(rootConfig);
320
+ }
321
+ return { test: {
322
+ projects: [...new Set(projects)],
323
+ coverage: {
324
+ enabled: options.coverageEnabled ?? true,
325
+ all: options.coverageAll ?? false,
326
+ skipFull: options.coverageSkipFull ?? true,
327
+ ...options.coverageExclude ? { exclude: options.coverageExclude } : {}
328
+ },
329
+ forceRerunTriggers: ["**/{vitest,vite}.config.*/**"]
330
+ } };
331
+ }
332
+ function mergeMonorepoVitestConfig(base, overrides = {}) {
333
+ const merged = mergeConfig(base, overrides);
334
+ if (!merged.test) return merged;
335
+ const coverageExclude = merged.test.coverage?.exclude;
336
+ const projects = merged.test.projects;
337
+ if (coverageExclude) merged.test.coverage = {
338
+ ...merged.test.coverage,
339
+ exclude: [...new Set(coverageExclude)]
340
+ };
341
+ if (projects) merged.test.projects = [...new Set(projects)];
342
+ return merged;
343
+ }
344
+ /**
345
+ * 从 `repoctl.config.ts` / `monorepo.config.ts` 读取 `tooling.vitest`,再叠加运行时 `options` 与 `overrides`
346
+ * 生成最终 Vitest 配置。
347
+ *
348
+ * 优先级从低到高:
349
+ * 1. `repoctl.config.ts` / `monorepo.config.ts -> tooling.vitest`
350
+ * 2. `options`
351
+ * 3. `overrides`
352
+ *
353
+ * 推荐把“参与默认值推导”的字段放在 `options`,把“最终局部覆盖”放在 `overrides`。
354
+ *
355
+ * @param input `options` 会先与 `tooling.vitest` 合并;`overrides` 用于最终局部覆盖;`cwd` 用于配置文件解析起点
356
+ * @returns 可直接作为 `defineConfig()` 返回值的 Vitest 配置对象
357
+ *
358
+ * @example
359
+ * ```ts
360
+ * import { defineVitestConfig } from '@icebreakers/monorepo/tooling'
361
+ * import { defineConfig } from 'vitest/config'
362
+ *
363
+ * export default defineConfig(async () => await defineVitestConfig({
364
+ * options: {
365
+ * includeWorkspaceRootConfig: false,
366
+ * },
367
+ * overrides: {
368
+ * test: {
369
+ * coverage: {
370
+ * exclude: ['dist output glob'],
371
+ * skipFull: true,
372
+ * },
373
+ * },
374
+ * },
375
+ * }))
376
+ * ```
377
+ */
378
+ async function defineVitestConfig(input = {}) {
379
+ const cwd = input.cwd ?? process.cwd();
380
+ const options = input.options ?? {};
381
+ const overrides = input.overrides ?? {};
382
+ const toolingOptions = await loadToolingSection("vitest", cwd);
383
+ const toolingOverrides = toolingOptions?.overrides ?? {};
384
+ const { overrides: _ignoredToolingOverrides, ...toolingBaseOptions } = toolingOptions ?? {};
385
+ return mergeMonorepoVitestConfig(createMonorepoVitestConfig({
386
+ ...toolingBaseOptions,
387
+ ...options
388
+ }), mergeMonorepoVitestConfig(toolingOverrides, overrides));
389
+ }
390
+ /**
391
+ * 创建项目级 Vitest 配置。
392
+ *
393
+ * 默认值:
394
+ * - `globals`: `true`
395
+ * - `testTimeout`: `60_000`
396
+ * - `environment`: `'node'`
397
+ *
398
+ * @param options 单个 package/app 的 Vitest 配置项
399
+ * @returns 可直接给项目内 `vitest.config.ts` 使用的 `test` 配置片段
400
+ */
401
+ function createMonorepoVitestProjectConfig(options = {}) {
402
+ return { test: {
403
+ ...options.alias ? { alias: options.alias } : {},
404
+ globals: options.globals ?? true,
405
+ testTimeout: options.testTimeout ?? 6e4,
406
+ ...options.environment ? { environment: options.environment } : {}
407
+ } };
408
+ }
409
+ /**
410
+ * 从 `repoctl.config.ts` / `monorepo.config.ts` 读取 `tooling.vitestProject`,再叠加运行时 `options`
411
+ * 生成单个 package/app 的项目级 Vitest 配置。
412
+ *
413
+ * 优先级从低到高:
414
+ * 1. `repoctl.config.ts` / `monorepo.config.ts -> tooling.vitestProject`
415
+ * 2. `options`
416
+ *
417
+ * @param input `cwd` 用于配置文件解析起点,`options` 用于追加项目内局部覆盖项
418
+ * @returns 可直接传给 `defineProject()` 或与其他 Vite/Vitest 配置 merge 的项目级配置片段
419
+ */
420
+ async function defineVitestProjectConfig(input = {}) {
421
+ return createMonorepoVitestProjectConfig({
422
+ ...await loadToolingSection("vitestProject", input.cwd ?? process.cwd()),
423
+ ...input.options ?? input.config
424
+ });
425
+ }
426
+ //#endregion
427
+ export { createMonorepoTsconfig as a, defineCommitlintConfig as c, defineStylelintConfig as d, defineTsconfigConfig as f, loadMonorepoToolingConfig as h, createMonorepoStylelintConfig as i, defineEslintConfig as l, defineVitestProjectConfig as m, createMonorepoEslintConfig as n, createMonorepoVitestConfig as o, defineVitestConfig as p, createMonorepoLintStagedConfig as r, createMonorepoVitestProjectConfig as s, createMonorepoCommitlintConfig as t, defineLintStagedConfig as u };
@@ -0,0 +1,2 @@
1
+ import { C as defineEslintConfig, D as defineVitestConfig, E as defineTsconfigConfig, O as defineVitestProjectConfig, S as defineCommitlintConfig, T as defineStylelintConfig, _ as createMonorepoLintStagedConfig, a as MonorepoEslintConfig, b as createMonorepoVitestConfig, c as MonorepoStylelintConfig, d as MonorepoVitestConfigOverrides, f as MonorepoVitestConfigResult, g as createMonorepoEslintConfig, h as createMonorepoCommitlintConfig, i as MonorepoCommitlintConfig, k as loadMonorepoToolingConfig, l as MonorepoTsconfig, m as MonorepoVitestProjectConfigResult, n as DefineVitestConfigOptions, o as MonorepoLintStagedConfig, p as MonorepoVitestProjectConfigOptions, r as DefineVitestProjectConfigOptions, s as MonorepoLintStagedConfigOptions, t as DefineConfigOptions, u as MonorepoVitestConfigOptions, v as createMonorepoStylelintConfig, w as defineLintStagedConfig, x as createMonorepoVitestProjectConfig, y as createMonorepoTsconfig } from "./index-DvZrxwOh.mjs";
2
+ export { DefineConfigOptions, DefineVitestConfigOptions, DefineVitestProjectConfigOptions, MonorepoCommitlintConfig, MonorepoEslintConfig, MonorepoLintStagedConfig, MonorepoLintStagedConfigOptions, MonorepoStylelintConfig, MonorepoTsconfig, MonorepoVitestConfigOptions, MonorepoVitestConfigOverrides, MonorepoVitestConfigResult, MonorepoVitestProjectConfigOptions, MonorepoVitestProjectConfigResult, createMonorepoCommitlintConfig, createMonorepoEslintConfig, createMonorepoLintStagedConfig, createMonorepoStylelintConfig, createMonorepoTsconfig, createMonorepoVitestConfig, createMonorepoVitestProjectConfig, defineCommitlintConfig, defineEslintConfig, defineLintStagedConfig, defineStylelintConfig, defineTsconfigConfig, defineVitestConfig, defineVitestProjectConfig, loadMonorepoToolingConfig };
@@ -0,0 +1,2 @@
1
+ import { a as createMonorepoTsconfig, c as defineCommitlintConfig, d as defineStylelintConfig, f as defineTsconfigConfig, h as loadMonorepoToolingConfig, i as createMonorepoStylelintConfig, l as defineEslintConfig, m as defineVitestProjectConfig, n as createMonorepoEslintConfig, o as createMonorepoVitestConfig, p as defineVitestConfig, r as createMonorepoLintStagedConfig, s as createMonorepoVitestProjectConfig, t as createMonorepoCommitlintConfig, u as defineLintStagedConfig } from "./tooling-DyUe-eiv.mjs";
2
+ export { createMonorepoCommitlintConfig, createMonorepoEslintConfig, createMonorepoLintStagedConfig, createMonorepoStylelintConfig, createMonorepoTsconfig, createMonorepoVitestConfig, createMonorepoVitestProjectConfig, defineCommitlintConfig, defineEslintConfig, defineLintStagedConfig, defineStylelintConfig, defineTsconfigConfig, defineVitestConfig, defineVitestProjectConfig, loadMonorepoToolingConfig };
@@ -0,0 +1,215 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "pathe";
3
+ import { access, cp, mkdir, mkdtemp, open, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
4
+ import { createConsola } from "consola";
5
+ import * as path$2 from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ //#region src/utils/fs.ts
8
+ function stringifyJson(data, options) {
9
+ const content = JSON.stringify(data, void 0, options?.spaces);
10
+ return options?.spaces ? `${content}\n` : content;
11
+ }
12
+ async function ensureParentDir(targetPath) {
13
+ await mkdir(path.dirname(targetPath), { recursive: true });
14
+ }
15
+ /**
16
+ * 判断文件或目录是否存在。
17
+ *
18
+ * @param targetPath 目标路径
19
+ * @returns 存在时返回 `true`
20
+ */
21
+ async function pathExists(targetPath) {
22
+ try {
23
+ await access(targetPath);
24
+ return true;
25
+ } catch {
26
+ return false;
27
+ }
28
+ }
29
+ /**
30
+ * `pathExists()` 的别名。
31
+ */
32
+ const exists = pathExists;
33
+ /**
34
+ * 递归创建目录。
35
+ */
36
+ async function ensureDir(targetPath) {
37
+ await mkdir(targetPath, { recursive: true });
38
+ }
39
+ /**
40
+ * 确保文件存在;若父目录不存在会自动创建。
41
+ */
42
+ async function ensureFile(targetPath) {
43
+ await ensureParentDir(targetPath);
44
+ await (await open(targetPath, "a")).close();
45
+ }
46
+ /**
47
+ * 递归删除文件或目录。
48
+ *
49
+ * 默认启用 `force: true`、`recursive: true`,并带少量重试。
50
+ */
51
+ async function remove(targetPath) {
52
+ await rm(targetPath, {
53
+ recursive: true,
54
+ force: true,
55
+ maxRetries: 3,
56
+ retryDelay: 100
57
+ });
58
+ }
59
+ /**
60
+ * 递归复制文件或目录。
61
+ */
62
+ async function copy(sourcePath, targetPath) {
63
+ await cp(sourcePath, targetPath, {
64
+ recursive: true,
65
+ force: true
66
+ });
67
+ }
68
+ /**
69
+ * 自动创建父目录后写入文件。
70
+ */
71
+ async function outputFile(targetPath, data, options) {
72
+ await ensureParentDir(targetPath);
73
+ await writeFile(targetPath, data, options);
74
+ }
75
+ /**
76
+ * 读取 JSON 文件并解析。
77
+ */
78
+ async function readJson(targetPath) {
79
+ return JSON.parse(await readFile(targetPath, "utf8"));
80
+ }
81
+ /**
82
+ * `readJson()` 的别名。
83
+ */
84
+ const readJSON = readJson;
85
+ /**
86
+ * 写入 JSON 文件,不会自动创建父目录。
87
+ */
88
+ async function writeJson(targetPath, data, options) {
89
+ await writeFile(targetPath, stringifyJson(data, options), "utf8");
90
+ }
91
+ /**
92
+ * `writeJson()` 的别名。
93
+ */
94
+ const writeJSON = writeJson;
95
+ /**
96
+ * 自动创建父目录后写入 JSON 文件。
97
+ */
98
+ async function outputJson(targetPath, data, options) {
99
+ await ensureParentDir(targetPath);
100
+ await writeJson(targetPath, data, options);
101
+ }
102
+ /**
103
+ * `outputJson()` 的别名。
104
+ */
105
+ const outputJSON = outputJson;
106
+ /**
107
+ * 判断是否为可忽略的文件系统错误。
108
+ * - ENOENT: 文件已被删除
109
+ * - EBUSY: Windows 中资源被系统占用
110
+ */
111
+ function isIgnorableFsError(error) {
112
+ if (!error) return false;
113
+ const code = error.code;
114
+ return code === "ENOENT" || code === "EBUSY" || code === "EEXIST";
115
+ }
116
+ const fs = {
117
+ copy,
118
+ ensureDir,
119
+ ensureFile,
120
+ exists,
121
+ mkdtemp,
122
+ outputFile,
123
+ outputJSON,
124
+ outputJson,
125
+ pathExists,
126
+ readFile,
127
+ readdir,
128
+ readJSON,
129
+ readJson,
130
+ remove,
131
+ stat,
132
+ writeFile,
133
+ writeJSON,
134
+ writeJson
135
+ };
136
+ //#endregion
137
+ //#region src/core/logger.ts
138
+ /**
139
+ * 统一的日志实例,便于在命令行中输出带有前缀和颜色的消息。
140
+ */
141
+ const logger = createConsola();
142
+ //#endregion
143
+ //#region package.json
144
+ var name = "@icebreakers/monorepo";
145
+ var version = "4.0.1";
146
+ var dependencies = {
147
+ "@icebreakers/commitlint-config": "^2.0.0",
148
+ "@icebreakers/eslint-config": "^4.0.10",
149
+ "@icebreakers/monorepo-templates": "workspace:*",
150
+ "@icebreakers/stylelint-config": "^3.0.6",
151
+ "@pnpm/find-workspace-dir": "^1000.1.5",
152
+ "@pnpm/logger": "^1100.0.0",
153
+ "@pnpm/types": "^1101.0.0",
154
+ "@pnpm/worker": "^1100.1.1",
155
+ "@pnpm/workspace.find-packages": "^1000.0.65",
156
+ "@pnpm/workspace.read-manifest": "^1000.3.1",
157
+ "c12": "^3.3.4",
158
+ "commander": "^14.0.3",
159
+ "comment-json": "^5.0.0",
160
+ "consola": "^3.4.2",
161
+ "git-url-parse": "^16.1.0",
162
+ "klaw": "^4.1.0",
163
+ "lint-staged": "^16.4.0",
164
+ "p-queue": "^9.2.0",
165
+ "pathe": "^2.0.3",
166
+ "picocolors": "^1.1.1",
167
+ "semver": "^7.7.4",
168
+ "simple-git": "^3.36.0",
169
+ "vitest": "~4.1.5",
170
+ "yaml": "^2.8.4"
171
+ };
172
+ var devDependencies = {
173
+ "@types/klaw": "^3.0.7",
174
+ "@types/micromatch": "^4.0.10",
175
+ "fdir": "^6.5.0",
176
+ "micromatch": "^4.0.8"
177
+ };
178
+ //#endregion
179
+ //#region src/constants.ts
180
+ const require = createRequire(import.meta.url);
181
+ /**
182
+ * 用户默认看到的 CLI 名称。兼容别名仍然可用,但帮助文案统一引导到 repo。
183
+ */
184
+ const cliName = "repo";
185
+ /**
186
+ * 还原出 package.json 所在的绝对路径,方便后续按目录组织资源文件。
187
+ */
188
+ const packageJsonPath = fileURLToPath(new URL("../package.json", import.meta.url));
189
+ /**
190
+ * @icebreakers/monorepo 包的根目录。
191
+ */
192
+ const packageDir = path$2.dirname(packageJsonPath);
193
+ /**
194
+ * CLI 提供的模板/资产目录来源于 @icebreakers/monorepo-templates。
195
+ * 这里只解析 package.json 路径,避免 CLI 启动时加载模板包入口。
196
+ */
197
+ const templatesPackageDir = path$2.dirname(require.resolve("@icebreakers/monorepo-templates/package.json"));
198
+ const assetsDir = path$2.join(templatesPackageDir, "assets");
199
+ const templatesDir = path$2.join(templatesPackageDir, "templates");
200
+ /**
201
+ * monorepo 根目录,方便需要跳出当前包的逻辑(例如定位工作区文件)。
202
+ */
203
+ const rootDir = path$2.resolve(packageDir, "..", "..");
204
+ //#endregion
205
+ //#region src/commands/init/tooling/types.ts
206
+ const initToolingTargets = [
207
+ "commitlint",
208
+ "eslint",
209
+ "stylelint",
210
+ "lint-staged",
211
+ "tsconfig",
212
+ "vitest"
213
+ ];
214
+ //#endregion
215
+ export { readJson as C, writeJson as E, readJSON as S, writeJSON as T, isIgnorableFsError as _, rootDir as a, outputJson as b, devDependencies as c, logger as d, copy as f, fs as g, exists as h, packageDir as i, name as l, ensureFile as m, assetsDir as n, templatesDir as o, ensureDir as p, cliName as r, dependencies as s, initToolingTargets as t, version as u, outputFile as v, remove as w, pathExists as x, outputJSON as y };