跳到正文
cccskills
免费在 GitHub 公开中文介绍

setup-ts-deep-modules

为 TypeScript 项目配置包边界检查,检测外部对包内部文件的直接引用和循环依赖。以包根目录文件作为公开入口,并完成示例、验证和文档。

原文查看原文说明

Wire dependency-cruiser into a TypeScript repo so each package is a deep module, with implementation hidden in subfolders and reachable only through its entry-point files. User-invoked.

AI 评分100分/ 100查看安装方法

适用场景

  • 防止直接引用包内部文件
  • 在类型检查时一并检查包边界
  • 创建可复制的包模板
  • 向智能体共享公开接口约定

中文介绍

功能

将 TypeScript 包整理为通过少量公开文件访问内部功能的结构。安装 dependency-cruiser,检测外部对包内子目录的直接引用及循环依赖。包根目录下的文件构成公开接口,因此可以设置多个入口。测试也必须通过公开文件验证行为。

适用场景

适合包内部实现被项目各处引用、导致修改困难的开发工作。也适合将边界检查纳入与类型检查相同的检查命令,并通过示例和文档共享后续开发约定。

使用示例

  • “添加边界检查,让其他代码只能通过公开文件引用包。”
  • “创建一个可复制的包示例,并确认检查能够发现违规引用。”

验证过程包括:正常示例通过检查,直接引用内部文件时检查失败,修复后再次通过。

注意事项

此技能须由用户明确调用。它会将 dependency-cruiser 添加为开发依赖,并把规则合并到现有配置中。包之间允许的依赖方向需要另外配置;不支持包内嵌套其他包。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

客观评估

AI 仅根据 SKILL.md 的内容,从 4 个方面进行了评估。星标数和热度不计入评估。

指令清晰度能否看出何时使用、做什么
A良好明确须主动调用,并列出入口、内部引用、测试和循环依赖四项规则。
步骤具体性步骤、输入输出和示例是否具体
A良好从环境识别到文档编写分为七步,并验证通过、失败和再次通过。
安全性发送数据、删除文件、执行命令等是否有说明
A良好明确合并而非覆盖现有配置,并撤销验证时临时加入的违规引用。
安装难易度所需工具和 API 密钥是否少且有说明
A良好说明了如何识别包管理器并安装 dependency-cruiser。

总分按每项 A=25 分、B=15 分、C=5 分相加。 由 AI(OpenAI Codex)于 2026年10月19日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(3)

  • SKILL.md7.4 KB
  • agents/openai.yaml149 B
  • dependency-cruiser.config.cjs3.6 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Setup TS Deep Modules

Make every package in this repo a deep module: a lot of behaviour behind a small interface. A package's public surface is its entry points (the files at the package root), and everything in its subfolders is hidden. This skill installs dependency-cruiser and the rules that make the entry points the only way in, then proves the rules bite.

For the vocabulary (deep module, interface, seam, depth), call the Skill tool with "codebase-design" and use its language throughout.

The shape this enforces

src/packages/
  <name>/
    index.ts        ← an entry point (public). Import this from outside.
    client.ts       ← another entry point. Packages may expose SEVERAL.
    lib/            ← implementation: hidden from outside, free to import each other.
    tests/          ← co-located tests + fixtures (a subfolder, so private).

The public surface is the package's root files, not one designated index.ts. By convention implementation lives in lib/ and tests in tests/, giving every package the same two-folder shape. The rule itself is general, though: anything in any subfolder is private, so you never extend the config to add a folder.

Four rules, all error:

  1. Entry-point boundary: code outside a package (app code or another package) may import only that package's entry points (its root files), never anything in its subfolders.
  2. Intra-package freedom: a package's own files import each other freely.
  3. Tests through the entry points: files under <pkg>/tests/ may import any package's entry points and their own tests/ fixtures, but never any package's subfolder internals (not even their own). Integration tests across packages are fine; deep imports are not.
  4. No cycles: no dependency cycles.

Entry points, not a barrel. Because the public surface is every root file, a package can expose several small entry points (index.ts, client.ts, server.ts) instead of funnelling everything through one giant index.ts. Barrel files that re-export a whole subtree are discouraged; keep entry points small and hide implementation in subfolders.

Layering (which packages may depend on which) is a different concern and is left as a commented stub in the config for this repo to fill in.

Steps

1. Detect the environment

  • Package manager: pnpm-lock.yaml → pnpm, yarn.lock → yarn, bun.lockb → bun, else npm. Use it for every command below (pnpm/yarn/npm run/bunx).
  • Packages root: if src/ exists use src/packages, else packages. Confirm the choice with the user if the repo already has a different obvious convention.
  • Existing config: check for a .dependency-cruiser.* file. If one exists, do not overwrite it: merge the four rules and the options in, and tell the user what you added.

Done when: package manager, packages root, and existing-config status are all known.

2. Install dependency-cruiser

Install dependency-cruiser as a devDependency with the detected package manager.

Done when: dependency-cruiser is in devDependencies.

3. Write the config

Copy dependency-cruiser.config.cjs to the repo root as .dependency-cruiser.cjs. Set PACKAGES_ROOT to the root detected in step 1. The rules are path-depth based and extension-agnostic, so nothing else needs adapting.

Done when: .dependency-cruiser.cjs exists with the correct PACKAGES_ROOT, and the four forbidden rules are present.

4. Wire it into the checks

  • Add a lint:boundaries script: depcruise <packages-root> (or depcruise src).
  • Fold it into the repo's umbrella check command, the one that already runs typecheck (e.g. a check / ci / validate script). Do not touch tsconfig or add path aliases.
  • If there is no umbrella script, add lint:boundaries and tell the user to include it in CI.

Done when: lint:boundaries exists and runs as part of the same command as typecheck.

5. Scaffold the example package

Create a committed <packages-root>/example/ as a copy-me template:

  • index.ts is an entry point. Export one function that delegates to an internal file (so the package is visibly deep, not a pass-through).
  • lib/impl.ts: an internal file in a subfolder, imported by index.ts, not reachable from outside.
  • tests/example.test.ts imports only ../index (an entry point) and asserts against the public function.

Tell the user this is a starter template to copy or delete.

Done when: the example package exists, exposes its behaviour through a root entry point, and hides impl in a subfolder.

6. Prove the rules bite

This is the completion criterion for the whole skill: a config that doesn't fail on a violation is worthless.

  1. Run lint:boundaries. It must pass on the clean example.
  2. Temporarily add a deep import to tests/example.test.ts (e.g. import { thing } from "../lib/impl"). Run lint:boundaries again; it must fail with tests-through-entrypoints.
  3. Revert the deep import. Run once more, and it must pass.

Done when: you have observed a pass, then a fail on the deep import, then a pass again. If step 2 does not fail, the rules are not wired correctly, so fix before finishing.

7. Document the convention

Write a README.md in the packages folder (<packages-root>/README.md, next to the packages it governs) covering: the src/packages/<name>/ layout (entry points at the root, lib/ for implementation, tests/ for tests), "import only through a package's entry points (its root files)", and how to run lint:boundaries. Discourage barrel files explicitly: expose several small entry points instead of re-exporting a whole subtree through one index. Keep it to the copy-me snippet plus the four rules in one paragraph each.

Then add a context pointer to it from the repo's agent-instructions file (CLAUDE.md if present, else AGENTS.md, creating AGENTS.md if neither exists). One line is enough, e.g. Packages are deep modules: see [src/packages/README.md](./src/packages/README.md) before adding or importing one. This is what makes an agent discover the boundary rule instead of tripping over it.

Done when: <packages-root>/README.md exists and discourages barrels, and the repo's CLAUDE.md/AGENTS.md links to it.

Notes

  • The config's $1 back-references (dependency-cruiser's group matching) are what let a package reach its own internals while outsiders can't. Don't flatten them into separate per-package rules.
  • Public vs private is decided by depth: a package's root files are entry points; anything in a subfolder is private. The conventional subfolders are lib/ (implementation) and tests/, but the rule doesn't hardcode them: any subfolder is private, so a new folder never needs a config change. Adding an entry point is just adding a root file (no barrel).
  • Packages are flat: one tier of immediate children under the root. A package's internals may nest as deep as you like; a package may not contain another package.
  • Use .cjs (not .js) so the config's module.exports works even in "type": "module" repos.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

ask-matt

免费有简介AI 评分 90分

根据任务的规模和阶段,指导你选择相关技能及其使用顺序,涵盖想法梳理、实现和故障排查,帮助确定下一步以及如何衔接后续工作。

  • 选择从想法到实现的步骤
  • 确定故障排查的起点
  • 规划分多次会话完成的开发
mattpocock/skills29.6万2026年10月13日 更新

chief-of-staff

免费有简介AI 评分 60分

在单次会话中协调承担不同任务的子智能体,推进长期目标。后台工作与用户对话同时进行,并改进共享规范、工作环境和后续任务所需的信息访问条件。

  • 协调长期目标中的任务分工
  • 后台推进工作并持续对话
  • 改进共享规范和工作环境
mattpocock/skills29.6万2026年10月13日 更新

claude-handoff

免费有简介AI 评分 90分

将进行中的对话整理为交接摘要,移除敏感信息,明确后续重点、参考资料和建议技能,再启动新的后台智能体,从当前工作目录继续处理任务。

  • 将后续工作交给新的智能体
  • 限定下一次会话的任务范围
  • 整理下一次会话所需的参考资料
mattpocock/skills29.6万2026年10月13日 更新

code-review

免费有简介AI 评分 90分

以指定提交、分支或标签为基准,从开发规范和原始需求两个角度审查代码变更。分别报告规范问题与需求缺漏,便于独立判断两方面的结果。

  • 审查分支或PR的变更
  • 检查指定提交或标签之后的变更
  • 对照已记录的开发规范
mattpocock/skills29.6万2026年10月13日 更新

codebase-design

免费有简介AI 评分 90分

帮助设计用法精简、内部集中处理复杂逻辑的模块。通过统一术语和判断标准,评估模块是否易用、实现替换位置是否合适,以及是否便于测试。

  • 简化模块的调用方式
  • 集中分散的复杂逻辑
  • 选择可替换实现的位置
mattpocock/skills29.6万2026年10月13日 更新

diagnosing-bugs

免费有简介AI 评分 80分

通过能检测具体症状的测试或脚本,调查难以复现的故障和性能下降。缩小失败条件,验证多个原因假设,完成修复后检查原始复现流程及防止复发的测试。

  • 调查难以复现的错误
  • 查找处理速度下降的原因
  • 重复验证间歇性故障
mattpocock/skills29.6万2026年10月13日 更新

查看 mattpocock 的全部技能

报告此技能的问题