Skip to content

Commit

Permalink
try to get rid of top-level await
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed Nov 21, 2024
1 parent 2f975d7 commit dd21d68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down

0 comments on commit dd21d68

Please sign in to comment.