5
5
var fs = require ( 'fs' ) ,
6
6
eol = require ( 'os' ) . EOL ,
7
7
mkdir = require ( 'mkdirp' ) ,
8
- npmconf = require ( 'npmconf' ) ,
9
8
path = require ( 'path' ) ,
10
9
sass = require ( '../lib/extensions' ) ,
11
10
request = require ( 'request' ) ,
@@ -30,65 +29,67 @@ function download(url, dest, cb) {
30
29
'or configure npm proxy via' , eol , eol ,
31
30
' npm config set proxy http://example.com:8080' ] . join ( '' ) ) ;
32
31
} ;
32
+
33
33
var successful = function ( response ) {
34
34
return response . statusCode >= 200 && response . statusCode < 300 ;
35
35
} ;
36
36
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 ( ) ,
60
42
}
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 ( '' ) ;
62
75
}
63
76
64
77
/**
65
- * Get applyProxy settings
78
+ * Determine local proxy settings
66
79
*
67
80
* @param {Object } options
68
81
* @param {Function } cb
69
82
* @api private
70
83
*/
71
84
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 ;
92
93
}
93
94
94
95
/**
@@ -129,7 +130,7 @@ if (process.env.SKIP_SASS_BINARY_DOWNLOAD_FOR_CI) {
129
130
}
130
131
131
132
/**
132
- * If binary does not exsit , download it
133
+ * If binary does not exist , download it
133
134
*/
134
135
135
136
checkAndDownloadBinary ( ) ;
0 commit comments