@@ -9,7 +9,11 @@ var fs = require('fs'),
99 merge = require ( './lib/merge' ) ,
1010 resolveSets = require ( './lib/resolve-sets' ) ,
1111
12- basePlugins = [ require ( './plugins/resolve-level' ) ] ;
12+ basePlugins = [ require ( './plugins/resolve-level' ) ] ,
13+
14+ accessAsync = ( cwd , mode ) =>
15+ new Promise ( ( resolve , reject ) =>
16+ fs . access ( cwd , mode , ( err ) => ! err ? resolve ( ) : reject ( err ) ) ) ;
1317
1418/**
1519 * Constructor
@@ -141,20 +145,16 @@ BemConfig.prototype.library = function(libName) {
141145 lib = libs && libs [ libName ] ;
142146
143147 if ( lib !== undefined && typeof lib !== 'object' ) {
144- return Promise . reject ( 'Invalid `libs` format' ) ;
148+ throw new Error ( 'Invalid `libs` format' ) ;
145149 }
146150
147- var cwd = lib && lib . path || path . resolve ( 'node_modules' , libName ) ;
148-
149- return new Promise ( function ( resolve , reject ) {
150- fs . exists ( cwd , function ( doesExist ) {
151- if ( ! doesExist ) {
152- return reject ( 'Library ' + libName + ' was not found at ' + cwd ) ;
153- }
151+ const cwd = lib && lib . path || path . resolve ( 'node_modules' , libName ) ;
154152
155- resolve ( cwd ) ;
156- } )
157- } ) ;
153+ return accessAsync ( cwd )
154+ . then ( ( ) => cwd )
155+ . catch ( err => {
156+ throw new Error ( 'Library ' + libName + ' was not found at ' + cwd + ( '\n' + err ) ) ;
157+ } ) ;
158158 } )
159159 . then ( cwd => new BemConfig ( { cwd : path . resolve ( cwd ) } ) ) ;
160160} ;
@@ -180,7 +180,7 @@ BemConfig.prototype.levelMap = function() {
180180 var allLevels = [ ] . concat . apply ( [ ] , libLevels . filter ( Boolean ) ) . concat ( projectLevels ) ;
181181
182182 return allLevels . reduce ( ( res , lvl ) => {
183- res [ lvl . path ] = merge ( res [ lvl . path ] || { } , lvl ) ;
183+ res [ lvl . path ] = merge ( [ res [ lvl . path ] || { } , lvl ] ) ;
184184 return res ;
185185 } , { } ) ;
186186 } ) ;
@@ -395,21 +395,21 @@ function getLevelByConfigs(pathToLevel, options, allConfigs, root) {
395395 var conf = allConfigs [ i ] ,
396396 levels = conf . levels || [ ] ;
397397
398- commonOpts = merge ( { } , conf , commonOpts ) ;
398+ commonOpts = merge ( [ { } , conf , commonOpts ] ) ;
399399
400400 for ( var j = 0 ; j < levels . length ; j ++ ) {
401401 var level = levels [ j ] ;
402402
403403 if ( level === undefined || level . path !== absLevelPath ) { continue ; }
404404
405405 // works like deep extend but overrides arrays
406- levelOpts = merge ( { } , level , levelOpts ) ;
406+ levelOpts = merge ( [ { } , level , levelOpts ] ) ;
407407 }
408408
409409 if ( conf . root ) { break ; }
410410 }
411411
412- levelOpts = merge ( commonOpts , levelOpts ) ;
412+ levelOpts = merge ( [ commonOpts , levelOpts ] ) ;
413413
414414 delete levelOpts . __source ;
415415 delete levelOpts . path ;
0 commit comments