Skip to content

Commit

Permalink
Fix filename resolution when importing files with extensions
Browse files Browse the repository at this point in the history
When Sass resolves `@import "foo/bar.scss"` it still fallsback to
`foo/_bar.scss`. Currently `getFileNames` incorrectly opts out of
the fallback behaviour for files with extensions.
  • Loading branch information
xzyfer committed Feb 10, 2016
1 parent 29d47bb commit a442ca5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ var getFileNames = function getFileNames(abstractName) {
basename;

if (path.extname(abstractName)) {
names.push(abstractName);
directory = path.dirname(abstractName);
basename = path.basename(abstractName);

[ '', '_' ].forEach(function(prefix) {
names.push(path.join(directory, prefix + basename));
});
}
else {
directory = path.dirname(abstractName);
Expand Down
2 changes: 2 additions & 0 deletions tests/css/imported-scss.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.foo {
content: 'This is Foo\'s Index file'; }
23 changes: 23 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ describe('import-once', function () {
});
});

it.only('should resolve imports with extensions', function(done) {
var file = filePath('import-scss.scss'),
expectedIncludes = [
file,
filePath('foo/_index.scss')
];

sass.render({
'file': file,
'importer': importer
}, function (err, result) {
if (err) {
throw err;
}
should.exist(result);
result.stats.includedFiles.should.eql(expectedIncludes);
String(result.css).should.equal(
fs.readFileSync(path.join(__dirname, 'css/imported-scss.css'), 'utf8')
);
done();
});
})

it('should import `index` files from a folder', function (done) {
var file = filePath('import-index.scss'),
expectedIncludes = [
Expand Down
1 change: 1 addition & 0 deletions tests/sass/import-scss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'foo/index.scss';

0 comments on commit a442ca5

Please sign in to comment.