pnpm-upgrade

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

pnpm Upgrade

pnpm 升级

Use these steps to update pnpm and CI pins without blunt search/replace.
按照以下步骤更新pnpm及CI中的版本固定配置,无需粗暴的搜索替换操作。

Steps (run from repo root)

步骤(从仓库根目录执行)

  1. Update pnpm locally
    • Try
      pnpm self-update
      ; if pnpm is missing or self-update fails, run
      corepack prepare pnpm@latest --activate
      .
    • Capture the resulting version as
      PNPM_VERSION=$(pnpm -v)
      .
  2. Align package.json
    • Open
      package.json
      and set
      packageManager
      to
      pnpm@${PNPM_VERSION}
      (preserve trailing newline and formatting).
  3. Find latest pnpm/action-setup tag
    • Query GitHub API:
      curl -fsSL https://api.github.com/repos/pnpm/action-setup/releases/latest | jq -r .tag_name
      .
    • Use
      GITHUB_TOKEN
      /
      GH_TOKEN
      if available for higher rate limits.
    • Store as
      ACTION_TAG
      (e.g.,
      v4.2.0
      ). Abort if missing.
  4. Update workflows carefully (no broad regex)
    • Files: everything under
      .github/workflows/
      that uses
      pnpm/action-setup
      .
    • For each file, edit by hand:
      • Set
        uses: pnpm/action-setup@${ACTION_TAG}
        .
      • If a
        with: version:
        field exists, set it to
        ${PNPM_VERSION}
        (keep quoting style/indent).
    • Do not touch unrelated steps. Avoid multiline sed/perl one-liners.
  5. Verify
    • Run
      pnpm -v
      and confirm it matches
      packageManager
      .
    • git diff
      to ensure only intended workflow/package.json changes.
  6. Follow-up
    • If runtime code/build/test config was changed (not typical here), run
      $code-change-verification
      ; otherwise, a light check is enough.
    • Commit with
      chore: upgrade pnpm toolchain
      and open a PR (automation may do this).
  1. 本地更新pnpm
    • 尝试执行
      pnpm self-update
      ;若pnpm未安装或self-update命令执行失败,运行
      corepack prepare pnpm@latest --activate
    • 将最终版本记录为
      PNPM_VERSION=$(pnpm -v)
  2. 同步package.json配置
    • 打开
      package.json
      ,将
      packageManager
      字段设置为
      pnpm@${PNPM_VERSION}
      (保留末尾换行符和原有格式)。
  3. 获取pnpm/action-setup的最新标签
    • 调用GitHub API:
      curl -fsSL https://api.github.com/repos/pnpm/action-setup/releases/latest | jq -r .tag_name
    • 若有
      GITHUB_TOKEN
      GH_TOKEN
      ,建议使用以提升请求速率限制。
    • 将结果保存为
      ACTION_TAG
      (例如:
      v4.2.0
      )。若获取失败则终止操作。
  4. 谨慎更新工作流配置(避免宽泛的正则替换)
    • 目标文件:
      .github/workflows/
      下所有使用
      pnpm/action-setup
      的文件。
    • 逐个手动编辑文件:
      • 设置
        uses: pnpm/action-setup@${ACTION_TAG}
      • 若存在
        with: version:
        字段,将其值设置为
        ${PNPM_VERSION}
        (保留原有的引号格式和缩进)。
    • 请勿修改无关步骤。避免使用多行sed或perl单行命令。
  5. 验证
    • 执行
      pnpm -v
      ,确认版本与packageManager字段中的值一致。
    • 执行
      git diff
      ,确保仅对工作流配置和package.json进行了预期的修改。
  6. 后续操作
    • 若运行时代码、构建或测试配置被修改(本场景中通常不会发生),执行
      $code-change-verification
      ;否则只需进行简单检查即可。
    • 提交信息使用
      chore: upgrade pnpm toolchain
      ,并创建PR(自动化流程可能会自动完成此步骤)。

Notes

注意事项

  • Tools needed:
    curl
    ,
    jq
    ,
    node
    ,
    pnpm
    /
    corepack
    . Install if missing.
  • Keep edits minimal and readable—prefer explicit file edits over global replacements.
  • If GitHub API is rate-limited, retry with a token or bail out rather than guessing the tag.
  • 所需工具:
    curl
    jq
    node
    pnpm
    /
    corepack
    。若未安装请先安装。
  • 尽量保持编辑内容简洁易读——优先选择显式的文件编辑而非全局替换。
  • 若GitHub API触发速率限制,使用令牌重试或终止操作,请勿猜测标签版本。