๐Ÿš„Node On Rails: ์›์‚ฌ๋กœ ์ž‘์—… ๊ณต๊ฐ„์ด๋ผ๊ณ ๋„ ๋ถˆ๋ฆฌ๋Š” Monorepo ๋งŒ๋“ค๊ธฐ

5972 ๋‹จ์–ด tutorialwebdevjavascriptbeginners
๋ชจ๋“ˆ์‹์ด๊ณ  ์ข…์†์„ฑ์ด ๋งŽ์€ ํ”„๋กœ์ ํŠธ๋ฅผ ์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๊นŒ? ๋˜ํ•œ, ๋‹น์‹ ์€ ๊ทธ๊ฒƒ์„ ๊ณต๊ฐœํ•  ์ฑ…์ž„์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ชจ๋“  ๊ฒƒ์„ ํ…Œ์ŠคํŠธ, ๋นŒ๋“œ ๋ฐ ๊ฒŒ์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๊นŒ?

์ด์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ… ์ค‘ ํ•˜๋‚˜๋Š” Monorepo๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค!

Node on Rails ๊ฐœ๋ฐœ ๊ตฌ์กฐ



node-on-rails์˜ ๋ชฉํ‘œ๋Š” ๋ชจ๋“ˆํ™”ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Javascript/Typescript ์„ธ๊ณ„์—์„œ ์ด๋Š” ํŒจํ‚ค์ง€๋กœ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  ๋ชจ๋“ˆ/๊ตฌ์„ฑ ์š”์†Œ/ํ”Œ๋Ÿฌ๊ทธ์ธ ์ด๋ฆ„์€ ์›ํ•˜๋Š” ๋Œ€๋กœ ์ž‘์€ ํŒจํ‚ค์ง€๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ฒ˜์Œ์—๋Š” cli ํŒจํ‚ค์ง€์™€ core ํŒจํ‚ค์ง€์˜ ๋‘ ๊ฐ€์ง€ ํŒจํ‚ค์ง€๋งŒ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‘˜์€ ์˜ค๋žซ๋™์•ˆ ํ˜ผ์ž๊ฐ€ ์•„๋‹ ๊ฒƒ์ด๊ณ , ๋นŒ๋“œ ๊ณผ์ •๊ณผ ํผ๋ธ”๋ฆฌ์‹ฑ์ด ์‰ฌ์›Œ์•ผ ํ•œ๋‹ค. ๊ทธ๋ž˜์„œ ์–ด๋Š ์‹œ์ ์—์„œ ์šฐ๋ฆฌ๋Š” N ํŒจํ‚ค์ง€๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์ง€๋งŒ ์šฐ๋ฆฌ๋Š” ๋‹จ์ง€ ํ•˜๋‚˜์˜ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์›ํ•ฉ๋‹ˆ๋‹ค!

๋ชจ๋…ธ๋ ˆํฌ๋ž€?



Wikipedia์—์„œ ๋งํ•˜๋Š” ๋‚ด์šฉ์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

In revision control systems, a Monorepo is a software development strategy where code for many projects is stored in the same repository. As of 2017, this software engineering practice was over a decade old but had only recently been named.



์•Œ๊ฒ ์Šต๋‹ˆ๋‹ค. ์•ฝ๊ฐ„์˜ ๋„์›€์ด ๋˜์ง€๋งŒ ์‹ค์ œ๋กœ๋Š” ๐Ÿคทโ€โ™‚๏ธ.

Monorepo๋Š” ๋งŽ์€ ์˜๋ฏธ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์œผ๋ฉฐ GitHub์—์„œ ๋‹ค์–‘ํ•œ ์œ ํ˜•์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ช‡ ๊ฐ€์ง€ ์ข…๋ฅ˜์˜ Monorepos๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
  • Monorepo ํšŒ์‚ฌ: ๊ฐ€์žฅ ์œ ๋ช…ํ•œ Monorepo๊ฐ€ โ€‹โ€‹Google์— ์žˆ์Šต๋‹ˆ๋‹ค. ๋‚ด๋ถ€์ž์— ๋”ฐ๋ฅด๋ฉด Google์˜ ๋ชจ๋“  ์ฝ”๋“œ ๋ผ์ธ์€ ์ด Monorepo์— ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋‚˜์˜ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์ˆ˜์‹ญ์–ต ์ค„์˜ ์ฝ”๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค! ๋ฏธ์นœ.
  • A Project Monorepo: ์—ฌ๊ธฐ์— ํ”„๋กœ์ ํŠธ์— ํ•„์š”ํ•œ ๋ชจ๋“  ์ฝ”๋“œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐฑ์—”๋“œ, ํ”„๋ก ํŠธ์—”๋“œ, ์Šคํฌ๋ฆฝํŠธ ๋ฐ ํ•ด๋‹น ํŠน์ • ํ”„๋กœ์ ํŠธ์— ํ•„์š”ํ•œ ๊ธฐํƒ€ ๋ชจ๋“  ๊ฒƒ. ์ด๊ฒƒ์€ ๋ฌธ์„œ, ๊ตฌ์„ฑ ๋ฐ ๊ธฐํƒ€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋…ธ๋ ˆํฌ ์Šคํƒ€์ผ์€ ์ œํ’ˆ์ด ์žˆ๊ณ  ๋ชจ๋‘์—๊ฒŒ
    ํ•˜๋‚˜์˜ ํด๋ก ์— ํ•„์š”ํ•œ ๋ชจ๋“  ์ •๋ณด์™€ ์ฝ”๋“œ๋ฅผ ํฌํ•จํ•˜๋Š” ํ•ด๋‹น ํ”„๋กœ์ ํŠธ
  • ํŒจํ‚ค์ง€ Monorepo: (npm) ํŒจํ‚ค์ง€ ๋ชจ์Œ์ด ์žˆ๋Š” Monorepo์ž…๋‹ˆ๋‹ค. ๋ชจ๋“  ํŒจํ‚ค์ง€๋Š” ๋” ํฐ ์‹œ์Šคํ…œ์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค. ์‹œ์Šคํ…œ์˜ ๋ชจ๋“  ๋ถ€๋ถ„์„ ํŒจํ‚ค์ง€์— ํฌํ•จํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋ชจ๋“  ํŒจํ‚ค์ง€๋ฅผ ์ž์ฒด์ ์œผ๋กœ ๋ฆด๋ฆฌ์Šคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. repo์—์„œ ๋ชจ๋‘ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

  • Monorepo์˜ ๋” ๋งŽ์€ ์œ ํ˜•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    ์ด์ œ node-on-rails์— ์‚ฌ์šฉํ•  ์œ ํ˜•์ด ๋ช…ํ™•ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. 'ํŒจํ‚ค์ง€ ๋ชจ๋…ธ๋ ˆํฌ'.

    ๋ชจ๋…ธ๋ ˆํฌ ์„ค์ •์€ ์–ด๋–ป๊ฒŒ ํ•˜๋‚˜์š”?



    ์ง€๊ธˆ์€ yarn workspaces ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์•„๋งˆ๋„ ๊ฐ€์žฅ ์ธ๊ธฐ ์žˆ๋Š” Monorepo ๋„๊ตฌ์ธ Lerna ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋‚˜์ค‘์— ์ถ”๊ฐ€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

    ๊ฐ€์žฅ ๋จผ์ € ๋งŒ๋“ค์–ด์•ผ ํ•  ๊ฒƒ์€ ๋ฃจํŠธ ํด๋”์ž…๋‹ˆ๋‹ค.

    mkdir node-on-rails
    

    ์ƒˆ๋กœ ์ƒ์„ฑ๋œnode-on-rails ํด๋”์— ๋‹ค์Œ JSON์ด ํฌํ•จ๋œ package.json ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    {
        "private": true,
        "name": "node-on-rails",
        "workspaces": [
            "packages/*"
        ],
    }
    
    

    "๊ฐœ์ธ"ํ‚ค๋Š” ๋ฃจํŠธ ํŒจํ‚ค์ง€๋ฅผ ๋Œ€์ค‘์—๊ฒŒ ๊ณต๊ฐœํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฆ„์€ ์„ ํƒ ์‚ฌํ•ญ์ด์ง€๋งŒ ์—ฌ์ „ํžˆ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

    ๋งˆ์ง€๋ง‰ ์„ธ ์ค„์€ ์—ฌ๊ธฐ์—์„œ ๊ฐ€์žฅ ํฅ๋ฏธ ๋กญ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์—์„œ ์ž‘์—… ๊ณต๊ฐ„์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ํด๋” ๊ฒฝ๋กœ์˜ ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค. ๋ชจ๋“  ํŒจํ‚ค์ง€๋Š” packages ํด๋”์— ์žˆ์œผ๋ฏ€๋กœ * ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ yarn ๋ชจ๋“  ํ•˜์œ„ ํด๋”๊ฐ€ ์ž‘์—… ๊ณต๊ฐ„์ด ๋˜๊ธฐ๋ฅผ ์›ํ•œ๋‹ค๊ณ  ์•Œ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์ด์ œ ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‘ ๊ฐœ์˜ ์ฒซ ๋ฒˆ์งธ ํŒจํ‚ค์ง€ ํด๋”๋ฅผ ์ƒ์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

    mkdir -p packages/CLI packages/core
    

    ์ด ๊ฒŒ์‹œ๋ฌผ์„ ์งง๊ฒŒ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด package.json ์ค‘ ํ•˜๋‚˜๋ฅผ ๋งŒ๋“ค์ง€๋งŒ ๋จผ์ € ๋ณต์‚ฌํ•˜์—ฌ ๋ถ™์—ฌ๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์ด์ œ package.json ํด๋”์— node-on-rails/packages/core๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋‚ด๋ถ€์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    {
      "name": "@nor/core",
      "version": "0.0.1",
      "dependencies": {
        "typescript": "^3.7.4"
      }
    }
    
    node-on-rails/packages/cli ํด๋”์—์„œ๋„ ๋™์ผํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ๋ชจ๋“  ์ข…์†์„ฑ์„ ์„ค์น˜ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

    yarn install
    

    ์˜ˆ! ๊ทธ๊ฒŒ ๋‹ค์•ผ ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋ชจ๋“  ์ž‘์—… ์˜์—ญ์— ๋Œ€ํ•œ ๋ชจ๋“  ์ข…์†์„ฑ์ด ์„ค์น˜๋ฉ๋‹ˆ๋‹ค!

    ์ด์ œ ์ž‘์—… ๊ณต๊ฐ„์—์„œ npm ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด cd ์ž‘์—… ๊ณต๊ฐ„์œผ๋กœ ๋“ค์–ด๊ฐ€๊ฑฐ๋‚˜ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    yarn workspace @nor/CLI run test
    

    ๋˜๋Š” ์˜ˆ๋ฅผ ๋“ค์–ด ๋ชจ๋“  ํŒจํ‚ค์ง€์—์„œ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ์„ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    yarn workspaces run test
    

    ๋ณด๋„ˆ์Šค: ๋ชจ๋“  npm ์ข…์†์„ฑ ์—…๋ฐ์ดํŠธ



    ๋ชจ๋“  ํŒจํ‚ค์ง€๋ฅผ ์ˆ˜๋™์œผ๋กœ ์—…๋ฐ์ดํŠธํ•˜์ง€ ์•Š์œผ๋ ค๋ฉด ๋‹ค์Œ์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.npm-check-updates:

    sudo yarn global add npm-check-updates
    

    ๋ฃจํŠธ package.json์— ๋‹ค์Œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜์‹ญ์‹œ์˜ค.

        "scripts": {
            "upgrade:all": "find . -type f -name 'package.json' -not -path './.git/*' -not -path '*/node_modules/*' -execdir ncu --upgrade \\;"
        },
    

    ์ด๊ฒƒ์ด ์ด ํฌ์ŠคํŠธ์˜ ์ „๋ถ€์ž…๋‹ˆ๋‹ค. ์ด์ œ Monorepo๊ฐ€ โ€‹โ€‹๋ฌด์—‡์ด๋ฉฐ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๋” ์ž˜ ์ดํ•ดํ•˜์…จ๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค.

    ์ด๊ฒƒ์ด ๊ท€ํ•˜์—๊ฒŒ ๊ฐ€์น˜๋ฅผ ๋”ํ–ˆ๋‹ค๋ฉด ํŠธ์œ„ํ„ฐ๋‚˜ ๋‹ค๋ฅธ ์†Œ์…œ ๋ฏธ๋””์–ด์—์„œ ์ด ๊ฒŒ์‹œ๋ฌผ์„ ๊ณต์œ ํ•˜๋Š” ๊ฒƒ์„ ๊ณ ๋ คํ•˜์‹ญ์‹œ์˜ค. ๋‚˜๋Š” ์„ธ์ƒ์—์„œ ๊ฐ€์žฅ ํ–‰๋ณตํ•œ ์‚ฌ๋žŒ์ด ๋ ๊ฑฐ์•ผ.๐Ÿ™๐Ÿ˜€

    ๐Ÿ‘‹์•ˆ๋…•ํ•˜์„ธ์š”! | | | Medium | |

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ