fumadocs-typescript 5.5.1 → 5.6.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { a as GeneratedDoc, c as RawTag, d as TypescriptConfig, f as createProject, g as GenerateTypeTableOptions, h as BaseTypeTableProps, i as GenerateOptions, l as createGenerator, m as generateHash, n as ShikiOptions, o as Generator, p as Cache, r as DocEntry, s as GeneratorOptions, t as MarkdownRenderer, u as Project } from "./markdown-CcCPhMmC.js";
1
+ import { a as GeneratedDoc, c as RawTag, d as TypescriptConfig, f as createProject, g as GenerateTypeTableOptions, h as BaseTypeTableProps, i as GenerateOptions, l as createGenerator, m as generateHash, n as ShikiOptions, o as Generator, p as Cache, r as DocEntry, s as GeneratorOptions, t as MarkdownRenderer, u as Project } from "./markdown-DtD6naEw.js";
2
+ import { Highlighter } from "fumadocs-core/highlight";
2
3
  import { Root } from "mdast";
3
4
  import { Transformer } from "unified";
4
5
  import { StructuredData } from "fumadocs-core/mdx-plugins/remark-structure";
@@ -13,9 +14,13 @@ export interface RemarkAutoTypeTableOptions {
13
14
  */
14
15
  outputName?: string;
15
16
  /**
16
- * config for Shiki when using default `renderMarkdown` & `renderType`.
17
+ * @deprecated use `highlighter`, like `createShikiHighlighter()`
17
18
  */
18
19
  shiki?: ShikiOptions;
20
+ /**
21
+ * highlight code with your own highlighter when using default `renderMarkdown` & `renderType`.
22
+ */
23
+ highlighter?: Highlighter;
19
24
  renderMarkdown?: MarkdownRenderer['renderMarkdownToHast'];
20
25
  renderType?: MarkdownRenderer['renderTypeToHast'];
21
26
  /**
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { n as markdownRenderer, t as parseTags } from "./parse-tags-Cikh_NrX.js";
2
- import { API, NodeBuilderFlags, ObjectFlags, SignatureKind, SymbolFlags, TypeFlags, isIntersectionType, isObjectType, isUnionType } from "typescript/unstable/sync";
1
+ import { n as markdownRenderer, t as parseTags } from "./parse-tags-Ba7L-m5r.js";
2
+ import { API, ObjectFlags, SignatureKind, SymbolFlags, TypeFlags, TypeFormatFlags, isIntersectionType, isObjectType, isUnionType } from "typescript/sync";
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { createHash } from "node:crypto";
6
- import fs$1 from "node:fs";
6
+ import { createFileSystemLayer } from "typescript/fs";
7
7
  import { valueToEstree } from "estree-util-value-to-estree";
8
8
  import { toEstree } from "hast-util-to-estree";
9
9
  import { tableRowToStructuredData } from "fumadocs-core/search";
@@ -33,7 +33,7 @@ function generateHash(str) {
33
33
  }
34
34
  //#endregion
35
35
  //#region package.json
36
- var version = "5.5.1";
36
+ var version = "5.6.0";
37
37
  //#endregion
38
38
  //#region src/lib/get-simple-form.ts
39
39
  function getSimpleForm(type, checker, location, options = {}) {
@@ -49,7 +49,7 @@ function getSimpleForm(type, checker, location, options = {}) {
49
49
  checker,
50
50
  type,
51
51
  location
52
- })) return checker.typeToString(type, location, NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope);
52
+ })) return checker.typeToString(type, location, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
53
53
  const alias = type.getAliasSymbol();
54
54
  if (alias) {
55
55
  const args = type.getAliasTypeArguments();
@@ -83,7 +83,7 @@ function getSimpleForm(type, checker, location, options = {}) {
83
83
  return "object";
84
84
  }
85
85
  if ((type.flags & (TypeFlags.Primitive | TypeFlags.AnyOrUnknown | TypeFlags.Never)) === 0 && checker.getSignaturesOfType(type, SignatureKind.Call).length > 0) return "function";
86
- return checker.typeToString(type, location, NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope);
86
+ return checker.typeToString(type, location, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
87
87
  }
88
88
  function dedupe(arr) {
89
89
  const dedupe = /* @__PURE__ */ new Set();
@@ -96,73 +96,59 @@ function dedupe(arr) {
96
96
  }
97
97
  //#endregion
98
98
  //#region src/lib/project.ts
99
- function normalizePath(p) {
100
- let out = path.resolve(p).replaceAll("\\", "/");
101
- if (process.platform === "win32" && /^[A-Z]:/.test(out)) out = out[0].toLowerCase() + out.slice(1);
102
- return out;
103
- }
104
- function readDiskFile(filePath) {
99
+ async function createProject(options = {}) {
100
+ const api = new API();
101
+ let compilerOptions;
105
102
  try {
106
- return fs$1.readFileSync(filePath, "utf-8");
107
- } catch {
108
- return;
103
+ compilerOptions = api.parseConfigFile(options.tsconfigPath ?? "tsconfig.json").options;
104
+ } catch (error) {
105
+ api.close();
106
+ throw error;
109
107
  }
110
- }
111
- async function createProject(options = {}) {
112
- const tsconfigPath = normalizePath(options.tsconfigPath ?? "./tsconfig.json");
113
- if (!fs$1.existsSync(tsconfigPath)) throw new Error(`tsconfig file not found: ${tsconfigPath}`);
114
- const dir = path.posix.dirname(tsconfigPath);
115
- /** in-memory files, overriding the file system */
116
- const virtualFiles = /* @__PURE__ */ new Map();
117
- /** root files of the generated tsconfig */
118
- const rootFiles = /* @__PURE__ */ new Set();
108
+ /** content of in-memory files */
109
+ const contents = /* @__PURE__ */ new Map();
119
110
  let snapshot;
120
- let configPath = `${dir}/tsconfig.fumadocs-typescript.json`;
121
- for (let i = 0; fs$1.existsSync(configPath); i++) configPath = `${dir}/tsconfig.fumadocs-typescript.${i}.json`;
122
- function writeConfig() {
123
- virtualFiles.set(configPath, JSON.stringify({
124
- extends: `./${path.posix.basename(tsconfigPath)}`,
125
- include: [],
126
- files: Array.from(rootFiles)
127
- }));
128
- }
129
- const api = new API({
130
- cwd: dir,
131
- fs: { readFile: (fileName) => virtualFiles.get(normalizePath(fileName)) }
132
- });
111
+ let id;
112
+ let root;
133
113
  return {
134
114
  api,
135
- tsconfigPath,
115
+ tsconfigPath: compilerOptions.configFilePath,
136
116
  getSourceFile(filePath, content) {
137
- const key = normalizePath(filePath);
138
- const changed = [];
139
- const created = [];
140
- if (content !== void 0) {
141
- const current = virtualFiles.has(key) ? virtualFiles.get(key) : readDiskFile(key);
142
- if (current !== content) {
143
- virtualFiles.set(key, content);
144
- if (current !== void 0) changed.push(key);
145
- else created.push(key);
146
- }
147
- }
148
- if (!rootFiles.has(key)) {
149
- rootFiles.add(key);
150
- writeConfig();
151
- changed.push(configPath);
152
- }
153
- if (!snapshot) snapshot = api.updateSnapshot({ openProjects: [configPath] });
154
- else if (changed.length > 0 || created.length > 0) {
117
+ const file = path.resolve(filePath);
118
+ const changed = content !== void 0 && contents.get(file) !== content;
119
+ if (!snapshot || root !== file || changed) {
120
+ if (changed) contents.set(file, content);
121
+ const fileSystem = createFileSystemLayer(changed ? [[file, content]] : []);
122
+ const program = {
123
+ rootFiles: [file],
124
+ compilerOptions
125
+ };
155
126
  const prev = snapshot;
156
- snapshot = api.updateSnapshot({ fileChanges: {
157
- changed: changed.length > 0 ? changed : void 0,
158
- created: created.length > 0 ? created : void 0
159
- } });
160
- prev.dispose();
127
+ if (!prev) {
128
+ const created = api.createSnapshot({
129
+ fileSystem,
130
+ createPrograms: [program]
131
+ });
132
+ id = created.operation.createdPrograms[0].id;
133
+ snapshot = created;
134
+ } else {
135
+ snapshot = prev.update(root === file ? {
136
+ fileSystem,
137
+ ensurePrograms: [id]
138
+ } : {
139
+ fileSystem,
140
+ reconfigurePrograms: [{
141
+ id,
142
+ ...program
143
+ }]
144
+ });
145
+ prev.dispose();
146
+ }
147
+ root = file;
161
148
  }
162
- const project = snapshot.getProject(configPath);
163
- if (!project) return;
164
- const sourceFile = project.program.getSourceFile(key);
165
- if (!sourceFile) return;
149
+ const project = snapshot.getProject(id);
150
+ const sourceFile = project?.program.getSourceFile(file);
151
+ if (!project || !sourceFile) return;
166
152
  return {
167
153
  project,
168
154
  sourceFile
@@ -208,7 +194,6 @@ function createGenerator(options = {}) {
208
194
  const declaration = symbol.declarations[0].resolve(tsProject);
209
195
  if (!declaration) continue;
210
196
  const type = checker.getTypeAtLocation(declaration);
211
- if (!type) continue;
212
197
  const entryContext = {
213
198
  ...options,
214
199
  program: tsProject,
@@ -266,7 +251,7 @@ function getDocEntry(prop, context) {
266
251
  name: prop.name,
267
252
  description: checker.getDocumentationCommentOfSymbol(prop),
268
253
  tags,
269
- type: checker.typeToString(subType, declaration, NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope | NodeBuilderFlags.NoTruncation),
254
+ type: checker.typeToString(subType, declaration, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | TypeFormatFlags.NoTruncation),
270
255
  simplifiedType: getSimpleForm(subType, checker, declaration, {
271
256
  ...context.typeSimplifier,
272
257
  noUndefined: isOptional
@@ -397,14 +382,14 @@ function typeTableRow(entry) {
397
382
  * MDX is required to use this plugin.
398
383
  */
399
384
  function remarkAutoTypeTable(config = {}) {
400
- const { name = "auto-type-table", outputName = "TypeTable", options: generateOptions = {}, remarkStringify = true, generator = createGenerator(), renderMarkdown, renderType, shiki } = config;
385
+ const { name = "auto-type-table", outputName = "TypeTable", options: generateOptions = {}, remarkStringify = true, generator = createGenerator(), renderMarkdown, renderType, shiki, highlighter } = config;
401
386
  let renderer;
402
387
  if (renderMarkdown && renderType) renderer = {
403
388
  renderMarkdownToHast: renderMarkdown,
404
389
  renderTypeToHast: renderType
405
390
  };
406
391
  else {
407
- renderer = markdownRenderer(shiki);
392
+ renderer = markdownRenderer(highlighter, shiki);
408
393
  if (renderMarkdown) renderer.renderMarkdownToHast = renderMarkdown;
409
394
  if (renderType) renderer.renderTypeToHast = renderType;
410
395
  }
@@ -1,6 +1,7 @@
1
- import { API, Checker, Project, Symbol, Type } from "typescript/unstable/sync";
2
- import { Node, SourceFile } from "typescript/unstable/ast";
1
+ import { API, Checker, Project, Symbol, Type } from "typescript/sync";
2
+ import { Node, SourceFile } from "typescript/ast";
3
3
  import { Nodes } from "hast";
4
+ import { Highlighter } from "fumadocs-core/highlight";
4
5
  import { BundledTheme, CodeOptionsThemes, CodeToHastOptionsCommon } from "shiki";
5
6
  //#region src/lib/type-table.d.ts
6
7
  interface BaseTypeTableProps {
@@ -72,14 +73,14 @@ interface TypescriptConfig {
72
73
  }
73
74
  interface Project$1 {
74
75
  /**
75
- * The underlying `typescript/unstable/sync` API instance (a native TypeScript process).
76
+ * The underlying `typescript/sync` API instance (a native TypeScript process).
76
77
  */
77
78
  readonly api: API;
78
79
  readonly tsconfigPath: string;
79
80
  /**
80
81
  * Load a source file into the project, and optionally override its content with an in-memory version.
81
82
  *
82
- * Only loaded files (and the files they import) are part of the program, similar to `tsc` with `files` set.
83
+ * The program only contains the file and the files it imports, similar to `tsc` with `files` set.
83
84
  */
84
85
  getSourceFile(filePath: string, content?: string): {
85
86
  project: Project;
@@ -118,7 +119,7 @@ interface RawTag {
118
119
  }
119
120
  interface EntryContext extends GenerateOptions {
120
121
  /**
121
- * The TypeScript project (from `typescript/unstable/sync`) containing the declaration.
122
+ * The TypeScript project (from `typescript/sync`) containing the declaration.
122
123
  */
123
124
  program: Project;
124
125
  checker: Checker;
@@ -1,18 +1,24 @@
1
1
  import { remark } from "remark";
2
2
  import { remarkGfm } from "fumadocs-core/mdx-plugins/remark-gfm";
3
- import { rehypeCode } from "fumadocs-core/mdx-plugins/rehype-code";
3
+ import { rehypeCodeFromHighlighter } from "fumadocs-core/mdx-plugins/rehype-code.core";
4
4
  import remarkRehype from "remark-rehype";
5
- import { highlightHast } from "fumadocs-core/highlight";
5
+ import { createShikiHighlighter } from "fumadocs-core/highlight/shiki";
6
+ import { defaultShikiFactory } from "fumadocs-core/highlight/shiki/full";
6
7
  //#region src/markdown.ts
7
- function markdownRenderer(options) {
8
- const processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, {
9
- langs: ["ts", "tsx"],
8
+ function markdownRenderer(highlighter, shiki) {
9
+ highlighter ??= createShikiHighlighter(() => defaultShikiFactory.getOrInit(), {
10
+ defaultColor: false,
11
+ fallbackLanguage: "plaintext",
10
12
  transformers: [],
11
- parseMetaString: void 0,
12
- ...options
13
+ ...shiki ?? { themes: {
14
+ light: "github-light",
15
+ dark: "github-dark"
16
+ } }
13
17
  });
18
+ const processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCodeFromHighlighter, highlighter, { parseMetaString: void 0 });
14
19
  return {
15
20
  async renderTypeToHast(type) {
21
+ await highlighter.loadLanguage?.("ts");
16
22
  return {
17
23
  type: "element",
18
24
  tagName: "span",
@@ -21,12 +27,10 @@ function markdownRenderer(options) {
21
27
  type: "element",
22
28
  tagName: "code",
23
29
  properties: {},
24
- children: (await highlightHast(type, {
30
+ children: highlighter.codeToHast(type, {
25
31
  lang: "ts",
26
- structure: "inline",
27
- defaultColor: false,
28
- ...options
29
- })).children
32
+ structure: "inline"
33
+ }).children
30
34
  }]
31
35
  };
32
36
  },
@@ -1,14 +1,16 @@
1
- import { g as GenerateTypeTableOptions, h as BaseTypeTableProps, n as ShikiOptions, o as Generator } from "../markdown-CcCPhMmC.js";
2
- import * as JsxRuntime from "react/jsx-runtime";
1
+ import { g as GenerateTypeTableOptions, h as BaseTypeTableProps, n as ShikiOptions, o as Generator } from "../markdown-DtD6naEw.js";
2
+ import { Highlighter } from "fumadocs-core/highlight";
3
3
  import { ComponentProps, ReactNode } from "react";
4
4
  //#region src/ui/auto-type-table.d.ts
5
5
  export interface AutoTypeTableProps extends BaseTypeTableProps, ComponentProps<'div'> {
6
6
  generator: Generator;
7
- /** Shiki configuration when using default `renderMarkdown` & `renderType` */
7
+ /** @deprecated use `highlighter`, like `createShikiHighlighter()` */
8
8
  shiki?: ShikiOptions;
9
+ /** highlight code with your own highlighter when using default `renderMarkdown` & `renderType` */
10
+ highlighter?: Highlighter;
9
11
  options?: GenerateTypeTableOptions;
10
12
  renderMarkdown?: (md: string) => Promise<ReactNode>;
11
13
  renderType?: (type: string) => Promise<ReactNode>;
12
14
  }
13
- export declare function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, name, path, type, ...props }: AutoTypeTableProps): Promise<Promise<JsxRuntime.JSX.Element>[]>;
15
+ export declare function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, highlighter, name, path, type, ...props }: AutoTypeTableProps): Promise<Promise<import("react").JSX.Element>[]>;
14
16
  //#endregion
package/dist/ui/index.js CHANGED
@@ -1,15 +1,14 @@
1
- import { n as markdownRenderer, t as parseTags } from "../parse-tags-Cikh_NrX.js";
1
+ import { n as markdownRenderer, t as parseTags } from "../parse-tags-Ba7L-m5r.js";
2
2
  import { TypeTable } from "fumadocs-ui/components/type-table";
3
- import { toJsxRuntime } from "hast-util-to-jsx-runtime";
4
- import * as JsxRuntime from "react/jsx-runtime";
5
- import { jsx } from "react/jsx-runtime";
3
+ import { toJsx } from "fumadocs-core/utils/hast-to-jsx";
6
4
  import defaultMdxComponents from "fumadocs-ui/mdx";
5
+ import { jsx } from "react/jsx-runtime";
7
6
  //#region src/ui/auto-type-table.tsx
8
- async function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, name, path, type, ...props }) {
7
+ async function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, highlighter, name, path, type, ...props }) {
9
8
  if (!renderType || !renderMarkdown) {
10
- const renderer = markdownRenderer(shiki);
11
- renderType ??= async (v) => toJsx(await renderer.renderTypeToHast(v));
12
- renderMarkdown ??= async (v) => toJsx(await renderer.renderMarkdownToHast(v));
9
+ const renderer = markdownRenderer(highlighter, shiki);
10
+ renderType ??= async (v) => render(await renderer.renderTypeToHast(v));
11
+ renderMarkdown ??= async (v) => render(await renderer.renderMarkdownToHast(v));
13
12
  }
14
13
  return (await generator.generateTypeTable({
15
14
  name,
@@ -42,14 +41,11 @@ async function AutoTypeTable({ generator, options, renderType, renderMarkdown, s
42
41
  }, item.name);
43
42
  });
44
43
  }
45
- function toJsx(hast) {
46
- return toJsxRuntime(hast, {
47
- ...JsxRuntime,
48
- components: {
49
- ...defaultMdxComponents,
50
- img: "img"
51
- }
52
- });
44
+ function render(hast) {
45
+ return toJsx(hast, { components: {
46
+ ...defaultMdxComponents,
47
+ img: "img"
48
+ } });
53
49
  }
54
50
  //#endregion
55
51
  export { AutoTypeTable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-typescript",
3
- "version": "5.5.1",
3
+ "version": "5.6.0",
4
4
  "description": "Typescript Integration for Fumadocs",
5
5
  "keywords": [
6
6
  "Docs",
@@ -36,11 +36,10 @@
36
36
  "dependencies": {
37
37
  "estree-util-value-to-estree": "^3.5.0",
38
38
  "hast-util-to-estree": "^3.1.3",
39
- "hast-util-to-jsx-runtime": "^2.3.6",
40
39
  "remark": "^15.0.1",
41
40
  "remark-rehype": "^11.1.2",
42
41
  "shiki": "^4.5.0",
43
- "typescript": "~7.0.2",
42
+ "typescript": "7.1.0-beta",
44
43
  "unified": "^11.0.5"
45
44
  },
46
45
  "devDependencies": {
@@ -48,14 +47,14 @@
48
47
  "@types/estree": "^1.0.9",
49
48
  "@types/hast": "^3.0.5",
50
49
  "@types/mdast": "^4.0.4",
51
- "@types/node": "26.6.4",
50
+ "@types/node": "26.6.5",
52
51
  "@types/react": "^19.3.0",
53
52
  "@types/react-dom": "^19.3.0",
54
- "fumadocs-core": "16.17.1",
55
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.1",
53
+ "fumadocs-core": "16.17.8",
54
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.17.8",
56
55
  "mdast-util-mdx": "^3.0.0",
57
56
  "tsconfig": "0.0.0",
58
- "tsdown": "0.23.0",
57
+ "tsdown": "0.23.1",
59
58
  "vfile": "^6.0.3"
60
59
  },
61
60
  "peerDependencies": {
@@ -63,7 +62,7 @@
63
62
  "@types/hast": "*",
64
63
  "@types/mdast": "*",
65
64
  "@types/react": "*",
66
- "fumadocs-core": "^16.17.1",
65
+ "fumadocs-core": "^16.17.8",
67
66
  "fumadocs-ui": "^16.7.0",
68
67
  "react": "^19.2.0",
69
68
  "react-dom": "^19.2.0"