Skip to content

Commit d573a80

Browse files
committed
Replace update-notifier with smaller packages
1 parent 66e6f6f commit d573a80

File tree

3 files changed

+31
-245
lines changed

3 files changed

+31
-245
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
"files": [
1313
"dist/locales/*",
1414
"dist/index.js",
15-
"dist/check.js",
1615
"dist/xdg-open"
1716
],
1817
"scripts": {
1918
"lint": "eslint src/ test/",
2019
"test": "TZ=Greenland NODE_ENV=testing jest --coverage --silent --maxWorkers=2 --ci",
2120
"coveralls": "cat ./coverage/lcov.info | coveralls",
2221
"build": "ncc build bin/index.js -o dist",
23-
"package": "pkg --targets node12.2.0-linux-x64,node12.2.0-win-x64,node12.2.0-macos-x64 -o exoframe index.js"
22+
"package": "pkg --targets node12.2.0-linux-x64,node12.2.0-win-x64,node12.2.0-macos-x64 -o exoframe dist/index.js"
2423
},
2524
"dependencies": {},
2625
"devDependencies": {
@@ -44,16 +43,17 @@
4443
"jest": "^24.9.0",
4544
"js-yaml": "^3.13.1",
4645
"jsonwebtoken": "^8.5.1",
46+
"latest-version": "^5.1.0",
4747
"lodash": "^4.17.15",
4848
"multimatch": "^4.0.0",
4949
"nock": "^11.7.0",
5050
"open": "^7.0.0",
5151
"ora": "^4.0.2",
5252
"pkg": "^4.4.0",
5353
"prettier": "^1.18.2",
54+
"semver-diff": "^3.1.1",
5455
"sinon": "^7.5.0",
5556
"tar-fs": "^2.0.0",
56-
"update-notifier": "^3.0.1",
5757
"yargs": "^14.2.0"
5858
},
5959
"jest": {

src/util/checkUpdate.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
// npm packages
22
const chalk = require('chalk');
3-
const updateNotifier = require('update-notifier');
3+
const latestVersion = require('latest-version');
4+
const semverDiff = require('semver-diff');
45

56
// packaged script path
67
const pkgPath = '/snapshot/exoframe-cli/src/util';
78

89
// check function
9-
module.exports = pkg => {
10+
module.exports = async pkg => {
11+
const current = '5.0.0'; // pkg.version;
1012
// Checks for available update and returns an instance
11-
const notifier = updateNotifier({
12-
pkg,
13-
updateCheckInterval: 1000,
14-
});
13+
const latest = await latestVersion('exoframe').then(r => r.trim());
1514
// show message if update is available
16-
if (notifier.update) {
17-
const {update} = notifier;
15+
if (semverDiff(current, latest)) {
1816
const isPackaged = __dirname === pkgPath;
1917
const upNpmMsg = `Run ${chalk.cyan('npm i -g exoframe')} to update`;
2018
const upPkgMsg = `Download from ${chalk.cyan('https://github.com/exoframejs/exoframe/releases')}`;
2119
const upmsg = isPackaged ? upPkgMsg : upNpmMsg;
22-
const message = `Update available ${chalk.dim(update.current)} ${chalk.reset('→')} ${chalk.green(update.latest)}`;
20+
const message = `Update available ${chalk.dim(current)} ${chalk.reset('→')} ${chalk.green(latest)}`;
2321
console.log(`
2422
┌───────────────────────────────────────┐
2523
│ │
26-
${message}
24+
${message}
2725
${upmsg}
2826
│ │
2927
└───────────────────────────────────────┘

0 commit comments

Comments
 (0)