Skip to content

fix(sass.node): allow raw css imports #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/sass.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function fileExists(path) {
return stat && stat.isFile();
}

function removeFileExtension(path) {
return path.slice(0, path.lastIndexOf('.'));
}

function importFileToSass(path, done) {
// any path must be relative to CWD to work in both environments (real FS, and emscripten FS)
var requestedPath = './' + path;
Expand All @@ -20,13 +24,19 @@ function importFileToSass(path, done) {
return;
}

// Make sure to omit the ".css" file extension when it was omitted in requestedPath.
// This allow raw css imports.
// see https://github.com/sass/libsass/pull/754
var isRawCss = !requestedPath.endsWith('.css') && filesystemPath.endsWith('.css');
var targetPath = isRawCss ? removeFileExtension(filesystemPath) : filesystemPath;

// write the file to emscripten FS so libsass internal FS handling
// can engage the scss/sass switch, which apparently does not happen
// for content provided through the importer callback directly
var content = fs.readFileSync(filesystemPath, {encoding: 'utf8'});
Sass.writeFile(filesystemPath, content, function() {
done({
path: filesystemPath,
path: targetPath,
});
});
}
Expand Down