修改 package.json
rush add
假設您需要新增對函式庫「example-lib」的新依賴項。如果沒有 Rush,您會執行類似這樣的操作
# DON'T DO THIS IN A RUSH REPO:
~/my-repo$ cd apps/my-app
~/my-repo/apps/my-app$ npm install --save example-lib
在 Rush 儲存庫中,您應該改用 rush add 指令
~/my-repo$ cd apps/my-app
# Add "example-lib" as a dependency of "my-app", and then automatically run "rush update":
~/my-repo/apps/my-app$ rush add --package example-lib
rush add
指令也可用來更新現有依賴項的版本
# Update "my-app" to use "example-lib" version "~1.2.3":
~/my-repo/apps/my-app$ rush add --package example-lib@1.2.3
# Or if you want the version specifier "^1.2.3":
~/my-repo/apps/my-app$ rush add --package example-lib@1.2.3 --caret
# A more advanced example, where we query the NPM registry to find latest version that is
# compatible with the SemVer specifier "^1.2.0" and then add it as a tilde dependency
# such as "~1.5.3".
#
# IMPORTANT: When specifying symbol characters on the command line, use quotes so they
# don't get misinterpreted by your shell.
~/my-repo/apps/my-app$ rush add --package "example-lib@^1.2.0"
# If any other projects in the repo are using "example-lib", you can update them all
# to "1.2.3" in bulk:
~/my-repo/apps/my-app$ rush add --package example-lib@1.2.3 --make-consistent
rush remove
也有對應的 rush remove 指令,可從 package.json 中刪除項目
~/my-repo$ cd apps/my-app
# Remove the "example-lib" dependency from package.json and then automatically run "rush update":
~/my-repo/apps/my-app$ rush remove --package example-lib
手動修改 package.json
當然,您也可以直接編輯 package.json 檔案。記得之後執行 rush update
來更新縮減包裝檔案。
提示:很棒的 VS Code 功能
順帶一提,如果您使用 Visual Studio Code 作為您的編輯器,Version Lens 擴充功能 可以顯示工具提示,顯示您 package.json 中每個依賴項的最新版本。這有助於尋找和修正過期的版本。
rush upgrade-interactive
rush add
和 rush remove
指令一次處理一個依賴項。若要升級整個儲存庫中的許多套件和專案,您可以使用 rush upgrade-interactive 指令。它會逐步引導您選取專案並選擇要升級的版本

選擇專案

選擇要升級的依賴項
pnpm outdated
若要建立關於過時依賴項的報告,您也可以使用 pnpm outdated 指令。請注意,在 Rush 單一儲存庫中叫用 PNPM 指令時,您必須使用 rush-pnpm
CLI 輔助程式。

叫用 rush-pnpm outdated