Closed17

Yarnのv3を試してみる

nus3nus3

目的

Renovateで最近yarnをv1.22.0→v1.22.1にバージョンアップしたけどRelease Noteに下記のようなことが書いてあった

Remember that Yarn 1.x won't receive further functional improvements.
We recommend you to switch to the recently-released 3.0, and to ping us on Discord if you find issues when migrating (also check our Migration Guide).

最近v3リリースしたよって内容だったのでv3へバージョンアップできるなら試してみようと思った

nus3nus3

Migration作業

Step by stepの通りのことをやった

  1. ドキュメントのmigrateの部分を読む
  2. yarn set version berry
  3. .yarnrc.ymlの修正
  4. yarn install して、yarn.lockを更新
  5. gitignoreを修正
  6. --frozen-lockfile--immutableに変更
  7. yarn setup等 npm scriptsでyarn installしてる箇所を使用しないように修正
nus3nus3

3. .yarnrc.ymlの修正

.yarnrc.yml
yarnPath: ".yarn/releases/yarn-berry.cjs"
defaultSemverRangePrefix: ""
nodeLinker: "node-modules"
nus3nus3

--frozen-lockfileオプションはいずれ消えるっぽいから--immutableに変えた方が良きなのか

If the --immutable option is set (defaults to true on CI), Yarn will abort with an error exit code if the lockfile was to be modified (other paths can be added using the immutablePatterns configuration setting). For backward compatibility we offer an alias under the name of --frozen-lockfile, but it will be removed in a later release.

https://yarnpkg.com/cli/install

nus3nus3

5. gitignoreを修正

これの通りにする

# yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
nus3nus3

CircleCi

node orbs使っててそれだとyarnのv1系にしか対応してない

Something went wrong; the specified version of Yarn could not be installed

nus3nus3

- image: cimg/node:14.17.4使ったら普通にyarn v3も使えそう

nus3nus3

yarn v2でのcacheの設定(Zero install使ってない場合)

#...
      - restore_cache:
          name: Restore Yarn Package Cache
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}
      - run:
          name: Install Dependencies
          command: yarn install --immutable
      - save_cache:
          name: Save Yarn Package Cache
          key: yarn-packages-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn
#...

https://circleci.com/docs/ja/2.0/yarn/#caching

nus3nus3

openapiの型生成のためにjavaのimageにnodeのorbs使ってたけど

orbs:
  node: circleci/node@4.5.2
executors:
  build:
    working_directory: /home/circleci/src/
    docker:
      - image: circleci/openjdk:18-jdk-buster

variants使えばjavaにnodeも乗っけられそう

jobs:
  build:
    docker:
      - image: cimg/openjdk:16.0.2-node

https://circleci.com/developer/images/image/cimg/openjdk

16.0.2-nodeはyarn 1.22.5って書いてあるけどyarn policies set-versionしてれば指定のバージョン(v3)使ってくれる?

build-essential 12.8ubuntu1.1, curl 7.68.0, docker 20.10.7, docker-compose 1.29.2, dockerize v0.6.1, git 2.32.0, gradle 7.1.1, java 16.0.2, jq 1.6, maven 3.8.1, node 14.17.4, ubuntu 20.04.2 LTS, wget 1.20.3, yarn 1.22.5

v3使ってくれてる〜〜

#!/bin/bash -eo pipefail
yarn -v
3.0.0
CircleCI received exit code 0
このスクラップは2021/09/22にクローズされました