typedoc-plugin-dt-links 1.1.16 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +8 -13
  2. package/dist/plugin.js +27 -28
  3. package/package.json +12 -14
package/README.md CHANGED
@@ -8,22 +8,17 @@ to their source code on GitHub.
8
8
  If VSCode can follow a link into an `@types` package, this plugin should also
9
9
  be able to provide links to that package.
10
10
 
11
- > Note: Using TypeDoc before 0.26.8 may result in links which go to the start of
12
- > the doc comment rather to the symbol name.
13
-
14
- Supports TypeDoc 0.23.14 through 0.26.x.
15
-
16
11
  ## Options
17
12
 
18
- - `warnOnUnstableDtLink`
13
+ - `warnOnUnstableDtLink`
19
14
 
20
- Defaults to `true`. If set, and an `@types` package is referenced which is newer
21
- than this plugin, produces a warning as this plugin won't be able to produce a stable
22
- link.
15
+ Defaults to `true`. If set, and an `@types` package is referenced which is newer
16
+ than this plugin, produces a warning as this plugin won't be able to produce a stable
17
+ link.
23
18
 
24
- This plugin is automatically published weekly, so if you are upgrading `@types` packages
25
- and rebuilding docs more frequently than that, you may want to disable this option as
26
- the link won't be dead long enough to matter.
19
+ This plugin is automatically published weekly, so if you are upgrading `@types` packages
20
+ and rebuilding docs more frequently than that, you may want to disable this option as
21
+ the link won't be dead long enough to matter.
27
22
 
28
23
  ## Changelog
29
24
 
@@ -50,4 +45,4 @@ was released more recently than this plugin, the plugin can't know what git hash
50
45
  should be used and will instead use `master` as the reference.
51
46
 
52
47
  [useTsLinkResolution]: https://typedoc.org/options/comments/#usetslinkresolution
53
- [ReflectionSymbolId]: (https://typedoc.org/api/classes/Models.ReflectionSymbolId.html)
48
+ [ReflectionSymbolId]: https://typedoc.org/api/classes/Models.ReflectionSymbolId.html
package/dist/plugin.js CHANGED
@@ -1,7 +1,7 @@
1
- import { ParameterType, splitUnquotedString, TypeScript as ts, } from "typedoc";
2
1
  import { readFileSync } from "node:fs";
3
2
  import { dirname } from "node:path";
4
3
  import { fileURLToPath } from "node:url";
4
+ import { ParameterType, splitUnquotedString, TypeScript as ts, } from "typedoc";
5
5
  const PLUGIN_PREFIX = "[typedoc-plugin-dt-links]";
6
6
  const DT_DEFAULT_BRANCH = "master";
7
7
  export const DT_COMMITS = readFileSync(dirname(fileURLToPath(import.meta.url)) + "/../data/dt_history.txt", "utf-8")
@@ -44,8 +44,8 @@ function discoverSourceFilePosition(sf, qualifiedName) {
44
44
  function walkPath(index, node) {
45
45
  if (index === path.length) {
46
46
  const name = node.name;
47
- if (name &&
48
- (ts.isMemberName(name) || ts.isComputedPropertyName(name))) {
47
+ if (name
48
+ && (ts.isMemberName(name) || ts.isComputedPropertyName(name))) {
49
49
  return name.getStart(sf, false);
50
50
  }
51
51
  return node.getStart(sf, false);
@@ -62,30 +62,30 @@ function discoverSourceFilePosition(sf, qualifiedName) {
62
62
  else if (child.name.text === path[index]) {
63
63
  return walkPath(index + 1, child);
64
64
  }
65
- else if (child.name.text === "global" &&
65
+ else if (child.name.text === "global"
66
66
  // Not quite sure why TypeDoc gives this name...
67
- path[index] === "__global") {
67
+ && path[index] === "__global") {
68
68
  return walkPath(index + 1, child);
69
69
  }
70
70
  }
71
- if (ts.isModuleBlock(child) ||
72
- ts.isVariableDeclaration(child) ||
73
- ts.isVariableDeclarationList(child)) {
71
+ if (ts.isModuleBlock(child)
72
+ || ts.isVariableDeclaration(child)
73
+ || ts.isVariableDeclarationList(child)) {
74
74
  return walkPath(index, child);
75
75
  }
76
- if (ts.isClassDeclaration(child) ||
77
- ts.isInterfaceDeclaration(child)) {
76
+ if (ts.isClassDeclaration(child)
77
+ || ts.isInterfaceDeclaration(child)) {
78
78
  if ((child.name?.text ?? "default") === path[index]) {
79
79
  return walkPath(index + 1, child);
80
80
  }
81
81
  }
82
- if (ts.isFunctionDeclaration(child) ||
83
- ts.isPropertyDeclaration(child) ||
84
- ts.isVariableDeclaration(child) ||
85
- ts.isMethodDeclaration(child) ||
86
- ts.isMethodSignature(child) ||
87
- ts.isPropertySignature(child) ||
88
- ts.isPropertyAssignment(child)) {
82
+ if (ts.isFunctionDeclaration(child)
83
+ || ts.isPropertyDeclaration(child)
84
+ || ts.isVariableDeclaration(child)
85
+ || ts.isMethodDeclaration(child)
86
+ || ts.isMethodSignature(child)
87
+ || ts.isPropertySignature(child)
88
+ || ts.isPropertyAssignment(child)) {
89
89
  if (child.name?.getText() === path[index]) {
90
90
  return walkPath(index + 1, child);
91
91
  }
@@ -95,6 +95,8 @@ function discoverSourceFilePosition(sf, qualifiedName) {
95
95
  }
96
96
  const sourceFileCache = new Map();
97
97
  export function getLineNumber(symbolId) {
98
+ if (!symbolId.fileName)
99
+ throw new Error("Requires a filename");
98
100
  let sf = sourceFileCache.get(symbolId.fileName);
99
101
  if (!sf) {
100
102
  try {
@@ -143,16 +145,15 @@ export function load(app) {
143
145
  else {
144
146
  const publishDate = Date.parse(update[1]);
145
147
  app.logger.verbose(`${PLUGIN_PREFIX} @types/${packageName} was updated at ${new Date(publishDate).toISOString()}`);
146
- hash =
147
- findDtCommitHash(publishDate / 1000) ??
148
- DT_DEFAULT_BRANCH;
148
+ hash = findDtCommitHash(publishDate / 1000)
149
+ ?? DT_DEFAULT_BRANCH;
149
150
  }
150
151
  }
151
152
  catch {
152
153
  hash = DT_DEFAULT_BRANCH;
153
154
  }
154
- if (hash === DT_DEFAULT_BRANCH &&
155
- app.options.getValue("warnOnUnstableDtLink")) {
155
+ if (hash === DT_DEFAULT_BRANCH
156
+ && app.options.getValue("warnOnUnstableDtLink")) {
156
157
  const version = JSON.parse(readFileSync(packagePath + "/package.json", "utf-8")).version;
157
158
  app.logger.warn(`${PLUGIN_PREFIX} Failed to discover git hash for @types/${packageName} v${version}, linking to ${DT_DEFAULT_BRANCH} branch. This will eventually cause broken links.`);
158
159
  }
@@ -162,7 +163,7 @@ export function load(app) {
162
163
  return publishHashCache.get(packagePath);
163
164
  }
164
165
  function resolveSymbol(_declaration, _refl, _part, symbolId) {
165
- if (!symbolId) {
166
+ if (!symbolId || !symbolId.packageName.startsWith("@types/") || !symbolId.fileName) {
166
167
  return;
167
168
  }
168
169
  // Attempt to decide package name from path if it contains "node_modules"
@@ -172,16 +173,14 @@ export function load(app) {
172
173
  startIndex += "node_modules/@types/".length;
173
174
  let stopIndex = symbolId.fileName.indexOf("/", startIndex);
174
175
  const packageName = symbolId.fileName.substring(startIndex, stopIndex);
175
- const innerPath = symbolId.fileName
176
- .substring(stopIndex)
177
- .replaceAll("\\", "/");
178
176
  const hash = getPublishHash(symbolId.fileName.substring(0, stopIndex), packageName);
179
177
  return [
180
178
  "https://github.com/DefinitelyTyped/DefinitelyTyped/blob/",
181
179
  hash,
182
180
  "/types/",
183
- packageName,
184
- innerPath,
181
+ symbolId.packageName.replace("@types/", ""),
182
+ "/",
183
+ symbolId.packagePath,
185
184
  "#L",
186
185
  getLineNumber(symbolId),
187
186
  ].join("");
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "typedoc-plugin-dt-links",
3
- "version": "1.1.16",
3
+ "version": "2.0.0",
4
4
  "main": "dist/plugin.js",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "devDependencies": {
8
8
  "@types/node": "22.7.4",
9
9
  "@voxpelli/node-test-pretty-reporter": "^1.1.2",
10
- "faucet": "^0.0.4",
11
- "prettier": "^3.3.3",
12
- "tap-prettify": "^0.0.2",
13
- "tsx": "^4.19.2",
14
- "typedoc": "^0.27.0-beta.1",
15
- "typescript": "^5.7.2"
10
+ "dprint": "^0.49.0",
11
+ "tsx": "^4.19.3",
12
+ "typedoc": "^0.28.0",
13
+ "typescript": "^5.8.2"
16
14
  },
17
15
  "keywords": [
18
16
  "typedoc-plugin"
@@ -22,12 +20,7 @@
22
20
  "data/dt_history.txt"
23
21
  ],
24
22
  "peerDependencies": {
25
- "typedoc": ">= 0.23.14 || 0.24.x || 0.25.x || 0.26.x || 0.27.x"
26
- },
27
- "scripts": {
28
- "lint": "prettier --check .",
29
- "build": "tsc",
30
- "test": "tsx --test --test-reporter=@voxpelli/node-test-pretty-reporter src/test/plugin.test.ts"
23
+ "typedoc": "0.28.x"
31
24
  },
32
25
  "repository": {
33
26
  "type": "git",
@@ -35,5 +28,10 @@
35
28
  },
36
29
  "bugs": {
37
30
  "url": "https://github.com/Gerrit0/typedoc-plugin-dt-links/issues"
31
+ },
32
+ "scripts": {
33
+ "lint": "dprint check",
34
+ "build": "tsc",
35
+ "test": "tsx --test --test-reporter=@voxpelli/node-test-pretty-reporter src/test/plugin.test.ts"
38
36
  }
39
- }
37
+ }