Skip to content

Commit

Permalink
fix(filesearch): fix, where @import statement without explicit extens…
Browse files Browse the repository at this point in the history
…ion throws ENOENT error

Fixing a bug where .less extension is not optional with some @import statements in certain directory
strcutures. This fix checks if the @import statement has an extension available, if an extension is
not provided we assume the default as .less, related to issue jonycheung#117

fix jonycheung#117
  • Loading branch information
hammad-celtx committed Nov 22, 2021
1 parent a66130d commit c9e4fba
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lib/filesearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ define(function (require){
while (m = re.exec(fileContent)){
let [ , , filename ] = m;
// console.log('found import ' + filename);

if (path.extname(filename).length < 1) {
// console.log("The imported file does not have an explicit extension, we will assume it's .less", filename);
filename = filename + ".less";
}

if (m) files.push(filename);
}
return files;
Expand Down
2 changes: 1 addition & 1 deletion test/filesearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('filesearch Module', function () {

it('should search through a file and find LESS @import statements ', function (done) {
var file = "./test/less/test.less";
var result = ['lvl1.less', 'lvl2/lvl2.less', 'lvl2/lvl3/lvl3.less', 'hidden/_hidden.less', 'hidden/.hidden2.less'],
var result = ['lvl1.less', 'lvl2/lvl2.less', 'lvl2/lvl2_no_extension.less', 'lvl2/lvl3/lvl3.less', 'hidden/_hidden.less', 'hidden/.hidden2.less'],
filesearchresult = filesearch.findLessImportsInFile(file);
assert.equal(result.toString(), filesearchresult.toString());
done();
Expand Down
3 changes: 3 additions & 0 deletions test/less/lvl2/lvl2_no_extension.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.lvl2_no_extension {
display: inline;
}
1 change: 1 addition & 0 deletions test/less/test.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Test Comments
}
@import 'lvl1.less';
@import "lvl2/lvl2.less";
@import "lvl2/lvl2_no_extension";
@import "lvl2/lvl3/lvl3.less";
@import "hidden/_hidden.less";
@import "hidden/.hidden2.less";

0 comments on commit c9e4fba

Please sign in to comment.