Skip to content

Commit c3d4f67

Browse files
committed
chore: Replace httpreq by axios
1 parent 3f56474 commit c3d4f67

File tree

10 files changed

+39
-57
lines changed

10 files changed

+39
-57
lines changed

e2e/appimage/server/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,25 @@ app.use('/updates', express.static(
1111
));
1212

1313
app.get('/finish', (req, res) => {
14-
console.log('v2 is going to quit, pid', req.query.pid);
15-
console.log('Successfully updated, test is finished.');
14+
console.log('e2e: v2 is going to quit, pid', req.query.pid);
15+
console.log('e2e: Successfully updated, test is finished.');
1616
res.send('ok');
1717
process.exit();
1818
});
1919

2020
// eslint-disable-next-line func-names
2121
app.listen(3003, function () {
22-
console.log(`Listening on port ${this.address().port}.`);
22+
console.log(`e2e: Listening on port ${this.address().port}.`);
2323
startAppImageV1();
2424
});
2525

2626
function startAppImageV1() {
27+
console.log('e2e: Starting v1 process');
2728
const v1 = spawn('../v0.0.1/dist/appimage-0.0.1.AppImage', [], {
2829
stdio: 'inherit',
2930
});
3031

3132
v1.on('exit', () => console.log('v1 process is killed'));
3233

33-
console.log('v1 process is started, pid', v1.pid);
34+
console.log('e2e: v1 process is started, pid', v1.pid);
3435
}

e2e/appimage/start

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
set -e
44

55
main() {
6-
local start_step=1
6+
local step="${1:-1}"
77

8-
while [ $# -gt 0 ]; do case "$1" in
9-
-s2) start_step=2;;
10-
-s3) start_step=3;;
11-
esac; shift; done
12-
13-
[ "${start_step}" -lt 2 ] && step1
14-
[ "${start_step}" -lt 3 ] && step2
8+
[ "${step}" -lt 2 ] && step1
9+
[ "${step}" -lt 3 ] && step2
1510
step3
1611
}
1712

1813
step1() {
14+
echo "e2e: step1"
1915
npm ci
2016
npm ci --prefix server --production -s
2117
npm ci --prefix v0.0.1 --production -s
@@ -24,10 +20,12 @@ step1() {
2420
}
2521

2622
step2() {
23+
echo "e2e: step2"
2724
npm run build --prefix v0.0.1 -s
2825
}
2926

3027
step3() {
28+
echo "e2e: step3"
3129
npm start -s --prefix server
3230
}
3331

e2e/appimage/v0.0.1/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"linux": {
1111
"category": "Development"
1212
},
13-
"electronVersion": "7.1.7"
13+
"electronVersion": "15.3.1"
1414
},
1515
"updater": {
1616
"url": "http://127.0.0.1:3003/updates/updates.json"

e2e/appimage/v0.0.2/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const { request } = require('http');
55

66
const SHOW_WINDOW = false;
77

8+
console.log('e2e: v2 started');
9+
810
request(`http://localhost:3003/finish?pid=${process.pid}`, (res) => {
911
res.on('data', () => SHOW_WINDOW || app.quit());
1012
}).end();

e2e/appimage/v0.0.2/package-lock.json

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/appimage/v0.0.2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"linux": {
1111
"category": "Development"
1212
},
13-
"electronVersion": "7.1.7"
13+
"electronVersion": "15.3.1"
1414
},
1515
"updater": {
1616
"url": "http://127.0.0.1:3003/updates/updates.json"

e2e/start

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -e
55
readonly __root="$(cd "$(dirname "$(dirname "$BASH_SOURCE")")"; pwd)"
66

77
cd "${__root}/e2e/appimage"
8-
"${__root}/e2e/appimage/start"
8+
"${__root}/e2e/appimage/start" $@

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"typescript": "^3.7.4"
4848
},
4949
"dependencies": {
50-
"httpreq": "0.4.24",
50+
"axios": "^0.24.0",
5151
"semver": "^7.1.1"
5252
}
5353
}

src/platform/Linux.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ class Linux extends Platform {
5656
...process.env,
5757
APP_IMAGE: this.getAppImagePath(),
5858
OLD_PID: process.pid,
59-
RESTART_REQUIRED: restartRequired === true ? 'true' : 'false',
59+
RESTART_REQUIRED: String(restartRequired),
6060
UPDATE_FILE: this.lastUpdatePath,
6161
},
6262
});
6363
proc.unref();
6464

6565
if (restartRequired === true) {
6666
electronApi.quit();
67+
process.exit();
6768
}
6869
}
6970

src/utils/HttpClient.js

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
'use strict';
22

3-
const request = require('httpreq');
3+
const axios = require('axios');
44
const fs = require('fs');
5+
const stream = require('stream');
6+
const util = require('util');
7+
8+
const pipeline = util.promisify(stream.pipeline);
59

610
class HttpClient {
711
/**
@@ -12,47 +16,16 @@ class HttpClient {
1216
}
1317

1418
async getJson(url) {
15-
return new Promise((resolve, reject) => {
16-
request.get(url, this.getHttpOptions(), (err, response) => {
17-
if (err) {
18-
reject(err);
19-
return;
20-
}
21-
22-
try {
23-
resolve(JSON.parse(response.body));
24-
} catch (e) {
25-
reject(new Error(
26-
`Error while parsing '${url}'. ${e}. Data:\\n ${response.body}`
27-
));
28-
}
29-
});
30-
});
19+
const { data } = await axios.get(url, this.getHttpOptions());
20+
return data;
3121
}
3222

3323
async downloadFile(url, savePath) {
34-
return new Promise((resolve, reject) => {
35-
const options = {
36-
...this.getHttpOptions(),
37-
url,
38-
method: 'GET',
39-
downloadlocation: savePath,
40-
allowRedirects: true,
41-
};
42-
43-
request.doRequest(options, async (err, res) => {
44-
if (err) {
45-
return reject(err);
46-
}
47-
48-
if (res.statusCode !== 200) {
49-
await fs.promises.unlink(savePath);
50-
return reject(new Error(`Wrong HTTP status: ${res.statusCode}`));
51-
}
52-
53-
resolve(savePath);
54-
});
24+
const { data: httpRequest } = await axios.get(url, {
25+
...this.getHttpOptions(),
26+
responseType: 'stream',
5527
});
28+
return pipeline(httpRequest, fs.createWriteStream(savePath));
5629
}
5730

5831
/**
@@ -64,7 +37,7 @@ class HttpClient {
6437
return {
6538
...options,
6639
headers: {
67-
'User-Agent': 'electron-simple-updater',
40+
'User-Agent': 'electron-simple-updater 1.0',
6841
...options.headers,
6942
},
7043
};

0 commit comments

Comments
 (0)