TR kizaki Tech Memo

volta v1.1.0 update =>"corepack enable" compatible with node v19.3.0

volta v1.1.0がついにyarn v3に対応したということで興奮してupdate

• Added support for pinning / installing Yarn 3+ (#1305) • Improved portability and installer effectiveness by removing dependency on OpenSSL (#1214)

Changes • Updated the dependency on attohttpc to enable the use of rustls instead of native-tls (OpenSSL on Linux) • Created a Dockerfile that builds off of Scientific Linux CERN 6, installing updated build tools • Updated the release CI workflow to build a single Linux version using the above Docker container. • Updated the install script to look for the new single version in the case of Linux

updateする前に現状の構成確認

➜  ~ git:(main) ✗ volta list
⚡️ Currently active tools:

    Node: v18.12.1 (current @ /Users/$HOME/package.json)
    npm: v8.19.2 (current @ /Users/$HOME/package.json)
    Yarn: v1.22.19 (default)
    Tool binaries available:
        gatsby (default)
        ntl, netlify (default)
        npm-check-updates, ncu (default)
        pm2, pm2-dev, pm2-docker, pm2-runtime (default)
        solcjs (current @ /Users/$HOME/package.json)
        truffle (default)
        tsc, tsserver (default)

See options for more detailed reports by running `volta list --help`.
➜  ~ git:(main) ✗ curl https://get.volta.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10930  100 10930    0     0  17668      0 --:--:-- --:--:-- --:--:-- 17918
  Installing latest version of Volta (1.1.0)
    Checking for existing Volta installation
    Fetching archive for macOS, version 1.1.0
######################################################################## 100.0%
    Creating directory layout
  Extracting Volta binaries and launchers
    Finished installation. Updating user profile settings.
success: Setup complete. Open a new terminal to start using Volta!
/Users/$HOME/Downloads/volta-1.1.0-macos/volta-migrate ; exit;
➜  ~ git:(main) ✗ /Users/$HOME/Downloads/volta-1.1.0-macos/volta-migrate ; exit;
Updating your Volta directory. This may take a few moments...

Saving session...completed.

[Process completed]

voltaでyarn version管理できるの嬉しすぎるわ

➜  ~ git:(main) ✗ volta install yarn@3.2.0
success: installed and set yarn@3.2.0 as default

Improvements

ref:yarn-31-corepack-esm-pnpm-optional-packages--3hak#new-install-mode-raw-pnpm-endraw-

  • まずnodeをvoltaで最新v19.3.0にupdate npmもついでに@9.2.0にする
➜  ~ git:(main) ✗ volta list
⚡️ Currently active tools:

    Node: v19.3.0 (current @ /Users/$HOME/package.json)
    npm: v9.2.0 (current @ /Users/$HOME/package.json)
    Yarn: v3.2.0 (current @ /Users/$HOME/package.json)
    Tool binaries available:
        gatsby (default)
        ntl, netlify (default)
        npm-check-updates, ncu (default)
        pm2, pm2-dev, pm2-docker, pm2-runtime (default)
        solcjs (current @ /Users/$HOME/package.json)
        truffle (default)
        tsc, tsserver (default)
  • nodeのversionがvoltaの最新とlinkしないのでnodebrewなどuninstallしまくる
➜  ~ git:(main) ✗ node -v
v16.15.0
➜  ~ git:(main) ✗ brew uninstall --ignore-dependencies node
Uninstalling /usr/local/Cellar/node/18.11.0... (1,993 files, 49.7MB)
➜  ~ git:(main) ✗ brew uninstall nodebrew
Uninstalling /usr/local/Cellar/nodebrew/1.1.0... (8 files, 39KB)
➜  ~ git:(main) ✗ sudo rm -rf /usr/local/include/node
Password:
➜  ~ git:(main) ✗ sudo rm -rf /usr/local/lib/dtrace
➜  ~ git:(main) ✗ rm -rf ~/.node-gyp

➜  ~ git:(main) ✗ rm -rf ~/.npm
➜  ~ git:(main) ✗ rm -rf ~/.sourcemint

➜  ~ git:(main) ✗ which node
/usr/local/bin/node
➜  ~ git:(main) ✗ rm -rf /usr/local/bin/node
  • volta setup コマンド入力→再起動でnodeとnpmとyarnが最新versionがvoltaを通して使える。消しまくったから反映されなかったら焦った…
➜  ~ git:(main) ✗ volta setup
success: Setup complete. Open a new terminal to start using Volta!
➜  ~ git:(main) ✗ node -v
v19.3.0
➜  ~ git:(main) ✗ npm -v
9.2.0
➜  ~ git:(main) ✗ yarn -v
3.2.0

Node.js Corepack Integration

Did you know that Yarn now ships with Node? This is done via the Node.js Corepack project, which includes both the Yarn and pnpm binaries as shims. By adding the packageManager field to your package.json, you can enforce the use of a specific package manager & package manager version in a completely transparent way:

➜  ~ git:(main) ✗ corepack prepare pnpm@7.20.0  --activate
Preparing pnpm@7.20.0 for immediate activation...