yarn이란?

yarn이란?

박상수
6 min readFeb 19, 2019
  • 의존성관리 javascript 패키지 매니저
  • java에 gradle , php의 composer 와 같은 역할을 한다.

NPM이 있는데 왜? yarn을?

yarn을 만든 facebook은 아래와 같이 설명한다.

  • Ultra Fast(고속)
    - 다운로드한 모든 패키지를 캐시하므로 다시 다운로드할 필요가 없습니다. 또한 운영을 병렬화하여 리소스 활용률을 극대화하므로 설치 시간이 그 어느 때보다 단축됩니다.
  • Mega Secure(보안)
    - 체크섬을 사용하여 코드가 실행되기 전에 설치된 모든 패키지의 무결성을 확인합니다.
  • Super Reliable(신뢰성)
    - 상세하고 간결하며 잠금 파일 형식과 설치용 결정 알고리즘을 사용하여 한 시스템에서 작동하는 설치가 다른 시스템에서 정확히 동일한 방식으로 작동하도록 보장할 수 있습니다.

또한

  • Offline Mode(오프라인모드)
    - 이전에 패키지를 설치한 경우 인터넷 연결 없이 패키지를 다시 설치할 수 있습니다.
  • Deterministic(결정적)
    - 설치 순서와 관계없이 모든 시스템에 동일한 종속성이 동일한 방식으로 설치됩니다.
  • Network Performance(네트워크 성능)
    - 네트워크 활용도를 극대화하기 위해 요청을 효율적으로 대기열에 올리고 요청 폭포를 방지합니다.
  • Same Packages(동일 패키지)
    - npm의 패키지를 설치하고 패키지 workflow를 동일하게 유지합니다.
  • Network Resilience(네트워크 복구)
    - 요청 실패 한 번으로 인해 설치에 실패하지 않습니다. 실패 시 요청이 재시도됩니다.
  • Flat Mode(플랫 모드)
    - 중복 항목을 생성하지 않으려면 일치하지 않는 버전의 종속성을 단일 버전으로 해결합니다.

설치

//yarn 설치
$ sudo apt-get update && sudo apt-get install yarn
//만약 설치가 안된다면 npm을 통해 설치
$ npm install -g yarn
// path설정
$ echo 'export PATH="$(yarn global bin):$PATH"' >> ~/.bashrc
//설치 버전 확인
$ yarn --version
1.13.0
// self update
$ yarn self-update

package.json 설정

$ yarn init
yarn init v1.13.0
question name (react): aa
question version (1.0.0): 1.0.0
question description: test
question entry point (index.js): index.js
question repository url: localhost
question author: pss
question license (MIT): MIT
question private:
success Saved package.json
Done in 34.17s.
//아래와 같은 package.json파일 생성
{
"name": "aa",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"repository": "localhost",
"author": "pss",
"license": "MIT"
}

패키지 설치

$ yarn install 
또는 (install은 생략가능)
$ yarn
yarn install
yarn install v1.13.0
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To
clear this warning, remove package-lock.json.
[1/4] Resolving packages...
warning react-scripts > eslint > file-entry-cache > flat-cache > circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
warning react-scripts > jest > jest-cli > prompts > kleur@2.0.2: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path
(s).
[4/4] Building fresh packages...
success Saved lockfile.
Done in 83.37s.
  • yarn.lock파일이 없을 경우 자동으로 생성된다.
  • package.json에 있는 패키지를 기반으로 설치

yarn upgrade

$ yarn upgrade
yarn upgrade v1.13.0
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To
clear this warning, remove package-lock.json.
[1/4] Resolving packages...
├─ y18n@4.0.0
├─ yallist@3.0.3
└─ yargs-parser@9.0.2
Done in 18.77s.
//특정 버전만 업그레이드
$ yarn upgrade request@^2.87.0
  • yarn.lock파일을 recreated

yarn remove

//package.json, yarn.lock 에서 패키지를 제거합니다.
$ yarn remove request

프로젝트 실행

$ yarn start

참고

--

--