diff --git a/CHANGELOG.md b/CHANGELOG.md index e47af9a7e..2de8084b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ - The color theme label in the default theme now has an accessible name, #2557. - Fixed issue where search results could not be navigated while Windows Narrator was on, #2563. - `charset` is now correctly cased in `` tag generated by the default theme, #2568. +- Fixed very slow conversion on Windows where Msys git was used by typedoc to discover repository links, #2586. - Fixed `externalSymbolLinkMappings` option's support for [meanings](https://typedoc.org/guides/declaration-references/#meaning) in declaration references. - Buttons to copy code now have the `type=button` attribute set to avoid being treated as submit buttons. - `--hostedBaseUrl` will now implicitly add a trailing slash to the generated URL. @@ -73,6 +74,7 @@ ### Thanks! - @Aryakoste +- @Dinnerbone - @HarelM - @kraenhansen - @Nil2000 diff --git a/src/lib/converter/utils/base-path.ts b/src/lib/converter/utils/base-path.ts index 5577642a8..429071032 100644 --- a/src/lib/converter/utils/base-path.ts +++ b/src/lib/converter/utils/base-path.ts @@ -82,16 +82,25 @@ export class BasePath { * @returns Normalized version of the given path. */ static normalize(path: string): string { - // Ensure forward slashes - path = path.replace(/\\/g, "/"); + if (process.platform === "win32") { + // Ensure forward slashes + path = path.replace(/\\/g, "/"); - // Remove all surrounding quotes - path = path.replace(/^["']+|["']+$/g, ""); + // Msys2 git on windows will give paths which use unix-style + // absolute paths, like /c/users/you. Since the rest of TypeDoc + // expects drive letters, convert it to that here. + path = path.replace( + /^\/([a-zA-Z])\//, + (_m, m1: string) => `${m1}:/`, + ); - // Make Windows drive letters upper case - return path.replace( - /^([^:]+):\//, - (_m, m1: string) => m1.toUpperCase() + ":/", - ); + // Make Windows drive letters upper case + path = path.replace( + /^([^:]+):\//, + (_m, m1: string) => m1.toUpperCase() + ":/", + ); + } + + return path; } } diff --git a/src/lib/converter/utils/repository.ts b/src/lib/converter/utils/repository.ts index 69c575460..405d53c48 100644 --- a/src/lib/converter/utils/repository.ts +++ b/src/lib/converter/utils/repository.ts @@ -71,9 +71,9 @@ export class GitRepository implements Repository { this.gitRevision = gitRevision; this.urlTemplate = urlTemplate; - const out = git("-C", path, "ls-files"); + const out = git("-C", path, "ls-files", "-z"); if (out.status === 0) { - out.stdout.split("\n").forEach((file) => { + out.stdout.split("\0").forEach((file) => { if (file !== "") { this.files.add(BasePath.normalize(path + "/" + file)); } diff --git a/src/test/utils/base-path.test.ts b/src/test/utils/base-path.test.ts new file mode 100644 index 000000000..a58e76614 --- /dev/null +++ b/src/test/utils/base-path.test.ts @@ -0,0 +1,27 @@ +import { equal } from "assert"; +import { BasePath } from "../../lib/converter/utils/base-path"; + +describe("BasePath.normalize", () => { + const winTest = process.platform === "win32" ? it : it.skip; + const nixTest = process.platform === "win32" ? it.skip : it; + + winTest("Returns paths with forward slashes", () => { + equal( + BasePath.normalize("test\\test\\another/forward"), + "test/test/another/forward", + ); + }); + + winTest("Normalizes drive letters", () => { + equal(BasePath.normalize("c:\\foo"), "C:/foo"); + equal(BasePath.normalize("D:/foo"), "D:/foo"); + }); + + winTest("Checks for unix style paths", () => { + equal(BasePath.normalize("/c/users/you"), "C:/users/you"); + }); + + nixTest("Returns the original path", () => { + equal(BasePath.normalize("/c/users\\foo"), "/c/users\\foo"); + }); +});