fumadocs-typescript 5.1.5 → 5.2.1

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,31 +1,46 @@
1
1
  import { TypeFormatFlags } from "ts-morph";
2
-
3
2
  //#region src/lib/get-simple-form.ts
4
- function getSimpleForm(type, checker, noUndefined = false, location) {
3
+ function getSimpleForm(type, checker, location, options = {}) {
4
+ const { override, shouldSimplify, noUndefined = false } = options;
5
5
  if (type.isUndefined() && noUndefined) return "";
6
+ const overridden = override?.({
7
+ checker,
8
+ type,
9
+ location
10
+ });
11
+ if (overridden) return overridden;
12
+ if (shouldSimplify && !shouldSimplify({
13
+ checker,
14
+ type,
15
+ location
16
+ })) return type.getText(location, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
6
17
  const alias = type.getAliasSymbol();
7
18
  if (alias) {
8
19
  const args = type.getAliasTypeArguments();
9
20
  if (args.length === 0) return alias.getName();
10
- return `${alias.getName()}<${args.map((arg) => getSimpleForm(arg, checker)).join(", ")}>`;
21
+ const nextOptions = {
22
+ ...options,
23
+ noUndefined: false
24
+ };
25
+ return `${alias.getName()}<${args.map((arg) => getSimpleForm(arg, checker, location, nextOptions)).join(", ")}>`;
11
26
  }
12
27
  if (type.isUnion()) {
13
- const types = [];
14
- for (const t of type.getUnionTypes()) {
15
- const str = getSimpleForm(t, checker, noUndefined);
16
- if (str.length > 0 && str !== "never") types.unshift(str);
28
+ if (noUndefined) {
29
+ const members = type.getUnionTypes().filter((t) => !t.isUndefined());
30
+ if (members.length === 0) return "undefined";
31
+ if (members.length === 1) return getSimpleForm(members[0], checker, location, options);
17
32
  }
18
- return types.length > 0 ? dedupe(types).join(" | ").replace("true | false", "boolean") : "never";
33
+ return "union";
19
34
  }
20
35
  if (type.isIntersection()) {
21
36
  const types = [];
22
37
  for (const t of type.getIntersectionTypes()) {
23
- const str = getSimpleForm(t, checker, noUndefined);
38
+ const str = getSimpleForm(t, checker, location, options);
24
39
  if (str.length > 0 && str !== "never") types.unshift(str);
25
40
  }
26
41
  return dedupe(types).join(" & ");
27
42
  }
28
- if (type.isTuple()) return `[${type.getTupleElements().map((t) => getSimpleForm(t, checker)).join(", ")}]`;
43
+ if (type.isTuple()) return "tuple";
29
44
  if (type.isArray() || type.isReadonlyArray()) return "array";
30
45
  if (type.getCallSignatures().length > 0) return "function";
31
46
  if (type.isClassOrInterface() || type.isObject()) return "object";
@@ -40,6 +55,5 @@ function dedupe(arr) {
40
55
  }
41
56
  return out;
42
57
  }
43
-
44
58
  //#endregion
45
- export { getSimpleForm };
59
+ export { getSimpleForm };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,7 @@
1
- import { a as GeneratorOptions, c as createGenerator, d as generateHash, f as BaseTypeTableProps, i as Generator, l as createProject, n as GenerateOptions, o as RawTag, p as GenerateTypeTableOptions, r as GeneratedDoc, s as TypescriptConfig, t as DocEntry, u as Cache } from "./base-CLqyTLv7.js";
2
- import { ResolvedShikiConfig } from "fumadocs-core/highlight/config";
3
- import { Nodes } from "hast";
1
+ import { a as GeneratedDoc, c as RawTag, d as createProject, f as Cache, h as GenerateTypeTableOptions, i as GenerateOptions, l as TypescriptConfig, m as BaseTypeTableProps, n as ShikiOptions, o as Generator, p as generateHash, r as DocEntry, s as GeneratorOptions, t as MarkdownRenderer, u as createGenerator } from "./markdown-cnIFnWzR.js";
4
2
  import { Root } from "mdast";
5
3
  import { Transformer } from "unified";
6
4
 
7
- //#region src/markdown.d.ts
8
- interface MarkdownRenderer {
9
- renderTypeToHast: (type: string) => Nodes | Promise<Nodes>;
10
- renderMarkdownToHast: (md: string) => Nodes | Promise<Nodes>;
11
- }
12
- //#endregion
13
5
  //#region src/lib/remark-auto-type-table.d.ts
14
6
  interface RemarkAutoTypeTableOptions {
15
7
  /**
@@ -23,7 +15,7 @@ interface RemarkAutoTypeTableOptions {
23
15
  /**
24
16
  * config for Shiki when using default `renderMarkdown` & `renderType`.
25
17
  */
26
- shiki?: ResolvedShikiConfig;
18
+ shiki?: ShikiOptions;
27
19
  renderMarkdown?: MarkdownRenderer['renderMarkdownToHast'];
28
20
  renderType?: MarkdownRenderer['renderTypeToHast'];
29
21
  /**
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
- import { n as markdownRenderer, t as parseTags } from "./parse-tags-DMoo_pSD.js";
1
+ import { n as markdownRenderer, t as parseTags } from "./parse-tags-CaW74X-R.js";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { createHash } from "node:crypto";
5
5
  import { valueToEstree } from "estree-util-value-to-estree";
6
6
  import { visit } from "unist-util-visit";
7
7
  import { toEstree } from "hast-util-to-estree";
8
-
9
8
  //#region src/lib/type-table.ts
10
9
  async function getTypeTableOutput(gen, { name, type, ...props }, options) {
11
10
  const file = props.path && options?.basePath ? path.join(options.basePath, props.path) : props.path;
@@ -24,17 +23,14 @@ async function getTypeTableOutput(gen, { name, type, ...props }, options) {
24
23
  if (name && output.length === 0) throw new Error(`${name} in ${file ?? "empty file"} doesn't exist`);
25
24
  return output;
26
25
  }
27
-
28
26
  //#endregion
29
27
  //#region src/cache/index.ts
30
28
  function generateHash(str) {
31
29
  return createHash("SHA256").update(str).digest("hex").slice(0, 12);
32
30
  }
33
-
34
31
  //#endregion
35
32
  //#region package.json
36
- var version = "5.1.5";
37
-
33
+ var version = "5.2.1";
38
34
  //#endregion
39
35
  //#region src/lib/base.ts
40
36
  async function createProject(options = {}) {
@@ -114,7 +110,7 @@ async function generate(id, name, entryContext) {
114
110
  }
115
111
  async function getDocEntry(prop, context) {
116
112
  const { ts } = await import("ts-morph");
117
- const { getSimpleForm } = await import("./get-simple-form-B8HWDNe0.js");
113
+ const { getSimpleForm } = await import("./get-simple-form-Bya17G4R.js");
118
114
  const { transform, allowInternal = false, program } = context;
119
115
  if (context.type.isClass() && prop.getName().startsWith("#")) return;
120
116
  const subType = prop.getTypeAtLocation(context.declaration);
@@ -132,7 +128,10 @@ async function getDocEntry(prop, context) {
132
128
  description: ts.displayPartsToString(prop.compilerSymbol.getDocumentationComment(program.getTypeChecker().compilerObject)),
133
129
  tags,
134
130
  type: subType.getText(context.declaration, ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation),
135
- simplifiedType: getSimpleForm(subType, program.getTypeChecker(), isOptional, context.declaration),
131
+ simplifiedType: getSimpleForm(subType, program.getTypeChecker(), context.declaration, {
132
+ ...context.typeSimplifier,
133
+ noUndefined: isOptional
134
+ }),
136
135
  required: !isOptional,
137
136
  deprecated: false
138
137
  };
@@ -159,7 +158,6 @@ async function getDocEntry(prop, context) {
159
158
  transform?.call(context, entry, subType, prop);
160
159
  return entry;
161
160
  }
162
-
163
161
  //#endregion
164
162
  //#region src/lib/remark-auto-type-table.ts
165
163
  function objectBuilder() {
@@ -319,7 +317,6 @@ function remarkAutoTypeTable(config = {}) {
319
317
  await Promise.all(queue);
320
318
  };
321
319
  }
322
-
323
320
  //#endregion
324
321
  //#region src/cache/fs-cache.ts
325
322
  function createFileSystemGeneratorCache(dir) {
@@ -339,6 +336,5 @@ function createFileSystemGeneratorCache(dir) {
339
336
  }
340
337
  };
341
338
  }
342
-
343
339
  //#endregion
344
- export { createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable };
340
+ export { createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable };
@@ -1,4 +1,6 @@
1
- import { ExportedDeclarations, Project, Symbol, Type } from "ts-morph";
1
+ import { ExportedDeclarations, Node, Project, Symbol, Type, TypeChecker } from "ts-morph";
2
+ import { Nodes } from "hast";
3
+ import { BundledTheme, CodeOptionsThemes, CodeToHastOptionsCommon } from "shiki";
2
4
 
3
5
  //#region src/lib/type-table.d.ts
4
6
  interface BaseTypeTableProps {
@@ -47,6 +49,23 @@ interface Cache {
47
49
  }
48
50
  declare function generateHash(str: string): string;
49
51
  //#endregion
52
+ //#region src/lib/get-simple-form.d.ts
53
+ interface TypeSimplifierContext {
54
+ type: Type;
55
+ checker: TypeChecker;
56
+ location?: Node;
57
+ }
58
+ interface TypeSimplifierOptions {
59
+ /**
60
+ * whether the simplified names should be preferred over the type names.
61
+ *
62
+ * Default: always prefer simplified ones.
63
+ */
64
+ shouldSimplify?: (ctx: TypeSimplifierContext) => boolean;
65
+ override?: (ctx: TypeSimplifierContext) => string | undefined;
66
+ noUndefined?: boolean;
67
+ }
68
+ //#endregion
50
69
  //#region src/lib/base.d.ts
51
70
  interface GeneratedDoc {
52
71
  /**
@@ -88,6 +107,7 @@ interface GenerateOptions {
88
107
  * Modify output property entry
89
108
  */
90
109
  transform?: Transformer;
110
+ typeSimplifier?: TypeSimplifierOptions;
91
111
  }
92
112
  type Generator = ReturnType<typeof createGenerator>;
93
113
  interface GeneratorOptions extends TypescriptConfig {
@@ -111,4 +131,11 @@ declare function createGenerator(options?: GeneratorOptions): {
111
131
  generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions): Promise<GeneratedDoc[]>;
112
132
  };
113
133
  //#endregion
114
- export { GeneratorOptions as a, createGenerator as c, generateHash as d, BaseTypeTableProps as f, Generator as i, createProject as l, GenerateOptions as n, RawTag as o, GenerateTypeTableOptions as p, GeneratedDoc as r, TypescriptConfig as s, DocEntry as t, Cache as u };
134
+ //#region src/markdown.d.ts
135
+ interface MarkdownRenderer {
136
+ renderTypeToHast: (type: string) => Nodes | Promise<Nodes>;
137
+ renderMarkdownToHast: (md: string) => Nodes | Promise<Nodes>;
138
+ }
139
+ type ShikiOptions = Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BundledTheme>;
140
+ //#endregion
141
+ export { GeneratedDoc as a, RawTag as c, createProject as d, Cache as f, GenerateTypeTableOptions as h, GenerateOptions as i, TypescriptConfig as l, BaseTypeTableProps as m, ShikiOptions as n, Generator as o, generateHash as p, DocEntry as r, GeneratorOptions as s, MarkdownRenderer as t, createGenerator as u };
@@ -1,17 +1,15 @@
1
1
  import { remark } from "remark";
2
2
  import { remarkGfm } from "fumadocs-core/mdx-plugins/remark-gfm";
3
- import { createRehypeCode } from "fumadocs-core/mdx-plugins/rehype-code.core";
3
+ import { rehypeCode } from "fumadocs-core/mdx-plugins/rehype-code";
4
4
  import remarkRehype from "remark-rehype";
5
- import { highlightHast } from "fumadocs-core/highlight/core";
6
- import { configDefault } from "fumadocs-core/highlight";
7
-
5
+ import { highlightHast } from "fumadocs-core/highlight";
8
6
  //#region src/markdown.ts
9
- function markdownRenderer(shiki = configDefault) {
10
- const processor = remark().use(remarkGfm).use(remarkRehype).use(createRehypeCode(shiki), {
11
- lazy: true,
7
+ function markdownRenderer(options) {
8
+ const processor = remark().use(remarkGfm).use(remarkRehype).use(rehypeCode, {
12
9
  langs: ["ts", "tsx"],
13
10
  transformers: [],
14
- parseMetaString: void 0
11
+ parseMetaString: void 0,
12
+ ...options
15
13
  });
16
14
  return {
17
15
  async renderTypeToHast(type) {
@@ -24,9 +22,10 @@ function markdownRenderer(shiki = configDefault) {
24
22
  tagName: "code",
25
23
  properties: {},
26
24
  children: (await highlightHast(type, {
27
- config: shiki,
28
25
  lang: "ts",
29
- structure: "inline"
26
+ structure: "inline",
27
+ defaultColor: false,
28
+ ...options
30
29
  })).children
31
30
  }]
32
31
  };
@@ -37,7 +36,6 @@ function markdownRenderer(shiki = configDefault) {
37
36
  }
38
37
  };
39
38
  }
40
-
41
39
  //#endregion
42
40
  //#region src/lib/parse-tags.ts
43
41
  /**
@@ -65,6 +63,5 @@ function parseTags(tags) {
65
63
  }
66
64
  return typed;
67
65
  }
68
-
69
66
  //#endregion
70
- export { markdownRenderer as n, parseTags as t };
67
+ export { markdownRenderer as n, parseTags as t };
@@ -1,14 +1,12 @@
1
- import { f as BaseTypeTableProps, i as Generator, p as GenerateTypeTableOptions } from "../base-CLqyTLv7.js";
2
- import * as runtime from "react/jsx-runtime";
3
- import "server-only";
4
- import { ResolvedShikiConfig } from "fumadocs-core/highlight/config";
1
+ import { h as GenerateTypeTableOptions, m as BaseTypeTableProps, n as ShikiOptions, o as Generator } from "../markdown-cnIFnWzR.js";
2
+ import * as JsxRuntime from "react/jsx-runtime";
5
3
  import { ComponentProps, ReactNode } from "react";
6
4
 
7
5
  //#region src/ui/auto-type-table.d.ts
8
6
  interface AutoTypeTableProps extends BaseTypeTableProps, ComponentProps<'div'> {
9
7
  generator: Generator;
10
8
  /** Shiki configuration when using default `renderMarkdown` & `renderType` */
11
- shiki?: ResolvedShikiConfig;
9
+ shiki?: ShikiOptions;
12
10
  options?: GenerateTypeTableOptions;
13
11
  renderMarkdown?: (md: string) => Promise<ReactNode>;
14
12
  renderType?: (type: string) => Promise<ReactNode>;
@@ -23,6 +21,6 @@ declare function AutoTypeTable({
23
21
  path,
24
22
  type,
25
23
  ...props
26
- }: AutoTypeTableProps): Promise<Promise<runtime.JSX.Element>[]>;
24
+ }: AutoTypeTableProps): Promise<Promise<JsxRuntime.JSX.Element>[]>;
27
25
  //#endregion
28
26
  export { AutoTypeTable, AutoTypeTableProps };
package/dist/ui/index.js CHANGED
@@ -1,11 +1,9 @@
1
- import { n as markdownRenderer, t as parseTags } from "../parse-tags-DMoo_pSD.js";
1
+ import { n as markdownRenderer, t as parseTags } from "../parse-tags-CaW74X-R.js";
2
2
  import { TypeTable } from "fumadocs-ui/components/type-table";
3
3
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
4
- import * as runtime from "react/jsx-runtime";
4
+ import * as JsxRuntime from "react/jsx-runtime";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import defaultMdxComponents from "fumadocs-ui/mdx";
7
- import "server-only";
8
-
9
7
  //#region src/ui/auto-type-table.tsx
10
8
  async function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, name, path, type, ...props }) {
11
9
  if (!renderType || !renderMarkdown) {
@@ -46,15 +44,12 @@ async function AutoTypeTable({ generator, options, renderType, renderMarkdown, s
46
44
  }
47
45
  function toJsx(hast) {
48
46
  return toJsxRuntime(hast, {
49
- Fragment: runtime.Fragment,
50
- jsx: runtime.jsx,
51
- jsxs: runtime.jsxs,
47
+ ...JsxRuntime,
52
48
  components: {
53
49
  ...defaultMdxComponents,
54
50
  img: void 0
55
51
  }
56
52
  });
57
53
  }
58
-
59
54
  //#endregion
60
- export { AutoTypeTable };
55
+ export { AutoTypeTable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-typescript",
3
- "version": "5.1.5",
3
+ "version": "5.2.1",
4
4
  "description": "Typescript Integration for Fumadocs",
5
5
  "keywords": [
6
6
  "Docs",
@@ -45,16 +45,16 @@
45
45
  "@types/estree": "^1.0.8",
46
46
  "@types/hast": "^3.0.4",
47
47
  "@types/mdast": "^4.0.4",
48
- "@types/node": "25.3.3",
48
+ "@types/node": "25.5.0",
49
49
  "@types/react": "^19.2.14",
50
50
  "@types/react-dom": "^19.2.3",
51
51
  "mdast-util-mdx": "^3.0.0",
52
- "tsdown": "0.20.3",
53
- "typescript": "^5.9.3",
52
+ "shiki": "^4.0.2",
53
+ "tsdown": "0.21.6",
54
+ "typescript": "^6.0.2",
54
55
  "vfile": "^6.0.3",
55
- "eslint-config-custom": "0.0.0",
56
- "fumadocs-core": "16.6.8",
57
- "fumadocs-ui": "16.6.8",
56
+ "fumadocs-core": "16.7.8",
57
+ "fumadocs-ui": "16.7.8",
58
58
  "tsconfig": "0.0.0"
59
59
  },
60
60
  "peerDependencies": {
@@ -62,12 +62,16 @@
62
62
  "@types/hast": "*",
63
63
  "@types/mdast": "*",
64
64
  "@types/react": "*",
65
- "fumadocs-core": "^16.5.0",
66
- "fumadocs-ui": "^16.5.0",
65
+ "fumadocs-core": "^16.7.0",
66
+ "fumadocs-ui": "^16.7.0",
67
67
  "react": "*",
68
+ "shiki": "*",
68
69
  "typescript": "*"
69
70
  },
70
71
  "peerDependenciesMeta": {
72
+ "shiki": {
73
+ "optional": true
74
+ },
71
75
  "@types/estree": {
72
76
  "optional": true
73
77
  },
@@ -88,7 +92,7 @@
88
92
  "build": "tsdown",
89
93
  "clean": "rimraf dist",
90
94
  "dev": "tsdown --watch",
91
- "lint": "eslint .",
95
+ "lint": "oxlint .",
92
96
  "types:check": "tsc --noEmit"
93
97
  }
94
98
  }