Skip to content
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

[FIX] fileUtils: Correctly provide stat property on readFile result and properly handle exceptions from fs.stat #382

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/fileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ module.exports = function(fs) {
function statFile(filePath) {
return new Promise(function(resolve, reject) {
fs.stat(filePath, function(err, stat) {
// No rejection here as it is ok if the file was not found
resolve(stat ? {path: filePath, stat: stat} : null);
if (err) {
if (err.code === "ENOENT") { // "File or directory does not exist"
return resolve(null);
} else {
return reject(err);
}
}
resolve({path: filePath, stat});
});
});
}
Expand Down Expand Up @@ -57,7 +63,7 @@ module.exports = function(fs) {
content: content,
path: fileInfo.path,
localPath: lessInputPath,
stats: fileInfo.stats
stat: fileInfo.stat
});
}
});
Expand Down
Loading