diff --git a/.gitignore b/.gitignore index e8a48bb..e21e8db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.idea/ # Logs logs *.log diff --git a/index.js b/index.js index 700520d..819f203 100644 --- a/index.js +++ b/index.js @@ -221,25 +221,28 @@ var readFirstFile = function readFirstFile(uri, filenames, css, cb, examinedFile var filename = filenames.shift(); examinedFiles = examinedFiles || []; examinedFiles.push(filename); - fs.readFile(filename, function(err, data) { - if (err) { - if (filenames.length) { - readFirstFile(uri, filenames, css, cb, examinedFiles); - } - else { - cb(new Error('Could not import `' + uri + '` from any of the following locations:\n ' + examinedFiles.join('\n '))); - } + try { + var data = fs.readFileSync(filename); + } catch (e) { + var err = e; + } + if (err) { + if (filenames.length) { + readFirstFile(uri, filenames, css, cb, examinedFiles); } else { - if ([ '.js', '.json', '.yml', '.yaml' ].indexOf(path.extname(filename)) !== -1) { - data = parseJSON(data, filename); - } - cb(null, { - 'contents': data.toString(), - 'file': filename - }); + cb(new Error('Could not import `' + uri + '` from any of the following locations:\n ' + examinedFiles.join('\n '))); } - }); + } + else { + if ([ '.js', '.json', '.yml', '.yaml' ].indexOf(path.extname(filename)) !== -1) { + data = parseJSON(data, filename); + } + cb(null, { + 'contents': data.toString(), + 'file': filename + }); + } }; // This is a bootstrap function for calling readFirstFile.