@@ -103,13 +103,20 @@ var less = {
103103
104104var isUrlRe = / ^ (?: h t t p s ? : ) ? \/ \/ / i;
105105
106- less . Parser . importer = function ( file , paths , callback , env ) {
107- var pathname , dirname , data ;
106+ less . Parser . importer = function ( file , currentFileInfo , callback , env ) {
107+ var pathname , dirname , data ,
108+ newFileInfo = {
109+ relativeUrls : env . relativeUrls ,
110+ entryPath : currentFileInfo . entryPath ,
111+ rootpath : currentFileInfo . rootpath ,
112+ rootFilename : currentFileInfo . rootFilename
113+ } ;
108114
109115 function parseFile ( e , data ) {
110116 if ( e ) { return callback ( e ) ; }
111117
112118 env = new less . tree . parseEnv ( env ) ;
119+ env . processImports = false ;
113120
114121 var j = file . lastIndexOf ( '/' ) ;
115122
@@ -121,23 +128,22 @@ less.Parser.importer = function (file, paths, callback, env) {
121128 // then rootpath should become 'less/module/nav/'
122129 // - If path of imported file is '../mixins.less' and rootpath is 'less/',
123130 // then rootpath should become 'less/../'
124- if ( env . relativeUrls && ! / ^ (?: [ a - z - ] + : | \/ ) / . test ( file ) && j != - 1 ) {
125- env . rootpath = env . rootpath + file . slice ( 0 , j + 1 ) ; // append (sub|sup) directory path of imported file
126- }
127- if ( env . relativeUrls ) {
128- env . currentDirectory = pathname . replace ( / [ ^ \\ \/ ] * $ / , "" ) ;
131+ if ( newFileInfo . relativeUrls && ! / ^ (?: [ a - z - ] + : | \/ ) / . test ( file ) && j != - 1 ) {
132+ var relativeSubDirectory = file . slice ( 0 , j + 1 ) ;
133+ newFileInfo . rootpath = newFileInfo . rootpath + relativeSubDirectory ; // append (sub|sup) directory path of imported file
129134 }
135+ newFileInfo . currentDirectory = pathname . replace ( / [ ^ \\ \/ ] * $ / , "" ) ;
136+ newFileInfo . filename = pathname ;
130137
131138 env . contents [ pathname ] = data ; // Updating top importing parser content cache.
132- env . paths = [ dirname ] . concat ( paths ) ;
133- env . filename = pathname ;
139+ env . currentFileInfo = newFileInfo ;
134140 new ( less . Parser ) ( env ) . parse ( data , function ( e , root ) {
135141 callback ( e , root , pathname ) ;
136142 } ) ;
137143 } ;
138144
139145 var isUrl = isUrlRe . test ( file ) ;
140- if ( isUrl || isUrlRe . test ( paths [ 0 ] ) ) {
146+ if ( isUrl || isUrlRe . test ( currentFileInfo . currentDirectory ) ) {
141147 if ( request === undefined ) {
142148 try { request = require ( 'request' ) ; }
143149 catch ( e ) { request = null ; }
@@ -147,7 +153,7 @@ less.Parser.importer = function (file, paths, callback, env) {
147153 return ;
148154 }
149155
150- var urlStr = isUrl ? file : url . resolve ( paths [ 0 ] , file ) ,
156+ var urlStr = isUrl ? file : url . resolve ( currentFileInfo . currentDirectory , file ) ,
151157 urlObj = url . parse ( urlStr ) ,
152158 req = {
153159 host : urlObj . hostname ,
@@ -172,9 +178,7 @@ less.Parser.importer = function (file, paths, callback, env) {
172178 } ) ;
173179 } else {
174180
175- // TODO: Undo this at some point,
176- // or use different approach.
177- var paths = [ ] . concat ( paths ) ;
181+ var paths = [ currentFileInfo . currentDirectory ] . concat ( env . paths ) ;
178182 paths . push ( '.' ) ;
179183
180184 for ( var i = 0 ; i < paths . length ; i ++ ) {
@@ -187,8 +191,6 @@ less.Parser.importer = function (file, paths, callback, env) {
187191 }
188192 }
189193
190- paths = paths . slice ( 0 , paths . length - 1 ) ;
191-
192194 if ( ! pathname ) {
193195
194196 callback ( { type : 'File' , message : "'" + file + "' wasn't found" } ) ;
0 commit comments