Skip to content

Commit 7993ce7

Browse files
committed
Rebuild specs to remove info dependent on git repo
As mentioned in #1977
1 parent ecb6e00 commit 7993ce7

File tree

23 files changed

+810
-766
lines changed

23 files changed

+810
-766
lines changed

scripts/rebuild_specs.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const fs = require("fs");
66
const path = require("path");
77
const TypeDoc = require("..");
88
const { getExpandedEntryPointsForPaths } = require("../dist/lib/utils");
9+
const { ok } = require("assert");
10+
const { SourceReference } = require("..");
911

1012
const base = path.join(__dirname, "../src/test/converter");
1113

@@ -21,6 +23,23 @@ app.bootstrap({
2123
logLevel: TypeDoc.LogLevel.Warn,
2224
gitRevision: "fake",
2325
});
26+
app.serializer.addSerializer({
27+
priority: -1,
28+
supports(obj) {
29+
return obj instanceof SourceReference;
30+
},
31+
/**
32+
* @param {SourceReference} ref
33+
*/
34+
toObject(ref, obj, _serializer) {
35+
if (obj.url) {
36+
obj.url = `typedoc://${obj.url.substring(
37+
obj.url.indexOf(ref.fileName)
38+
)}`;
39+
}
40+
return obj;
41+
},
42+
});
2443

2544
/** @type {[string, () => void, () => void][]} */
2645
const conversions = [
@@ -68,20 +87,17 @@ function rebuildConverterTests(dirs) {
6887
if (fs.existsSync(out)) {
6988
TypeDoc.resetReflectionID();
7089
before();
71-
const result = app.converter.convert(
72-
getExpandedEntryPointsForPaths(
73-
app.logger,
74-
[fullPath],
75-
app.options,
76-
[program]
77-
)
90+
const entry = getExpandedEntryPointsForPaths(
91+
app.logger,
92+
[fullPath],
93+
app.options,
94+
[program]
7895
);
96+
ok(entry, "Missing entry point");
97+
const result = app.converter.convert(entry);
7998
const serialized = app.serializer.toObject(result);
8099

81-
const data =
82-
JSON.stringify(serialized, null, " ")
83-
.split(TypeDoc.normalizePath(base))
84-
.join("%BASE%") + "\n";
100+
const data = JSON.stringify(serialized, null, " ") + "\n";
85101
after();
86102
fs.writeFileSync(out, data);
87103
}

src/lib/serialization/components.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export interface SerializerComponent<T> {
1717
*/
1818
readonly priority: number;
1919

20-
supports(item: unknown): item is T;
20+
/**
21+
* Technically this should return `item is T`, but that doesn't play nicely
22+
* with inference, so allow the looser `boolean` return type.
23+
* @param item
24+
*/
25+
supports(item: unknown): boolean;
2126

2227
toObject(
2328
item: T,

src/test/converter.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { deepStrictEqual as equal, ok } from "assert";
22
import * as FS from "fs";
33
import * as Path from "path";
4-
import { normalizePath, ProjectReflection, resetReflectionID } from "..";
4+
import { ProjectReflection, resetReflectionID } from "..";
55
import { getExpandedEntryPointsForPaths } from "../lib/utils";
66
import {
77
getConverterApp,
@@ -76,14 +76,12 @@ describe("Converter", function () {
7676
const specs = JSON.parse(
7777
FS.readFileSync(specsFile, "utf-8")
7878
);
79-
let data = JSON.stringify(
80-
result && app.serializer.toObject(result),
81-
null,
82-
" "
79+
// Pass data through a parse/stringify to get rid of undefined properties
80+
const data = JSON.parse(
81+
JSON.stringify(app.serializer.toObject(result))
8382
);
84-
data = data.split(normalizePath(base)).join("%BASE%");
8583

86-
equal(JSON.parse(data), specs);
84+
equal(data, specs);
8785
});
8886
}
8987
});

src/test/converter/alias/specs.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"fileName": "alias.ts",
2525
"line": 14,
2626
"character": 12,
27-
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L14"
27+
"url": "typedoc://alias.ts#L14"
2828
}
2929
],
3030
"typeParameters": [
@@ -76,7 +76,7 @@
7676
"fileName": "alias.ts",
7777
"line": 19,
7878
"character": 12,
79-
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L19"
79+
"url": "typedoc://alias.ts#L19"
8080
}
8181
],
8282
"typeParameters": [
@@ -129,7 +129,7 @@
129129
"fileName": "alias.ts",
130130
"line": 4,
131131
"character": 12,
132-
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L4"
132+
"url": "typedoc://alias.ts#L4"
133133
}
134134
],
135135
"typeParameters": [
@@ -154,7 +154,7 @@
154154
"fileName": "alias.ts",
155155
"line": 4,
156156
"character": 34,
157-
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L4"
157+
"url": "typedoc://alias.ts#L4"
158158
}
159159
],
160160
"signatures": [
@@ -226,7 +226,7 @@
226226
"fileName": "alias.ts",
227227
"line": 9,
228228
"character": 12,
229-
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L9"
229+
"url": "typedoc://alias.ts#L9"
230230
}
231231
],
232232
"type": {
@@ -260,7 +260,7 @@
260260
"fileName": "alias.ts",
261261
"line": 4,
262262
"character": 0,
263-
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L4"
263+
"url": "typedoc://alias.ts#L4"
264264
}
265265
]
266266
}

0 commit comments

Comments
 (0)