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 @@
"mkdirp": "^0.5.1",
"nan": "^2.3.2",
"node-gyp": "^3.3.1",
"npmconf": "^2.1.2",
"request": "^2.61.0",
"sass-graph": "^2.1.1"
},
......
......@@ -5,7 +5,6 @@
var fs = require('fs'),
eol = require('os').EOL,
mkdir = require('mkdirp'),
npmconf = require('npmconf'),
path = require('path'),
sass = require('../lib/extensions'),
request = require('request'),
......@@ -30,17 +29,19 @@ function download(url, dest, cb) {
'or configure npm proxy via', eol, eol,
' npm config set proxy http://example.com:8080'].join(''));
};
var successful = function(response) {
return response.statusCode >= 200 && response.statusCode < 300;
};
applyProxy({ rejectUnauthorized: false }, function(options) {
options.headers = {
'User-Agent': [
'node/', process.version, ' ',
'node-sass-installer/', pkg.version
].join('')
var options = {
rejectUnauthorized: false,
proxy: getProxy(),
headers: {
'User-Agent': getUserAgent(),
}
};
try {
request(url, options, function(err, response) {
if (err) {
......@@ -50,7 +51,8 @@ function download(url, dest, cb) {
} else {
cb();
}
}).on('response', function(response) {
})
.on('response', function(response) {
if (successful(response)) {
response.pipe(fs.createWriteStream(dest));
}
......@@ -58,37 +60,36 @@ function download(url, dest, cb) {
} catch (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 {Function} cb
* @api private
*/
function applyProxy(options, cb) {
npmconf.load({}, function (er, conf) {
var proxyUrl;
if (!er) {
proxyUrl = conf.get('https-proxy') ||
conf.get('proxy') ||
conf.get('http-proxy');
}
var env = process.env;
options.proxy = proxyUrl ||
env.HTTPS_PROXY ||
env.https_proxy ||
env.HTTP_PROXY ||
env.http_proxy;
cb(options);
});
function getProxy() {
return process.env.npm_config_https_proxy ||
process.env.npm_config_proxy ||
process.env.npm_config_http_proxy ||
process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy;
}
/**
......@@ -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();
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