rspress-plugin-api-extractor 0.3.0 → 0.3.2

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.
@@ -1,4 +1,4 @@
1
- import { ApiItemKind, ApiModel } from "@microsoft/api-extractor-model";
1
+ import { ApiItemKind, ApiModel, ExcerptTokenKind } from "@microsoft/api-extractor-model";
2
2
  import { VirtualPackage } from "type-registry-effect";
3
3
 
4
4
  //#region src/api-extracted-package.ts
@@ -82,10 +82,10 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
82
82
  if (jsDoc) lines.push(jsDoc);
83
83
  let name = apiClass.displayName;
84
84
  if (apiClass.typeParameters?.length) name += this.formatTypeParameters(apiClass.typeParameters);
85
- const headerParts = ["export declare class", name];
86
- if (apiClass.extendsType) headerParts.push(`extends ${apiClass.extendsType.excerpt.text}`);
85
+ const headerParts = apiClass.isAbstract ? ["export declare abstract class", name] : ["export declare class", name];
86
+ if (apiClass.extendsType) headerParts.push(`extends ${this.renderExcerpt(apiClass.extendsType.excerpt)}`);
87
87
  if (apiClass.implementsTypes?.length) {
88
- const impl = apiClass.implementsTypes.map((t) => t.excerpt.text).join(", ");
88
+ const impl = apiClass.implementsTypes.map((t) => this.renderExcerpt(t.excerpt)).join(", ");
89
89
  headerParts.push(`implements ${impl}`);
90
90
  }
91
91
  lines.push(`${headerParts.join(" ")} {`);
@@ -104,7 +104,7 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
104
104
  if (apiInterface.typeParameters?.length) name += this.formatTypeParameters(apiInterface.typeParameters);
105
105
  const headerParts = ["export declare interface", name];
106
106
  if (apiInterface.extendsTypes?.length) {
107
- const ext = apiInterface.extendsTypes.map((t) => t.excerpt.text).join(", ");
107
+ const ext = apiInterface.extendsTypes.map((t) => this.renderExcerpt(t.excerpt)).join(", ");
108
108
  headerParts.push(`extends ${ext}`);
109
109
  }
110
110
  lines.push(`${headerParts.join(" ")} {`);
@@ -121,14 +121,14 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
121
121
  if (jsDoc) lines.push(jsDoc);
122
122
  let name = typeAlias.displayName;
123
123
  if (typeAlias.typeParameters?.length) name += this.formatTypeParameters(typeAlias.typeParameters);
124
- lines.push(`export declare type ${name} = ${typeAlias.typeExcerpt.text};`);
124
+ lines.push(`export declare type ${name} = ${this.renderExcerpt(typeAlias.typeExcerpt)};`);
125
125
  return lines.join("\n");
126
126
  }
127
127
  generateFunctionDeclaration(apiFunction) {
128
128
  const lines = [];
129
129
  const jsDoc = this.formatJSDoc(apiFunction);
130
130
  if (jsDoc) lines.push(jsDoc);
131
- const cleaned = this.cleanExcerpt(apiFunction.excerpt.text);
131
+ const cleaned = this.cleanExcerpt(this.renderExcerpt(apiFunction.excerpt));
132
132
  const decl = cleaned.startsWith("function ") ? cleaned : `const ${cleaned}`;
133
133
  lines.push(`export declare ${decl};`);
134
134
  return lines.join("\n");
@@ -155,7 +155,7 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
155
155
  const lines = [];
156
156
  const jsDoc = this.formatJSDoc(apiVariable);
157
157
  if (jsDoc) lines.push(jsDoc);
158
- let cleaned = this.cleanExcerpt(apiVariable.excerpt.text);
158
+ let cleaned = this.cleanExcerpt(this.renderExcerpt(apiVariable.excerpt));
159
159
  if (!cleaned.startsWith("const ") && !cleaned.startsWith("let ") && !cleaned.startsWith("var ")) cleaned = `const ${cleaned}`;
160
160
  lines.push(`export declare ${cleaned};`);
161
161
  return lines.join("\n");
@@ -187,7 +187,7 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
187
187
  const lines = [];
188
188
  const jsDoc = this.formatJSDoc(apiFunction, " ");
189
189
  if (jsDoc) lines.push(jsDoc);
190
- const cleaned = this.cleanExcerpt(apiFunction.excerpt.text);
190
+ const cleaned = this.cleanExcerpt(this.renderExcerpt(apiFunction.excerpt));
191
191
  lines.push(` export ${cleaned};`);
192
192
  return lines.join("\n");
193
193
  }
@@ -199,7 +199,7 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
199
199
  if (apiInterface.typeParameters?.length) name += this.formatTypeParameters(apiInterface.typeParameters);
200
200
  const headerParts = ["export interface", name];
201
201
  if (apiInterface.extendsTypes?.length) {
202
- const ext = apiInterface.extendsTypes.map((t) => t.excerpt.text).join(", ");
202
+ const ext = apiInterface.extendsTypes.map((t) => this.renderExcerpt(t.excerpt)).join(", ");
203
203
  headerParts.push(`extends ${ext}`);
204
204
  }
205
205
  lines.push(` ${headerParts.join(" ")} {`);
@@ -234,14 +234,14 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
234
234
  if (jsDoc) lines.push(jsDoc);
235
235
  let name = typeAlias.displayName;
236
236
  if (typeAlias.typeParameters?.length) name += this.formatTypeParameters(typeAlias.typeParameters);
237
- lines.push(` export type ${name} = ${typeAlias.typeExcerpt.text};`);
237
+ lines.push(` export type ${name} = ${this.renderExcerpt(typeAlias.typeExcerpt)};`);
238
238
  return lines.join("\n");
239
239
  }
240
240
  generateNamespaceVariable(apiVariable) {
241
241
  const lines = [];
242
242
  const jsDoc = this.formatJSDoc(apiVariable, " ");
243
243
  if (jsDoc) lines.push(jsDoc);
244
- let cleaned = this.cleanExcerpt(apiVariable.excerpt.text);
244
+ let cleaned = this.cleanExcerpt(this.renderExcerpt(apiVariable.excerpt));
245
245
  if (!cleaned.startsWith("const ") && !cleaned.startsWith("let ") && !cleaned.startsWith("var ")) cleaned = `const ${cleaned}`;
246
246
  lines.push(` export ${cleaned};`);
247
247
  return lines.join("\n");
@@ -249,7 +249,7 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
249
249
  generateNamespaceClass(apiClass) {
250
250
  const decl = this.generateClassDeclaration(apiClass);
251
251
  if (!decl) return "";
252
- return decl.replace(/\bexport declare class\b/, "export class").split("\n").map((line) => line.trim() ? ` ${line}` : line).join("\n");
252
+ return decl.replace(/\bexport declare (abstract )?class\b/, "export $1class").split("\n").map((line) => line.trim() ? ` ${line}` : line).join("\n");
253
253
  }
254
254
  generateClassMember(member, indent = " ") {
255
255
  switch (member.kind) {
@@ -273,11 +273,43 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
273
273
  const lines = [];
274
274
  const jsDoc = this.formatJSDoc(member, indent);
275
275
  if (jsDoc) lines.push(jsDoc);
276
- const cleaned = this.cleanExcerpt(member.excerpt.text);
276
+ const cleaned = this.cleanExcerpt(this.renderExcerpt(member.excerpt));
277
277
  lines.push(`${indent}${cleaned};`);
278
278
  return lines.join("\n");
279
279
  }
280
280
  /**
281
+ * Render an excerpt to source text, normalizing dts-rollup disambiguation
282
+ * aliases. The dts rollup renames a re-imported symbol as `Name$1`, but its
283
+ * canonical reference is the un-suffixed `Name` (the same symbol). The import
284
+ * prepender ({@link TypeReferenceExtractor}) imports the canonical name, so
285
+ * emitting the suffixed text would leave `Name$1` undefined (TS2304). Emit the
286
+ * canonical name so the body and the prepended import agree.
287
+ *
288
+ * Equivalent to `excerpt.text` for excerpts without rollup aliases (the text
289
+ * is the concatenation of the spanned tokens), so unaliased output is unchanged.
290
+ */
291
+ renderExcerpt(excerpt) {
292
+ return excerpt.spannedTokens.map((token) => this.normalizeTokenText(token)).join("");
293
+ }
294
+ /**
295
+ * Strip a dts-rollup `$N` suffix from a reference token when the de-suffixed
296
+ * text matches the token's canonical symbol. Never touches a non-reference
297
+ * token or a legitimate identifier that genuinely ends in `$N` (its canonical
298
+ * name would carry the suffix too).
299
+ */
300
+ normalizeTokenText(token) {
301
+ if (token.kind !== ExcerptTokenKind.Reference) return token.text;
302
+ const match = /^(.+)\$\d+$/.exec(token.text);
303
+ if (!match) return token.text;
304
+ const canonical = token.canonicalReference?.toString();
305
+ if (!canonical) return token.text;
306
+ const afterBang = canonical.slice(canonical.indexOf("!") + 1);
307
+ const colon = afterBang.indexOf(":");
308
+ const symbol = colon === -1 ? afterBang : afterBang.slice(0, colon);
309
+ const leaf = symbol.includes(".") ? symbol.slice(symbol.lastIndexOf(".") + 1) : symbol;
310
+ return match[1] === symbol || match[1] === leaf ? match[1] : token.text;
311
+ }
312
+ /**
281
313
  * Clean an excerpt text: strip export/declare keywords and trailing semicolons/whitespace.
282
314
  */
283
315
  cleanExcerpt(text) {
@@ -287,8 +319,8 @@ var ApiExtractedPackage = class ApiExtractedPackage extends VirtualPackageClass
287
319
  if (!typeParameters.length) return "";
288
320
  return `<${typeParameters.map((tp) => {
289
321
  const parts = [tp.name];
290
- if (tp.constraintExcerpt?.text.trim()) parts.push(`extends ${tp.constraintExcerpt.text.trim()}`);
291
- if (tp.defaultTypeExcerpt?.text.trim()) parts.push(`= ${tp.defaultTypeExcerpt.text.trim()}`);
322
+ if (tp.constraintExcerpt && this.renderExcerpt(tp.constraintExcerpt).trim()) parts.push(`extends ${this.renderExcerpt(tp.constraintExcerpt).trim()}`);
323
+ if (tp.defaultTypeExcerpt && this.renderExcerpt(tp.defaultTypeExcerpt).trim()) parts.push(`= ${this.renderExcerpt(tp.defaultTypeExcerpt).trim()}`);
292
324
  return parts.join(" ");
293
325
  }).join(", ")}>`;
294
326
  }
package/build-stages.js CHANGED
@@ -755,4 +755,4 @@ function buildPipelineForApi(input) {
755
755
  }
756
756
 
757
757
  //#endregion
758
- export { buildPipelineForApi, cleanupAndCommit, prepareWorkItems, writeMetadata };
758
+ export { buildPipelineForApi, cleanupAndCommit, crossLinkKindPriority, generateSinglePage, normalizeMarkdownSpacing, prepareWorkItems, writeMetadata, writeSingleFile };
package/config-utils.js CHANGED
@@ -284,4 +284,4 @@ function validateExternalPackages(externalPackages, packageJson) {
284
284
  }
285
285
 
286
286
  //#endregion
287
- export { extractAutoDetectedPackages, isLoadedModel, isVersionConfig, mergeLlmsPluginConfig, resolveExternalPackageVersions, validateExternalPackages };
287
+ export { extractAutoDetectedPackages, extractPeerDependencies, extractTypeUtilities, isLoadedModel, isVersionConfig, mergeLlmsPluginConfig, normalizeLlmsPluginConfig, resolveExternalPackageVersions, resolvePackageVersionConflicts, validateExternalPackages };
package/content-hash.js CHANGED
@@ -76,4 +76,4 @@ function hashFrontmatter(frontmatter) {
76
76
  }
77
77
 
78
78
  //#endregion
79
- export { hashContent, hashFrontmatter };
79
+ export { hashContent, hashFrontmatter, normalizeContent };
package/errors.js CHANGED
@@ -26,4 +26,4 @@ const TwoslashProcessingErrorBase = Data.TaggedError("TwoslashProcessingError");
26
26
  const PrettierFormatErrorBase = Data.TaggedError("PrettierFormatError");
27
27
 
28
28
  //#endregion
29
- export { ConfigValidationError, SnapshotDbError, TypeRegistryError };
29
+ export { ConfigValidationError, ConfigValidationErrorBase, SnapshotDbError, SnapshotDbErrorBase, TypeRegistryError, TypeRegistryErrorBase };
@@ -97,4 +97,4 @@ const logBuildSummary = (slowCodeBlockMs) => Effect.gen(function* () {
97
97
  });
98
98
 
99
99
  //#endregion
100
- export { buildEventBus, logBuildSummary, makeSummaryLoggerLayer };
100
+ export { BuildMetrics, buildEventBus, logBuildSummary, makeSummaryLoggerLayer };
@@ -361,4 +361,4 @@ async function formatExampleCode(code, language, _context) {
361
361
  }
362
362
 
363
363
  //#endregion
364
- export { escapeMdxGenerics, escapeYamlString, formatExampleCode, generateAvailableFrom, generateFrontmatter, prepareExampleCode, prependHiddenImports, sanitizeId, stripTwoslashDirectives };
364
+ export { escapeMdxGenerics, escapeYamlString, formatExampleCode, formatImportsWithCut, generateAvailableFrom, generateFrontmatter, prepareExampleCode, prependHiddenImports, sanitizeId, stripTwoslashDirectives };
package/markdown/index.js CHANGED
@@ -8,4 +8,4 @@ import { NamespacePageGenerator } from "./page-generators/namespace-page.js";
8
8
  import { TypeAliasPageGenerator } from "./page-generators/type-alias-page.js";
9
9
  import { VariablePageGenerator } from "./page-generators/variable-page.js";
10
10
 
11
- export { };
11
+ export { ClassPageGenerator, EnumPageGenerator, FunctionPageGenerator, InterfacePageGenerator, MainIndexPageGenerator, NamespacePageGenerator, TypeAliasPageGenerator, VariablePageGenerator, markdownCrossLinker };
@@ -35,4 +35,4 @@ function makeRuntimeEmitter(runtime) {
35
35
  }
36
36
 
37
37
  //#endregion
38
- export { emit, makeEventBusLayer, makeRuntimeEmitter, wantsLevel };
38
+ export { EventBus, emit, makeEventBusLayer, makeRuntimeEmitter, wantsLevel };
@@ -54,4 +54,4 @@ function withPhase(phase, ctx, effect, thresholds) {
54
54
  }
55
55
 
56
56
  //#endregion
57
- export { withPhase };
57
+ export { PHASE_THRESHOLD_KEY, withPhase };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rspress-plugin-api-extractor",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "description": "RSPress plugin for generating API documentation from TypeScript API Extractor models",
6
6
  "keywords": [
@@ -37,8 +37,8 @@
37
37
  "@effect/sql": "^0.51.1",
38
38
  "@effect/sql-sqlite-node": "^0.52.0",
39
39
  "@microsoft/api-extractor-model": "^7.33.8",
40
- "@shikijs/twoslash": "^4.2.0",
41
- "api-extractor-llms": "0.1.0",
40
+ "@shikijs/twoslash": "^4.3.0",
41
+ "api-extractor-llms": "0.2.0",
42
42
  "clsx": "^2.1.1",
43
43
  "effect": "^3.21.4",
44
44
  "gray-matter": "^4.0.3",
@@ -50,7 +50,7 @@
50
50
  "prettier": "^3.8.4",
51
51
  "react-markdown": "^10.1.0",
52
52
  "semver-effect": "^0.2.1",
53
- "shiki": "^4.2.0",
53
+ "shiki": "^4.3.0",
54
54
  "type-registry-effect": "^1.0.0",
55
55
  "typescript": "^6.0.3",
56
56
  "unist-util-visit": "^5.1.0"
@@ -49,4 +49,4 @@ function assertNoRouteCollisions(candidates, baseRoute) {
49
49
  }
50
50
 
51
51
  //#endregion
52
- export { assertNoRouteCollisions };
52
+ export { assertNoRouteCollisions, detectRouteCollisions, formatRouteCollisionError };
package/schemas/index.js CHANGED
@@ -3,4 +3,4 @@ import { EventLevelSchema, ObservabilityConfig, resolveObservability } from "./o
3
3
  import { OpenGraphImageConfig, OpenGraphImageMetadata } from "./opengraph.js";
4
4
  import { AutoDetectDependencies, CategoryConfig, DEFAULT_CATEGORIES, ErrorConfig, ExternalPackageSpec, LlmsPlugin, LogLevel, ModelInput, MultiApiConfig, PluginOptions, SingleApiConfig, SourceConfig, ThemeConfig, VersionConfig } from "./config.js";
5
5
 
6
- export { };
6
+ export { DEFAULT_CATEGORIES, PluginOptions };
@@ -124,4 +124,4 @@ function extractTypeResolutionOptions(tsOptions) {
124
124
  }
125
125
 
126
126
  //#endregion
127
- export { TsConfigParseError, parseTsConfig };
127
+ export { TsConfigParseError, parseTsConfig, parseTsConfigWithMetadata };
@@ -84,4 +84,4 @@ function classifyCutDirective(trimmedLine) {
84
84
  }
85
85
 
86
86
  //#endregion
87
- export { classifyCutDirective, isTwoslashDirective };
87
+ export { RE_ANNOTATION, RE_CONFIG, RE_CUT, classifyCutDirective, isTwoslashDirective };
@@ -183,10 +183,8 @@ var TypeReferenceExtractor = class {
183
183
  const isBuiltIn = packagePart === "" || packagePart.startsWith("\"");
184
184
  const isInternal = packagePart === this.currentPackageName;
185
185
  let symbolName;
186
- if (symbolText.includes(".")) {
187
- const parts = symbolText.split(".");
188
- symbolName = parts[parts.length - 1].trim();
189
- } else symbolName = symbolFromCanonical.trim();
186
+ if (symbolText.includes(".")) symbolName = symbolText.split(".")[0].trim();
187
+ else symbolName = symbolFromCanonical.trim();
190
188
  return {
191
189
  symbolName,
192
190
  packageName: packagePart,
@@ -165,4 +165,4 @@ async function resolveTypeScriptConfig(projectRoot, global, api, version, packag
165
165
  }
166
166
 
167
167
  //#endregion
168
- export { DEFAULT_COMPILER_OPTIONS, resolveTypeScriptConfig };
168
+ export { DEFAULT_COMPILER_OPTIONS, mergeCompilerOptions, resolveTypeScriptConfig, resolveTypeScriptConfigSingleAsync };