Skip to content

Commit

Permalink
Merge pull request #85 from XionWCFM/post
Browse files Browse the repository at this point in the history
docs: pnpm catalog post add
  • Loading branch information
XionWCFM authored Nov 22, 2024
2 parents 7d216fd + eadbcc0 commit 1ebb38f
Show file tree
Hide file tree
Showing 2 changed files with 12,107 additions and 4,286 deletions.
163 changes: 163 additions & 0 deletions apps/blog/posts/frontend/pnpm-catalog.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
title: Pnpm์˜ Workspace ๊ธฐ๋Šฅ Catalog๊ฐ€ ๋ญ˜๊นŒ?
description: ์ฐธ ์ข‹์€๋ฐ ๋ญ๋ผ ์„ค๋ช…ํ•  ๋ฐฉ๋ฒ•์ด ์—†๋„ค์š”
thumbnail: fallback
categories: frontend
writeDate: 2024-11-21T08:29:07.053Z
releaseDate: 2024-11-21T11:34:00.053Z
canView: true
authority: public
---

pnpm์€ 9.5.0 version์—์„œ Workspace๋ฅผ ์œ„ํ•ด Catalogs๋ผ๋Š” ๊ธฐ๋Šฅ์„ ์ถœ์‹œํ–ˆ์Šต๋‹ˆ๋‹ค. [pnpm catalogs](https://pnpm.io/catalogs) ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์†Œ๊ฐœ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

`Catalogs" are a workspace feature for defining dependency version ranges as reusable constants. Constants defined in catalogs can later be referenced in package.json files`

catalogs๋Š” ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ƒ์ˆ˜๋กœ ์ข…์†์„ฑ์˜ ๋ฒ„์ „ ๋ฒ”์œ„๋ฅผ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•œ ์ž‘์—… ๊ณต๊ฐ„ ๊ธฐ๋Šฅ์ด๋ผ๋Š” ์†Œ๊ฐœ์ž…๋‹ˆ๋‹ค. ํ•ต์‹ฌ์€ "์ข…์†์„ฑ์˜ ๋ฒ„์ „ ๋ฒ”์œ„๋ฅผ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋Šฅ" ์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”

์™œ ์›Œํฌ์ŠคํŽ˜์ด์Šค์—๋Š” catalogs์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ–ˆ์„๊นŒ์š”? ์ด๋ฒˆ์—๋Š” ๊ธฐ์กด pnpm์—๋Š” ์–ด๋–ค ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋Š”์ง€, ๊ทธ๋ฆฌ๊ณ  catalogs๊ฐ€ ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๋Š”๋ฐ ์–ด๋–ค ๋„์›€์„ ์ฃผ๋Š”์ง€๋ฅผ ๋‹ค๋ฃจ์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

## ๋ชจ๋…ธ๋ ˆํฌ์˜ ๋ฌธ์ œ์ 

๋ชจ๋…ธ๋ ˆํฌ๋ฅผ ๊ด€๋ฆฌํ•˜๋ฉด์„œ ๊ฐ€์žฅ ์–ด๋ ค์šด ๊ฒƒ์€ ๋ฌด์—‡์ผ๊นŒ์š”? ๋ชจ๋…ธ๋ ˆํฌ์—๋Š” ๋‹ค์–‘ํ•œ ์–ด๋ ค์›€์ด ์กด์žฌํ•˜์ง€๋งŒ ๊ทธ ์ค‘์—์„œ๋„ ๋ฌด์‹œํ•  ์ˆ˜ ์—†๋Š” ์–ด๋ ค์›€์€ ๋ฐ”๋กœ **๋ฒ„์ „๊ด€๋ฆฌ์˜ ํŒŒํŽธํ™”**์ž…๋‹ˆ๋‹ค.

ํ”„๋ก ํŠธ์—”๋“œ ์ƒํƒœ๊ณ„์—๋Š” ์ด์ œ ์–ด๋Š ํ™˜๊ฒฝ์—์„œ๋‚˜ ๋น ์ง€์ง€์•Š๊ณ  ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ํŒจํ‚ค์ง€๋“ค์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ๋Œ€ํ‘œ์ ์œผ๋กœ๋Š” TypeScript๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๊ณ  ํ…Œ์ŠคํŠธ๋ฅผ ์ง ๋‹ค๊ณ ํ•˜๋ฉด ํ…Œ์ŠคํŒ… ํ”„๋ ˆ์ž„์›Œํฌ๋„ ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๊ณ ์š”

๊ทธ๋Ÿฐ๋ฐ ๊ฐ ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ํ•„์š”ํ•œ ์˜์กด์„ฑ๋“ค์„ ๊ฐ ํ”„๋กœ์ ํŠธ์— ๊ฐœ๋ณ„์ ์œผ๋กœ ์„ค์น˜ํ•  ์ˆ˜ ๋ฐ–์— ์—†๋‹ค๋Š” ํ•œ๊ณ„๋Š” ์˜คํ”ˆ์†Œ์Šค๋Š” ํ•˜๋ฃจ๊ฐ€ ๋‹ค๋ฅด๊ฒŒ ์ƒˆ๋กœ์šด ๋ฒ„์ „์ด ๋‚˜์˜ค๊ณ  ๋ฐœ์ „์„ ๊ฑฐ๋“ญํ•œ๋‹ค๋Š” ์ ๊ณผ ๋งž๋ฌผ๋ ค ๋ฌธ์ œ๋กœ ๋ณ€ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.


ํ•œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ ๊ฐ™์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์—ฌ๋Ÿฌ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ฒŒ๋˜๋Š” ๊ฒฝ์šฐ ํฌ๊ฒŒ ๋‘๊ฐ€์ง€ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ๋ฉ๋‹ˆ๋‹ค.

์ฒซ๋ฒˆ์งธ๋Š” ๊ฐœ๋ฐœ์ž ๊ฒฝํ—˜์˜ ํ•˜๋ฝ์ž…๋‹ˆ๋‹ค. ๊ฐ ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ํŒŒํŽธํ™”๋˜์–ด ๋ฒ„์ „์„ ๊ด€๋ฆฌํ•˜๊ฒŒ ๋˜๋ฉด ์˜์กด์„ฑ ์ตœ์‹ ํ™” ์ž‘์—…์ด ์–ด๋ ค์›Œ์ง€๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๋™์ž‘์ด ์–ด๋–ป๊ฒŒ ๋ณ€ํ•˜๋Š”์ง€ ์ถ”์ ํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

๋‘๋ฒˆ์งธ๋Š” ๋””์Šคํฌ๊ณต๊ฐ„์˜ ๋‚ญ๋น„์ž…๋‹ˆ๋‹ค. ํŠนํžˆ ๋ฌด๊ฑฐ์šด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ผ์ˆ˜๋ก ๋ฒ„์ „๋งˆ๋‹ค ์„ค์น˜ํ•˜๊ฒŒ๋˜๋ฉด ๋””์Šคํฌ ๊ณต๊ฐ„์„ ๊ฝค ๋งŽ์ด ์ฐจ์ง€ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์ด๋Ÿฌํ•œ ๊ฒฝํ—˜์„ ์ตœ์†Œํ™”ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ชจ๋…ธ๋ ˆํฌ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋‹จ์ผ ์›์ฒœ์—์„œ ๊ณตํ†ต๋œ configuration์„ ๊ณต์œ ํ•˜๊ณ  ๊ณตํ†ต๋œ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.


## ๋‹ค๋ฅธ ํŒจํ‚ค์ง€๋งค๋‹ˆ์ €๋Š” ์ด ๋ฌธ์ œ๋ฅผ ์–ด๋–ป๊ฒŒ ํ–ˆ์„๊นŒ์š”?

<br/>

๋˜ ๋‹ค๋ฅธ PackageManager์ธ [Yarn](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/)์—์„œ๋Š” ๊ณตํ†ต๋œ ๋ฒ„์ „๊ด€๋ฆฌ๋ฅผ ์œ„ํ•ด resolutions ํ•„๋“œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

```
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"left-pad": "1.0.0",
"c": "file:../c-1",
"d2": "file:../d2-1"
},
"resolutions": {
"d2/left-pad": "1.1.1",
"c/**/left-pad": "^1.1.2"
}
}
```

yarn 2 ๋ถ€ํ„ฐ๋Š” ๋˜ ๋‹ค๋ฅธ ํ•„๋“œ์ธ [constraints](https://yarnpkg.com/features/constraints)๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

```ts
// yarn.config.cjs
module.exports = {
async constraints({Yarn}) {
for (const dep of Yarn.dependencies({ ident: 'react' })) {
dep.update(`18.0.0`);
}
},
};
```

์ด ์˜ˆ์ œ๋Š” ํ”„๋กœ์ ํŠธ์˜ ๋ชจ๋“  ๋ฆฌ์•กํŠธ์˜ ์ข…์†์„ฑ์„ 18.0.0์œผ๋กœ ๊ณ ์ •ํ•˜๊ฒŒ ํ•˜๋Š” Yarn2์˜ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.


๊ทธ๋Ÿฐ๋ฐ pnpm์—์„œ๋Š” ์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ์„ ๋”ฐ๋กœ ์ œ๊ณตํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

๊ผญ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด overrides ํ•„๋“œ๋ฅผ ํ†ตํ•ด์„œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ ๋ฒ„์ „์„ ๊ณ ์ •ํ•˜์—ฌ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์—ˆ์ง€๋งŒ ๊ทธ ๋ฐฉ๋ฒ•์ด ์ง๊ด€์ ์ด์ง€ ์•Š์•˜์ฃ 


```
{
"pnpm": {
"overrides": {
"foo": "^1.0.0",
"quux": "npm:@myorg/quux@^1.0.0",
"bar@^2.1.0": "3.0.0",
"qar@1>zoo": "2"
}
}
}
```

๊ฐœ์ธ์ ์œผ๋กœ๋Š” overrides ๋ผ๋Š” ๋‹จ์–ด ์ž์ฒด๊ฐ€ ์˜์กด์„ฑ์„ ๊ณ ์ •ํ•˜๊ณ  ๊ด€๋ฆฌํ•˜๋Š” ์šฉ๋„๋ผ๋Š” ๋Š๋‚Œ๋ณด๋‹ค๋Š” ๊ทธ๋ƒฅ ๋ฎ์–ด์”Œ์šด๋‹ค๋Š” ์–ด๊ฐ์ด ๊ฐ•ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ด์„œ ์กฐ๊ธˆ ๊ฑฐ๋ถ€๊ฐ์ด ๋“ค์—ˆ๋˜ ๊ฒƒ ๊ฐ™์•„์š”

## catalogs๋Š” ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•˜๋‚˜์š”?

catalogs๋Š” pnpm-workspace.yaml ์—์„œ ์ •์˜ํ•˜๋Š” ๊ฒƒ์„ ํ†ตํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

```
packages:
- packages/*
# Define a catalog of version ranges.
catalog:
react: ^18.3.1
redux: ^5.0.1
typescript: ^5.6.2
```

์ด๋ ‡๊ฒŒ catalog ํ•„๋“œ๋ฅผ yaml ์–‘์‹์— ๋งž๊ฒŒ ์ •์˜ํ•ด๋‘๋ฉด package.json์—์„œ ์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”

```
"typescript": "catalog:",
```

typescript์˜ ๋ฒ„์ „์„ ํ•ญ์ƒ ์ผ๊ด€์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ณ ์‹ถ๋‹ค๋ฉด catalog ํ•„๋“œ๋ฅผ ์ด์šฉํ•˜๋ฉด ๋˜๋Š”๊ฒƒ์ด์ฃ 

<br/>

๋˜ ํ•œํŽธ์œผ๋กœ๋Š” ์ด๋Ÿฐ ์‚ฌ์šฉ์‚ฌ๋ก€๋„ ์ง€์›ํ•˜๊ณ  ์žˆ์–ด์š”

์˜ˆ๋ฅผ ๋“ค์–ด ํŠน์ • ํ”„๋กœ์ ํŠธ์—์„œ๋Š” react 18.3.1 ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜์ง€๋งŒ ํŠน์ • ํ”„๋กœ์ ํŠธ์—์„œ๋Š” react 16.8 ๋ฒ„์ „์„ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ์ƒ๊ฐํ•ด๋ด…์‹œ๋‹ค.

```
catalogs:
# Can be referenced through "catalog:react17"
react16:
react: ^16.8.0
react-dom: ^16.8.0
# Can be referenced through "catalog:react18"
react18:
react: ^18.2.0
react-dom: ^18.2.0
```

์ด์ œ ์ด catalogs๋Š” ์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”

```
"react": "catalog:react16"
```

## catalogs๋ฅผ ์‚ฌ์šฉํ•ด๋ณธ ๊ฒฝํ—˜์€ ์–ด๋–ค๊ฐ€์š”?

์ €๋Š” yarn2 ๋ฅผ ๋ชจ๋…ธ๋ ˆํฌ์˜ ํŒจํ‚ค์ง€๋งค๋‹ˆ์ €๋กœ ์ฃผ๋กœ ์‚ฌ์šฉํ•ด์™”๋Š”๋ฐ์š” yarn์˜ pnp ๋ฐฉ์‹์˜ ๋ฌธ์ œ์™€ ์•„์ง ๊ฐ„ํ˜น ์ƒํƒœ๊ณ„์™€ ์ž˜ ํ˜ธํ™˜๋˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด pnpm์œผ๋กœ ํŒจํ‚ค์ง€๋งค๋‹ˆ์ €๋ฅผ ๋ฐ”๊พธ์—ˆ์–ด์š”

pnpm์˜ ๊ฐœ๋ฐœ๊ฒฝํ—˜์€ ๋Œ€์ฒด์ ์œผ๋กœ ๋งŒ์กฑ์Šค๋Ÿฌ์› ์ง€๋งŒ ๋ชจ๋…ธ๋ ˆํฌ์—์„œ์˜ ๋ฒ„์ „๊ด€๋ฆฌ์— ์žˆ์–ด yarn์˜ constraints ๊ธฐ๋Šฅ๊ณผ ๋น„์Šทํ•œ ๊ธฐ๋Šฅ์„ ์ฐพ์ง€ ๋ชปํ•ด ๋ฒ„์ „๊ด€๋ฆฌ์—๋Š” ์•„์‰ฌ์šด ์ ์ด ์žˆ์—ˆ๋Š”๋ฐ์š”

catalogs๋Š” ์ง๊ด€์ ์ธ ๊ด€๋ฆฌ ๋ฐฉ์‹์„ ๊ฐ€์ง€๊ณ  ์žˆ์—ˆ๊ณ  VsCode๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด [pnpm-catalog-lens](https://marketplace.visualstudio.com/items?itemName=antfu.pnpm-catalog-lens) ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ†ตํ•ด ๋”์šฑ ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

์กฐ๊ธˆ ์•„์‰ฌ์šด ์ ์ด ์žˆ๋‹ค๋ฉด ๋น„๊ต์  ์ตœ๊ทผ์— ์ถœ์‹œ๋œ ๊ธฐ๋Šฅ์ด๋‹ค๋ณด๋‹ˆ ์•„์ง ์ž˜ ์•ˆ๋˜๋Š” ๋ถ€๋ถ„๋“ค์ด ์กด์žฌํ•˜๊ธด ํ•œ๋‹ค๋Š” ๊ฒƒ ์ •๋„์ผ๊ฒƒ๊ฐ™์•„์š”

์˜ˆ๋ฅผ ๋“ค์–ด dependabot์„ ์ด์šฉํ•ด ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ์ž๋™ํ™”ํ•˜๊ณ  ์žˆ๋˜ ๋ถ„๋“ค์ด๋ผ๋ฉด dependabot์ด catalogs๋ฅผ ์ธ์‹ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ์ˆ˜๋™์œผ๋กœ ํ•ด๊ฒฐํ•˜์…”์•ผ ํ•œ๋‹ค๋Š” ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

[Add support for pnpm catalogs](https://github.com/dependabot/dependabot-core/issues/10202) ์ด์™€ ๊ด€๋ จํ•ด์„œ dependabot-core์— PR์ด ์—ด๋ ค์žˆ๊ธดํ•œ๋ฐ ๋ณ‘ํ•ฉ์ด ๋˜์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋„ค์š”


## ๋งˆ์น˜๋ฉฐ

catalogs๋Š” ๋ชจ๋…ธ๋ ˆํฌ์—์„œ์˜ ๊ณตํ†ต๋œ ๋ฒ„์ „๊ด€๋ฆฌ๋ผ๋Š” ๋ฌธ์ œ๋ฅผ ์ž˜ ํ’€์–ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ด์š” ์•„์ง ์‚ฌ์šฉํ•ด๋ณด์‹œ์ง€ ์•Š์•˜๋‹ค๋ฉด ํ•œ๋ฒˆ ์ ์šฉํ•ด๋ณด์‹œ๋Š” ๊ฒƒ์„ ๋งค์šฐ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
Loading

0 comments on commit 1ebb38f

Please sign in to comment.