C.W.K.
Stream
Lesson 04 of 05 · published

PnP, Zero-Installs, Constraints

~12 min · yarn, concepts, pnp

Level 0초심자
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

Yarn Berry 의 시그니처 아이디어가 PnP, zero-installs, constraints. 각각 한 단락 가치 있어.

Plug'n'Play (PnP). 수천 개 패키지를 node_modules 에 압축 풀기 대신 Yarn 이 .yarn/cache/ 에 zip 파일로 유지. 코드가 import foo from 'lodash' 하면, 생성된 .pnp.cjs 파일이 그 import 를 캐시된 zip 안의 정확한 byte range 로 resolve. 결과: 더 빠른 install (압축 해제 없음), 더 빠른 boot time, 미선언 deps loud 하게 fail (manifest 에 등록 안 됐었으니까). Trade-off: PnP 안 말하는 도구 (일부 IDE, 옛 bundler) 가 SDK helper 필요.

PnP fallback. PnP 가 toolchain 너무 깨면 .yarnrc.ymlnodeLinker: node-modules 설정. Yarn 이 traditional node_modules 레이아웃으로 돌아가면서 Berry 의 다른 개선 유지. PnP 에 commit 안 해도 Berry 사용 가능.

Zero-installs. .yarn/cache/ 를 Git 에 commit. 이제 팀원과 CI 머신이 git clone 만 필요 — install 단계 없음. CI install time 분에서 초로 떨어짐. 비용은 더 큰 Git repo (deps 많으면 기가바이트); 승은 극적인 CI speedup.

Constraints. 프로젝트 전체 룰 강제하는 JavaScript 기반 엔진 — 모든 workspace 가 같은 React 버전 사용해야 함, lodash 직접 의존 안 됨 등. yarn.config.cjs 에 룰 정의; yarn constraints 가 violation 보고. 한 팀의 머리 너머로 자란 monorepo 에 invaluable.

Code

Toolchain 깨면 PnP 끄기·yaml
# repo root 의 .yarnrc.yml
nodeLinker: node-modules

# Berry 가 이제 일반 node_modules 만들고 .pnp.cjs 건너뜀.
# Berry 의 다른 기능 (캐시, lockfile, workspaces, constraints) 유지
# 그치만 PnP 싫어하는 도구가 normal 작동.
Constraints — workspace 들 사이 한 공유 React 버전·javascript
// yarn.config.cjs
module.exports = {
  constraints: async ({ Yarn }) => {
    for (const dep of Yarn.dependencies({ ident: 'react' })) {
      dep.update('19.0.0');
    }
  },
};

// 그 다음 돌려:
//   yarn constraints           — 체크
//   yarn constraints --fix     — 자동 적용

External links

Exercise

Berry 프로젝트에서 .yarnrc.yml 보고 nodeLinker 설정됐나 체크. PnP 가 디폴트면 한 VS Code extension install 시도 (ZipFS extension + 'yarn dlx @yarnpkg/sdks vscode') 해서 PnP 가 에디터와 어떻게 통합되는지 봐. 고통스러우면 nodeLinker: node-modules 로 전환 — PnP 없는 Berry 도 여전히 Classic 보다 나음.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.