mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Switch less back to fully synchronous, now that the NPM module supports it.
syncImport was added in 1.3.2 and we just upgraded from 1.3.1 to 1.3.3. Otherwise error handling gets pretty fussy (eg, sometimes less throws from within a callback).
This commit is contained in:
@@ -5,7 +5,6 @@ Package.describe({
|
||||
var less = require('less');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var Future = require(path.join('fibers', 'future'));
|
||||
|
||||
Package.register_extension(
|
||||
"less", function (bundle, source_path, serve_path, where) {
|
||||
@@ -14,16 +13,30 @@ Package.register_extension(
|
||||
var contents = fs.readFileSync(source_path, 'utf8');
|
||||
|
||||
try {
|
||||
var css = Future.wrap(less.render)(contents, {
|
||||
less.render(contents.toString('utf8'), {
|
||||
// Use fs.readFileSync to process @imports. This is the bundler, so
|
||||
// that's not going to cause concurrency issues, and it means that (a)
|
||||
// we don't have to use Futures and (b) errors thrown by bugs in less
|
||||
// actually get caught.
|
||||
syncImport: true,
|
||||
paths: [path.resolve(source_path, '..')] // for @import
|
||||
}).wait();
|
||||
bundle.add_resource({
|
||||
type: "css",
|
||||
path: serve_path,
|
||||
data: new Buffer(css),
|
||||
where: where
|
||||
}, function (err, css) {
|
||||
if (err) {
|
||||
bundle.error(source_path + ": Less compiler error: " + err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
bundle.add_resource({
|
||||
type: "css",
|
||||
path: serve_path,
|
||||
data: new Buffer(css),
|
||||
where: where
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
// less.render() is supposed to report any errors via its
|
||||
// callback. But sometimes, it throws them instead. This is
|
||||
// probably a bug in less. Be prepared for either behavior.
|
||||
bundle.error(source_path + ": Less compiler error: " + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user