@icebreakers/monorepo-templates 0.1.16 → 1.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.
Files changed (92) hide show
  1. package/README.md +12 -0
  2. package/assets/.changeset/config.json +7 -2
  3. package/assets/.github/workflows/ci.yml +8 -2
  4. package/assets/.github/workflows/release.yml +2 -2
  5. package/assets/.husky/commit-msg +1 -1
  6. package/assets/.husky/pre-commit +1 -1
  7. package/assets/.husky/pre-push +5 -0
  8. package/assets/AGENTS.md +8 -7
  9. package/assets/Dockerfile +5 -14
  10. package/assets/commitlint.config.ts +2 -2
  11. package/assets/eslint.config.js +2 -6
  12. package/assets/lint-staged.config.js +3 -0
  13. package/assets/package.json +41 -31
  14. package/assets/repoctl.config.ts +68 -0
  15. package/assets/stylelint.config.js +2 -2
  16. package/assets/tsconfig.json +1 -49
  17. package/assets/turbo.json +17 -6
  18. package/assets/vitest.config.ts +2 -125
  19. package/assets-data.mjs +3 -2
  20. package/dist/index.d.mts +22 -1
  21. package/dist/index.mjs +114 -32
  22. package/package.json +12 -8
  23. package/template-data.mjs +48 -8
  24. package/templates/cli/bin/index.js +1 -1
  25. package/templates/cli/package.json +5 -2
  26. package/templates/cli/{tsup.config.ts → tsdown.config.ts} +3 -2
  27. package/templates/client/eslint.config.js +5 -5
  28. package/templates/client/gitignore +0 -1
  29. package/templates/client/package.json +22 -22
  30. package/templates/client/vite.config.ts +4 -3
  31. package/templates/client/worker-configuration.d.ts +13557 -0
  32. package/templates/client/wrangler.jsonc +4 -6
  33. package/templates/server/eslint.config.js +8 -0
  34. package/templates/server/gitignore +0 -1
  35. package/templates/server/package.json +9 -8
  36. package/templates/server/src/app.ts +4 -4
  37. package/templates/server/tsconfig.json +1 -2
  38. package/templates/server/{tsup.config.ts → tsdown.config.ts} +2 -1
  39. package/templates/server/vitest.config.ts +7 -5
  40. package/templates/server/worker-configuration.d.ts +13557 -0
  41. package/templates/server/wrangler.jsonc +4 -6
  42. package/templates/tsdown/package.json +2 -1
  43. package/templates/tsdown/test-d/index.test-d.ts +5 -0
  44. package/templates/tsdown/tsconfig.json +1 -2
  45. package/templates/tsdown/vitest.config.ts +7 -5
  46. package/templates/vitepress/.vitepress/config.ts +34 -36
  47. package/templates/vitepress/getting-started.md +243 -0
  48. package/templates/vitepress/gitignore +2 -1
  49. package/templates/vitepress/index.md +144 -79
  50. package/templates/vitepress/monorepo/commands.md +291 -0
  51. package/templates/vitepress/monorepo/index.md +103 -34
  52. package/templates/vitepress/monorepo/manage.md +181 -80
  53. package/templates/vitepress/monorepo/publish.md +128 -57
  54. package/templates/vitepress/monorepo/templates.md +67 -0
  55. package/templates/vitepress/monorepo/troubleshooting.md +226 -0
  56. package/templates/vitepress/package.json +5 -5
  57. package/templates/vitepress/thinking.md +1 -1
  58. package/templates/vitepress/tools/husky.md +7 -2
  59. package/templates/vitepress/tools/lint-staged.md +15 -1
  60. package/templates/vitepress/why/examples/3.npm-basic-package/package-lock.json +605 -2770
  61. package/templates/vitepress/why/examples/3.npm-basic-package/package.json +5 -6
  62. package/templates/vitepress/why/examples/3.npm-basic-package/tsdown.config.ts +16 -0
  63. package/templates/vitepress/why/examples/usage-cjs/index.js +2 -6
  64. package/templates/vitepress/why/examples/usage-cjs/package-lock.json +7 -13
  65. package/templates/vitepress/why/examples/usage-cjs/package.json +2 -2
  66. package/templates/vitepress/why/examples/usage-esm/index.js +2 -2
  67. package/templates/vitepress/why/examples/usage-esm/package-lock.json +7 -13
  68. package/templates/vitepress/why/examples/usage-esm/package.json +2 -2
  69. package/templates/vitepress/why/modern/bundlers.md +19 -46
  70. package/templates/vue-lib/eslint.config.js +4 -4
  71. package/templates/vue-lib/package.json +15 -10
  72. package/templates/vue-lib/test-d/index.test-d.ts +6 -0
  73. package/templates/vue-lib/tsconfig.test.json +1 -1
  74. package/templates/vue-lib/vitest.config.ts +6 -5
  75. package/assets/monorepo.config.ts +0 -22
  76. package/assets/nano-staged.js +0 -18
  77. package/templates/tsup/build.config.ts +0 -24
  78. package/templates/tsup/package.json +0 -49
  79. package/templates/tsup/src/index.ts +0 -12
  80. package/templates/tsup/test/index.test.ts +0 -18
  81. package/templates/tsup/tsconfig.json +0 -15
  82. package/templates/tsup/tsup.config.ts +0 -18
  83. package/templates/tsup/vitest.config.ts +0 -15
  84. package/templates/unbuild/build.config.ts +0 -24
  85. package/templates/unbuild/package.json +0 -49
  86. package/templates/unbuild/src/index.ts +0 -9
  87. package/templates/unbuild/src/utils.ts +0 -5
  88. package/templates/unbuild/test/index.test.ts +0 -18
  89. package/templates/unbuild/tsconfig.json +0 -15
  90. package/templates/unbuild/vitest.config.ts +0 -15
  91. package/templates/vitepress/why/examples/3.npm-basic-package/build.config.ts +0 -24
  92. package/templates/vitepress/why/examples/3.npm-basic-package/tsup.config.ts +0 -16
@@ -2,16 +2,14 @@
2
2
  "$schema": "./node_modules/wrangler/config-schema.json",
3
3
  "name": "monorepo-service",
4
4
  "compatibility_date": "2025-10-16",
5
+ "compatibility_flags": [
6
+ "nodejs_compat"
7
+ ],
5
8
  "main": "./src/fetch-entry.ts",
6
9
  "dev": {
7
10
  "port": 8787
8
11
  },
9
- "routes": [
10
- {
11
- "custom_domain": true,
12
- "pattern": "sls.monorepo.icebreaker.top"
13
- }
14
- ],
12
+ // Add "routes" here when you bind a real custom domain.
15
13
  "observability": {
16
14
  "enabled": true
17
15
  }
@@ -42,7 +42,8 @@
42
42
  "release": "pnpm publish",
43
43
  "lint": "eslint .",
44
44
  "lint:fix": "eslint . --fix",
45
- "typecheck": "tsc -p tsconfig.json"
45
+ "typecheck": "tsc -p tsconfig.json",
46
+ "tsd": "pnpm build && tsd --files test-d/**/*.test-d.ts"
46
47
  },
47
48
  "publishConfig": {}
48
49
  }
@@ -0,0 +1,5 @@
1
+ import { expectType } from 'tsd'
2
+ import { greet, VERSION } from '..'
3
+
4
+ expectType<string>(greet('icebreaker'))
5
+ expectType<'0.0.0'>(VERSION)
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "baseUrl": ".",
5
4
  "paths": {
6
5
  "@/*": [
7
- "src/*"
6
+ "./src/*"
8
7
  ]
9
8
  }
10
9
  },
@@ -1,15 +1,17 @@
1
1
  import path from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { defineVitestProjectConfig } from 'repoctl/tooling'
2
4
  import { defineProject } from 'vitest/config'
3
5
 
4
- export default defineProject({
5
- test: {
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
7
+
8
+ export default defineProject(await defineVitestProjectConfig({
9
+ options: {
6
10
  alias: [
7
11
  {
8
12
  find: '@',
9
13
  replacement: path.resolve(__dirname, './src'),
10
14
  },
11
15
  ],
12
- globals: true,
13
- testTimeout: 60_000,
14
16
  },
15
- })
17
+ }))
@@ -3,13 +3,16 @@ import { defineConfig } from 'vitepress'
3
3
  import { withMermaid } from 'vitepress-plugin-mermaid'
4
4
  // https://vitepress.dev/reference/site-config
5
5
  export default withMermaid(defineConfig({
6
- outDir: '../../dist',
6
+ outDir: '.vitepress/dist',
7
7
  title: 'icebreaker\'s monorepo',
8
- description: 'icebreaker\'s monorepo. upgrade your monorepo',
8
+ description: 'A practical pnpm + turbo monorepo template with short onboarding commands and repo tooling.',
9
9
  themeConfig: {
10
10
  // https://vitepress.dev/reference/default-theme-config
11
11
  nav: [
12
- { text: '使用手册', link: '/' },
12
+ { text: '开始使用', link: '/' },
13
+ { text: '新手指南', link: '/getting-started' },
14
+ { text: 'Monorepo', link: '/monorepo/' },
15
+ { text: '工具专题', link: '/tools/turborepo' },
13
16
  { text: '一些思考', link: '/thinking' },
14
17
  ],
15
18
  socialLinks: [
@@ -22,56 +25,51 @@ export default withMermaid(defineConfig({
22
25
  logo: '/logo.jpg',
23
26
  sidebar: {
24
27
  '/': [
25
- { text: '使用手册', link: '/' },
26
- { text: '一些思考', link: 'thinking' },
27
28
  {
28
- text: 'npm 发包',
29
- base: '/why/',
29
+ text: '开始使用',
30
30
  items: [
31
- { text: '如何复用 js 代码', link: '/how-to-reuse-js-code' },
32
- { text: 'JS 文件的各种后缀', link: '/js-cjs-mjs' },
33
- { text: 'CJS和ESM关键字/全局变量对比', link: '/js-keywords' },
34
- { text: '什么是 npm 包', link: '/what-is-npm-package' },
35
- { text: '如何发布 npm 包', link: '/publish-basic-npm-package' },
36
- {
37
- text: '改进并发布现代 npm 包',
38
- link: 'index',
39
- base: 'why/modern/',
40
- items: [
41
- { text: 'package entry points 字段', link: '/package-entry-points' },
42
- { text: '添加 DTS', link: '/dts' },
43
- { text: 'ESM vs CJS', link: '/esm-vs-cjs' },
44
- { text: '使用 TypeScript', link: '/typescript' },
45
- { text: '使用打包器', link: '/bundlers' },
46
- ],
47
- },
31
+ { text: '首页', link: '/' },
32
+ { text: '新手使用指南', link: '/getting-started' },
33
+ { text: '一些思考', link: '/thinking' },
48
34
  ],
49
35
  },
50
36
  {
51
37
  text: 'Monorepo',
52
- base: '/monorepo/',
53
38
  items: [
54
- { text: '为什么往 monorepo 方向演进', link: '/' },
55
- { text: '如何管理 monorepo', link: '/manage' },
56
- { text: 'monorepo 发包生成变更日志', link: '/publish' },
39
+ { text: '为什么往 monorepo 方向演进', link: '/monorepo/' },
40
+ { text: '如何管理 monorepo', link: '/monorepo/manage' },
41
+ { text: '模板速查', link: '/monorepo/templates' },
42
+ { text: '命令速查', link: '/monorepo/commands' },
43
+ { text: '常见问题排障', link: '/monorepo/troubleshooting' },
44
+ { text: '发包与变更日志', link: '/monorepo/publish' },
45
+ ],
46
+ },
47
+ {
48
+ text: 'npm 与包',
49
+ items: [
50
+ { text: '如何复用 js 代码', link: '/why/how-to-reuse-js-code' },
51
+ { text: 'JS 文件的各种后缀', link: '/why/js-cjs-mjs' },
52
+ { text: 'CJS 和 ESM 关键字/全局变量对比', link: '/why/js-keywords' },
53
+ { text: '什么是 npm 包', link: '/why/what-is-npm-package' },
54
+ { text: '如何发布 npm 包', link: '/why/publish-basic-npm-package' },
55
+ { text: '改进并发布现代 npm 包', link: '/why/index' },
57
56
  ],
58
57
  },
59
58
  {
60
59
  text: '相关的工具',
61
- base: '/tools/',
62
60
  items: [
63
- { text: 'pnpm', link: '/pnpm' },
64
- { text: 'turborepo', link: '/turborepo' },
65
- { text: 'changeset', link: '/changeset' },
66
- { text: 'husky', link: '/husky' },
67
- { text: 'lint-staged', link: '/lint-staged' },
68
- { text: 'renovate', link: '/renovate' },
61
+ { text: 'pnpm', link: '/tools/pnpm' },
62
+ { text: 'turborepo', link: '/tools/turborepo' },
63
+ { text: 'changeset', link: '/tools/changeset' },
64
+ { text: 'husky', link: '/tools/husky' },
65
+ { text: 'lint-staged', link: '/tools/lint-staged' },
66
+ { text: 'renovate', link: '/tools/renovate' },
69
67
  ],
70
68
  },
71
69
  ],
72
70
  },
73
71
  editLink: {
74
- pattern: 'https://github.com/sonofmagic/monorepo-template/edit/main/apps/website/:path',
72
+ pattern: 'https://github.com/sonofmagic/monorepo-template/edit/main/templates/vitepress/:path',
75
73
  text: '为此页提供修改建议',
76
74
  },
77
75
  },
@@ -0,0 +1,243 @@
1
+ ---
2
+ layout: doc
3
+ ---
4
+
5
+ # 新手使用指南
6
+
7
+ 这篇指南按第一次接手仓库的顺序写。你不需要先理解所有工具,只要先把仓库跑起来,再慢慢看更细的命令。
8
+
9
+ ## 你需要先准备什么
10
+
11
+ - Node.js 20 或更高版本。
12
+ - pnpm。推荐通过 Corepack 启用:`corepack enable`。
13
+ - Git。`repo doctor` 会读取仓库信息,用来补全新包的 repository、bugs 和 author。
14
+
15
+ 确认版本:
16
+
17
+ ```bash
18
+ node -v
19
+ pnpm -v
20
+ git --version
21
+ ```
22
+
23
+ ## 第一次进入仓库
24
+
25
+ ```bash
26
+ pnpm install
27
+ pnpm setup
28
+ pnpm doctor
29
+ ```
30
+
31
+ 这三步分别解决三件事:
32
+
33
+ | 命令 | 作用 |
34
+ | -------------- | ---------------------------------- |
35
+ | `pnpm install` | 安装 workspace 依赖 |
36
+ | `pnpm setup` | 同步推荐的根脚本、配置和工具链入口 |
37
+ | `pnpm doctor` | 检查当前仓库能不能顺利开始开发 |
38
+
39
+ 如果 `doctor` 报错,先按输出里的 `fix:` 处理。处理完再跑一次 `pnpm doctor`,直到没有 blocking issue。
40
+
41
+ 如果要在 CI 或脚本里读取诊断结果:
42
+
43
+ ```bash
44
+ pnpm exec repo doctor --json
45
+ pnpm exec repo doctor --json --out reports/doctor.json
46
+ ```
47
+
48
+ 如果希望 CI 把建议项也当成失败,使用 strict 模式:
49
+
50
+ ```bash
51
+ pnpm exec repo doctor --strict
52
+ pnpm exec repo doctor --strict --json --out reports/doctor.json
53
+ ```
54
+
55
+ ## 创建第一个包或应用
56
+
57
+ 不知道要用哪个模板时,先看列表:
58
+
59
+ ```bash
60
+ pnpm exec repo templates
61
+ ```
62
+
63
+ 只看库包模板:
64
+
65
+ ```bash
66
+ pnpm exec repo templates --category library
67
+ ```
68
+
69
+ 常用模板:
70
+
71
+ | 模板 | 适合什么 |
72
+ | ------------- | ----------------- |
73
+ | `tsdown` | TypeScript 库包 |
74
+ | `vue-lib` | Vue 3 组件库 |
75
+ | `vue-hono` | Vue 3 + Hono 应用 |
76
+ | `hono-server` | Hono API 服务 |
77
+ | `vitepress` | 文档站 |
78
+ | `cli` | 命令行工具 |
79
+
80
+ 创建时可以走交互式:
81
+
82
+ ```bash
83
+ pnpm new
84
+ ```
85
+
86
+ 也可以直接指定:
87
+
88
+ ```bash
89
+ pnpm new my-lib --template tsdown
90
+ pnpm new website --template vitepress
91
+ pnpm new api --template hono-server
92
+ ```
93
+
94
+ 创建前想先确认目标目录:
95
+
96
+ ```bash
97
+ pnpm new website --template vitepress --dry-run
98
+ pnpm new website --template vitepress --json
99
+ pnpm new website --template vitepress --json --out plans/website.json
100
+ ```
101
+
102
+ 如果模板 key 拼错,CLI 会直接失败并提示最接近的模板 key;它不会静默回退到默认模板。
103
+ `--json` 用于脚本读取创建计划,隐含 `--dry-run`,不会写入文件。
104
+ `--out` 会把创建计划写入文件,也隐含 `--dry-run`。
105
+
106
+ 普通名字会自动放进合适目录,比如库包放到 `packages/`,应用放到 `apps/`。如果你传入了带 `/` 的路径,例如 `packages/shared-utils`,CLI 会尊重这个路径。
107
+
108
+ ## 开发时怎么跑
109
+
110
+ 先看新建 workspace 的 `package.json`,确认它提供了哪些脚本。常见流程是:
111
+
112
+ ```bash
113
+ pnpm dev
114
+ pnpm build
115
+ pnpm typecheck
116
+ pnpm test
117
+ ```
118
+
119
+ 整仓命令由 Turborepo 调度。你在根目录执行 `pnpm build`,会构建所有声明了 `build` 脚本的 workspace 包。
120
+
121
+ ## 提交前检查
122
+
123
+ 提交前推荐按这个顺序跑:
124
+
125
+ ```bash
126
+ pnpm build
127
+ pnpm lint
128
+ pnpm typecheck
129
+ pnpm test
130
+ ```
131
+
132
+ 如果只是想跑模板推荐的本地检查:
133
+
134
+ ```bash
135
+ pnpm check
136
+ ```
137
+
138
+ 如果你改了公开类型 API,并且对应包有 `tsd`:
139
+
140
+ ```bash
141
+ pnpm tsd
142
+ ```
143
+
144
+ ## 什么时候用 repo 命令
145
+
146
+ 生成仓库里优先记住短命令:
147
+
148
+ | 日常命令 | 等价 CLI |
149
+ | ------------- | ----------------------- |
150
+ | `pnpm setup` | `pnpm exec repo setup` |
151
+ | `pnpm new` | `pnpm exec repo new` |
152
+ | `pnpm doctor` | `pnpm exec repo doctor` |
153
+ | `pnpm check` | `pnpm exec repo check` |
154
+
155
+ 需要更细的能力时再用 `repo`:
156
+
157
+ ```bash
158
+ pnpm exec repo templates
159
+ pnpm exec repo env paths
160
+ pnpm exec repo env support --json --out reports/support.json
161
+ pnpm exec repo config inspect
162
+ pnpm exec repo ws ls
163
+ pnpm exec repo ws ls --json --out reports/workspaces.json
164
+ pnpm exec repo tg init --all
165
+ pnpm exec repo upgrade
166
+ ```
167
+
168
+ `repoctl`、`monorepo`、`rc`、`mo` 这些入口仍然兼容。新项目文档统一推荐 `repo`,减少新人记忆负担。
169
+
170
+ ## 更新模板标准资产
171
+
172
+ 当模板仓库升级后,可以同步最新推荐配置:
173
+
174
+ ```bash
175
+ pnpm exec repo upgrade
176
+ pnpm doctor
177
+ ```
178
+
179
+ 如果只想同步核心配置,跳过 GitHub、Renovate、开源社区文件:
180
+
181
+ ```bash
182
+ pnpm exec repo upgrade --core
183
+ ```
184
+
185
+ 如果你不希望覆盖已有文件:
186
+
187
+ ```bash
188
+ pnpm exec repo upgrade --skip-overwrite
189
+ ```
190
+
191
+ ## 常见问题
192
+
193
+ ### 提示目录已经存在
194
+
195
+ `pnpm new` 不会覆盖已有目录。换一个名字,或者手动处理已有目录后再创建。
196
+
197
+ ### 不知道模板 key 怎么写
198
+
199
+ 运行:
200
+
201
+ ```bash
202
+ pnpm exec repo templates
203
+ ```
204
+
205
+ 查看单个模板详情:
206
+
207
+ ```bash
208
+ pnpm exec repo templates tsdown
209
+ ```
210
+
211
+ 需要给脚本读取时:
212
+
213
+ ```bash
214
+ pnpm exec repo templates --json
215
+ ```
216
+
217
+ ### `repoctl.config.ts` 和 `monorepo.config.ts` 同时存在
218
+
219
+ 只保留一个。推荐保留 `repoctl.config.ts`,旧文件名仅作为兼容入口。
220
+
221
+ ### 新建包之后依赖没装上
222
+
223
+ 新建模板只负责生成文件。生成后回到根目录运行:
224
+
225
+ ```bash
226
+ pnpm install
227
+ ```
228
+
229
+ 然后再跑:
230
+
231
+ ```bash
232
+ pnpm build
233
+ pnpm typecheck
234
+ pnpm test
235
+ ```
236
+
237
+ ## 下一步
238
+
239
+ - 想看完整命令:[命令速查](./monorepo/commands.md)
240
+ - 想选择合适模板:[模板速查](./monorepo/templates.md)
241
+ - 想理解 workspace 管理:[如何管理 monorepo](./monorepo/manage.md)
242
+ - 遇到校验问题:[常见问题排障](./monorepo/troubleshooting.md)
243
+ - 准备发包:[发包与变更日志](./monorepo/publish.md)
@@ -1 +1,2 @@
1
- .vitepress/cache
1
+ .vitepress/cache
2
+ .vitepress/dist