Commit b8506847 by Michael Mifsud

Replace deprecated npmconf package. (#1492)

This was previously attempted in #1413. Shortly after it's
release proxy users started experiencing installation issues so
this was reverted. It was later determined that #1458 was likely
at fault for the proxy issues.

Full credit for this patch goes to @delitescere.

I've also taken the liberty of cleaning the request config generation.

Fixes #1333
parent ff179332
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"nan": "^2.3.2", "nan": "^2.3.2",
"node-gyp": "^3.3.1", "node-gyp": "^3.3.1",
"npmconf": "^2.1.2",
"request": "^2.61.0", "request": "^2.61.0",
"sass-graph": "^2.1.1" "sass-graph": "^2.1.1"
}, },
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
var fs = require('fs'), var fs = require('fs'),
eol = require('os').EOL, eol = require('os').EOL,
mkdir = require('mkdirp'), mkdir = require('mkdirp'),
npmconf = require('npmconf'),
path = require('path'), path = require('path'),
sass = require('../lib/extensions'), sass = require('../lib/extensions'),
request = require('request'), request = require('request'),
...@@ -30,17 +29,19 @@ function download(url, dest, cb) { ...@@ -30,17 +29,19 @@ function download(url, dest, cb) {
'or configure npm proxy via', eol, eol, 'or configure npm proxy via', eol, eol,
' npm config set proxy http://example.com:8080'].join('')); ' npm config set proxy http://example.com:8080'].join(''));
}; };
var successful = function(response) { var successful = function(response) {
return response.statusCode >= 200 && response.statusCode < 300; return response.statusCode >= 200 && response.statusCode < 300;
}; };
applyProxy({ rejectUnauthorized: false }, function(options) { var options = {
options.headers = { rejectUnauthorized: false,
'User-Agent': [ proxy: getProxy(),
'node/', process.version, ' ', headers: {
'node-sass-installer/', pkg.version 'User-Agent': getUserAgent(),
].join('') }
}; };
try { try {
request(url, options, function(err, response) { request(url, options, function(err, response) {
if (err) { if (err) {
...@@ -50,7 +51,8 @@ function download(url, dest, cb) { ...@@ -50,7 +51,8 @@ function download(url, dest, cb) {
} else { } else {
cb(); cb();
} }
}).on('response', function(response) { })
.on('response', function(response) {
if (successful(response)) { if (successful(response)) {
response.pipe(fs.createWriteStream(dest)); response.pipe(fs.createWriteStream(dest));
} }
...@@ -58,37 +60,36 @@ function download(url, dest, cb) { ...@@ -58,37 +60,36 @@ function download(url, dest, cb) {
} catch (err) { } catch (err) {
cb(err); cb(err);
} }
});
} }
/** /**
* Get applyProxy settings * A custom user agent use for binary downloads.
*
* @api private
*/
function getUserAgent() {
return [
'node/', process.version, ' ',
'node-sass-installer/', pkg.version
].join('');
}
/**
* Determine local proxy settings
* *
* @param {Object} options * @param {Object} options
* @param {Function} cb * @param {Function} cb
* @api private * @api private
*/ */
function applyProxy(options, cb) { function getProxy() {
npmconf.load({}, function (er, conf) { return process.env.npm_config_https_proxy ||
var proxyUrl; process.env.npm_config_proxy ||
process.env.npm_config_http_proxy ||
if (!er) { process.env.HTTPS_PROXY ||
proxyUrl = conf.get('https-proxy') || process.env.https_proxy ||
conf.get('proxy') || process.env.HTTP_PROXY ||
conf.get('http-proxy'); process.env.http_proxy;
}
var env = process.env;
options.proxy = proxyUrl ||
env.HTTPS_PROXY ||
env.https_proxy ||
env.HTTP_PROXY ||
env.http_proxy;
cb(options);
});
} }
/** /**
...@@ -129,7 +130,7 @@ if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) { ...@@ -129,7 +130,7 @@ if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) {
} }
/** /**
* If binary does not exsit, download it * If binary does not exist, download it
*/ */
checkAndDownloadBinary(); checkAndDownloadBinary();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment