Skip to content

Commit 30b241a

Browse files
committed
Switch emulator script to node-fetch.
1 parent 910e9db commit 30b241a

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

scripts/emulator-testing/emulators/emulator.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ChildProcess } from 'child_process';
2121
import * as fs from 'fs';
2222
import * as os from 'os';
2323
import * as path from 'path';
24-
import * as request from 'request';
24+
import fetch from 'node-fetch';
2525
// @ts-ignore
2626
import * as tmp from 'tmp';
2727

@@ -57,25 +57,29 @@ export abstract class Emulator {
5757
const writeStream: fs.WriteStream = fs.createWriteStream(filepath);
5858

5959
console.log(`Downloading emulator from [${this.binaryUrl}] ...`);
60-
request(this.binaryUrl)
61-
.pipe(writeStream)
62-
.on('finish', () => {
63-
console.log(`Saved emulator binary file to [${filepath}].`);
64-
// Change emulator binary file permission to 'rwxr-xr-x'.
65-
// The execute permission is required for it to be able to start
66-
// with 'java -jar'.
67-
fs.chmod(filepath, 0o755, err => {
68-
if (err) reject(err);
69-
console.log(`Changed emulator file permissions to 'rwxr-xr-x'.`);
70-
this.binaryPath = filepath;
71-
72-
if (this.copyToCache()) {
73-
console.log(`Cached emulator at ${this.cacheBinaryPath}`);
74-
}
75-
resolve();
76-
});
77-
})
78-
.on('error', reject);
60+
fetch(this.binaryUrl).then(resp => {
61+
resp.body
62+
.pipe(writeStream)
63+
.on('finish', () => {
64+
console.log(`Saved emulator binary file to [${filepath}].`);
65+
// Change emulator binary file permission to 'rwxr-xr-x'.
66+
// The execute permission is required for it to be able to start
67+
// with 'java -jar'.
68+
fs.chmod(filepath, 0o755, err => {
69+
if (err) reject(err);
70+
console.log(
71+
`Changed emulator file permissions to 'rwxr-xr-x'.`
72+
);
73+
this.binaryPath = filepath;
74+
75+
if (this.copyToCache()) {
76+
console.log(`Cached emulator at ${this.cacheBinaryPath}`);
77+
}
78+
resolve();
79+
});
80+
})
81+
.on('error', reject);
82+
});
7983
});
8084
});
8185
}

0 commit comments

Comments
 (0)