@@ -167,36 +167,46 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
167167 var paths = [ currentFileInfo . currentDirectory ] . concat ( env . paths ) ;
168168 paths . push ( '.' ) ;
169169
170- for ( var i = 0 ; i < paths . length ; i ++ ) {
171- try {
172- pathname = path . join ( paths [ i ] , file ) ;
173- fs . statSync ( pathname ) ;
174- break ;
175- } catch ( e ) {
176- pathname = null ;
170+ if ( env . syncImports ) {
171+ for ( var i = 0 ; i < paths . length ; i ++ ) {
172+ try {
173+ pathname = path . join ( paths [ i ] , file ) ;
174+ fs . statSync ( pathname ) ;
175+ break ;
176+ } catch ( e ) {
177+ pathname = null ;
178+ }
177179 }
178- }
179-
180- if ( ! pathname ) {
181180
182- callback ( { type : 'File' , message : "'" + file + "' wasn't found" } ) ;
183- return ;
184- }
185-
186- dirname = path . dirname ( pathname ) ;
181+ if ( ! pathname ) {
182+ callback ( { type : 'File' , message : "'" + file + "' wasn't found" } ) ;
183+ return ;
184+ }
187185
188- if ( env . syncImport ) {
189186 try {
190187 data = fs . readFileSync ( pathname , 'utf-8' ) ;
191188 handleDataAndCallCallback ( data ) ;
192189 } catch ( e ) {
193190 callback ( e ) ;
194191 }
195192 } else {
196- fs . readFile ( pathname , 'utf-8' , function ( e , data ) {
197- if ( e ) { callback ( e ) ; }
198- handleDataAndCallCallback ( data ) ;
199- } ) ;
193+ ( function tryPathIndex ( i ) {
194+ if ( i < paths . length ) {
195+ pathname = path . join ( paths [ i ] , file ) ;
196+ fs . stat ( pathname , function ( err ) {
197+ if ( err ) {
198+ tryPathIndex ( i + 1 ) ;
199+ } else {
200+ fs . readFile ( pathname , 'utf-8' , function ( e , data ) {
201+ if ( e ) { callback ( e ) ; }
202+ handleDataAndCallCallback ( data ) ;
203+ } ) ;
204+ }
205+ } ) ;
206+ } else {
207+ callback ( { type : 'File' , message : "'" + file + "' wasn't found" } ) ;
208+ }
209+ } ( 0 ) ) ;
200210 }
201211 }
202212} ;
0 commit comments