Skip to content

Commit

Permalink
Simple fix for git discovery issue in #2586
Browse files Browse the repository at this point in the history
More testing needed, and likely a complete rework of SourcePlugin as it makes bad assumptions.
  • Loading branch information
Gerrit0 committed Jun 7, 2024
1 parent 9baabcc commit 774ac92
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@
- 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 `<meta>` 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.

### Thanks!

- @Aryakoste
- @Dinnerbone
- @HarelM
- @kraenhansen
- @Nil2000
Expand Down
27 changes: 18 additions & 9 deletions src/lib/converter/utils/base-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/lib/converter/utils/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
27 changes: 27 additions & 0 deletions src/test/utils/base-path.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit 774ac92

Please sign in to comment.