@yarn-tool/update-notifier
v1.0.45
Published
CLI 工具更新通知器,在適當時機提醒使用者有新版本可用 / CLI tool update notifier that reminds users of new versions at appropriate times
Maintainers
Readme
@yarn-tool/update-notifier
CLI 工具更新通知器,在適當時機提醒使用者有新版本可用
CLI tool update notifier that reminds users of new versions at appropriate times
安裝 / Install
npm install @yarn-tool/update-notifier或 / or
yarn add @yarn-tool/update-notifier或 / or
pnpm add @yarn-tool/update-notifier使用方式 / Usage
基本用法 / Basic Usage
import { updateNotifier } from '@yarn-tool/update-notifier';
// 在 CLI 工具入口處呼叫 / Call at CLI tool entry point
updateNotifier(__dirname);進階用法 / Advanced Usage
import { updateNotifier } from '@yarn-tool/update-notifier';
// 強制檢查(忽略環境限制)/ Force check (ignore environment restrictions)
updateNotifier(__dirname, true);
// 使用路徑片段陣列 / Use path segments array
updateNotifier([__dirname, '..', '..']);
// 自訂通知選項 / Custom notification options
updateNotifier(__dirname, false, {
updateCheckInterval: 1000 * 60 * 60 * 24, // 每天檢查一次 / Check once per day
shouldNotifyInNpmScript: true, // 在 npm script 中也顯示通知 / Show notification in npm script
});API
updateNotifier(__dirname, force?, inputNoticeOptions?)
建立更新通知器,檢查套件是否有新版本並在適當時機通知使用者。
Create an update notifier that checks if the package has a new version and notifies users at appropriate times.
參數 / Parameters:
| 參數 / Parameter | 型別 / Type | 必填 / Required | 說明 / Description |
|-----------------|------------|----------------|-------------------|
| __dirname | string \| string[] | 是 / Yes | 套件目錄路徑或路徑片段陣列 / Package directory path or path segments array |
| force | boolean | 否 / No | 是否強制檢查(忽略環境限制)/ Whether to force check (ignore environment restrictions) |
| inputNoticeOptions | Settings & NotifyOptions | 否 / No | 通知選項 / Notification options |
回傳值 / Returns: IUpdateNotifierObject \| null - Update Notifier 物件或 null / Update Notifier object or null
shouldCheckMaybe(__dirname)
判斷是否應該檢查更新。
Determine if should check for updates.
參數 / Parameters:
| 參數 / Parameter | 型別 / Type | 必填 / Required | 說明 / Description |
|-----------------|------------|----------------|-------------------|
| __dirname | string | 是 / Yes | 套件目錄路徑 / Package directory path |
回傳值 / Returns: boolean - 是否應該檢查更新 / Whether should check for updates
檢查機制 / Check Mechanism
此模組會在以下情況下跳過更新檢查:
This module skips update checks in the following conditions:
- CI 環境 / CI Environment - 透過
ci-info檢測 / Detected viaci-info - 環境變數 / Environment Variable -
NO_UPDATE_NOTIFIER已設定 /NO_UPDATE_NOTIFIERis set - 測試環境 / Test Environment -
NODE_ENV為test/NODE_ENVistest - NPX/YPX 環境 / NPX/YPX Environment - 透過
@yarn-tool/is-npx檢測 / Detected via@yarn-tool/is-npx
預設選項 / Default Options
{
shouldNotifyInNpmScript: false, // 不在 npm script 中顯示 / Don't show in npm script
updateCheckInterval: 1000 * 60 * 60 * 24 * 7, // 每 7 天檢查一次 / Check every 7 days
}相關套件 / Related Packages
@yarn-tool/is-npx- 檢測是否在 NPX/YPX 環境中 / Detect if running in NPX/YPX environmentupdate-notifier- 底層更新通知功能 / Underlying update notification functionality
授權 / License
ISC
