From 785b987bd61e182fe659f7eefa1cc41ea5635d1b Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 21 Oct 2022 12:33:53 -0400 Subject: [PATCH] fix: correct browser build and improve isAsyncFunction check for browser Re: #12576 --- lib/helpers/isAsyncFunction.js | 27 +++++++-------------------- package.json | 3 ++- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/lib/helpers/isAsyncFunction.js b/lib/helpers/isAsyncFunction.js index 998705304a9..8210c0d1cfe 100644 --- a/lib/helpers/isAsyncFunction.js +++ b/lib/helpers/isAsyncFunction.js @@ -1,22 +1,9 @@ 'use strict'; -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) {} - -if (asyncFunctionPrototype == null) { - module.exports = function isAsyncFunction() { - return false; - }; -} else { - module.exports = function isAsyncFunction(v) { - return ( - typeof v === 'function' && - Object.getPrototypeOf(v) === asyncFunctionPrototype - ); - }; -} +module.exports = function isAsyncFunction(v) { + return ( + typeof v === 'function' && + v.constructor && + v.constructor.name === 'AsyncFunction' + ); +}; \ No newline at end of file diff --git a/package.json b/package.json index be779b793aa..7a37a154456 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ }, "devDependencies": { "@babel/core": "7.19.3", + "@babel/preset-env": "7.19.3", "@typescript-eslint/eslint-plugin": "5.38.1", "@typescript-eslint/parser": "5.38.1", "acquit": "1.2.1", @@ -88,7 +89,7 @@ "lint": "eslint .", "lint-js": "eslint . --ext .js", "lint-ts": "eslint . --ext .ts", - "build-browser": "node ./scripts/build-browser.js", + "build-browser": "(rm ./dist/* || true) && node ./scripts/build-browser.js", "prepublishOnly": "npm run build-browser", "release": "git pull && git push origin master --tags && npm publish", "release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",