From c04fd346e4eb06266a274bf2ce91439abafa6e76 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Thu, 16 May 2019 16:55:55 +0800 Subject: [PATCH 1/5] Deprecated `callback` option --- index.js | 16 +--------------- test/update-notifier.js | 12 ------------ 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/index.js b/index.js index 50425ac..5985f3c 100644 --- a/index.js +++ b/index.js @@ -38,14 +38,12 @@ class UpdateNotifier { this.packageName = options.pkg.name; this.packageVersion = options.pkg.version; this.updateCheckInterval = typeof options.updateCheckInterval === 'number' ? options.updateCheckInterval : ONE_DAY; - this.hasCallback = typeof options.callback === 'function'; - this.callback = options.callback || (() => {}); this.disabled = 'NO_UPDATE_NOTIFIER' in process.env || process.argv.includes('--no-update-notifier') || isCi(); this.shouldNotifyInNpmScript = options.shouldNotifyInNpmScript; - if (!this.disabled && !this.hasCallback) { + if (!this.disabled) { try { const ConfigStore = configstore(); this.config = new ConfigStore(`update-notifier-${this.packageName}`, { @@ -70,18 +68,6 @@ class UpdateNotifier { } check() { - if (this.hasCallback) { - (async () => { - try { - this.callback(null, await this.checkNpm()); - } catch (error) { - this.callback(error); - } - })(); - - return; - } - if ( !this.config || this.config.get('optOut') || diff --git a/test/update-notifier.js b/test/update-notifier.js index fcdd24f..00eacc8 100644 --- a/test/update-notifier.js +++ b/test/update-notifier.js @@ -13,7 +13,6 @@ const generateSettings = (options = {}) => { name: 'update-notifier-tester', version: '0.0.2' }, - callback: options.callback, distTag: options.distTag }; }; @@ -44,17 +43,6 @@ test('check for update with dist-tag', async t => { t.is(update.latest, '0.0.3-rc1'); }); -test.cb('check for update with callback', t => { - t.plan(1); - - updateNotifier(generateSettings({ - callback: () => { - t.pass(); - t.end(); - } - })); -}); - test('don\'t initialize configStore when NO_UPDATE_NOTIFIER is set', t => { process.env.NO_UPDATE_NOTIFIER = '1'; const notifier = updateNotifier(generateSettings()); From f6d62686d343a063aa65985ae9f1f067bef58584 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Tue, 4 Jun 2019 18:14:17 +0800 Subject: [PATCH 2/5] Rename `checkNpm()` to `getSemverDiff()` --- check.js | 6 +++--- index.js | 2 +- test/update-notifier.js | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/check.js b/check.js index 11dba33..5d0889f 100644 --- a/check.js +++ b/check.js @@ -10,13 +10,13 @@ updateNotifier = new updateNotifier.UpdateNotifier(options); // Exit process when offline setTimeout(process.exit, 1000 * 30); - const update = await updateNotifier.checkNpm(); + const diff = await updateNotifier.getSemverDiff(); // Only update the last update check time on success updateNotifier.config.set('lastUpdateCheck', Date.now()); - if (update.type && update.type !== 'latest') { - updateNotifier.config.set('update', update); + if (diff.type && diff.type !== 'latest') { + updateNotifier.config.set('update', diff); } // Call process exit explicitly to terminate the child process, diff --git a/index.js b/index.js index 5985f3c..a5a13db 100644 --- a/index.js +++ b/index.js @@ -94,7 +94,7 @@ class UpdateNotifier { }).unref(); } - async checkNpm() { + async getSemverDiff() { const {distTag} = this.options; const latest = await latestVersion()(this.packageName, {version: distTag}); diff --git a/test/update-notifier.js b/test/update-notifier.js index 00eacc8..531da96 100644 --- a/test/update-notifier.js +++ b/test/update-notifier.js @@ -33,13 +33,13 @@ test.afterEach(() => { }, 10000); }); -test('check for update', async t => { - const update = await updateNotifier(generateSettings()).checkNpm(); +test('get semver diff', async t => { + const update = await updateNotifier(generateSettings()).getSemverDiff(); t.is(update.latest, '0.0.2'); }); -test('check for update with dist-tag', async t => { - const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).checkNpm(); +test('get semver diff with dist-tag', async t => { + const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).getSemverDiff(); t.is(update.latest, '0.0.3-rc1'); }); From 148fda03146bbfd8f442593fee1f8d96333f69ca Mon Sep 17 00:00:00 2001 From: LitoMore Date: Tue, 4 Jun 2019 18:22:37 +0800 Subject: [PATCH 3/5] Update doc --- readme.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index f9999a5..d0f18cd 100644 --- a/readme.md +++ b/readme.md @@ -124,12 +124,6 @@ Default: `1000 * 60 * 60 * 24` *(1 day)* How often to check for updates. -#### callback(error, update) - -Type: `Function` - -Passing a callback here will make it check for an update directly and report right away. Not recommended as you won't get the benefits explained in [`How`](#how). `update` is equal to `notifier.update`. - #### shouldNotifyInNpmScript Type: `boolean`
@@ -144,6 +138,10 @@ Default: `latest` Which [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages) to use to find the latest version. +### notifier.getSemverDiff() + +Get semver difference directly. This method will not trigger the checking process. + ### notifier.notify([options]) Convenience method to display a notification message. *(See screenshot)* From a303bf39816313bc4e4eb3ccc23db168ff6a9103 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Mon, 1 Jul 2019 14:35:04 +0800 Subject: [PATCH 4/5] Rename `getSemverDiff` to `checkImmediately` --- check.js | 6 +++--- index.js | 2 +- readme.md | 11 +++++++++-- test/update-notifier.js | 9 +++++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/check.js b/check.js index 5d0889f..0dd693f 100644 --- a/check.js +++ b/check.js @@ -10,13 +10,13 @@ updateNotifier = new updateNotifier.UpdateNotifier(options); // Exit process when offline setTimeout(process.exit, 1000 * 30); - const diff = await updateNotifier.getSemverDiff(); + const update = await updateNotifier.checkImmediately(); // Only update the last update check time on success updateNotifier.config.set('lastUpdateCheck', Date.now()); - if (diff.type && diff.type !== 'latest') { - updateNotifier.config.set('update', diff); + if (update.type && update.type !== 'latest') { + updateNotifier.config.set('update', update); } // Call process exit explicitly to terminate the child process, diff --git a/index.js b/index.js index a5a13db..5e4d502 100644 --- a/index.js +++ b/index.js @@ -94,7 +94,7 @@ class UpdateNotifier { }).unref(); } - async getSemverDiff() { + async checkImmediately() { const {distTag} = this.options; const latest = await latestVersion()(this.packageName, {version: distTag}); diff --git a/readme.md b/readme.md index d0f18cd..523cc4e 100644 --- a/readme.md +++ b/readme.md @@ -138,9 +138,16 @@ Default: `latest` Which [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages) to use to find the latest version. -### notifier.getSemverDiff() +### notifier.checkImmediately() -Get semver difference directly. This method will not trigger the checking process. +Check update immediately. This method will not trigger the checking process. + +Returns an `object` with: + +- `latest` _(String)_ - Latest version. +- `current` _(String)_ - Current version. +- `type` _(String)_ - Type of current update. Possible values: `latest`, `major`, `minor`, `patch`, `prerelease`, `build`. +- `name` _(String)_ - Package name. ### notifier.notify([options]) diff --git a/test/update-notifier.js b/test/update-notifier.js index 531da96..8bef813 100644 --- a/test/update-notifier.js +++ b/test/update-notifier.js @@ -33,13 +33,14 @@ test.afterEach(() => { }, 10000); }); -test('get semver diff', async t => { - const update = await updateNotifier(generateSettings()).getSemverDiff(); +test('check immediately', async t => { + const update = await updateNotifier(generateSettings()).checkImmediately(); + console.log(update); t.is(update.latest, '0.0.2'); }); -test('get semver diff with dist-tag', async t => { - const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).getSemverDiff(); +test('check immeditely with dist-tag', async t => { + const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).checkImmediately(); t.is(update.latest, '0.0.3-rc1'); }); From 211464378c73895b8bfe9c8e5594f7b5709c1fb6 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Fri, 13 Dec 2019 02:17:21 +0800 Subject: [PATCH 5/5] Rename `checkImmediately` to `fetchInfo` --- check.js | 2 +- index.js | 2 +- readme.md | 6 +++--- test/update-notifier.js | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/check.js b/check.js index 0dd693f..fc0ee9c 100644 --- a/check.js +++ b/check.js @@ -10,7 +10,7 @@ updateNotifier = new updateNotifier.UpdateNotifier(options); // Exit process when offline setTimeout(process.exit, 1000 * 30); - const update = await updateNotifier.checkImmediately(); + const update = await updateNotifier.fetchInfo(); // Only update the last update check time on success updateNotifier.config.set('lastUpdateCheck', Date.now()); diff --git a/index.js b/index.js index 5e4d502..bbd4050 100644 --- a/index.js +++ b/index.js @@ -94,7 +94,7 @@ class UpdateNotifier { }).unref(); } - async checkImmediately() { + async fetchInfo() { const {distTag} = this.options; const latest = await latestVersion()(this.packageName, {version: distTag}); diff --git a/readme.md b/readme.md index 523cc4e..52d55e5 100644 --- a/readme.md +++ b/readme.md @@ -138,13 +138,13 @@ Default: `latest` Which [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages) to use to find the latest version. -### notifier.checkImmediately() +### notifier.fetchInfo() -Check update immediately. This method will not trigger the checking process. +Check update information. Returns an `object` with: -- `latest` _(String)_ - Latest version. +- `latest` _(String)_ - Latest version. - `current` _(String)_ - Current version. - `type` _(String)_ - Type of current update. Possible values: `latest`, `major`, `minor`, `patch`, `prerelease`, `build`. - `name` _(String)_ - Package name. diff --git a/test/update-notifier.js b/test/update-notifier.js index 8bef813..7c42315 100644 --- a/test/update-notifier.js +++ b/test/update-notifier.js @@ -33,14 +33,14 @@ test.afterEach(() => { }, 10000); }); -test('check immediately', async t => { - const update = await updateNotifier(generateSettings()).checkImmediately(); +test('fetch info', async t => { + const update = await updateNotifier(generateSettings()).fetchInfo(); console.log(update); t.is(update.latest, '0.0.2'); }); -test('check immeditely with dist-tag', async t => { - const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).checkImmediately(); +test('fetch info with dist-tag', async t => { + const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).fetchInfo(); t.is(update.latest, '0.0.3-rc1'); });