Skip to content

Commit 4bb52ef

Browse files
authored
Merge pull request #5 from GreatAuk/bump-dep
Bump dep
2 parents 12e7afe + 9fd5323 commit 4bb52ef

File tree

21 files changed

+2595
-291
lines changed

21 files changed

+2595
-291
lines changed

CLAUDE.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## 项目概述
6+
7+
Utopia-Utils 是一个 TypeScript monorepo 工具库集合,使用 pnpm workspaces 管理多个子包。主要包含以下子包:
8+
- `@utopia-utils/core` - 核心工具函数集合(数组、对象、函数、Promise、字符串、数值等)
9+
- `@utopia-utils/dom` - DOM 和浏览器环境相关工具
10+
- `@utopia-utils/tree` - 树结构操作工具
11+
- `@utopia-utils/vueuse` - Vue 3 Composables
12+
- `@utopia-utils/share` - 类型判断和共享工具
13+
- `@utopia-utils/cli` - CLI 工具函数
14+
- `@utopia-utils/type` - 类型定义
15+
16+
## 常用命令
17+
18+
### 构建和开发
19+
```bash
20+
# 构建所有包(会先检查依赖是否过时)
21+
pnpm build
22+
23+
# 开发模式运行示例项目
24+
pnpm example
25+
26+
# 清理所有包的构建产物
27+
pnpm clean
28+
29+
# 类型检查
30+
pnpm typecheck
31+
```
32+
33+
### 测试
34+
```bash
35+
# 运行所有测试(watch 模式)
36+
pnpm test
37+
38+
# 运行单次测试
39+
pnpm test:once
40+
41+
# 测试单个文件
42+
pnpm test:once packages/dom/src/styleUtil.test.ts
43+
44+
# 生成测试覆盖率报告
45+
pnpm coverage
46+
```
47+
48+
### 代码质量
49+
```bash
50+
# 运行 linter(oxlint)
51+
pnpm lint
52+
53+
# 自动修复 lint 问题
54+
pnpm lint:fix
55+
```
56+
57+
### 发布
58+
```bash
59+
# 版本发布(会先检查依赖是否过时)
60+
pnpm release
61+
```
62+
63+
## 项目架构
64+
65+
### Monorepo 结构
66+
- 使用 **pnpm workspaces** 管理多包
67+
- 使用 **Turbo** 进行构建优化和缓存
68+
- 使用 **tsdown** 构建各个子包
69+
- 使用 **Vitest** 进行单元测试
70+
71+
### 构建系统
72+
- 每个子包都有独立的 `tsdown.config.ts` 配置
73+
- 构建产物输出到各包的 `dist/` 目录
74+
- 支持 sourcemap、类型声明文件生成
75+
- 生产环境自动 minify
76+
77+
### 依赖管理
78+
- 使用 `stale-dep` 在构建、测试、发布前自动检查过时依赖
79+
- 子包之间使用 `workspace:*` 协议互相引用
80+
- 强制使用 pnpm(preinstall hook)
81+
82+
## 测试规范
83+
84+
### 测试文件命名和位置
85+
- 测试文件命名:`[function-name].test.ts`
86+
- **测试文件与源文件放在同一目录下**
87+
- 使用 TypeScript 编写
88+
89+
### 测试框架配置
90+
- 使用 **Vitest**,启用全局变量模式(`globals: true`
91+
- **DOM 相关测试自动使用 happy-dom 环境**`packages/dom/**` 下的所有测试)
92+
- 非 DOM 测试使用默认 node 环境
93+
- 如果在非 `packages/dom` 下需要 DOM 环境,在文件头部添加:`/** @vitest-environment happy-dom */`
94+
95+
### 测试用例结构
96+
- 使用 `describe` 描述测试套件,命名与被测试函数相同
97+
- 使用 `it` 描述具体测试用例
98+
- 测试分类:正常路径、边界情况、错误处理、类型安全
99+
- 遵循 AAA 模式:Arrange(准备)、Act(执行)、Assert(断言)
100+
101+
### Mock 和清理
102+
```typescript
103+
import { describe, expect, it, afterEach, vi } from 'vitest'
104+
105+
describe('functionName', () => {
106+
afterEach(() => {
107+
vi.restoreAllMocks()
108+
})
109+
110+
// 测试用例...
111+
})
112+
```
113+
114+
### 测试覆盖率
115+
- 核心业务逻辑应达到 100% 覆盖率
116+
- 覆盖所有分支和边界条件
117+
- `index.ts` 导出文件被排除在覆盖率统计之外
118+
119+
## 代码风格
120+
121+
### 注释规范
122+
- 在 JS/TS 代码中,变量名和函数名使用 `/** */` 进行注释
123+
- 测试代码中使用多行注释格式:`/* 注释内容 */`
124+
125+
### 类型安全
126+
- 启用严格模式(`strict: true`
127+
- 启用 `isolatedDeclarations` 用于类型声明
128+
- 所有导出的函数都应有完整的类型定义
129+
130+
### 第三方库复用
131+
`@utopia-utils/core` 重新导出了以下优秀的第三方库:
132+
- `debounce` / `throttle` - 来自 throttle-debounce
133+
- `Cookies` - 来自 js-cookie
134+
- `mitt` - 事件发布/订阅
135+
- `merge` / `merge.all` - 来自 deepmerge
136+
- `NP` - 来自 number-precision
137+
138+
## 开发注意事项
139+
140+
### 新增工具函数
141+
1. 在对应子包的 `src/` 目录下创建功能文件
142+
2. 在同一目录创建对应的 `.test.ts` 测试文件
143+
3. 在子包的 `src/index.ts` 中导出
144+
4. 如果是 core 包,需要在根目录 README.md 中添加 API 文档
145+
146+
### 树结构工具的特点
147+
所有 tree utils 支持自定义字段名(`fieldNames`):
148+
```typescript
149+
interface FieldNames {
150+
id?: string
151+
children?: string
152+
parentId?: string
153+
}
154+
```
155+
156+
### Node 版本要求
157+
- Node >= 22.16.0
158+
- pnpm >= 10.8.0
159+
160+
### 构建输出
161+
- 所有包输出 ESM 格式(`.mjs`
162+
- 类型定义文件后缀为 `.d.mts`
163+
- 使用 `fixedExtension: true` 确保扩展名一致性

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
"@types/node": "^18.14.6",
4040
"@vitest/coverage-v8": "^3.2.4",
4141
"bumpp": "^9.0.0",
42-
"oxlint": "^1.32.0",
42+
"oxlint": "^1.35.0",
4343
"rimraf": "^4.4.0",
4444
"stale-dep": "^0.8.2",
45-
"tsdown": "^0.17.3",
45+
"tsdown": "^0.18.3",
4646
"tsx": "^3.12.3",
4747
"turbo": "^2.5.4",
4848
"typescript": "^5.8.3",

packages/cli/tsdown.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const config: UserConfigFn | UserConfig = defineConfig((options) => {
88
},
99
sourcemap: true,
1010
clean: true,
11-
dts: true,
11+
dts: {
12+
sourcemap: true,
13+
},
1214
fixedExtension: true,
1315
minify: !options.watch,
1416
}

0 commit comments

Comments
 (0)