Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 71ff0ef

Browse files
committed
Fix #154
1 parent 0090df8 commit 71ff0ef

File tree

6 files changed

+121
-387
lines changed

6 files changed

+121
-387
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ The `vscode` NPM module provides VS Code extension authors tools to write extens
1212

1313
For more information around extension authoring for VS Code, please see http://code.visualstudio.com/docs/extensions/overview
1414

15-
# License
15+
## Changes
16+
17+
**1.1.37** | 2020-04-22
18+
19+
- Remove `request` and `url-parse` dependencies. [#154](https://github.com/microsoft/vscode-extension-vscode/issues/154).
20+
21+
## License
1622

1723
[MIT](LICENSE)

bin/install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function getURLMatchingEngine(engine, callback) {
6666
});
6767
}
6868

69-
shared.getContents('https://vscode-update.azurewebsites.net/api/releases/stable', null, { "X-API-Version": "2" }, function (error, tagsRaw) {
69+
shared.getContents('https://update.code.visualstudio.com/api/releases/stable', null, { "X-API-Version": "2" }, function (error, tagsRaw) {
7070
if (error) {
7171
exitWithError(error);
7272
}

lib/shared.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,54 @@
33
*--------------------------------------------------------*/
44
'use strict';
55
Object.defineProperty(exports, "__esModule", { value: true });
6-
var request = require('request');
7-
var URL = require('url-parse');
6+
var url_1 = require("url");
7+
var https = require("https");
8+
var HttpsProxyAgent = require('https-proxy-agent');
9+
var HttpProxyAgent = require('http-proxy-agent');
10+
var PROXY_AGENT = undefined;
11+
var HTTPS_PROXY_AGENT = undefined;
12+
if (process.env.npm_config_proxy) {
13+
PROXY_AGENT = new HttpProxyAgent(process.env.npm_config_proxy);
14+
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_proxy);
15+
}
16+
if (process.env.npm_config_https_proxy) {
17+
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_https_proxy);
18+
}
819
function getContents(url, token, headers, callback) {
9-
request.get(toRequestOptions(url, token, headers), function (error, response, body) {
10-
if (!error && response && response.statusCode >= 400) {
11-
error = new Error('Request returned status code: ' + response.statusCode + '\nDetails: ' + response.body);
20+
var options = toRequestOptions(url, token, headers);
21+
https.get(options, function (res) {
22+
if (res && res.statusCode >= 400) {
23+
callback(new Error('Request returned status code: ' + res.statusCode));
1224
}
13-
callback(error, body);
25+
var data = '';
26+
res.on('data', function (chunk) {
27+
data += chunk;
28+
});
29+
res.on('end', function () {
30+
callback(null, data);
31+
});
32+
}).on('error', function (e) {
33+
callback(e);
1434
});
1535
}
1636
exports.getContents = getContents;
1737
function toRequestOptions(url, token, headers) {
18-
headers = headers || {
19-
'user-agent': 'nodejs'
20-
};
38+
if (headers === void 0) { headers = { 'user-agent': 'nodejs' }; }
39+
var options = url_1.parse(url);
40+
if (PROXY_AGENT && options.protocol.startsWith('http:')) {
41+
options.agent = PROXY_AGENT;
42+
}
43+
if (HTTPS_PROXY_AGENT && options.protocol.startsWith('https:')) {
44+
options.agent = HTTPS_PROXY_AGENT;
45+
}
2146
if (token) {
2247
headers['Authorization'] = 'token ' + token;
2348
}
24-
var parsedUrl = new URL(url);
25-
var options = {
26-
url: url,
27-
headers: headers
28-
};
49+
options.headers = headers;
2950
// We need to test the absence of true here because there is an npm bug that will not set boolean
3051
// env variables if they are set to false.
3152
if (process.env.npm_config_strict_ssl !== 'true') {
32-
options.strictSSL = false;
33-
}
34-
if (process.env.npm_config_proxy && parsedUrl.protocol === 'http:') {
35-
options.proxy = process.env.npm_config_proxy;
36-
}
37-
else if (process.env.npm_config_https_proxy && parsedUrl.protocol === 'https:') {
38-
options.proxy = process.env.npm_config_https_proxy;
53+
options.rejectUnauthorized = false;
3954
}
4055
return options;
4156
}
42-
exports.toRequestOptions = toRequestOptions;

lib/shared.ts

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,64 @@
44

55
'use strict';
66

7-
var request = require('request');
8-
var URL = require('url-parse');
7+
import { parse as parseUrl } from 'url';
8+
import * as https from 'https';
99

10-
export function getContents(url, token, headers, callback) {
11-
request.get(toRequestOptions(url, token, headers), function (error, response, body) {
12-
if (!error && response && response.statusCode >= 400) {
13-
error = new Error('Request returned status code: ' + response.statusCode + '\nDetails: ' + response.body);
10+
const HttpsProxyAgent = require('https-proxy-agent');
11+
const HttpProxyAgent = require('http-proxy-agent');
12+
13+
let PROXY_AGENT = undefined;
14+
let HTTPS_PROXY_AGENT = undefined;
15+
16+
if (process.env.npm_config_proxy) {
17+
PROXY_AGENT = new HttpProxyAgent(process.env.npm_config_proxy);
18+
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_proxy);
19+
}
20+
if (process.env.npm_config_https_proxy) {
21+
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_https_proxy);
22+
}
23+
24+
export function getContents(url: string, token?: string, headers?: any, callback?: (err: Error, body?: any) => void) {
25+
const options = toRequestOptions(url, token, headers);
26+
27+
https.get(options, res => {
28+
if (res && res.statusCode >= 400) {
29+
callback(new Error('Request returned status code: ' + res.statusCode));
1430
}
1531

16-
callback(error, body);
32+
let data = '';
33+
34+
res.on('data', chunk => {
35+
data += chunk;
36+
});
37+
38+
res.on('end', () => {
39+
callback(null, data);
40+
});
41+
}).on('error', e => {
42+
callback(e);
1743
});
1844
}
1945

20-
export function toRequestOptions(url, token, headers) {
21-
headers = headers || {
22-
'user-agent': 'nodejs'
23-
};
46+
function toRequestOptions(url: string, token: string | null, headers = { 'user-agent': 'nodejs' }): https.RequestOptions {
47+
const options: https.RequestOptions = parseUrl(url);
48+
if (PROXY_AGENT && options.protocol.startsWith('http:')) {
49+
options.agent = PROXY_AGENT;
50+
}
51+
if (HTTPS_PROXY_AGENT && options.protocol.startsWith('https:')) {
52+
options.agent = HTTPS_PROXY_AGENT;
53+
}
2454

2555
if (token) {
2656
headers['Authorization'] = 'token ' + token;
2757
}
2858

29-
let parsedUrl = new URL(url);
30-
31-
var options: any = {
32-
url: url,
33-
headers: headers
34-
};
59+
options.headers = headers;
3560

3661
// We need to test the absence of true here because there is an npm bug that will not set boolean
3762
// env variables if they are set to false.
3863
if (process.env.npm_config_strict_ssl !== 'true') {
39-
options.strictSSL = false;
40-
}
41-
42-
if (process.env.npm_config_proxy && parsedUrl.protocol === 'http:') {
43-
options.proxy = process.env.npm_config_proxy;
44-
} else if (process.env.npm_config_https_proxy && parsedUrl.protocol === 'https:') {
45-
options.proxy = process.env.npm_config_https_proxy;
64+
options.rejectUnauthorized = false;
4665
}
4766

4867
return options;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
},
1616
"dependencies": {
1717
"glob": "^7.1.2",
18+
"http-proxy-agent": "^4.0.1",
19+
"https-proxy-agent": "^5.0.0",
1820
"mocha": "^5.2.0",
19-
"request": "^2.88.0",
2021
"semver": "^5.4.1",
2122
"source-map-support": "^0.5.0",
22-
"url-parse": "^1.4.4",
2323
"vscode-test": "^0.4.1"
2424
},
2525
"devDependencies": {

0 commit comments

Comments
 (0)