rspress-plugin-api-extractor 0.14.0 → 0.15.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 (37) hide show
  1. package/BuildEnv.js +0 -1
  2. package/build-program.js +4 -4
  3. package/build-stages.js +98 -281
  4. package/config-helpers.js +1 -1
  5. package/emit/mdx.js +311 -0
  6. package/emit/meta.js +62 -0
  7. package/index.d.ts +1 -42
  8. package/layers/build-metrics.js +1 -2
  9. package/layers/config-resolution.js +3 -5
  10. package/layers/type-environment.js +1 -2
  11. package/llms-program.js +3 -3
  12. package/markdown/helpers.js +10 -176
  13. package/observability/sinks/console-sink.js +0 -1
  14. package/observability/sinks/metrics-sink.js +0 -2
  15. package/package.json +6 -5
  16. package/path-derivation.js +1 -29
  17. package/plugin.js +2 -1
  18. package/prettier-formatter.js +27 -59
  19. package/remark-with-api.js +3 -2
  20. package/schemas/config.js +1 -18
  21. package/schemas/observability.js +0 -2
  22. package/schemas/performance.js +0 -1
  23. package/services/TwoslashCacheService.js +1 -1
  24. package/twoslash-transformer.js +14 -2
  25. package/code-post-processor.js +0 -38
  26. package/llms-processing.js +0 -270
  27. package/markdown/page-generators/class-page.js +0 -363
  28. package/markdown/page-generators/enum-page.js +0 -152
  29. package/markdown/page-generators/function-page.js +0 -127
  30. package/markdown/page-generators/index-pages.js +0 -25
  31. package/markdown/page-generators/interface-page.js +0 -310
  32. package/markdown/page-generators/namespace-page.js +0 -277
  33. package/markdown/page-generators/type-alias-page.js +0 -110
  34. package/markdown/page-generators/variable-page.js +0 -110
  35. package/markdown/prose-linker.js +0 -22
  36. package/twoslash-cache.js +0 -174
  37. package/twoslash-patterns.js +0 -87
package/twoslash-cache.js DELETED
@@ -1,174 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { gunzipSync, gzipSync } from "node:zlib";
3
-
4
- //#region src/twoslash-cache.ts
5
- /**
6
- * Persisted Twoslash result cache.
7
- *
8
- * Type-checking code blocks is by far the dominant cost of the render phase —
9
- * measured at ~97% of it, concentrated in the minority of blocks that carry an
10
- * `@example` (see `render-phase-instrumentation.md`). `@shikijs/twoslash`
11
- * exposes a first-class `typesCache` seam for exactly this, so the work here is
12
- * a keying scheme and a store rather than a new interception point.
13
- *
14
- * ## Soundness
15
- *
16
- * A Twoslash result depends on the code, the compiler options, the declarations
17
- * it is checked against, and the compiler doing the checking. The keys cover
18
- * all four: the per-entry key carries the code, its language and the compiler
19
- * options; {@link twoslashEnvHash} carries the declarations and the TypeScript
20
- * version.
21
- *
22
- * The TypeScript version is load-bearing and easy to overlook — `lib.d.ts`
23
- * ships with the compiler and inference changes between releases, so an upgrade
24
- * against unchanged declarations yields different hovers. Omitting it would let
25
- * a warm cache serve results from the previous compiler and stay wrong until
26
- * the API's own declarations happened to change.
27
- *
28
- * NOT covered, and covered instead by {@link TWOSLASH_CACHE_FORMAT}: the
29
- * `@shikijs/twoslash` / `twoslash` renderer version, which determines the shape
30
- * of the stored `nodes`. Bump the format constant when upgrading those, since
31
- * nothing derives it automatically.
32
- *
33
- * ## Invalidation granularity
34
- *
35
- * The consequence of that soundness is coarse invalidation: any VFS change
36
- * discards the whole generation, because a declaration change anywhere can
37
- * legitimately change any block's inferred types. So this cache makes repeat
38
- * builds over an UNCHANGED API nearly free — CI re-runs, prose-only edits,
39
- * theme and config changes, rebuilding a site without touching the library —
40
- * and does nothing for the build right after an API item changes.
41
- *
42
- * Sharpening that would need per-scope type environments, so one package's
43
- * change stops invalidating every other package's blocks. That is fix (b) in
44
- * `render-phase-instrumentation.md`, tracked as a correctness fix; it would
45
- * make this cache substantially more effective on a multi-API site as a side
46
- * effect.
47
- *
48
- * ## Synchronous by necessity
49
- *
50
- * `TwoslashTypesCache.read`/`write` are synchronous — they are called from
51
- * inside Shiki's `preprocess` hook. Persistence is therefore load-once at
52
- * startup and save-once at the end, against an in-memory map; there is no
53
- * per-entry I/O. See `TwoslashCacheService`.
54
- */
55
- /**
56
- * Bumped when the stored shape changes, so an older blob is treated as absent
57
- * rather than deserialized into the wrong shape.
58
- *
59
- * Also the manual lever for renderer changes: bump this when upgrading
60
- * `@shikijs/twoslash` or `twoslash`, whose versions determine the shape of the
61
- * stored `nodes` and are not derived into any key.
62
- */
63
- const TWOSLASH_CACHE_FORMAT = 1;
64
- function sha256(input) {
65
- return createHash("sha256").update(input).digest("hex");
66
- }
67
- /**
68
- * Fingerprint the type environment a generation is checked against.
69
- *
70
- * Covers the declarations (`vfs`) and the compiler that interprets them
71
- * (`toolchain`). The VFS is hashed over sorted `path\0content` pairs so the
72
- * digest is stable against map iteration order.
73
- *
74
- * `toolchain` must carry the TypeScript version. The declarations alone do not
75
- * determine the answer: `lib.d.ts` ships with the compiler and inference
76
- * behaviour changes between releases, so upgrading TypeScript against unchanged
77
- * declarations produces different hovers. Without the version in the key the
78
- * warm cache would serve results computed by the previous compiler, and stay
79
- * wrong until the API's own declarations happened to change.
80
- *
81
- * Compiler OPTIONS are deliberately not folded in here — they belong on the
82
- * per-entry key, so one generation can hold results from the several
83
- * configurations a multi-API site may declare.
84
- */
85
- function twoslashEnvHash(vfs, toolchain) {
86
- const hash = createHash("sha256");
87
- hash.update(`format:${1}\0toolchain:${toolchain}\0`);
88
- for (const key of [...vfs.keys()].sort()) hash.update(`${key}\0${vfs.get(key) ?? ""}\0`);
89
- return hash.digest("hex");
90
- }
91
- /** JSON with object keys sorted, so equivalent options hash identically. */
92
- function stableStringify(value) {
93
- if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
94
- if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
95
- return `{${Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`).join(",")}}`;
96
- }
97
- /**
98
- * Per-entry key: the code, its language, and the compiler configuration it is
99
- * checked under.
100
- *
101
- * The configuration matters because two APIs on one site may be documented
102
- * under different `tsconfig`s — the same source checked under different options
103
- * can produce different types, so it must not share a cache entry.
104
- */
105
- function twoslashEntryKey(code, lang, compilerOptions) {
106
- return sha256(`${lang ?? "ts"}\0${stableStringify(compilerOptions ?? {})}\0${code}`);
107
- }
108
- /**
109
- * The cache key a whole generation is stored under. One blob per environment,
110
- * so a changed environment reads as a miss rather than serving stale results.
111
- */
112
- function twoslashBlobKey(envHash) {
113
- return `twoslash/v${1}/${envHash}`;
114
- }
115
- /**
116
- * Build a synchronous Twoslash cache over an in-memory map, optionally seeded
117
- * with entries loaded from a previous build.
118
- */
119
- function makeTwoslashCache(initial) {
120
- const map = new Map(initial);
121
- let hits = 0;
122
- let misses = 0;
123
- let dirty = false;
124
- return {
125
- read: (code, lang, options) => {
126
- const found = map.get(twoslashEntryKey(code, lang, options?.compilerOptions));
127
- if (found === void 0) {
128
- misses += 1;
129
- return null;
130
- }
131
- hits += 1;
132
- return found;
133
- },
134
- write: (code, data, lang, options) => {
135
- const value = {
136
- nodes: data.nodes,
137
- code: data.code,
138
- ...data.meta?.extension != null ? { meta: { extension: data.meta.extension } } : {}
139
- };
140
- map.set(twoslashEntryKey(code, lang, options?.compilerOptions), value);
141
- dirty = true;
142
- },
143
- stats: () => ({
144
- hits,
145
- misses,
146
- entries: map.size,
147
- dirty
148
- }),
149
- entries: () => map
150
- };
151
- }
152
- /** Serialize a generation for storage. Gzipped JSON — hover text compresses well. */
153
- function encodeTwoslashCache(entries) {
154
- return gzipSync(Buffer.from(JSON.stringify(Object.fromEntries(entries)), "utf-8"));
155
- }
156
- /**
157
- * Deserialize a stored generation.
158
- *
159
- * Returns an empty map for anything unreadable — a truncated blob, a format
160
- * change, a corrupted file. A cache that cannot be read is a cache miss, never
161
- * a build failure.
162
- */
163
- function decodeTwoslashCache(blob) {
164
- try {
165
- const parsed = JSON.parse(gunzipSync(blob).toString("utf-8"));
166
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return /* @__PURE__ */ new Map();
167
- return new Map(Object.entries(parsed));
168
- } catch {
169
- return /* @__PURE__ */ new Map();
170
- }
171
- }
172
-
173
- //#endregion
174
- export { decodeTwoslashCache, encodeTwoslashCache, makeTwoslashCache, twoslashBlobKey, twoslashEntryKey, twoslashEnvHash };
@@ -1,87 +0,0 @@
1
- //#region src/twoslash-patterns.ts
2
- /**
3
- * Twoslash directive detection patterns.
4
- *
5
- * These regexes mirror the upstream Twoslash source at:
6
- * https://github.com/twoslashes/twoslash/blob/main/packages/twoslash/src/regexp.ts
7
- *
8
- * All patterns allow an optional space after `//` (e.g., both `// @noErrors`
9
- * and `//@noErrors` are valid Twoslash syntax).
10
- */
11
- /**
12
- * Config directives: boolean flags and key-value pairs.
13
- *
14
- * Upstream: `reConfigBoolean` + `reConfigValue` + `reFilenamesMakers`
15
- *
16
- * @example
17
- * ```
18
- * // @noErrors
19
- * //@strict
20
- * // @errors: 2304
21
- * // @target: ES2020
22
- * // @filename: example.ts
23
- * ```
24
- */
25
- const RE_CONFIG = /^\/\/\s?@\w+/;
26
- /**
27
- * Annotation markers: query, completion, and highlight markers.
28
- *
29
- * Upstream: `reAnnonateMarkers` — `/^\s*\/\/\s*\^(\?|\||\^+)( .*)?$/gm`
30
- *
31
- * These are positioned under code lines with `^` characters for alignment.
32
- * After `line.trim()`, leading whitespace is removed but internal spaces
33
- * between `//` and `^` are preserved.
34
- *
35
- * @example
36
- * ```
37
- * // ^? — query (show type info)
38
- * // ^? — query with alignment spaces
39
- * // ^| — completion (show autocomplete)
40
- * // ^^^ — highlight range
41
- * // ^^^^ description text
42
- * ```
43
- */
44
- const RE_ANNOTATION = /^\/\/\s*\^[?|^]/;
45
- /**
46
- * Cut directives: control which code is visible in output.
47
- *
48
- * Upstream: `reCutBefore`, `reCutAfter`, `reCutStart`, `reCutEnd`
49
- *
50
- * @example
51
- * ```
52
- * // ---cut---
53
- * //---cut-before---
54
- * // ---cut-after---
55
- * // ---cut-start---
56
- * // ---cut-end---
57
- * ```
58
- */
59
- const RE_CUT = /^\/\/\s?---cut/;
60
- /**
61
- * Test whether a trimmed line is any Twoslash directive.
62
- *
63
- * Covers all directive types: config flags, config values, filename markers,
64
- * annotation markers (query/completion/highlight), and cut directives.
65
- *
66
- * @param trimmedLine - The line with leading/trailing whitespace removed
67
- * @returns true if the line is a Twoslash directive
68
- */
69
- function isTwoslashDirective(trimmedLine) {
70
- return RE_CONFIG.test(trimmedLine) || RE_ANNOTATION.test(trimmedLine) || RE_CUT.test(trimmedLine);
71
- }
72
- /**
73
- * Classify a cut directive line.
74
- *
75
- * @param trimmedLine - The line with leading/trailing whitespace removed
76
- * @returns The cut type, or null if not a cut directive
77
- */
78
- function classifyCutDirective(trimmedLine) {
79
- if (/^\/\/\s?---cut(-before)?---$/.test(trimmedLine)) return "cut-before";
80
- if (/^\/\/\s?---cut-after---$/.test(trimmedLine)) return "cut-after";
81
- if (/^\/\/\s?---cut-start---$/.test(trimmedLine)) return "cut-start";
82
- if (/^\/\/\s?---cut-end---$/.test(trimmedLine)) return "cut-end";
83
- return null;
84
- }
85
-
86
- //#endregion
87
- export { classifyCutDirective, isTwoslashDirective };