Skip to content

Commit 270941a

Browse files
jmbyunrodneyrehm
authored andcommitted
fix(sass.node): allow raw css imports (#94)
1 parent 9d7fac0 commit 270941a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/sass.node.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function fileExists(path) {
77
return stat && stat.isFile();
88
}
99

10+
function removeFileExtension(path) {
11+
return path.slice(0, path.lastIndexOf('.'));
12+
}
13+
1014
function importFileToSass(path, done) {
1115
// any path must be relative to CWD to work in both environments (real FS, and emscripten FS)
1216
var requestedPath = './' + path;
@@ -20,13 +24,19 @@ function importFileToSass(path, done) {
2024
return;
2125
}
2226

27+
// Make sure to omit the ".css" file extension when it was omitted in requestedPath.
28+
// This allow raw css imports.
29+
// see https://github.com/sass/libsass/pull/754
30+
var isRawCss = !requestedPath.endsWith('.css') && filesystemPath.endsWith('.css');
31+
var targetPath = isRawCss ? removeFileExtension(filesystemPath) : filesystemPath;
32+
2333
// write the file to emscripten FS so libsass internal FS handling
2434
// can engage the scss/sass switch, which apparently does not happen
2535
// for content provided through the importer callback directly
2636
var content = fs.readFileSync(filesystemPath, {encoding: 'utf8'});
2737
Sass.writeFile(filesystemPath, content, function() {
2838
done({
29-
path: filesystemPath,
39+
path: targetPath,
3040
});
3141
});
3242
}

0 commit comments

Comments
 (0)