55var 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
135136checkAndDownloadBinary ( ) ;
0 commit comments