-
Notifications
You must be signed in to change notification settings - Fork 135
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
importing UTF-8 encoded files #72
Comments
After running var fs = require('fs');
var Sass = require('sass.js');
Sass.importer(function(request, done) {
// sass.js works in the "/sass/" directory, make that relative to CWD
var path = '.' + request.resolved.replace(/^\/sass\//, '/' );
var file = Sass.findPathVariation(fs.statSync, path);
done({
path: file,
content: fs.readFileSync(file, {encoding: 'utf8'}),
});
});
Sass.compile('@import "bourbon/_bourbon";', function(res) {
console.log(res);
}); This produces the (absurd and unhelpful) error message
Fiddling around with the content of _margin.scss, I figured out that the characters I'm not aware of any UTF-8 problems in the past so I'm a bit stumped by this. Which node version are you running? (I'm on 7.1.0). |
What about this: https://github.com/jgillich/sassjs-bulma
Something definitely seems off with UTF-8 handling. |
Ok, things are beginning to make some sense now. The short answer is that content returned by the importer callback directly is treated differently from the content libsass reads from emscripten's FS (i.e. when using @tjaartvdwalt's problem has to do with UTF-8 not being ingested properly when the content is passed as string from the importer callback. I guess that's the fault of @jgillich's problem has to do with libsass not realizing that the content provided by the importer callback is SASS, but attempts to parse everything as SCSS. That's why the I assume the UTF-8 problem can be dealt with somehow. However, I have no idea why the importer callback doesn't like SASS. Both problems disappear if the content from the real FS is imported in the following way: var fs = require('fs');
var Sass = require('sass.js');
function fileExists(path) {
var stat = fs.statSync(path);
return stat && stat.isFile();
}
function importFileToSass(path, done) {
// any path must be relative to CWD to work in both environments (real FS, and emscripten FS)
var requestedPath = './' + path;
// figure out the *actual* path of the file
var filesystemPath = Sass.findPathVariation(fileExists, requestedPath);
if (!filesystemPath) {
done({
error: 'File "' + requestedPath + '" not found',
});
return;
}
// 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,
});
});
}
Sass.importer(function(request, done) {
// sass.js works in the "/sass/" directory, make that relative to CWD
var requestedPath = request.resolved.replace(/^\/sass\//, '' );
importFileToSass(requestedPath, done);
});
var rootFile = 'node_modules/bulma/bulma.sass';
importFileToSass(rootFile, function() {
Sass.compileFile(rootFile, function(res) {
console.log(res);
});
}); |
I just released 0.10.0. This release fixes the UTF-8 problems encountered by @tjaartvdwalt. @jgillich's problem is not resolved, but the workaround I posted has been included in the the library |
Great news, thanks! |
thanks! |
Hi,
I am using plugin-sass, which uses sass.js for parsing.
I logged dougludlow/plugin-sass#74, but the authors seem to think the problem is upstream.
The problem is that I cannot seem to import files that contain
@charset "UTF-8";
.If you are interested, I have created a test repository to illustrate the problem: https://github.com/tjaartvdwalt/systemjs-sass-plugin-example
The text was updated successfully, but these errors were encountered: