make some changes suggested in #1107 to improve open file handles

This commit is contained in:
Luke Page
2014-05-06 06:50:40 +01:00
parent 9ad5f181dc
commit 028fe1a4ca

View File

@@ -24,7 +24,7 @@ var less = {
var css;
try {
css = root && root.toCSS && root.toCSS(options);
}
}
catch (err) { callback(err); return; }
callback(null, css);
});
@@ -34,7 +34,7 @@ var less = {
process.nextTick(function () {
parser.parse(input, function (e, root) {
if (e) { return ee.emit('error', e); }
try { ee.emit('success', root.toCSS(options)); }
try { ee.emit('success', root.toCSS(options)); }
catch (err) { ee.emit('error', err); }
});
});
@@ -143,13 +143,13 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
function handleDataAndCallCallback(data) {
var j = file.lastIndexOf('/');
// Pass on an updated rootpath if path of imported file is relative and file
// Pass on an updated rootpath if path of imported file is relative and file
// is in a (sub|sup) directory
//
// Examples:
//
// Examples:
// - If path of imported file is 'module/nav/nav.less' and rootpath is 'less/',
// then rootpath should become 'less/module/nav/'
// - If path of imported file is '../mixins.less' and rootpath is 'less/',
// - If path of imported file is '../mixins.less' and rootpath is 'less/',
// then rootpath should become 'less/../'
if(newFileInfo.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
var relativeSubDirectory = file.slice(0, j+1);
@@ -160,7 +160,7 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
callback(null, data, pathname, newFileInfo);
}
var isUrl = isUrlRe.test( file );
if (isUrl || isUrlRe.test(currentFileInfo.currentDirectory)) {
if (request === undefined) {
@@ -227,8 +227,13 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
tryPathIndex(i + 1);
} else {
fs.readFile(pathname, 'utf-8', function(e, data) {
if (e) { callback(e); }
handleDataAndCallCallback(data);
if (e) { callback(e); return; }
// do processing in the next tick to allow
// file handling to dispose
process.nextTick(function() {
handleDataAndCallCallback(data);
});
});
}
});