Skip to content

Commit 23e635f

Browse files
authored
Merge pull request #256 from Marsup/bump-deps
Bump request and mocha to avoid npm warnings
2 parents 3a835d1 + b75cddd commit 23e635f

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

lib/install.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ function install(opts, cb) {
9898
});
9999

100100
function onlyInstallMissingFiles(opts, cb) {
101-
async.series([
101+
async.waterfall([
102102
checksum.bind(null, opts.to),
103-
etag.bind(null, opts.from, requestOpts)
104-
], function (error, results) {
103+
isUpToDate.bind(null, opts.from, requestOpts)
104+
], function (error, isLatest) {
105105
if (error) {
106106
return cb(error);
107107
}
108108

109109
// File already exists. Prevent download/installation.
110-
if (results[0] === results[1]) {
110+
if (isLatest) {
111111
logger('---');
112112
logger('File from ' + opts.from + ' has already been downloaded');
113113
expectedRequests -= 1;
@@ -391,7 +391,7 @@ function logInstallSummary(logger, paths, urls) {
391391

392392
function checksum (filepath, cb) {
393393
if (!fs.existsSync(filepath)) {
394-
return cb();
394+
return cb(null, null);
395395
}
396396

397397
var hash = crypto.createHash('md5');
@@ -414,13 +414,31 @@ function unquote (str, quoteChar) {
414414
return str;
415415
}
416416

417-
function etag (url, requestOpts, cb) {
418-
request.head(url, requestOpts).on('response', function (res) {
417+
function isUpToDate (url, requestOpts, hash, cb) {
418+
if (!hash) {
419+
return cb(null, false);
420+
}
421+
422+
var query = Object.assign({}, requestOpts, {
423+
url: url,
424+
headers: {
425+
'If-None-Match': '"' + hash + '"'
426+
}
427+
});
428+
429+
var req = request.get(query);
430+
req.on('response', function (res) {
431+
req.abort();
432+
433+
if (res.statusCode === 304) {
434+
return cb(null, true);
435+
}
436+
419437
if (res.statusCode !== 200) {
420438
return cb(new Error('Could not request headers from ' + url + ': ', res.statusCodestatusCode));
421439
}
422440

423-
cb(null, unquote(res.headers.etag));
441+
cb(null, false);
424442
}).once('error', function (err) {
425443
cb(new Error('Could not request headers from ' + url + ': ' + err));
426444
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
"minimist": "1.1.0",
2828
"mkdirp": "0.5.0",
2929
"progress": "1.1.8",
30-
"request": "2.51.0",
30+
"request": "2.79.0",
3131
"tar-stream": "1.5.2",
3232
"urijs": "1.16.1",
3333
"which": "1.1.1",
3434
"yauzl": "^2.5.0"
3535
},
3636
"devDependencies": {
3737
"chai": "3.5.0",
38-
"mocha": "2.1.0"
38+
"mocha": "3.2.0"
3939
}
4040
}

0 commit comments

Comments
 (0)