Skip to content

Commit 60f30ca

Browse files
authored
Remove callback in intall-utils.js (#627)
1 parent f6483ce commit 60f30ca

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

lib/install-utils.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ function checksum(filepath, cb) {
9898
.once('error', cb);
9999
}
100100

101-
function isUpToDate(url, requestOpts, hash, cb) {
101+
async function isUpToDate(url, requestOpts, hash) {
102102
if (!hash) {
103-
return cb(false);
103+
return false;
104104
}
105105

106106
/**
@@ -109,29 +109,25 @@ function isUpToDate(url, requestOpts, hash, cb) {
109109
* it. To prevent this we always assume it is the latest
110110
*/
111111
if (hash && url.includes('edgedriver')) {
112-
return cb(true);
112+
return true;
113113
}
114114

115115
const options = merge({}, requestOpts, {
116116
headers: {
117117
'If-None-Match': `"${hash}"`,
118118
},
119119
});
120-
got(url, options)
121-
.then((res) => {
122-
if (res.statusCode === 304) {
123-
return cb(true);
124-
}
125-
cb(false);
126-
})
127-
.catch((err) => {
128-
logError(
129-
`Could not request headers from ${url}: ` +
130-
(err.response ? err.response.statusCode : err.message) +
131-
', continue without checking for latest version.'
132-
);
133-
return cb(true);
134-
});
120+
try {
121+
const response = await got(url, options);
122+
return response.statusCode === 304;
123+
} catch (err) {
124+
logError(
125+
`Could not request headers from ${url}: ` +
126+
(err.response ? err.response.statusCode : err.message) +
127+
', continue without checking for latest version.'
128+
);
129+
return true;
130+
}
135131
}
136132

137133
function getTempFileName(suffix) {

lib/install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async function install(_opts) {
116116

117117
async function onlyInstallMissingFiles(opts) {
118118
const hash = await new Promise((resolve) => checksum(opts.to, resolve));
119-
const isLatest = await new Promise((resolve) => isUpToDate(opts.from, requestOpts, hash, resolve));
119+
const isLatest = await isUpToDate(opts.from, requestOpts, hash);
120120

121121
// File already exists. Prevent download/installation.
122122
if (isLatest) {

0 commit comments

Comments
 (0)