Closed aggieben closed 8 years ago
just to clarify: I did this in collusion with @morethanfire
Also, another possible way to do this that might be easier to understand at first glance is something like this:
function fileExistsWithCaseSync(filepath) {
var dir = path.dirname(filepath);
var paths = path.parse(dir);
//if ((dir === '/' || (os.platform() === 'win32' && dir.split(':')[1] === '\\')) || dir === '.') return;
if ((paths.dir === paths.root) || dir === '.') return;
var filenames = fs.readdirSync(dir);
if (filenames.indexOf(path.basename(filepath)) === - 1) {
// This could easily be accomplished with various requires, but I want to keep this module thin.
var lowercasedFilenames = [];
for (var i = 0; i < filenames.length; i++) {
lowercasedFilenames.push(filenames[i].toLowerCase());
}
var index = lowercasedFilenames.indexOf(path.basename(filepath).toLowerCase());
return path.join(dir, filenames[index]);
}
return fileExistsWithCaseSync(dir);
}
Good catch! I don't have a windows dev box so I wasn't able to test that.
I'll double-check this new version and release a patch.
Windows root paths don't look like '/', but rather 'C:\'. This change will allow the function to end it's recursion correctly on Windows. Addresses #1