Skip to content

Commit 042e97b

Browse files
committed
update to typescript 2.1
1 parent 098e43b commit 042e97b

File tree

6 files changed

+19
-2416
lines changed

6 files changed

+19
-2416
lines changed

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "request-light",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Lightweight request library. Promise based, with proxy support.",
55
"main": "./lib/main.js",
66
"typings": "./lib/main",
@@ -14,12 +14,14 @@
1414
"url": "https://github.com/Microsoft/node-request-light/issues"
1515
},
1616
"devDependencies": {
17-
"typescript": "^1.8.9"
17+
"typescript": "^2.1.5",
18+
"@types/node": "^6.0.51",
19+
"@types/mocha": "^2.2.33"
1820
},
1921
"dependencies": {
2022
"http-proxy-agent": "^0.2.6",
2123
"https-proxy-agent": "^0.3.5",
22-
"vscode-nls": "^1.0.4"
24+
"vscode-nls": "^2.0.2"
2325
},
2426
"scripts": {
2527
"prepublish": "tsc -p ./src",

src/main.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function xhr(options: XHROptions): Promise<XHRResponse> {
5757

5858
return request(options).then(result => new Promise<XHRResponse>((c, e) => {
5959
let res = result.res;
60-
let data: string[] = [];
60+
let data: any = [];
6161
res.on('data', c => data.push(c));
6262
res.on('end', () => {
6363
if (options.followRedirects > 0 && (res.statusCode >= 300 && res.statusCode <= 303 || res.statusCode === 307)) {
@@ -129,8 +129,7 @@ function request(options: XHROptions): Promise<RequestResult> {
129129
opts.auth = options.user + ':' + options.password;
130130
}
131131

132-
let protocol = endpoint.protocol === 'https:' ? https : http;
133-
req = protocol.request(opts, (res: http.ClientResponse) => {
132+
let handler = (res: http.ClientResponse) => {
134133
if (res.statusCode >= 300 && res.statusCode < 400 && options.followRedirects && options.followRedirects > 0 && res.headers['location']) {
135134
c(<any> request(assign({}, options, {
136135
url: res.headers['location'],
@@ -139,7 +138,13 @@ function request(options: XHROptions): Promise<RequestResult> {
139138
} else {
140139
c({ req, res });
141140
}
142-
});
141+
}
142+
if (endpoint.protocol === 'https:') {
143+
req = https.request(opts, handler);
144+
} else {
145+
req = http.request(opts, handler);
146+
}
147+
143148
req.on('error', e);
144149

145150
if (options.timeout) {

src/tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"sourceMap": true,
77
"declaration": true,
88
"stripInternal": true,
9-
"outDir": "../lib"
9+
"outDir": "../lib" ,
10+
"lib": [
11+
"es5",
12+
"es2015.promise"
13+
]
1014
}
1115
}

src/typings/mocha.d.ts

-215
This file was deleted.

0 commit comments

Comments
 (0)