Skip to content

Commit 50b0b98

Browse files
author
codexromeo88
committed
fix issues for windows deadlinks paths
1 parent 9cdf831 commit 50b0b98

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

scripts/deadLinkChecker.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ const contributorMap = new Map(); // Map<anchorId, URL>
1919
const redirectMap = new Map(); // Map<source, destination>
2020
let errorCodes = new Set();
2121

22+
function normalizeFilePath(filePath) {
23+
// Ensure we use a consistent, OS-native absolute path for Map keys.
24+
// globby returns POSIX-style paths on Windows (e.g. C:/...), while path.join
25+
// returns Windows-style paths (e.g. C:\...). Without normalization, anchor
26+
// lookups fail on Windows.
27+
return path.resolve(filePath);
28+
}
29+
2230
async function readFileWithCache(filePath) {
31+
filePath = normalizeFilePath(filePath);
2332
if (!fileCache.has(filePath)) {
2433
try {
2534
const content = await fs.promises.readFile(filePath, 'utf8');
@@ -47,7 +56,7 @@ function getMarkdownFiles() {
4756
path.posix.join(baseDir, '**/*.md'),
4857
path.posix.join(baseDir, '**/*.mdx'),
4958
];
50-
return globby.sync(patterns);
59+
return globby.sync(patterns).map(normalizeFilePath);
5160
}
5261

5362
function extractAnchorsFromContent(content) {
@@ -80,7 +89,7 @@ async function buildAnchorMap(files) {
8089
const content = await readFileWithCache(filePath);
8190
const anchors = extractAnchorsFromContent(content);
8291
if (anchors.size > 0) {
83-
anchorMap.set(filePath, anchors);
92+
anchorMap.set(normalizeFilePath(filePath), anchors);
8493
}
8594
}
8695
}
@@ -135,7 +144,7 @@ async function findTargetFile(urlPath) {
135144

136145
for (const p of publicPaths) {
137146
if (await fileExists(p)) {
138-
return p;
147+
return normalizeFilePath(p);
139148
}
140149
}
141150
}
@@ -154,7 +163,7 @@ async function findTargetFile(urlPath) {
154163

155164
for (const p of possiblePaths) {
156165
if (await fileExists(p)) {
157-
return p;
166+
return normalizeFilePath(p);
158167
}
159168
}
160169
return null;

0 commit comments

Comments
 (0)