From dd21d68e4a66c68b0e840c3210bd0b9c1c69ffb0 Mon Sep 17 00:00:00 2001 From: Adriano Raiano Date: Thu, 21 Nov 2024 11:48:12 +0100 Subject: [PATCH] try to get rid of top-level await --- CHANGELOG.md | 4 ++++ lib/request.js | 6 +++++- package.json | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84f1125..c710e5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 3.0.1 + +- try to get rid of top-level await + ### 3.0.0 - fix for Deno 2 and removal of unnecessary .cjs file diff --git a/lib/request.js b/lib/request.js index 24188d5..b5bfbf7 100644 --- a/lib/request.js +++ b/lib/request.js @@ -31,7 +31,11 @@ if (typeof fetchApi !== 'function') fetchApi = undefined if (!fetchApi && !XmlHttpRequestApi && !ActiveXObjectApi) { try { - fetchApi = (await import('cross-fetch')).default + // top-level await is not available on everywhere + // fetchApi = (await import('cross-fetch')).default + import('cross-fetch').then((mod) => { + fetchApi = mod.default + }).catch(() => {}) } catch (e) {} } diff --git a/package.json b/package.json index 4617841..01f1e3a 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ }, "license": "MIT", "config": { - "fixcjs": "fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace(`(await Promise.resolve().then(function () {\n return _interopRequireWildcard(require('cross-fetch'));\n })).default`, `require('cross-fetch')`))" + "fixcjs": "fs.writeFileSync('cjs/request.js', fs.readFileSync('cjs/request.js').toString().replace(`Promise.resolve().then(function () {\n return _interopRequireWildcard(require('cross-fetch'));\n }).then(function (mod) {\n fetchApi = mod.default;\n }).catch(function () {});`, `fetchApi = require('cross-fetch');`))" }, "scripts": { "lint": "eslint .",