setup-ts-deep-modules
하는 일
의존성 검사기와 규칙을 설치해, 코드가 패키지의 숨겨진 부분에 직접 접근하지 못하도록 막습니다. 여러 패키지로 이루어진 TypeScript 프로젝트를 다루는 개발자를 위한 스킬입니다.
사용하는 경우
- ✓TypeScript 저장소의 각 패키지가 작은 공개 인터페이스를 갖기를 원할 때.
- ✓다른 코드가 건드리지 말아야 할 내부 파일을 계속 가져올 때.
- ✓잘못된 가져오기를 자동으로 잡아내는 규칙을 원할 때.
스킬 링크
https://github.com/mattpocock/skills/blob/main/skills/in-progress/setup-ts-deep-modules/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“다른 패키지가 각 패키지의 진입 파일에서만 가져올 수 있도록 우리 TypeScript 저장소를 설정해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 dependency-cruiser를 설치하고 오류 규칙 네 개를 추가한 뒤, 규칙이 실제 위반을 잡아내는지 확인합니다. 구현 코드는 lib 폴더에, 테스트는 tests 폴더에 둡니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
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:
- 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.
- Intra-package freedom: a package's own files import each other freely.
- Tests through the entry points: files under
<pkg>/tests/may import any package's entry points and their owntests/fixtures, but never any package's subfolder internals (not even their own). Integration tests across packages are fine; deep imports are not. - 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 usesrc/packages, elsepackages. 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:boundariesscript:depcruise <packages-root>(ordepcruise src). - Fold it into the repo's umbrella check command, the one that already runs typecheck (e.g. a
check/ci/validatescript). Do not touchtsconfigor add path aliases. - If there is no umbrella script, add
lint:boundariesand 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.tsis 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 byindex.ts, not reachable from outside.tests/example.test.tsimports only../index(an entry point) and asserts ag
자주 묻는 질문
어떤 도구를 설치하나요?
코드 파일들이 서로를 어떻게 가져오는지 점검하는 도구인 dependency-cruiser를 설치합니다.
외부 코드에서 어떤 폴더가 숨겨지나요?
패키지의 하위 폴더, 예를 들어 lib와 tests에 있는 것은 모두 비공개로 취급됩니다.
규칙이 작동하는지도 테스트하나요?
예. 규칙이 실제로 위반을 잡는지 확인하므로, 규칙이 작동한다는 것을 알 수 있습니다.
상세 정보
작성자의 원본 설명
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.
repo: mattpocock/skills
인기도
- GitHub 스타
- 310k
- 순위
- #115
- 라이선스
- MIT
- 업데이트
- 2026. 11. 1.
댓글
- …
이 저장소의 다른 스킬
ask-matt
310k에이전트가 아이디어에서 배포된 코드까지 이어지는 코딩 스킬 모음의 안내자가 되어, 상황에 맞는 스킬을 찾아 주도록 돕습니다.
code-review
310k마지막 기준점 이후 바뀐 내용을 저장소의 코딩 표준과 원래 명세에 나란히 비교해, 병합 전에 검토하도록 돕습니다.
domain-modeling
310k팀이 쓰는 용어를 담은 공유 프로젝트 용어집을 만들고, 중요한 설계 결정을 기록해 코드가 같은 단어를 쓰도록 돕습니다.
implement-spec
310k완성된 명세와 그 티켓을 작동하는 코드로 바꾸고, 티켓을 순서대로 처리한 뒤 하나의 브랜치에 모아 줍니다.