Skip to content

Commit 73711f8

Browse files
committed
refactor: replace urllib
1 parent a78c9a2 commit 73711f8

File tree

5 files changed

+22
-82
lines changed

5 files changed

+22
-82
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"@types/lodash.uniqby": "^4.1.6",
103103
"@types/md5": "^2.1.33",
104104
"@types/node": "^10.14.6",
105+
"@types/node-fetch": "^2.5.12",
105106
"@types/react": "^16.9.20",
106107
"@types/react-dom": "^16.9.5",
107108
"@types/react-is": "^16.7.1",
@@ -144,7 +145,6 @@
144145
"strip-html-comments": "^1.0.0",
145146
"temp": "^0.9.0",
146147
"ts-jest": "^27.0.3",
147-
"urllib": "^2.37.4",
148148
"uuid": "^8.3.2",
149149
"write-pkg": "^4.0.0",
150150
"yauzl": "^2.10.0"

packages/extension-manager/package.json

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"build": "tsc --build ../../configs/ts/references/tsconfig.extension-manager.json"
1212
},
1313
"dependencies": {
14+
"@opensumi/di": "^1.0.0",
15+
"@opensumi/ide-core-browser": "2.13.9",
1416
"@opensumi/ide-components": "2.13.9",
1517
"@opensumi/ide-core-common": "2.13.9",
1618
"@opensumi/ide-core-node": "2.13.9",
@@ -21,71 +23,14 @@
2123
"@opensumi/ide-overlay": "2.13.9",
2224
"@opensumi/ide-static-resource": "2.13.9",
2325
"@opensumi/ide-theme": "2.13.9",
24-
"@types/urllib": "^2.33.0",
25-
"await-event": "^2.1.0",
26-
"compare-versions": "^3.5.1",
2726
"fs-extra": "^8.1.0",
28-
"lodash.uniqby": "^4.7.0",
29-
"query-string": "^6.8.3",
30-
"request": "^2.88.2",
3127
"requestretry": "^5.0.0",
32-
"urllib": "^2.37.1",
3328
"uuid": "^8.3.2",
3429
"yauzl": "^2.10.0"
3530
},
3631
"devDependencies": {
37-
"@opensumi/ide-addons": "2.13.9",
38-
"@opensumi/ide-comments": "2.13.9",
39-
"@opensumi/ide-components": "2.13.9",
40-
"@opensumi/ide-core-browser": "2.13.9",
41-
"@opensumi/ide-core-common": "2.13.9",
42-
"@opensumi/ide-core-node": "2.13.9",
43-
"@opensumi/ide-debug": "2.13.9",
44-
"@opensumi/ide-decoration": "2.13.9",
45-
"@opensumi/ide-dev-tool": "^1.3.1",
46-
"@opensumi/ide-editor": "2.13.9",
47-
"@opensumi/ide-explorer": "2.13.9",
48-
"@opensumi/ide-express-file-server": "2.13.9",
49-
"@opensumi/ide-extension-storage": "2.13.9",
50-
"@opensumi/ide-file-scheme": "2.13.9",
51-
"@opensumi/ide-file-search": "2.13.9",
52-
"@opensumi/ide-file-service": "2.13.9",
53-
"@opensumi/ide-file-tree-next": "2.13.9",
54-
"@opensumi/ide-i18n": "2.13.9",
55-
"@opensumi/ide-extension": "2.13.9",
56-
"@opensumi/ide-keymaps": "2.13.9",
57-
"@opensumi/ide-logs": "2.13.9",
58-
"@opensumi/ide-main-layout": "2.13.9",
59-
"@opensumi/ide-markdown": "2.13.9",
60-
"@opensumi/ide-markers": "2.13.9",
61-
"@opensumi/ide-menu-bar": "2.13.9",
62-
"@opensumi/ide-monaco": "2.13.9",
63-
"@opensumi/ide-monaco-enhance": "2.13.9",
64-
"@opensumi/ide-opened-editor": "2.13.9",
65-
"@opensumi/ide-outline": "2.13.9",
66-
"@opensumi/ide-output": "2.13.9",
67-
"@opensumi/ide-overlay": "2.13.9",
68-
"@opensumi/ide-preferences": "2.13.9",
69-
"@opensumi/ide-process": "2.13.9",
70-
"@opensumi/ide-quick-open": "2.13.9",
71-
"@opensumi/ide-scm": "2.13.9",
72-
"@opensumi/ide-search": "2.13.9",
73-
"@opensumi/ide-static-resource": "2.13.9",
74-
"@opensumi/ide-status-bar": "2.13.9",
75-
"@opensumi/ide-storage": "2.13.9",
76-
"@opensumi/ide-task": "2.13.9",
77-
"@opensumi/ide-terminal-next": "2.13.9",
78-
"@opensumi/ide-theme": "2.13.9",
79-
"@opensumi/ide-toolbar": "2.13.9",
80-
"@opensumi/ide-userstorage": "2.13.9",
81-
"@opensumi/ide-variable": "2.13.9",
82-
"@opensumi/ide-webview": "2.13.9",
83-
"@opensumi/ide-workspace": "2.13.9",
84-
"@opensumi/ide-workspace-edit": "2.13.9",
32+
"@types/node-fetch": "^2.5.12",
8533
"@types/requestretry": "^1.12.7",
86-
"browserfs": "^1.4.3",
87-
"clean-webpack-plugin": "^3.0.0",
88-
"compression": "^1.7.4",
89-
"http-proxy-middleware": "^1.0.4"
34+
"node-fetch": "^2.6.1"
9035
}
9136
}

packages/extension-manager/src/node/vsx-extension.service.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import urllib from 'urllib';
21
import path from 'path';
32
import yauzl from 'yauzl';
43
import { Readable } from 'stream';
54
import os from 'os';
65
import fs from 'fs-extra';
6+
import nodeFetch from 'node-fetch';
77
import requestretry from 'requestretry';
88
import { v4 as uuidv4 } from 'uuid';
99
import { Injectable, Autowired } from '@opensumi/di';
@@ -49,9 +49,7 @@ function createZipFile(zipFilePath: string): Promise<yauzl.ZipFile> {
4949
}
5050

5151
function cleanup(paths: string[]) {
52-
paths.forEach((p) => {
53-
fs.removeSync(p);
54-
});
52+
return Promise.all(paths.map((path) => fs.remove(path)));
5553
}
5654

5755
@Injectable()
@@ -61,15 +59,14 @@ export class VSXExtensionService implements IVSXExtensionBackService {
6159

6260
async getExtension(param: QueryParam): Promise<QueryResult | undefined> {
6361
const uri = `${this.appConfig.marketplace.endpoint}/-/query`;
64-
const res = await urllib.request(uri, {
62+
const res = await nodeFetch(uri, {
6563
headers: {
6664
...commonHeaders,
6765
},
6866
method: 'POST',
69-
dataType: 'json',
70-
data: JSON.stringify(param),
67+
body: JSON.stringify(param),
7168
});
72-
return res.data;
69+
return res.json();
7370
}
7471

7572
async install(param: IExtensionInstallParam): Promise<string> {
@@ -181,13 +178,12 @@ export class VSXExtensionService implements IVSXExtensionBackService {
181178

182179
async search(param?: VSXSearchParam): Promise<VSXSearchResult> {
183180
const uri = `${this.appConfig.marketplace.endpoint}/-/search?query=${param?.query}`;
184-
const res = await urllib.request(uri, {
181+
const res = await nodeFetch(uri, {
185182
headers: {
186183
...commonHeaders,
187184
},
188-
dataType: 'json',
189185
timeout: 30000,
190186
});
191-
return res.data;
187+
return res.json();
192188
}
193189
}

scripts/download.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const yauzl = require('yauzl');
66
const log = require('debug')('InstallExtension');
77
const os = require('os');
88
const got = require('got');
9-
const urllib = require('urllib');
9+
const nodeFetch = require('node-fetch');
1010
const awaitEvent = require('await-event');
1111
const { v4 } = require('uuid');
1212

@@ -50,7 +50,7 @@ const parallelRunPromise = (lazyPromises, n) => {
5050

5151
const api = 'https://open-vsx.org/api/';
5252

53-
async function downloadExtension (url, namespace, extensionName) {
53+
async function downloadExtension(url, namespace, extensionName) {
5454
const tmpPath = path.join(os.tmpdir(), 'extension', v4());
5555
const tmpZipFile = path.join(tmpPath, path.basename(url));
5656
await fs.mkdirp(tmpPath);
@@ -67,7 +67,7 @@ async function downloadExtension (url, namespace, extensionName) {
6767
return { tmpZipFile, targetDirName };
6868
}
6969

70-
function openZipStream (zipFile, entry) {
70+
function openZipStream(zipFile, entry) {
7171
return new Promise((resolve, reject) => {
7272
zipFile.openReadStream(entry, (error, stream) => {
7373
if (error) {
@@ -79,15 +79,15 @@ function openZipStream (zipFile, entry) {
7979
});
8080
}
8181

82-
function modeFromEntry (entry) {
82+
function modeFromEntry(entry) {
8383
const attr = entry.externalFileAttributes >> 16 || 33188;
8484

8585
return [448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */]
8686
.map((mask) => attr & mask)
8787
.reduce((a, b) => a + b, attr & 61440 /* S_IFMT */);
8888
}
8989

90-
function createZipFile (zipFilePath) {
90+
function createZipFile(zipFilePath) {
9191
return new Promise((resolve, reject) => {
9292
yauzl.open(zipFilePath, { lazyEntries: true }, (err, zipfile) => {
9393
if (err) {
@@ -98,7 +98,7 @@ function createZipFile (zipFilePath) {
9898
});
9999
}
100100

101-
function unzipFile (dist, targetDirName, tmpZipFile) {
101+
function unzipFile(dist, targetDirName, tmpZipFile) {
102102
const sourcePathRegex = new RegExp('^extension');
103103
return new Promise(async (resolve, reject) => {
104104
try {
@@ -163,12 +163,12 @@ function unzipFile (dist, targetDirName, tmpZipFile) {
163163

164164
const installExtension = async (namespace, name, version) => {
165165
const path = version ? `${namespace}/${name}/${version}` : `${namespace}/${name}`;
166-
const res = await urllib.request(`${api}${path}`, {
167-
dataType: 'json',
166+
const res = await nodeFetch(`${api}${path}`, {
168167
timeout: 100000,
169168
});
170-
if (res.data.files && res.data.files.download) {
171-
const { targetDirName, tmpZipFile } = await downloadExtension(res.data.files.download, namespace, name);
169+
const data = await res.json();
170+
if (data.files && data.files.download) {
171+
const { targetDirName, tmpZipFile } = await downloadExtension(data.files.download, namespace, name);
172172
// 解压插件
173173
await unzipFile(targetDir, targetDirName, tmpZipFile);
174174
rimraf.sync(tmpZipFile);

tools/electron/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"yargs": "^13.2.4"
4646
},
4747
"resolutions": {
48-
"urllib": "2.37.3",
4948
"canvas": "2.6.1",
5049
"y18n": "4.0.0"
5150
},

0 commit comments

Comments
 (0)