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 adae049
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ var getFileNames = function getFileNames(abstractName) {
directory,
basename;

if (path.extname(abstractName)) {
if ([ '.scss', '.sass' ].indexOf(path.extname(abstractName)) !== -1) {
directory = path.dirname(abstractName);
basename = path.basename(abstractName);

[ '', '_' ].forEach(function(prefix) {
names.push(path.join(directory, prefix + basename));
});
}
else if (path.extname(abstractName)) {
names.push(abstractName);
}
else {
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 import with Sass 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 adae049

Please sign in to comment.