Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit b850684

Browse files
committed
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
1 parent ff17933 commit b850684

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"mkdirp": "^0.5.1",
6464
"nan": "^2.3.2",
6565
"node-gyp": "^3.3.1",
66-
"npmconf": "^2.1.2",
6766
"request": "^2.61.0",
6867
"sass-graph": "^2.1.1"
6968
},

scripts/install.js

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
var fs = require('fs'),
66
eol = require('os').EOL,
77
mkdir = require('mkdirp'),
8-
npmconf = require('npmconf'),
98
path = require('path'),
109
sass = require('../lib/extensions'),
1110
request = require('request'),
@@ -30,65 +29,67 @@ function download(url, dest, cb) {
3029
'or configure npm proxy via', eol, eol,
3130
' npm config set proxy http://example.com:8080'].join(''));
3231
};
32+
3333
var successful = function(response) {
3434
return response.statusCode >= 200 && response.statusCode < 300;
3535
};
3636

37-
applyProxy({ rejectUnauthorized: false }, function(options) {
38-
options.headers = {
39-
'User-Agent': [
40-
'node/', process.version, ' ',
41-
'node-sass-installer/', pkg.version
42-
].join('')
43-
};
44-
try {
45-
request(url, options, function(err, response) {
46-
if (err) {
47-
reportError(err);
48-
} else if (!successful(response)) {
49-
reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
50-
} else {
51-
cb();
52-
}
53-
}).on('response', function(response) {
54-
if (successful(response)) {
55-
response.pipe(fs.createWriteStream(dest));
56-
}
57-
});
58-
} catch (err) {
59-
cb(err);
37+
var options = {
38+
rejectUnauthorized: false,
39+
proxy: getProxy(),
40+
headers: {
41+
'User-Agent': getUserAgent(),
6042
}
61-
});
43+
};
44+
45+
try {
46+
request(url, options, function(err, response) {
47+
if (err) {
48+
reportError(err);
49+
} else if (!successful(response)) {
50+
reportError(['HTTP error', response.statusCode, response.statusMessage].join(' '));
51+
} else {
52+
cb();
53+
}
54+
})
55+
.on('response', function(response) {
56+
if (successful(response)) {
57+
response.pipe(fs.createWriteStream(dest));
58+
}
59+
});
60+
} catch (err) {
61+
cb(err);
62+
}
63+
}
64+
65+
/**
66+
* A custom user agent use for binary downloads.
67+
*
68+
* @api private
69+
*/
70+
function getUserAgent() {
71+
return [
72+
'node/', process.version, ' ',
73+
'node-sass-installer/', pkg.version
74+
].join('');
6275
}
6376

6477
/**
65-
* Get applyProxy settings
78+
* Determine local proxy settings
6679
*
6780
* @param {Object} options
6881
* @param {Function} cb
6982
* @api private
7083
*/
7184

72-
function applyProxy(options, cb) {
73-
npmconf.load({}, function (er, conf) {
74-
var proxyUrl;
75-
76-
if (!er) {
77-
proxyUrl = conf.get('https-proxy') ||
78-
conf.get('proxy') ||
79-
conf.get('http-proxy');
80-
}
81-
82-
var env = process.env;
83-
84-
options.proxy = proxyUrl ||
85-
env.HTTPS_PROXY ||
86-
env.https_proxy ||
87-
env.HTTP_PROXY ||
88-
env.http_proxy;
89-
90-
cb(options);
91-
});
85+
function getProxy() {
86+
return process.env.npm_config_https_proxy ||
87+
process.env.npm_config_proxy ||
88+
process.env.npm_config_http_proxy ||
89+
process.env.HTTPS_PROXY ||
90+
process.env.https_proxy ||
91+
process.env.HTTP_PROXY ||
92+
process.env.http_proxy;
9293
}
9394

9495
/**
@@ -129,7 +130,7 @@ if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) {
129130
}
130131

131132
/**
132-
* If binary does not exsit, download it
133+
* If binary does not exist, download it
133134
*/
134135

135136
checkAndDownloadBinary();

0 commit comments

Comments
 (0)