gloriaJun / til

Lessoned Learned
3 stars 0 forks source link

yarn2 (yarn-berry) #125

Open gloriaJun opened 3 years ago

gloriaJun commented 3 years ago

Version

yarn v3.2.0

Installation

  1. execute the following command in the project_dir

    yarn set version berry
  2. remove the following files

    • node_modules
    • yarn.lock
    • package-lock.json
  3. install the package modules

yarn install
  1. update .gitignore
    ### yarn ###
    .yarn/*
    !.yarn/patches
    !.yarn/releases
    !.yarn/plugins
    !.yarn/sdks
    !.yarn/versions
    # if you want to unused Zero-Install
    .pnp.*
    yarn.lock
    # if you want to used Zero-Install
    #!.yarn/cache

configure TypeScript for VSCode

Run the following command

yarn dlx @yarnpkg/sdks vscode

If vscode displayed the following popup, click allow button image

If vscode dosen't display it, ctrl+shift+p in a TypeScript file (for Mac : cmd+shift+p)

image

And Pick Use Workspace Version

image

References

gloriaJun commented 2 years ago

yarn tips

yarn.lock

package.json에 정의된 버전의 범위에 따라 패키지를 관리하게 되는데, 이는 yarn install을 수행하는 시점마다 설치되는 패키지의 버전이 달라질 수 있음을 의미한다. 이러한 문제를 해결하기 위해 yarn.lock 파일 install 시점에 프로젝트의 루트 경로에 생성이 된다. 해당 파일을 git으로 버전을 관리하게 되면 같은 프로젝트를 하는 팀원들 또는 해당 프로젝트를 받아서 설치하는 어떠한 환경에서도 yarn.lock에 정의된 버전을 기준으로 설치하게 되어 조금 더 안정적으로 프로젝트를 관리할 수 있다.

yarn command

yarn install

빌드, 테스트 등을 위한 패키지(주로 devDepnedencies에 정의되는 부분들)는 런타임에 영향을 미치지 않아야 한다.

아래와 같이 production 키워드를 주어 실행하는 경우 devDepnedencies에 정의된 패키지의 설치를 생략할 수 있다.

yarn install --production
# or
NODE_ENV=production yarn install

yarn upgrade

package.json에 정의된 패키지의 버전 범위 내에서 업데이트 또는 삭제를 하여, yarn.lock 파일을 재생성한다.

yarn upgrade

기존 설치된 특정 패키지의 업데이트가 필요하다면 아래와 같은 방법으로 업데이트를 하는 것이 package.json에 정의된 모든 패키지가 일괄적으로 업데이트되는 것을 예방할 수 있다.

yarn upgrade <package_name>
# ex) yarn upgrade mocha@^4.0.0

yarn remove

프로젝트에 설치되어있는 특정 패키지를 제거한다.

yarn remove <package_name>
# ex) yarn remove mocha

yarn check

패키지 버전에 따른 의존 패키지들이 유효한지 체크한다. 즉, 현재 package.json에 정의된 것과 yarn.lock 파일이 일치한지 확인한다.

yarn outdated

yarn v3에서는 존재하지 않는 명령어인 듯.

프로젝트에 설치되어있는 패키지들에 대해 업데이트가 필요한 리스트를 정리하여 보여준다.

그리고 색상별 의미는 아래와 같다.

╰─❯ yarn outdated
yarn outdated v1.22.10
info Color legend : 
 "<red>"    : Major Update backward-incompatible updates 
 "<yellow>" : Minor Update backward-compatible features 
 "<green>"  : Patch Update backward-compatible bug fixes
Package                          Current  Wanted   Latest  Package Type    URL                                                                                                                              
eslint                           7.21.0   7.32.0   8.14.0  devDependencies https://eslint.org                                                                       
eslint-config-prettier           8.1.0    8.5.0    8.5.0   devDependencies https://github.com/prettier/eslint-config-prettier#readme                                
eslint-plugin-cypress            2.11.2   2.12.1   2.12.1  devDependencies https://github.com/cypress-io/eslint-plugin-                                              
ts-node                          9.1.1    9.1.1    10.7.0  devDependencies https://typestrong.org/ts-node                                                           
twin.macro                       2.3.0    2.8.2    2.8.2   devDependencies https://github.com/ben-rogerson/twin.macro#readme                                        
typescript                       4.2.3    4.6.4    4.6.4   devDependencies https://www.typescriptlang.org/                                                          
✨  Done in 7.04s.

References