@@ -7,7 +7,7 @@ var eol = require('os').EOL,
77 pkg = require ( '../package.json' ) ,
88 mkdir = require ( 'mkdirp' ) ,
99 path = require ( 'path' ) ,
10- defaultBinaryPath = path . join ( __dirname , '..' , 'vendor' ) ,
10+ defaultBinaryDir = path . join ( __dirname , '..' , 'vendor' ) ,
1111 trueCasePathSync = require ( 'true-case-path' ) ;
1212
1313/**
@@ -126,7 +126,7 @@ function getHumanEnvironment(env) {
126126 * @api public
127127 */
128128function getInstalledBinaries ( ) {
129- return fs . readdirSync ( defaultBinaryPath ) ;
129+ return fs . readdirSync ( getBinaryDir ( ) ) ;
130130}
131131
132132/**
@@ -245,6 +245,38 @@ function getBinaryUrl() {
245245 return [ site , 'v' + pkg . version , getBinaryName ( ) ] . join ( '/' ) ;
246246}
247247
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+
248280/**
249281 * Get binary path.
250282 * If environment variable SASS_BINARY_PATH,
@@ -271,7 +303,7 @@ function getBinaryPath() {
271303 } else if ( pkg . nodeSassConfig && pkg . nodeSassConfig . binaryPath ) {
272304 binaryPath = pkg . nodeSassConfig . binaryPath ;
273305 } 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 ) / , '/' ) ) ;
275307 }
276308
277309 if ( process . versions . modules < 46 ) {
@@ -415,6 +447,7 @@ function getPlatformVariant() {
415447module . exports . hasBinary = hasBinary ;
416448module . exports . getBinaryUrl = getBinaryUrl ;
417449module . exports . getBinaryName = getBinaryName ;
450+ module . exports . getBinaryDir = getBinaryDir ;
418451module . exports . getBinaryPath = getBinaryPath ;
419452module . exports . getBinaryCachePath = getBinaryCachePath ;
420453module . exports . getCachedBinary = getCachedBinary ;
0 commit comments