mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
feat(update-notifier): update to v4.1 (#42540)
- create v2 for compatibility - update API according to release notes: - `callback` option removed - `fetchInfo` method added - remove `checkNpm` method - `boxenOptions` renamed - `distTag` option added - deprecate `packageName` and `packageVersion` - enumerate update info types Thanks!
This commit is contained in:
parent
7da9c6129d
commit
dea60ec84b
Vendored
+34
-12
@@ -1,33 +1,47 @@
|
||||
// Type definitions for update-notifier 2.5
|
||||
// Type definitions for update-notifier 4.1
|
||||
// Project: https://github.com/yeoman/update-notifier
|
||||
// Definitions by: vvakame <https://github.com/vvakame>
|
||||
// Noah Chen <https://github.com/nchen63>
|
||||
// Jason Dreyzehner <https://github.com/bitjson>
|
||||
// Michael Grinich <https://github.com/grinich>
|
||||
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import ConfigStore = require('configstore');
|
||||
|
||||
export = UpdateNotifier;
|
||||
|
||||
declare function UpdateNotifier(
|
||||
settings?: UpdateNotifier.Settings
|
||||
): UpdateNotifier.UpdateNotifier;
|
||||
/** Checks if there is an available update */
|
||||
declare function UpdateNotifier(settings?: UpdateNotifier.Settings): UpdateNotifier.UpdateNotifier;
|
||||
|
||||
declare namespace UpdateNotifier {
|
||||
class UpdateNotifier {
|
||||
constructor(settings?: Settings);
|
||||
|
||||
update?: UpdateInfo;
|
||||
readonly config: ConfigStore;
|
||||
readonly update?: UpdateInfo;
|
||||
check(): void;
|
||||
checkNpm(): void;
|
||||
/** Check update information */
|
||||
fetchInfo(): UpdateInfo | Promise<UpdateInfo>;
|
||||
/** Convenience method to display a notification message */
|
||||
notify(customMessage?: NotifyOptions): void;
|
||||
}
|
||||
|
||||
interface Settings {
|
||||
/** Which dist-tag to use to find the latest version */
|
||||
distTag?: string;
|
||||
pkg?: Package;
|
||||
callback?(error: Error | null, update?: UpdateInfo): any;
|
||||
/**
|
||||
* @deprecated use `pkg.name`
|
||||
*/
|
||||
packageName?: string;
|
||||
/**
|
||||
* @deprecated use `pkg.version`
|
||||
*/
|
||||
packageVersion?: string;
|
||||
updateCheckInterval?: number; // in milliseconds, default 1000 * 60 * 60 * 24 (1 day)
|
||||
/** How often to check for updates */
|
||||
updateCheckInterval?: number;
|
||||
/** Allows notification to be shown when running as an npm script */
|
||||
shouldNotifyInNpmScript?: boolean;
|
||||
}
|
||||
|
||||
@@ -40,10 +54,14 @@ declare namespace UpdateNotifier {
|
||||
}
|
||||
|
||||
interface NotifyOptions {
|
||||
/** Message that will be shown when an update is available */
|
||||
message?: string;
|
||||
/** Defer showing the notification to after the process has exited */
|
||||
defer?: boolean;
|
||||
/** Include the -g argument in the default message's npm i recommendation */
|
||||
isGlobal?: boolean;
|
||||
boxenOpts?: BoxenOptions;
|
||||
/** Options object that will be passed to `boxen` */
|
||||
boxenOptions?: BoxenOptions;
|
||||
}
|
||||
|
||||
interface Package {
|
||||
@@ -52,9 +70,13 @@ declare namespace UpdateNotifier {
|
||||
}
|
||||
|
||||
interface UpdateInfo {
|
||||
latest: string;
|
||||
current: string;
|
||||
type: string;
|
||||
/** Latest version */
|
||||
readonly latest: string;
|
||||
/** Current version */
|
||||
readonly current: string;
|
||||
/** Type of current update */
|
||||
readonly type: 'latest' | 'major' | 'minor' | 'patch' | 'prerelease' | 'build';
|
||||
/** Package name */
|
||||
name: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
@@ -21,4 +21,4 @@
|
||||
"index.d.ts",
|
||||
"update-notifier-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import UpdateNotifier = require('update-notifier');
|
||||
|
||||
let notifier = UpdateNotifier();
|
||||
@@ -10,7 +12,7 @@ console.log(notifier.update);
|
||||
|
||||
// Also exposed as a class
|
||||
notifier = new UpdateNotifier.UpdateNotifier({
|
||||
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
|
||||
updateCheckInterval: 1000 * 60 * 60 * 24 * 7, // 1 week
|
||||
});
|
||||
|
||||
if (notifier.update) {
|
||||
@@ -22,27 +24,24 @@ if (notifier.update) {
|
||||
message: 'Update available: ' + notifier.update.latest,
|
||||
defer: false,
|
||||
isGlobal: true,
|
||||
boxenOpts: {
|
||||
boxenOptions: {
|
||||
padding: 1,
|
||||
margin: 1,
|
||||
align: 'center',
|
||||
borderColor: 'yellow',
|
||||
borderStyle: 'round'
|
||||
}
|
||||
borderStyle: 'round',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Using the callback option
|
||||
notifier = new UpdateNotifier.UpdateNotifier({
|
||||
callback: (err, update) => {
|
||||
if (err) throw err;
|
||||
if (update) {
|
||||
console.log(
|
||||
update.current,
|
||||
update.latest,
|
||||
update.name,
|
||||
update.type
|
||||
);
|
||||
}
|
||||
(async () => {
|
||||
const update = await notifier.fetchInfo();
|
||||
update.current; // $ExpectType string
|
||||
update.latest; // $ExpectType string
|
||||
update.name; // $ExpectType string
|
||||
update.type; // $ExpectType "latest" | "major" | "minor" | "patch" | "prerelease" | "build"
|
||||
notifier.config.set('lastUpdateCheck', Date.now());
|
||||
if (update.type && update.type !== 'latest') {
|
||||
notifier.config.set('update', update);
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
// Type definitions for update-notifier 2.5
|
||||
// Project: https://github.com/yeoman/update-notifier
|
||||
// Definitions by: vvakame <https://github.com/vvakame>
|
||||
// Noah Chen <https://github.com/nchen63>
|
||||
// Jason Dreyzehner <https://github.com/bitjson>
|
||||
// Michael Grinich <https://github.com/grinich>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = UpdateNotifier;
|
||||
|
||||
declare function UpdateNotifier(
|
||||
settings?: UpdateNotifier.Settings
|
||||
): UpdateNotifier.UpdateNotifier;
|
||||
|
||||
declare namespace UpdateNotifier {
|
||||
class UpdateNotifier {
|
||||
constructor(settings?: Settings);
|
||||
|
||||
update?: UpdateInfo;
|
||||
check(): void;
|
||||
checkNpm(): void;
|
||||
notify(customMessage?: NotifyOptions): void;
|
||||
}
|
||||
|
||||
interface Settings {
|
||||
pkg?: Package;
|
||||
callback?(error: Error | null, update?: UpdateInfo): any;
|
||||
packageName?: string;
|
||||
packageVersion?: string;
|
||||
updateCheckInterval?: number; // in milliseconds, default 1000 * 60 * 60 * 24 (1 day)
|
||||
shouldNotifyInNpmScript?: boolean;
|
||||
}
|
||||
|
||||
interface BoxenOptions {
|
||||
padding?: number;
|
||||
margin?: number;
|
||||
align?: string;
|
||||
borderColor?: string;
|
||||
borderStyle?: string;
|
||||
}
|
||||
|
||||
interface NotifyOptions {
|
||||
message?: string;
|
||||
defer?: boolean;
|
||||
isGlobal?: boolean;
|
||||
boxenOpts?: BoxenOptions;
|
||||
}
|
||||
|
||||
interface Package {
|
||||
name: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
interface UpdateInfo {
|
||||
latest: string;
|
||||
current: string;
|
||||
type: string;
|
||||
name: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"update-notifier": [
|
||||
"update-notifier/v2"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"update-notifier-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,48 @@
|
||||
import UpdateNotifier = require('update-notifier');
|
||||
|
||||
let notifier = UpdateNotifier();
|
||||
|
||||
if (notifier.update) {
|
||||
notifier.notify();
|
||||
}
|
||||
|
||||
console.log(notifier.update);
|
||||
|
||||
// Also exposed as a class
|
||||
notifier = new UpdateNotifier.UpdateNotifier({
|
||||
updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
|
||||
});
|
||||
|
||||
if (notifier.update) {
|
||||
notifier.notify(); // test no options
|
||||
notifier.notify({}); // test empty object
|
||||
|
||||
// test all options
|
||||
notifier.notify({
|
||||
message: 'Update available: ' + notifier.update.latest,
|
||||
defer: false,
|
||||
isGlobal: true,
|
||||
boxenOpts: {
|
||||
padding: 1,
|
||||
margin: 1,
|
||||
align: 'center',
|
||||
borderColor: 'yellow',
|
||||
borderStyle: 'round'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Using the callback option
|
||||
notifier = new UpdateNotifier.UpdateNotifier({
|
||||
callback: (err, update) => {
|
||||
if (err) throw err;
|
||||
if (update) {
|
||||
console.log(
|
||||
update.current,
|
||||
update.latest,
|
||||
update.name,
|
||||
update.type
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user