본문으로 건너뛰기
Skillpedia
일반 코딩310k · #115

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/mattpocock/skills/blob/main/skills/in-progress/setup-ts-deep-modules/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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:

  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 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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬