setup-ts-deep-modules
Agent skill fromvinvcn/mattpocock-skills-zh-CN
在 TypeScript repo 中接入 dependency-cruiser,让每个 package 成为 deep module:implementation 隐藏在 subfolders 中,只能通过 entry-point files 访问。User-invoked。
How to install setup-ts-deep-modules
install setup-ts-deep-modules
# install the mattpocock-skills-zh-CN pack with the skills CLI
npx skills add vinvcn/mattpocock-skills-zh-CN# or add only this skill to Claude Code: copy the folder
skills/in-progress/setup-ts-deep-modules/
# into
~/.claude/skills/setup-ts-deep-modules/ (all projects)
.claude/skills/setup-ts-deep-modules/ (one project)
1# Setup TS Deep Modules23让 repo 中每个 package 成为 **deep module**:用小 interface 隐藏大量 behaviour。Package 的 public surface 是其 **entry points**(package root 中的 files),所有 subfolders 都隐藏。这个 skill 会安装 [dependency-cruiser](https://github.com/sverweij/dependency-cruiser),加入强制只能通过 entry points 访问的 rules,并证明这些 rules 确实会拦截违规。45Vocabulary(deep module、interface、seam、depth)来自调用 Skill 工具并指定 `codebase-design`;整个过程都使用它的语言。67## The shape this enforces89```10src/packages/11 <name>/12 index.ts ← an entry point (public). Import this from outside.13 client.ts ← another entry point. Packages may expose SEVERAL.14 lib/ ← implementation: hidden from outside, free to import each other.15 tests/ ← co-located tests + fixtures (a subfolder, so private).16```1718Public surface 是 package 的 **root files**,并非指定的单个 `index.ts`。按 convention,implementation 放在 `lib/`,tests 放在 `tests/`,使所有 packages 采用相同的 two-folder shape。Rule 本身是通用的:*任何* subfolder 中的*任何*内容都是 private,因此永远无需为了新增 folder 扩展 config。1920四条 rules,全部为 `error`:21221. **Entry-point boundary** — package 外的 code(app code 或其他 package)只能 import 该 package 的 entry points(root files),不能 import subfolder 中的任何内容。232. **Intra-package freedom** — package 自己的 files 可以自由互相 import。243. **Tests through the entry points** — `<pkg>/tests/` 下的 files 可以 import 任意 package 的 entry points 和自己的 `tests/` fixtures,但不能 import 任何 package 的 subfolder internals(包括自己的)。允许跨 package integration tests,不允许 deep imports。254. **No cycles** — 不允许 dependency cycles。26…
Excerpt shown under the repository's MIT license.
