自定义提示 (实验性)
自定义提示允许您使用针对您的特定多仓库定制的建议来注释 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.node.org.cn
*/
{
"$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 软件的官方消息区分开来。
贡献新的提示
您是否想自定义 Rush 消息,但没有可用的 `tipId`?实现新提示相对容易。代码位于 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.json 中的 `disallowInsecureSha1` 策略的违规行为报告;有关详细信息,请参阅该文档。
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 install` 或 `rush update` 打印,前提是在 **rush.json** 中启用了 `ensureConsistentVersions`。
Rush 输出示例
Found 5 mis-matching dependencies!