Skip to content

Commit 13b9df8

Browse files
committed
1 parent c90309d commit 13b9df8

File tree

8 files changed

+38
-12
lines changed

8 files changed

+38
-12
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"editor.formatOnSave": true,
1212
"markdownlint.config": {
1313
"MD033": false
14-
}
14+
},
15+
"typescript.tsdk": "node_modules/typescript/lib"
1516
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@
382382
"process": "^0.11.10",
383383
"rimraf": "^3.0.2",
384384
"ts-loader": "^9.2.6",
385-
"typescript": "^4.4.4",
385+
"typescript": "^4.6.0-dev.20211205",
386386
"vscode-test": "^1.4.1",
387387
"vscode-uri": "^3.0.2",
388388
"webpack": "^5.60.0",
@@ -400,4 +400,4 @@
400400
"email": "xsro@foxmail.com"
401401
},
402402
"license": "MIT"
403-
}
403+
}

src/test/suite/download.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import assert = require("assert");
2+
import { downloadFromMultiSources } from "../../utils/downloadFile";
3+
4+
suite("test download", async function () {
5+
test("test download with fetch", async function () {
6+
const list = [
7+
'https://cdn.jsdelivr.net/gh/MicrosoftDocs/cpp-docs@master/docs/assembler/masm/assume.md',
8+
'https://raw.githubusercontent.com/MicrosoftDocs/cpp-docs/master/docs/assembler/masm/assume.md',
9+
'https://gitee.com/dosasm/cpp-docs/raw/master/docs/assembler/masm/assume.md'
10+
];
11+
for (const url of list) {
12+
const str = await downloadFromMultiSources([url]);
13+
assert.ok(str, url);
14+
}
15+
});
16+
});

src/utils/downloadFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* API for downloading information from web
33
*/
44
import { logger } from "./logger";
5-
import fetch from 'node-fetch';
5+
import { fetch } from "./fetch";
66

77
export async function downloadFromMultiSources(urls: string[]): Promise<string | undefined> {
88
for (const url of urls) {

src/utils/fetch.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
3+
export const fetch =
4+
process.platform
5+
? (...args: any[]) => import(
6+
/* webpackIgnore: true */'node-fetch').then((module) => {
7+
console.log(module);
8+
return (module.default as any)(...args);
9+
}
10+
)
11+
: window.fetch;

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module": "commonjs",
3+
"module": "node12",
44
"target": "es2017",
55
"outDir": "dist",
66
"lib": [

webpack.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'use strict';
99

1010
const path = require('path');
11+
const webpack = require('webpack');
1112
/** @typedef {import('webpack').Configuration} WebpackConfig **/
1213

1314
/** @type WebpackConfig */
@@ -51,8 +52,6 @@ const config = {
5152
}
5253
};
5354

54-
const webpack = require('webpack');
55-
5655
/** @type WebpackConfig */
5756
const webExtensionConfig = {
5857
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
@@ -70,7 +69,6 @@ const webExtensionConfig = {
7069
mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules
7170
extensions: ['.ts', '.js'], // support ts-files and js-files
7271
alias: {
73-
// 'node-fetch': './browser-fetch'
7472
// provides alternate implementation for node module and source files
7573
},
7674
fallback: {

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -3284,10 +3284,10 @@ type-is@^1.6.16:
32843284
media-typer "0.3.0"
32853285
mime-types "~2.1.24"
32863286

3287-
typescript@^4.4.4:
3288-
version "4.5.2"
3289-
resolved "https://registry.npmmirror.com/typescript/download/typescript-4.5.2.tgz#8ac1fba9f52256fdb06fb89e4122fa6a346c2998"
3290-
integrity sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==
3287+
typescript@^4.6.0-dev.20211205:
3288+
version "4.6.0-dev.20211205"
3289+
resolved "https://registry.npmmirror.com/typescript/download/typescript-4.6.0-dev.20211205.tgz#38a5a152e432442faa1f9593220e3b8abaf1726a"
3290+
integrity sha512-OThM062cY8geGPmZFgih9QNtslG04mUgJYFNlGAkqZKBGOOS84gEdV5omwIi09q7viDSabIlyFd45YiIhUjaLA==
32913291

32923292
unbox-primitive@^1.0.1:
32933293
version "1.0.1"

0 commit comments

Comments
 (0)