Skip to content

Commit

Permalink
a workaround for node-fetch using esm
Browse files Browse the repository at this point in the history
  • Loading branch information
xsro committed Dec 5, 2021
1 parent 05e6de2 commit ac2030e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
"js-yaml": "^4.0.0",
"jszip": "^3.7.1",
"mocha": "^9.1.3",
"node-fetch": "^3.x",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"rimraf": "^3.0.2",
Expand All @@ -389,6 +388,9 @@
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1"
},
"dependencies": {
"node-fetch": "^3.x"
},
"repository": {
"type": "git",
"url": "https://github.com/dosasm/masm-tasm"
Expand All @@ -398,4 +400,4 @@
"email": "[email protected]"
},
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion src/utils/downloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* API for downloading information from web
*/
import { logger } from "./logger";
import fetch from "node-fetch";
import { fetch } from "./fetch";

export async function downloadFromMultiSources(urls: string[]): Promise<string | undefined> {
for (const url of urls) {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// @ts-check

export const fetch =
process.platform
? eval("(...args) => import('node-fetch').then(({default: fetch}) => fetch(...args))")
: window.fetch;

0 comments on commit ac2030e

Please sign in to comment.