From ed96f51b756b7dc03dc8a299c4e76161c9169f90 Mon Sep 17 00:00:00 2001 From: Luke265 Date: Fri, 17 Jul 2015 19:36:15 +0300 Subject: [PATCH] Ordered file push Using fs.readFile there is no guarantee that files will be read in requested order. --- lib/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 1750cb8..4d732b9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -69,9 +69,16 @@ module.exports = function(opt) { } cb = callCounter(files.length, cb); - pathsToCss.forEach(function(f) { - readFileAndPush(f, _this, cb); - }); + var f = 0; + var next = function() { + readFileAndPush(pathsToCss[f], _this, function() { + cb(); + if(pathsToCss.length > f) + next(); + }); + f++; + }; + next(); }); };