Skip to content

Commit

Permalink
Replace deprecated npmconf package.
Browse files Browse the repository at this point in the history
This was previously attempted in sass#1413. Shortly after it's
release proxy users started experiencing installation issues so
this was reverted. It was later determined that sass#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 sass#1333
  • Loading branch information
xzyfer committed Apr 27, 2016
1 parent c56f4a1 commit 265fdae
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"mkdirp": "^0.5.1",
"nan": "^2.2.0",
"node-gyp": "^3.3.1",
"npmconf": "^2.1.2",
"request": "^2.61.0",
"sass-graph": "^2.1.1"
},
Expand Down
95 changes: 48 additions & 47 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -30,65 +29,67 @@ 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('')
};
try {
request(url, options, function(err, response) {
if (err) {
reportError(err);
} else if (!successful(response)) {
reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
} else {
cb();
}
}).on('response', function(response) {
if (successful(response)) {
response.pipe(fs.createWriteStream(dest));
}
});
} catch (err) {
cb(err);
var options = {
rejectUnauthorized: false,
proxy: getProxy(),
headers: {
'User-Agent': getUserAgent(),
}
});
};

try {
request(url, options, function(err, response) {
if (err) {
reportError(err);
} else if (!successful(response)) {
reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
} else {
cb();
}
})
.on('response', function(response) {
if (successful(response)) {
response.pipe(fs.createWriteStream(dest));
}
});
} catch (err) {
cb(err);
}
}

/**
* A custom user agent use for binary downloads.
*
* @api private
*/
function getUserAgent() {
return [
'node/', process.version, ' ',
'node-sass-installer/', pkg.version
].join('');
}

/**
* Get applyProxy settings
* 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;
}

/**
Expand Down Expand Up @@ -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();

0 comments on commit 265fdae

Please sign in to comment.