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

自訂提示 (實驗性)

自訂提示允許您使用針對特定單一儲存庫量身打造的建議來註解 Rush 的主控台訊息。

以下是自訂提示可提供協助的範例情況:假設您的公司使用私有 NPM 登錄,該登錄會定期從上游 npmjs.com 伺服器同步最新的套件版本。有時使用者可能會嘗試安裝剛發佈但尚未同步的版本,在這種情況下,rush update 可能會顯示此錯誤

Progress: resolved 0, reused 1, downloaded 0, added 0
/users/example/code/my-repo/apps/my-app:
 ERR_PNPM_NO_MATCHING_VERSION  No matching version found for example-library@1.2.3

This error happened while installing a direct dependency of my-app

The latest release of example-library is "1.1.0".

此錯誤有點令人困惑,因為最新的發行版本確實是 1.2.3,而此錯誤指的是私有登錄同步的最新版本。如果您維護單一儲存庫的服務專線,您可能會經常收到關於此錯誤的支援票證,而這些票證可藉由顯示自訂提示來避免。

設定自訂提示

上述的 ERR_PNPM_NO_MATCHING_VERSION 程式碼來自 PNPM。Rush 對應的提示 ID 是 TIP_PNPM_NO_MATCHING_VERSION。我們可以定義提示如下

common/config/rush/custom-tips.json

/**
* This configuration file allows repo maintainers to configure extra details to be
* printed alongside certain Rush messages. More documentation is available on the
* Rush website: https://rush.dev.org.tw
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/custom-tips.schema.json",

/**
* Specifies the custom tips to be displayed by Rush.
*/
"customTips": [
// {
// /**
// * (REQUIRED) An identifier indicating a message that may be printed by Rush.
// * If that message is printed, then this custom tip will be shown.
// * Consult the Rush documentation for the current list of possible identifiers.
// */
// "tipId": "TIP_RUSH_INCONSISTENT_VERSIONS",
//
// /**
// * (REQUIRED) The message text to be displayed for this tip.
// */
// "message": "For additional troubleshooting information, refer this wiki article:\n\nhttps://intranet.contoso.com/docs/pnpm-mismatch"
// }
{
"tipId": "TIP_PNPM_NO_MATCHING_VERSION",
"message": "This \"no matching version\" error from PNPM often results from a new version that has not been synced yet to our company's internal NPM registry.\n\nFor troubleshooting guidance, consult our team wiki:\n\nhttps://example.com/wiki/npm-syncing"
}
]
}

如果您沒有這個檔案,可以使用 rush init 來產生。

進行此變更後,使用者現在會看到自訂訊息以及原始錯誤

Progress: resolved 0, reused 1, downloaded 0, added 0
/users/example/code/my-repo/apps/my-app:
 ERR_PNPM_NO_MATCHING_VERSION  No matching version found for example-library@1.2.3

This error happened while installing a direct dependency of my-app

The latest release of example-library is "1.1.0".

| Custom Tip (TIP_PNPM_NO_MATCHING_VERSION)
|
| This "no matching version" error from PNPM often results from a new version that has not been synced
| yet to our company's internal NPM registry.
|
| For troubleshooting guidance, consult our team wiki:
|
| https://example.com/wiki/npm-syncing

請注意,Rush 會在自訂提示前面加上 |,以區分它們與 Rush 軟體的官方訊息。

貢獻新的提示

是否有想要自訂但沒有可用的 tipId 的 Rush 訊息?實作新的提示相對容易。程式碼位於 rush-lib/src/api/CustomTipsConfiguration.ts,所以請隨意建立提取要求來提議新的提示。

自訂提示識別碼

TIP_PNPM_INVALID_NODE_VERSION

對應於 PNPM 的 ERR_PNPM_INVALID_NODE_VERSION

TIP_PNPM_MISMATCHED_RELEASE_CHANNEL

對應於 PNPM 的 ERR_PNPM_MISMATCHED_RELEASE_CHANNEL

TIP_PNPM_NO_MATCHING_VERSION

對應於 PNPM 的 ERR_PNPM_NO_MATCHING_VERSION

TIP_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE

對應於 PNPM 的 ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE

TIP_PNPM_OUTDATED_LOCKFILE

對應於 PNPM 的 ERR_PNPM_OUTDATED_LOCKFILE

TIP_PNPM_PEER_DEP_ISSUES

對應於 PNPM 的 ERR_PNPM_PEER_DEP_ISSUES

TIP_PNPM_TARBALL_INTEGRITY

對應於 PNPM 的 ERR_PNPM_TARBALL_INTEGRITY

TIP_PNPM_UNEXPECTED_STORE

對應於 PNPM 的 ERR_PNPM_UNEXPECTED_STORE

TIP_RUSH_DISALLOW_INSECURE_SHA1

針對違反 pnpm-config.jsondisallowInsecureSha1 政策回報;請參閱該文件以了解詳細資訊。

Rush 輸出範例

Error: An integrity field with "sha1" was found in pnpm-lock.yaml; this conflicts with the
"disallowInsecureSha1" policy from pnpm-config.json.

TIP_RUSH_INCONSISTENT_VERSIONS

當專案的相依性版本不一致時,此訊息會由 rush installrush update 列印,僅當在 rush.json 中啟用 ensureConsistentVersions 時才會列印。

Rush 輸出範例

Found 5 mis-matching dependencies!

另請參閱