Skip to content

Commit 28fe19a

Browse files
committed
Fix #22
1 parent 059ede5 commit 28fe19a

File tree

10 files changed

+243
-190
lines changed

10 files changed

+243
-190
lines changed

Diff for: .github/workflows/ci.yml

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
name: CI
22
on: [push, pull_request]
33
jobs:
4-
build:
5-
runs-on: ubuntu-latest
6-
strategy:
7-
matrix:
8-
node: ["16", "18", "20"]
9-
name: Node ${{ matrix.node }}
10-
steps:
11-
- name: Checkout repository
12-
uses: actions/checkout@v2
13-
- name: Set up Node
14-
uses: actions/setup-node@v1
15-
with:
16-
node-version: ${{ matrix.node }}
17-
- name: Install
18-
run: yarn
19-
- name: Build
20-
run: yarn build
21-
- name: Test
22-
run: yarn test
23-
- name: Lint
24-
run: yarn prettier --check .
25-
- name: Circular dependency check
26-
uses: gerrit0/circular-dependency-check@v1
27-
with:
28-
entry: index.js
4+
build:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
node: ["16", "18", "20"]
9+
name: Node ${{ matrix.node }}
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
- name: Set up Node
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: ${{ matrix.node }}
17+
- name: Install
18+
run: yarn
19+
- name: Build
20+
run: yarn build
21+
- name: Test
22+
run: yarn test
23+
- name: Lint
24+
run: yarn prettier --check .
25+
build-windows:
26+
runs-on: windows-latest
27+
name: Node 20 Windows
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
- name: Set up Node
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: ${{ matrix.node }}
34+
- name: Install
35+
run: yarn
36+
- name: Build
37+
run: yarn build
38+
- name: Test
39+
run: yarn test

Diff for: .github/workflows/publish.yml

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
name: Publish
22
on:
3-
push:
4-
branches:
5-
- main
3+
push:
4+
branches:
5+
- main
66
jobs:
7-
npm-publish:
8-
name: npm-publish
9-
runs-on: ubuntu-latest
10-
steps:
11-
- name: Checkout repository
12-
uses: actions/checkout@v2
13-
with:
14-
fetch-depth: 0
15-
- id: check
16-
uses: EndBug/version-check@v1
17-
with:
18-
diff-search: true
19-
- name: Set up Node
20-
if: steps.check.outputs.changed == 'true'
21-
uses: actions/setup-node@v1
22-
with:
23-
node-version: "16"
24-
- name: Install
25-
if: steps.check.outputs.changed == 'true'
26-
run: yarn
27-
- name: Build
28-
if: steps.check.outputs.changed == 'true'
29-
run: yarn build
30-
- name: Test
31-
if: steps.check.outputs.changed == 'true'
32-
run: yarn test
33-
- name: Setup publish token
34-
if: steps.check.outputs.changed == 'true'
35-
run: echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
36-
env:
37-
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
38-
- name: Publish
39-
if: steps.check.outputs.changed == 'true'
40-
run: |
41-
yarn publish --non-interactive
42-
git tag v$(jq '.version' package.json -r)
43-
git push --tags
7+
npm-publish:
8+
name: npm-publish
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
- id: check
16+
uses: EndBug/version-check@v2.1.0
17+
with:
18+
diff-search: true
19+
- name: Set up Node
20+
if: steps.check.outputs.changed == 'true'
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: "20"
24+
- name: Install
25+
if: steps.check.outputs.changed == 'true'
26+
run: yarn
27+
- name: Build
28+
if: steps.check.outputs.changed == 'true'
29+
run: yarn build
30+
- name: Test
31+
if: steps.check.outputs.changed == 'true'
32+
run: yarn test
33+
- name: Setup publish token
34+
if: steps.check.outputs.changed == 'true'
35+
run: echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
36+
env:
37+
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
38+
- name: Publish
39+
if: steps.check.outputs.changed == 'true'
40+
run: |
41+
yarn publish --non-interactive
42+
git tag v$(jq '.version' package.json -r)
43+
git push --tags

Diff for: CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### 2.1.1 (2024-01-14)
2+
3+
- Fixed an issue where if a re-exported symbol referenced an internal symbol, and more than one entry point was provided to TypeDoc,
4+
this plugin would add the internal symbol to the last module, rather than the one it was associated with, #22.
5+
16
### 2.1.0 (2023-08-25)
27

38
- Added support for TypeDoc 0.25.x
@@ -12,7 +17,7 @@
1217

1318
### 1.0.0 (2022-08-12)
1419

15-
- BREAKING: Will now create an `<internals>`**module** rather than a **namespace** to allow support for referenced default exports, #15.
20+
- BREAKING: Will now create an `<internals>` **module** rather than a **namespace** to allow support for referenced default exports, #15.
1621
- BREAKING: Renamed `internalNamespace` option to `internalModule`
1722

1823
### 0.23.0 (2022-06-26)

Diff for: index.ts

+41-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ok } from "assert";
21
import {
32
Application,
43
Context,
@@ -15,9 +14,16 @@ declare module "typedoc" {
1514
export interface TypeDocOptionMap {
1615
internalModule: string;
1716
}
17+
18+
export interface Reflection {
19+
[InternalModule]?: boolean;
20+
}
1821
}
1922

2023
let hasMonkeyPatched = false;
24+
const ModuleLike: ReflectionKind =
25+
ReflectionKind.Project | ReflectionKind.Module;
26+
const InternalModule = Symbol();
2127

2228
export function load(app: Application) {
2329
if (hasMonkeyPatched) {
@@ -27,26 +33,25 @@ export function load(app: Application) {
2733
}
2834
hasMonkeyPatched = true;
2935

30-
let activeReflection: Reflection | undefined;
3136
const referencedSymbols = new Map<ts.Program, Set<ts.Symbol>>();
32-
const symbolToActiveRefl = new Map<ts.Symbol, Reflection>();
37+
const symbolToOwningModule = new Map<ts.Symbol, Reflection>();
3338
const knownPrograms = new Map<Reflection, ts.Program>();
3439

3540
function discoverMissingExports(
41+
owningModule: Reflection,
3642
context: Context,
3743
program: ts.Program,
3844
): Set<ts.Symbol> {
3945
// An export is missing if if was referenced
4046
// Is not contained in the documented
41-
// And is "owned" by the active reflection
4247
const referenced = referencedSymbols.get(program) || new Set();
4348
const ownedByOther = new Set<ts.Symbol>();
4449
referencedSymbols.set(program, ownedByOther);
4550

4651
for (const s of [...referenced]) {
4752
if (context.project.getReflectionFromSymbol(s)) {
4853
referenced.delete(s);
49-
} else if (symbolToActiveRefl.get(s) !== activeReflection) {
54+
} else if (symbolToOwningModule.get(s) !== owningModule) {
5055
referenced.delete(s);
5156
ownedByOther.add(s);
5257
}
@@ -58,9 +63,15 @@ export function load(app: Application) {
5863
// Monkey patch the constructor for references so that we can get every
5964
const origCreateSymbolReference = ReferenceType.createSymbolReference;
6065
ReferenceType.createSymbolReference = function (symbol, context, name) {
61-
ok(activeReflection, "active reflection has not been set");
66+
const owningModule = getOwningModule(context);
67+
console.log(
68+
"Created ref",
69+
symbol.name,
70+
"owner",
71+
owningModule.getFullName(),
72+
);
6273
const set = referencedSymbols.get(context.program);
63-
symbolToActiveRefl.set(symbol, activeReflection);
74+
symbolToOwningModule.set(symbol, owningModule);
6475
if (set) {
6576
set.add(symbol);
6677
} else {
@@ -78,9 +89,8 @@ export function load(app: Application) {
7889
app.converter.on(
7990
Converter.EVENT_CREATE_DECLARATION,
8091
(context: Context, refl: Reflection) => {
81-
if (refl.kindOf(ReflectionKind.Project | ReflectionKind.Module)) {
92+
if (refl.kindOf(ModuleLike)) {
8293
knownPrograms.set(refl, context.program);
83-
activeReflection = refl;
8494
}
8595
},
8696
);
@@ -96,12 +106,11 @@ export function load(app: Application) {
96106
}
97107

98108
for (const mod of modules) {
99-
activeReflection = mod;
100-
101109
const program = knownPrograms.get(mod);
102110
if (!program) continue;
103-
let missing = discoverMissingExports(context, program);
104-
if (!missing || !missing.size) continue;
111+
112+
let missing = discoverMissingExports(mod, context, program);
113+
if (!missing.size) continue;
105114

106115
// Nasty hack here that will almost certainly break in future TypeDoc versions.
107116
context.setActiveProgram(program);
@@ -114,6 +123,7 @@ export function load(app: Application) {
114123
void 0,
115124
context.converter.application.options.getValue("internalModule"),
116125
);
126+
internalNs[InternalModule] = true;
117127
context.finalizeDeclarationReflection(internalNs);
118128
const internalContext = context.withScope(internalNs);
119129

@@ -130,7 +140,7 @@ export function load(app: Application) {
130140
tried.add(s);
131141
}
132142

133-
missing = discoverMissingExports(context, program);
143+
missing = discoverMissingExports(mod, context, program);
134144
for (const s of tried) {
135145
missing.delete(s);
136146
}
@@ -146,12 +156,28 @@ export function load(app: Application) {
146156

147157
knownPrograms.clear();
148158
referencedSymbols.clear();
149-
symbolToActiveRefl.clear();
159+
symbolToOwningModule.clear();
150160
},
151161
void 0,
152162
1e9,
153163
);
154164
}
165+
166+
function getOwningModule(context: Context): Reflection {
167+
let refl = context.scope;
168+
// Go up the reflection hierarchy until we get to a module
169+
while (!refl.kindOf(ModuleLike)) {
170+
refl = refl.parent!;
171+
}
172+
173+
// The <internal> module cannot be an owning module.
174+
if (refl[InternalModule]) {
175+
return refl.parent!;
176+
}
177+
178+
return refl;
179+
}
180+
155181
function shouldConvertSymbol(symbol: ts.Symbol, checker: ts.TypeChecker) {
156182
while (symbol.flags & ts.SymbolFlags.Alias) {
157183
symbol = checker.getAliasedSymbol(symbol);

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"license": "MIT",
99
"devDependencies": {
1010
"@types/node": "18",
11+
"outdent": "^0.8.0",
1112
"prettier": "3.2.1",
1213
"typedoc": "^0.25.7",
1314
"typescript": "^5.3.3",

0 commit comments

Comments
 (0)