Skip to content

Commit 9348530

Browse files
committed
Fix possibility of absolute paths, resolves #12
1 parent 3d3b69d commit 9348530

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### 3.0.1 (2024-10-15)
2+
3+
- Fixed an issue where modules could be created by this plugin with names
4+
including an absolute path, #12.
5+
16
### 3.0.0 (2024-06-22)
27

38
- Support TypeDoc 0.26

index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { relative } from "path";
12
import {
23
Application,
34
Context,
@@ -127,6 +128,19 @@ export function load(app: Application) {
127128
if (refl.kindOf(ModuleLike)) {
128129
knownPrograms.set(refl, context.program);
129130
}
131+
132+
// #12 - This plugin might cause TypeDoc to convert some module without
133+
// an export symbol to give it a name other than the full absolute
134+
// path to the symbol. Detect this and rename it to a relative path
135+
// based on base path if specified or CWD.
136+
const symbol = context.project.getSymbolFromReflection(refl);
137+
const file = symbol?.declarations?.find(ts.isSourceFile);
138+
if (file && /^".*"$/.test(refl.name)) {
139+
refl.name = relative(
140+
app.options.getValue("basePath") || process.cwd(),
141+
file.fileName,
142+
);
143+
}
130144
},
131145
);
132146

test/packages.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ beforeAll(async () => {
7575
afterEach(() => {
7676
app.options.reset("internalModule");
7777
app.options.reset("placeInternalsInOwningModule");
78+
app.options.reset("basePath");
7879

7980
expect(logger.messages).toEqual([]);
8081
logger.messages = [];
@@ -159,6 +160,30 @@ test("Missing declaration", () => {
159160
expect(toStringHierarchy(project)).toBe(hierarchy);
160161
});
161162

163+
// https://github.com/Gerrit0/typedoc-plugin-missing-exports/issues/12
164+
test("Issue #12", () => {
165+
const project = convert("gh12/index.ts");
166+
167+
const hierarchy = outdent`
168+
Module <internal>
169+
Namespace test/packages/gh12/mod.ts
170+
Variable ReferencesModule
171+
`;
172+
173+
expect(toStringHierarchy(project)).toBe(hierarchy);
174+
175+
app.options.setValue("basePath", "test/packages");
176+
const project2 = convert("gh12/index.ts");
177+
178+
const hierarchy2 = outdent`
179+
Module <internal>
180+
Namespace gh12/mod.ts
181+
Variable ReferencesModule
182+
`;
183+
184+
expect(toStringHierarchy(project2)).toBe(hierarchy2);
185+
});
186+
162187
// https://github.com/Gerrit0/typedoc-plugin-missing-exports/issues/15
163188
test("Issue #15", () => {
164189
const project = convert("gh15/index.ts");

test/packages/gh12/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare const ReferencesModule: {
2+
mod: typeof import("./mod.js");
3+
};

test/packages/gh12/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const abc = 123;

0 commit comments

Comments
 (0)