TypeScript monorepo (@rtpackx/toolkit),提供 Vue、React、NestJS、Vite 等框架的工具库。使用 pnpm workspaces,核心工具在 core 包中,其他框架包依赖 core。
packages/
├── core/ - 框架无关的工具函数(基础层)
├── vue/ - Vue 3 composables
├── react/ - React hooks(当前为空)
├── nestjs/ - NestJS 装饰器和工具
└── vite/ - Vite 插件
框架无关的工具库,导出:
utils/- 纯工具函数:is.ts(类型判断、IP/域名验证)、trait.ts(接口定义)、string.ts、time.tsuse-cache/- 内存缓存(基于 Map,支持 TTL 过期)use-spliter/- 分隔工具indexdb/- IndexedDB 封装monitor/- 性能/错误监控
Vue 3 composables,依赖 @rtpackx/core,peerDependencies: vue@^3.0.0, vue-router@^4.0.0
use-ext-router/- 路由扩展(resetRouter, addRoutes, deepDelete, goBackOrDefault)use-replace-state/- 状态替换use-route-listener/- 路由监听use-select/- 选择器use-switchable/- 可切换状态use-tree/- 树形数据处理(支持 checkbox 半选、父子联动)
React hooks 库,当前为空包
NestJS 工具库
Assert.ts- 运行时断言工具,使用 NestJS 异常
Vite 插件
lazyload-normalize/- 懒加载规范化staticload-normalize/- 静态加载规范化compress/- 压缩插件(已注释,存在构建问题)
# 安装依赖
pnpm install
# 构建
pnpm build # 构建源码 + 类型声明
pnpm build:dts # 仅构建类型声明
tsx scripts/build.ts # 仅构建源码
# 代码检查
pnpm lint # 检查代码风格
pnpm lint:fix # 修复代码风格
# 测试
pnpm test # 运行 vitest
# 发布
pnpm release # 升级版本、创建 tag、生成 changelog
pnpm push # 推送 commit 和 tag
pnpm publish:r # 发布并推送@rtpackx/core是基础包,其他包都依赖它@rtpackx/vue依赖 core,需要vue和vue-router作为 peer dependencies- 每个包输出 ESM (.mjs) 和 CommonJS (.cjs) 格式,以及 TypeScript 声明 (.d.ts)
- 包配置:
meta/packages.ts- 定义入口点、输出目录、外部依赖 - 构建脚本:
scripts/build.ts- 使用 Vite 打包,移除 console/debuggerscripts/build-dts.ts- 使用 rollup 生成类型声明
- 别名配置:
meta/alias.ts-@指向 packages 目录
// 工具类型
type ValueType<T, K extends keyof T> = T[K]
type UnionNull<T> = T | null
type UnionUndefined<T> = T | undefined
type UnionNone<T> = UnionNull<T> | UnionUndefined<T>
type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> }
// 常见类型
type Unit<T = unknown> = T extends unknown ? string | number : string | number | T
type BaseType = string | number
type UnionType = BaseType | Record<string, any>
type Data = Record<string, any>
// 树形类型
interface IOption<T extends Unit = Unit> {
key: string | number
label: string
value: T
[k: string]: any
}
interface TreeNode<T extends Unit = Unit> {
key: string | number
label: string
value: T
icon?: string
count?: number
children?: TreeNode<T>[]
[k: string]: any
}
interface FieldNames {
key: string
label: string
title: string
value: string
icon: string
count: string
parent: string
children: string
[k: string]: any
}Composable 模式: 以 use- 前缀的函数返回方法对象(非响应式 ref)
export function useCache() {
const cache = new Map<string, CacheItem<any>>();
return { get, set, deleteKey, clear };
}Tree 组件模式: 支持 checkbox 半选、父子联动、字段别名配置
interface TreeOption {
fieldNames: { id: string; parent: string; children: string; }
}- 提交规范: conventional commits (@commitlint/config-conventional)
- 发布流程:
scripts/release.ts使用 bumpp 升级版本,自动生成 CHANGELOG
- pnpm@10.23.0
- Node >=20.0.0