@icebreakers/monorepo 5.5.10 → 5.6.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.
@@ -1,110 +1,69 @@
1
- import { a as loadMonorepoConfig } from "./config-p842Knhq.mjs";
1
+ import { a as loadToolingSection, o as resolveConfigInput, r as isDefineConfigWrapper } from "./tsconfig-BrjI_5yI.mjs";
2
2
  import process from "node:process";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import YAML from "yaml";
6
- import { fileURLToPath } from "node:url";
7
6
  import { icebreaker } from "@icebreakers/commitlint-config";
8
7
  import { icebreaker as icebreaker$1 } from "@icebreakers/eslint-config";
9
8
  import { icebreaker as icebreaker$2 } from "@icebreakers/stylelint-config";
10
- import { parse } from "comment-json";
11
9
  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(import.meta.resolve("@icebreakers/monorepo/tsconfig"));
10
+ //#region src/tooling/lint-staged.ts
35
11
  function escapeForShell(value) {
36
12
  return `'${value.replaceAll("'", "'\\''")}'`;
37
13
  }
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
14
  /**
79
- * 读取当前工作目录下的 `repoctl.config.*` 中 `tooling` 配置块。
15
+ * 创建适用于当前仓库约定的 `lint-staged` 配置。
16
+ *
17
+ * 默认行为:
18
+ * - `*.{js,jsx,mjs,ts,tsx,mts,cts}` 运行 `eslint --fix`
19
+ * - `*.vue` 同时运行 `eslint --fix` 与 `stylelint --fix --allow-empty-input`
20
+ * - TypeScript/Vue files and workspace `package.json` files share one
21
+ * `pnpm exec repo verify staged-typecheck` task to avoid concurrent builds
22
+ * - 样式文件运行 `stylelint --fix --allow-empty-input`
80
23
  *
81
- * @param cwd 配置文件解析起点。默认使用 `process.cwd()`
82
- * @returns 标准化后的 tooling 配置;未配置时返回空对象
24
+ * @param options 可配置 `repoCommand`,默认值为 `pnpm exec repo`
25
+ * @returns 可直接导出的 `lint-staged` 配置对象
83
26
  *
84
27
  * @example
85
- * ```ts
86
- * import { loadMonorepoToolingConfig } from 'repoctl/tooling'
28
+ * ```js
29
+ * import { createMonorepoLintStagedConfig } from 'repoctl/tooling'
87
30
  *
88
- * const tooling = await loadMonorepoToolingConfig()
89
- * console.log(tooling.vitest?.includeWorkspaceRootConfig)
31
+ * export default createMonorepoLintStagedConfig({
32
+ * repoCommand: 'pnpm exec repo',
33
+ * })
90
34
  * ```
91
35
  */
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) {
36
+ function createMonorepoLintStagedConfig(options = {}) {
37
+ if (options.config) return options.config;
38
+ const repoCommand = options.repoCommand ?? "pnpm exec repo";
99
39
  return {
100
- cwd: input?.cwd ?? process.cwd(),
101
- options: input?.options
40
+ "*.{js,jsx,mjs,ts,tsx,mts,cts}": ["eslint --fix"],
41
+ "*.astro": ["eslint --fix"],
42
+ "*.vue": ["eslint --fix", "stylelint --fix --allow-empty-input"],
43
+ "*.{ts,tsx,mts,cts,vue,astro,mdx,json}": (files) => {
44
+ const uniqueFiles = [...new Set(files)];
45
+ if (uniqueFiles.length === 0) return [];
46
+ return `${repoCommand} verify staged-typecheck ${uniqueFiles.map(escapeForShell).join(" ")}`;
47
+ },
48
+ "*.{json,md,mdx,html,yml,yaml}": ["eslint --fix"],
49
+ "*.{css,scss,sass,less}": ["stylelint --fix --allow-empty-input"]
102
50
  };
103
51
  }
104
- function isDefineConfigWrapper(input) {
105
- if (input === null || typeof input !== "object" || Array.isArray(input)) return false;
106
- return "cwd" in input || "options" in input;
52
+ /**
53
+ * 从 `repoctl.config.ts` 读取 `tooling.lintStaged`,并生成 `lint-staged` 配置。
54
+ *
55
+ * @param input `cwd` 用于指定配置文件解析起点,`options` 用于追加运行时覆盖项
56
+ * @returns 可直接导出的 `lint-staged` 配置对象
57
+ */
58
+ async function defineLintStagedConfig(input = {}) {
59
+ const resolved = resolveConfigInput(input);
60
+ return createMonorepoLintStagedConfig({
61
+ ...await loadToolingSection("lintStaged", resolved.cwd),
62
+ ...resolved.options
63
+ });
107
64
  }
65
+ //#endregion
66
+ //#region src/tooling/linters.ts
108
67
  function resolveEslintOptions(options = {}, configs = []) {
109
68
  const { configs: inlineConfigs = [], ...rest } = options;
110
69
  return {
@@ -112,21 +71,6 @@ function resolveEslintOptions(options = {}, configs = []) {
112
71
  configs: [...inlineConfigs, ...configs]
113
72
  };
114
73
  }
115
- function mergeTsconfig(base, override) {
116
- if (!override) return base;
117
- return {
118
- ...base,
119
- ...override,
120
- ...base.compilerOptions || override.compilerOptions ? { compilerOptions: {
121
- ...base.compilerOptions ?? {},
122
- ...override.compilerOptions ?? {}
123
- } } : {}
124
- };
125
- }
126
- function loadBundledTsconfig() {
127
- const configContent = fs.readFileSync(monorepoTsconfigPath, "utf8");
128
- return parse(configContent);
129
- }
130
74
  /**
131
75
  * 基于 `@icebreakers/commitlint-config` 创建 commitlint 配置。
132
76
  *
@@ -239,75 +183,71 @@ async function defineStylelintConfig(input = {}) {
239
183
  ...resolved.options
240
184
  });
241
185
  }
242
- /**
243
- * 创建 monorepo 内置的 TypeScript 基线配置。
244
- *
245
- * @param options 额外覆盖项,会与包内置 `tsconfig.base.json` 合并
246
- * @returns 可直接写入或二次扩展的 `tsconfig.json` 配置对象
247
- */
248
- function createMonorepoTsconfig(options = {}) {
249
- return mergeTsconfig(loadBundledTsconfig(), options);
186
+ //#endregion
187
+ //#region src/tooling/vitest/discovery.ts
188
+ const defaultProjectRoots = ["packages", "apps"];
189
+ const defaultConfigCandidates = [
190
+ "vitest.config.ts",
191
+ "vitest.config.mts",
192
+ "vitest.config.js",
193
+ "vitest.config.cjs",
194
+ "vitest.workspace.ts",
195
+ "vitest.workspace.mts"
196
+ ];
197
+ const defaultWorkspaceConfigCandidates = [
198
+ "vitest.config.ts",
199
+ "vitest.config.mts",
200
+ "vitest.config.cts",
201
+ "vitest.config.js",
202
+ "vitest.config.cjs",
203
+ "vitest.config.mjs"
204
+ ];
205
+ const windowsPathSeparatorPattern = /\\/g;
206
+ const relativeCurrentDirPattern = /^\.\//;
207
+ const globTokenPattern = /[*?[{]/;
208
+ const trailingSlashPattern = /\/+$/;
209
+ function resolveProjects(rootDir, projectRoots, configCandidates) {
210
+ const projects = [];
211
+ for (const folder of projectRoots) {
212
+ const rootPath = path.resolve(rootDir, folder);
213
+ if (!fs.existsSync(rootPath)) continue;
214
+ const entries = fs.readdirSync(rootPath, { withFileTypes: true });
215
+ for (const entry of entries) {
216
+ if (!entry.isDirectory()) continue;
217
+ const projectDir = path.join(rootPath, entry.name);
218
+ const configPath = configCandidates.map((candidate) => path.join(projectDir, candidate)).find(fs.existsSync);
219
+ if (configPath) projects.push(path.relative(rootDir, configPath));
220
+ }
221
+ }
222
+ return projects;
250
223
  }
251
- /**
252
- * 从 `repoctl.config.ts` 读取 `tooling.tsconfig`,并生成最终的 TypeScript 配置对象。
253
- *
254
- * @param input `cwd` 用于指定配置文件解析起点,`options` 用于追加运行时覆盖项
255
- * @returns 可直接写入或导出的 `tsconfig.json` 配置对象
256
- */
257
- async function defineTsconfigConfig(input = {}) {
258
- const resolved = resolveConfigInput(input);
259
- return createMonorepoTsconfig(mergeTsconfig(await loadToolingSection("tsconfig", resolved.cwd) ?? {}, resolved.options));
224
+ function extractBaseDirFromGlob(pattern) {
225
+ if (!pattern) return null;
226
+ const normalized = pattern.replace(windowsPathSeparatorPattern, "/").replace(relativeCurrentDirPattern, "");
227
+ const globIndex = normalized.search(globTokenPattern);
228
+ return (globIndex === -1 ? normalized : normalized.slice(0, globIndex)).replace(trailingSlashPattern, "") || null;
260
229
  }
261
- /**
262
- * 创建适用于当前仓库约定的 `lint-staged` 配置。
263
- *
264
- * 默认行为:
265
- * - `*.{js,jsx,mjs,ts,tsx,mts,cts}` 运行 `eslint --fix`
266
- * - `*.vue` 同时运行 `eslint --fix` 与 `stylelint --fix --allow-empty-input`
267
- * - TypeScript/Vue files and workspace `package.json` files share one
268
- * `pnpm exec repo verify staged-typecheck` task to avoid concurrent builds
269
- * - 样式文件运行 `stylelint --fix --allow-empty-input`
270
- *
271
- * @param options 可配置 `repoCommand`,默认值为 `pnpm exec repo`
272
- * @returns 可直接导出的 `lint-staged` 配置对象
273
- *
274
- * @example
275
- * ```js
276
- * import { createMonorepoLintStagedConfig } from 'repoctl/tooling'
277
- *
278
- * export default createMonorepoLintStagedConfig({
279
- * repoCommand: 'pnpm exec repo',
280
- * })
281
- * ```
282
- */
283
- function createMonorepoLintStagedConfig(options = {}) {
284
- if (options.config) return options.config;
285
- const repoCommand = options.repoCommand ?? "pnpm exec repo";
286
- return {
287
- "*.{js,jsx,mjs,ts,tsx,mts,cts}": ["eslint --fix"],
288
- "*.vue": ["eslint --fix", "stylelint --fix --allow-empty-input"],
289
- "*.{ts,tsx,mts,cts,vue,json}": (files) => {
290
- const uniqueFiles = [...new Set(files)];
291
- if (uniqueFiles.length === 0) return [];
292
- return `${repoCommand} verify staged-typecheck ${uniqueFiles.map(escapeForShell).join(" ")}`;
293
- },
294
- "*.{json,md,mdx,html,yml,yaml}": ["eslint --fix"],
295
- "*.{css,scss,sass,less}": ["stylelint --fix --allow-empty-input"]
296
- };
230
+ function loadProjectRootsFromWorkspace(rootDir, workspaceFile) {
231
+ const workspacePath = path.resolve(rootDir, workspaceFile);
232
+ if (!fs.existsSync(workspacePath)) return [];
233
+ try {
234
+ const workspaceContent = fs.readFileSync(workspacePath, "utf8");
235
+ const workspace = YAML.parse(workspaceContent) ?? {};
236
+ 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));
237
+ return roots.length ? [...new Set(roots)] : [];
238
+ } catch {
239
+ return [];
240
+ }
297
241
  }
298
- /**
299
- * 从 `repoctl.config.ts` 读取 `tooling.lintStaged`,并生成 `lint-staged` 配置。
300
- *
301
- * @param input `cwd` 用于指定配置文件解析起点,`options` 用于追加运行时覆盖项
302
- * @returns 可直接导出的 `lint-staged` 配置对象
303
- */
304
- async function defineLintStagedConfig(input = {}) {
305
- const resolved = resolveConfigInput(input);
306
- return createMonorepoLintStagedConfig({
307
- ...await loadToolingSection("lintStaged", resolved.cwd),
308
- ...resolved.options
309
- });
242
+ function findConfig(basePath, configCandidates) {
243
+ for (const filename of configCandidates) {
244
+ const candidate = path.join(basePath, filename);
245
+ if (fs.existsSync(candidate)) return candidate;
246
+ }
247
+ return null;
310
248
  }
249
+ //#endregion
250
+ //#region src/tooling/vitest/index.ts
311
251
  /**
312
252
  * 创建 monorepo 根级 Vitest 配置。
313
253
  *
@@ -446,10 +386,11 @@ function createMonorepoVitestProjectConfig(options = {}) {
446
386
  * @returns 可直接传给 `defineProject()` 或与其他 Vite/Vitest 配置 merge 的项目级配置片段
447
387
  */
448
388
  async function defineVitestProjectConfig(input = {}) {
389
+ const cwd = input.cwd ?? process.cwd();
449
390
  return createMonorepoVitestProjectConfig({
450
- ...await loadToolingSection("vitestProject", input.cwd ?? process.cwd()),
391
+ ...await loadToolingSection("vitestProject", cwd),
451
392
  ...input.options
452
393
  });
453
394
  }
454
395
  //#endregion
455
- 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 };
396
+ export { createMonorepoCommitlintConfig as a, defineCommitlintConfig as c, createMonorepoLintStagedConfig as d, defineLintStagedConfig as f, defineVitestProjectConfig as i, defineEslintConfig as l, createMonorepoVitestProjectConfig as n, createMonorepoEslintConfig as o, defineVitestConfig as r, createMonorepoStylelintConfig as s, createMonorepoVitestConfig as t, defineStylelintConfig as u };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@icebreakers/monorepo",
3
3
  "type": "module",
4
- "version": "5.5.10",
4
+ "version": "5.6.0",
5
5
  "description": "Core engine and programmatic APIs for repoctl",
6
6
  "author": "ice breaker <hi@sonofmagic.top>",
7
7
  "license": "MIT",
@@ -77,13 +77,13 @@
77
77
  },
78
78
  "dependencies": {
79
79
  "@icebreakers/commitlint-config": "4.1.1",
80
- "@icebreakers/eslint-config": "8.0.6",
81
- "@icebreakers/monorepo-templates": "2.0.7",
80
+ "@icebreakers/eslint-config": "8.0.7",
81
+ "@icebreakers/monorepo-templates": "2.1.0",
82
82
  "@icebreakers/stylelint-config": "5.1.3",
83
83
  "@pnpm/find-workspace-dir": "^1000.1.5",
84
84
  "@pnpm/logger": "^1100.0.0",
85
85
  "@pnpm/types": "^1102.1.1",
86
- "@pnpm/worker": "^1100.4.5",
86
+ "@pnpm/worker": "^1100.4.6",
87
87
  "@pnpm/workspace.find-packages": "^1000.0.65",
88
88
  "@pnpm/workspace.read-manifest": "^1000.3.1",
89
89
  "c12": "^3.3.4",
@@ -98,7 +98,7 @@
98
98
  "picocolors": "^1.1.1",
99
99
  "semver": "^7.8.5",
100
100
  "simple-git": "^3.36.0",
101
- "vitest": "^5.0.2",
101
+ "vitest": "^5.0.3",
102
102
  "yaml": "^2.9.1"
103
103
  },
104
104
  "devDependencies": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: repoctl
3
- description: Create and maintain pnpm/Turborepo workspaces with repoctl. Use when the user says 使用 repoctl 创建项目, create a monorepo, pnpm create repoctl@latest, scaffold Vue/Hono/tsdown/vitepress, or run repo init/doctor/new/check.
3
+ description: Create and maintain pnpm/Turborepo workspaces with repoctl. Use when the user says 使用 repoctl 创建项目, create a monorepo, pnpm create repoctl@latest, scaffold Vue/Hono/tsdown/Nimbus/VitePress, or run repo init/doctor/new/check.
4
4
  ---
5
5
 
6
6
  # repoctl
@@ -32,7 +32,7 @@ pnpm exec repo doctor
32
32
  | API / Hono service | `hono-server` |
33
33
  | TypeScript library / SDK | `tsdown` |
34
34
  | Vue component library | `vue-lib` |
35
- | Documentation site | `vitepress` |
35
+ | Documentation site | `nimbus` |
36
36
  | CLI | `cli` |
37
37
  | Unspecified | omit `--templates` |
38
38
 
@@ -8,7 +8,7 @@ Intent defaults:
8
8
  - library -> `tsdown` -> `packages/<name>`
9
9
  - web-app -> `vue-hono` -> `apps/<name>`
10
10
  - api-service -> `hono-server` -> `apps/<name>`
11
- - docs-site -> `vitepress` -> `apps/<name>`
11
+ - docs-site -> `nimbus` -> `apps/<name>`
12
12
  - cli-tool -> `cli` -> `apps/<name>`
13
13
 
14
14
  Run `repo templates` to discover template keys, categories, default targets, and
@@ -36,7 +36,8 @@ Built-in template map:
36
36
  - vue-lib -> templates/vue-lib => packages/vue-lib
37
37
  - hono-server -> templates/server => apps/server
38
38
  - vue-hono -> templates/client => apps/client
39
- - vitepress -> templates/vitepress => apps/website
39
+ - nimbus -> templates/nimbus => apps/docs (default documentation template)
40
+ - vitepress -> templates/vitepress => apps/website (explicit alternative)
40
41
  - cli -> templates/cli => apps/cli
41
42
 
42
43
  Notes: