Skip to content

Commit

Permalink
Ensure serve starts even when update check fails (#360)
Browse files Browse the repository at this point in the history
* Ensure serve starts even if update check fails

* Add timeout for update check

* Bumped lockfile
  • Loading branch information
n0v1 authored and leo committed May 14, 2018
1 parent 7d05813 commit 096d128
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
39 changes: 27 additions & 12 deletions bin/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {red, bold} = require('chalk');
const nodeVersion = require('node-version');
const cert = require('openssl-self-signed-certificate');
const boxen = require('boxen');
const promiseTimeout = require('promise-timeout');

// Utilities
const pkg = require('../package');
Expand Down Expand Up @@ -83,19 +84,33 @@ detect(port).then(async open => {
const {NODE_ENV} = process.env;

if (NODE_ENV !== 'production') {
const update = await checkForUpdate(pkg);

if (update) {
const message = `${bold(
'UPDATE AVAILABLE:'
)} The latest version of \`serve\` is ${update.latest}`;

try {
const update = await promiseTimeout.timeout(checkForUpdate(pkg), 2000);

if (update) {
const message = `${bold(
'UPDATE AVAILABLE:'
)} The latest version of \`serve\` is ${update.latest}`;

console.log(
boxen(message, {
padding: 1,
borderColor: 'green',
margin: 1
})
);
}
} catch (err) {
console.log(
boxen(message, {
padding: 1,
borderColor: 'green',
margin: 1
})
boxen(
`${bold(
'UPDATE CHECK FAILED:'
)} ${err.message}`, {
padding: 1,
borderColor: 'red',
margin: 1
}
)
);
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"opn": "5.3.0",
"path-is-inside": "1.0.2",
"path-type": "3.0.0",
"promise-timeout": "1.3.0",
"send": "0.16.2",
"update-check": "1.5.0"
},
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3197,6 +3197,10 @@ progress@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f"

promise-timeout@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/promise-timeout/-/promise-timeout-1.3.0.tgz#d1c78dd50a607d5f0a5207410252a3a0914e1014"

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down

0 comments on commit 096d128

Please sign in to comment.