From c84f3f0b2d39261c990d7b7319a3da669aaee8a5 Mon Sep 17 00:00:00 2001 From: slorber Date: Thu, 23 Jul 2020 19:11:14 +0200 Subject: [PATCH] broken links: we should ignore folders when looking for existing files in the build folder --- packages/docusaurus/src/server/brokenLinks.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index a07e5ec056d9..31080b58cc24 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -130,14 +130,17 @@ async function filterExistingFileLinks({ allCollectedLinks: Record; }): Promise> { // 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)); }); }