Skip to content

Commit

Permalink
Moved to node-exec-path
Browse files Browse the repository at this point in the history
  • Loading branch information
kmalakoff committed Aug 11, 2022
1 parent 13bb556 commit a8a81c7
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 738 deletions.
5 changes: 2 additions & 3 deletions lib/Response/extract.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var assign = require('just-extend');
var fastExtract = require('../utils/optionalRequire')('fast-extract');

var extname = require('../utils/extname');
Expand All @@ -15,13 +14,13 @@ module.exports = function extract(dest, options, callback) {
}

if (typeof callback === 'function') {
options = assign({}, this.options, options || {});
options = Object.assign({}, this.options, options || {});
return this.stream(options, function (err, res) {
if (err) return callback(err);

var type = extname(res.basename, options);
if (!type) return callback(new Error('Cannot determine extract type for ' + res.basename));
fastExtract(res, dest, assign({}, options, { type: type }), callback);
fastExtract(res, dest, Object.assign({}, options, { type: type }), callback);
});
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Response/file.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var path = require('path');
var fs = require('fs');
var assign = require('just-extend');
var eos = require('end-of-stream');
var mkpath = require('mkpath');

Expand All @@ -15,7 +14,7 @@ module.exports = function file(dest, options, callback) {

var self = this;
if (typeof callback === 'function') {
options = assign({}, this.options, options || {});
options = Object.assign({}, this.options, options || {});
return this.stream(options, function (err, res) {
if (err) return callback(err);

Expand Down
19 changes: 12 additions & 7 deletions lib/Response/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var https = require('https');
var url = require('url');
var fs = require('fs');
var path = require('path');
var assign = require('just-extend');
var eos = require('end-of-stream');
var rimraf = require('rimraf');
var wrapResponse = require('../utils/wrapResponse');
Expand All @@ -14,29 +13,35 @@ var minor = +process.versions.node.split('.')[1];
var noHTTPS = major === 0 && minor <= 8;

var streamCompat = path.resolve(__dirname, '..', 'utils', 'streamCompat.js');
var execPath = null;

function Response(endpoint, options) {
this.endpoint = endpoint;
this.options = options || {};
}

var call = null; // break dependencies
var functionExec = null; // break dependencies
Response.prototype.stream = function stream(options, callback) {
if (!call) call = require('node-version-call'); // break dependencies

if (typeof options === 'function') {
callback = options;
options = null;
}

var self = this;
if (typeof callback === 'function') {
options = assign({}, this.options, options || {});
options = Object.assign({}, this.options, options || {});

// node <=0.8 does not support https
if (noHTTPS) {
if (!functionExec) functionExec = require('function-exec-sync'); // break dependencies
if (!execPath) {
var satisfiesSemverSync = require('node-exec-path').satisfiesSemverSync;
execPath = satisfiesSemverSync('>=0.10.0'); // must be more than node 0.8
if (!execPath) return callback(new Error('get-remote on node versions without https need a version of node >=0.10.0 to call using https'));
}

try {
var streamInfo = call({ version: 'lts', callbacks: true }, streamCompat, [self.endpoint, self.options], options);
var streamInfo = functionExec({ execPath: execPath, callbacks: true }, streamCompat, [self.endpoint, self.options], options);
if (options.method === 'HEAD') {
streamInfo.resume = function () {};
callback(null, streamInfo);
Expand All @@ -57,7 +62,7 @@ Response.prototype.stream = function stream(options, callback) {

var parsed = url.parse(this.endpoint); // eslint-disable-line n/no-deprecated-api
var secure = parsed.protocol === 'https:';
var requestOptions = assign({ host: parsed.host, path: parsed.path, port: secure ? 443 : 80, method: 'GET' }, options);
var requestOptions = Object.assign({ host: parsed.host, path: parsed.path, port: secure ? 443 : 80, method: 'GET' }, options);
var req = secure ? https.request(requestOptions) : http.request(requestOptions);
req.on('response', function (res) {
// Follow 3xx redirects
Expand Down
3 changes: 2 additions & 1 deletion lib/polyfills.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require('es6-promise/auto');
require('core-js/actual/object/assign');
require('core-js/actual/promise');
3 changes: 1 addition & 2 deletions lib/utils/pump.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var assign = require('just-extend');
var pump = require('pump');

module.exports = function pipe(from, to) {
if (from.headers) to.headers = to.headers === undefined ? from.headers : assign({}, from.headers, to.headers || {});
if (from.headers) to.headers = to.headers === undefined ? from.headers : Object.assign({}, from.headers, to.headers || {});
if (from.statusCode) to.statusCode = from.statusCode;
return pump(from, to);
};
5 changes: 2 additions & 3 deletions lib/utils/wrapResponse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var assign = require('just-extend');
var progressStream = require('progress-stream');
var PassThrough = require('stream').PassThrough || require('readable-stream').PassThrough;

Expand All @@ -20,14 +19,14 @@ module.exports = function wrapResponse(res, self, options, callback) {
time: options.time,
},
function (update) {
options.progress(assign({ progress: 'download' }, update, stats));
options.progress(Object.assign({ progress: 'download' }, update, stats));
}
);
res = pump(res, progress);
}

// store stats on the source
res = assign(res, stats);
res = Object.assign(res, stats);
return callback(null, res);
});
};
Loading

0 comments on commit a8a81c7

Please sign in to comment.