broken links: we should ignore folders when looking for existing files in the build folder (#3107)

This commit is contained in:
Sébastien Lorber 2020-07-24 13:49:29 +02:00 committed by GitHub
parent a78f703366
commit 6aec331963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -130,14 +130,17 @@ async function filterExistingFileLinks({
allCollectedLinks: Record<string, string[]>;
}): Promise<Record<string, string[]>> {
// not easy to make this async :'(
function linkFileDoesNotExist(link: string): boolean {
function linkFileExists(link: string): boolean {
const filePath = `${outDir}/${removePrefix(link, baseUrl)}`;
const exists = fs.existsSync(filePath);
return !exists;
try {
return fs.statSync(filePath).isFile(); // only consider files
} catch (e) {
return false;
}
}
return mapValues(allCollectedLinks, (links) => {
return links.filter(linkFileDoesNotExist);
return links.filter((link) => !linkFileExists(link));
});
}