Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] update node-fetch to v3 #33

Open
wants to merge 2 commits into
base: 2022
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"editor.formatOnSave": true,
"markdownlint.config": {
"MD033": false
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@
"@types/glob": "^7.2.0",
"@types/js-yaml": "^4.0.3",
"@types/mocha": "^9.0.0",
"@types/node-fetch": "^2.x",
"@types/vscode": "^1.61.0",
"@types/webpack-env": "^1.16.2",
"@typescript-eslint/eslint-plugin": "^5.2.0",
Expand All @@ -379,17 +378,19 @@
"js-yaml": "^4.0.0",
"jszip": "^3.7.1",
"mocha": "^9.1.3",
"node-fetch": "^2.x",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"typescript": "^4.6.0-dev.20211205",
"vscode-test": "^1.4.1",
"vscode-uri": "^3.0.2",
"webpack": "^5.60.0",
"webpack-cli": "^4.9.1"
},
"dependencies": {
"node-fetch": "^3.x"
},
"repository": {
"type": "git",
"url": "https://github.com/dosasm/masm-tasm"
Expand All @@ -399,4 +400,4 @@
"email": "[email protected]"
},
"license": "MIT"
}
}
16 changes: 16 additions & 0 deletions src/test/suite/download.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import assert = require("assert");
import { downloadFromMultiSources } from "../../utils/downloadFile";

suite("test download", async function () {
test("test download with fetch", async function () {
const list = [
'https://cdn.jsdelivr.net/gh/MicrosoftDocs/cpp-docs@master/docs/assembler/masm/assume.md',
'https://raw.githubusercontent.com/MicrosoftDocs/cpp-docs/master/docs/assembler/masm/assume.md',
'https://gitee.com/dosasm/cpp-docs/raw/master/docs/assembler/masm/assume.md'
];
for (const url of list) {
const str = await downloadFromMultiSources([url]);
assert.ok(str, url);
}
});
});
4 changes: 2 additions & 2 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';
import Mocha from 'mocha';
import glob from 'glob';
import * as vscode from 'vscode';

export function run(): Promise<void> {
Expand Down
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
11 changes: 11 additions & 0 deletions src/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

export const fetch =
process.platform
? (...args: any[]) => import(
/* webpackIgnore: true */'node-fetch').then((module) => {
console.log(module);
return (module.default as any)(...args);
}
)
: window.fetch;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "node12",
"target": "es2017",
"outDir": "dist",
"lib": [
Expand Down
4 changes: 1 addition & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'use strict';

const path = require('path');
const webpack = require('webpack');
/** @typedef {import('webpack').Configuration} WebpackConfig **/

/** @type WebpackConfig */
Expand Down Expand Up @@ -51,8 +52,6 @@ const config = {
}
};

const webpack = require('webpack');

/** @type WebpackConfig */
const webExtensionConfig = {
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
Expand All @@ -70,7 +69,6 @@ const webExtensionConfig = {
mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules
extensions: ['.ts', '.js'], // support ts-files and js-files
alias: {
// 'node-fetch': './browser-fetch'
// provides alternate implementation for node module and source files
},
fallback: {
Expand Down
Loading