From eb25cf4cb533a531c53bbb9eb9bde0430665de9c Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Sun, 6 May 2018 18:39:29 +0200 Subject: [PATCH] Support Node 6 again. check if async/await is supported (#4283) --- server/index.js | 3 ++- server/lib/is-async-supported.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 server/lib/is-async-supported.js diff --git a/server/index.js b/server/index.js index cf7d0023..c5f28bcb 100644 --- a/server/index.js +++ b/server/index.js @@ -21,6 +21,7 @@ import pkg from '../../package' import * as asset from '../lib/asset' import * as envConfig from '../lib/runtime-config' import { isResSent } from '../lib/utils' +import isAsyncSupported from './lib/is-async-supported' const access = promisify(fs.access) @@ -113,7 +114,7 @@ export default class Server { } async prepare () { - if (this.dev && process.stdout.isTTY) { + if (this.dev && process.stdout.isTTY && isAsyncSupported()) { try { const checkForUpdate = require('update-check') const update = await checkForUpdate(pkg, { diff --git a/server/lib/is-async-supported.js b/server/lib/is-async-supported.js new file mode 100644 index 00000000..394a2688 --- /dev/null +++ b/server/lib/is-async-supported.js @@ -0,0 +1,12 @@ +// based on https://github.com/timneutkens/is-async-supported +const vm = require('vm') + +module.exports = function isAsyncSupported () { + try { + // eslint-disable-next-line no-new + new vm.Script('(async () => ({}))()') + return true + } catch (e) { + return false + } +}