Rush Stack商店部落格活動
跳至主要內容

rushx

rushx 命令類似於 npm runpnpm run:它會叫用在個別專案的 package.json 檔案的 "scripts" 區段中定義的 Shell 指令碼。任何其他 CLI 參數都會傳遞給該 Shell 指令碼,而不會進行任何驗證。

考量這個非常簡單的範例專案

<我的專案>/package.json

{
"name": "my-project",
"version": "0.0.0",
"scripts": {
"build": "rm -Rf lib && tsc",
"test": "jest"
}
}

如果您單獨叫用 rushx,它只會顯示可用的指令

usage: rushx [-h]
rushx [-q/--quiet] <command> ...

Optional arguments:
-h, --help Show this help message and exit.
-q, --quiet Hide rushx startup information.

Project commands for my-project:
build: "rm -Rf lib && tsc"
test: "jest"

如果您叫用 rushx build,則它會執行 rm -Rf lib && tsc。如果您加入像是 rushx build --verbose 的參數,它會盲目地附加到字串結尾:rm -Rf lib && tsc --verbose

rush vs rushx

這兩個指令很容易混淆

  • rush 會叫用影響整個儲存庫的通用操作(「全域指令」),或影響多個專案的操作(「批次指令」)。這類指令應謹慎設計。Rush 會強制驗證並記錄它們的參數。
  • rushx 會針對單一專案執行自訂操作。雖然其中一些用於實作批次指令,但其中許多將是僅由該特定專案的開發人員瞭解的協助程式指令碼。Rush 不會嚴格驗證這些指令。

為何使用「rushx」而非「pnpm run」或「npx」?

rushx 命令的功能與 pnpm runnpx 類似,但有一些額外的好處

  • 透過使用Rush 版本選取器確保工具的決定性
  • 根據 Rush 的設定準備 Shell 環境
  • 實作其他驗證