diff --git a/lib/helpers/immediate.js b/lib/helpers/immediate.js index 0a1c26c32f6..73085f7d420 100644 --- a/lib/helpers/immediate.js +++ b/lib/helpers/immediate.js @@ -7,7 +7,9 @@ 'use strict'; -const nextTick = process.nextTick.bind(process); +const nextTick = typeof process !== 'undefined' && typeof process.nextTick === 'function' ? + process.nextTick.bind(process) : + cb => setTimeout(cb, 0); // Fallback for browser build module.exports = function immediate(cb) { return nextTick(cb); diff --git a/lib/helpers/isAsyncFunction.js b/lib/helpers/isAsyncFunction.js index 2a136dcd934..998705304a9 100644 --- a/lib/helpers/isAsyncFunction.js +++ b/lib/helpers/isAsyncFunction.js @@ -1,10 +1,22 @@ 'use strict'; -const asyncFunctionPrototype = Object.getPrototypeOf(async function() {}); +let asyncFunctionPrototype = null; +// try/catch for Babel compatibility, because Babel preset-env requires +// regenerator-runtime for async/await and we don't want to include that +// for a simple check. +try { + asyncFunctionPrototype = Object.getPrototypeOf(async function() {}); +} catch (err) {} -module.exports = function isAsyncFunction(v) { - return ( - typeof v === 'function' && - Object.getPrototypeOf(v) === asyncFunctionPrototype - ); -}; +if (asyncFunctionPrototype == null) { + module.exports = function isAsyncFunction() { + return false; + }; +} else { + module.exports = function isAsyncFunction(v) { + return ( + typeof v === 'function' && + Object.getPrototypeOf(v) === asyncFunctionPrototype + ); + }; +} diff --git a/package.json b/package.json index 05653305ae9..6c73e1ea0f9 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "babel-loader": "8.2.4", "benchmark": "2.1.4", "bluebird": "3.7.2", + "buffer": "6.0.3", "cheerio": "1.0.0-rc.10", "crypto-browserify": "3.12.0", "dox": "0.3.1", diff --git a/webpack.config.js b/webpack.config.js index ea65591e8d0..ebecbab2f84 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,6 @@ 'use strict'; +const webpack = require('webpack'); const paths = require('path'); const webpackConfig = { @@ -35,12 +36,21 @@ const webpackConfig = { resolve: { fallback: { assert: require.resolve('assert-browserify'), + buffer: require.resolve('buffer/'), crypto: require.resolve('crypto-browserify'), stream: require.resolve('stream-browserify') } }, target: 'web', - mode: 'production' + mode: 'production', + plugins: [ + new webpack.DefinePlugin({ + process: '({env:{}})' + }), + new webpack.ProvidePlugin({ + Buffer: ['buffer', 'Buffer'] + }) + ] }; module.exports = webpackConfig;