@@ -7,7 +7,7 @@ var eol = require('os').EOL,
7
7
pkg = require ( '../package.json' ) ,
8
8
mkdir = require ( 'mkdirp' ) ,
9
9
path = require ( 'path' ) ,
10
- defaultBinaryPath = path . join ( __dirname , '..' , 'vendor' ) ,
10
+ defaultBinaryDir = path . join ( __dirname , '..' , 'vendor' ) ,
11
11
trueCasePathSync = require ( 'true-case-path' ) ;
12
12
13
13
/**
@@ -126,7 +126,7 @@ function getHumanEnvironment(env) {
126
126
* @api public
127
127
*/
128
128
function getInstalledBinaries ( ) {
129
- return fs . readdirSync ( defaultBinaryPath ) ;
129
+ return fs . readdirSync ( getBinaryDir ( ) ) ;
130
130
}
131
131
132
132
/**
@@ -245,6 +245,38 @@ function getBinaryUrl() {
245
245
return [ site , 'v' + pkg . version , getBinaryName ( ) ] . join ( '/' ) ;
246
246
}
247
247
248
+ /**
249
+ * Get binary dir.
250
+ * If environment variable SASS_BINARY_DIR,
251
+ * .npmrc variable sass_binary_dir or
252
+ * process argument --sass-binary-dir is provided,
253
+ * select it by appending binary name, otherwise
254
+ * use default binary dir.
255
+ * Once the primary selection is made, check if
256
+ * callers wants to throw if file not exists before
257
+ * returning.
258
+ *
259
+ * @api public
260
+ */
261
+
262
+ function getBinaryDir ( ) {
263
+ var binaryDir ;
264
+
265
+ if ( getArgument ( '--sass-binary-dir' ) ) {
266
+ binaryDir = getArgument ( '--sass-binary-dir' ) ;
267
+ } else if ( process . env . SASS_BINARY_DIR ) {
268
+ binaryDir = process . env . SASS_BINARY_DIR ;
269
+ } else if ( process . env . npm_config_sass_binary_dir ) {
270
+ binaryDir = process . env . npm_config_sass_binary_dir ;
271
+ } else if ( pkg . nodeSassConfig && pkg . nodeSassConfig . binaryDir ) {
272
+ binaryDir = pkg . nodeSassConfig . binaryDir ;
273
+ } else {
274
+ binaryDir = defaultBinaryDir ;
275
+ }
276
+
277
+ return binaryDir ;
278
+ }
279
+
248
280
/**
249
281
* Get binary path.
250
282
* If environment variable SASS_BINARY_PATH,
@@ -271,7 +303,7 @@ function getBinaryPath() {
271
303
} else if ( pkg . nodeSassConfig && pkg . nodeSassConfig . binaryPath ) {
272
304
binaryPath = pkg . nodeSassConfig . binaryPath ;
273
305
} else {
274
- binaryPath = path . join ( defaultBinaryPath , getBinaryName ( ) . replace ( / _ (? = b i n d i n g \. n o d e ) / , '/' ) ) ;
306
+ binaryPath = path . join ( getBinaryDir ( ) , getBinaryName ( ) . replace ( / _ (? = b i n d i n g \. n o d e ) / , '/' ) ) ;
275
307
}
276
308
277
309
if ( process . versions . modules < 46 ) {
@@ -415,6 +447,7 @@ function getPlatformVariant() {
415
447
module . exports . hasBinary = hasBinary ;
416
448
module . exports . getBinaryUrl = getBinaryUrl ;
417
449
module . exports . getBinaryName = getBinaryName ;
450
+ module . exports . getBinaryDir = getBinaryDir ;
418
451
module . exports . getBinaryPath = getBinaryPath ;
419
452
module . exports . getBinaryCachePath = getBinaryCachePath ;
420
453
module . exports . getCachedBinary = getCachedBinary ;
0 commit comments