fumadocs-typescript 5.1.4 → 5.2.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/{get-simple-form-B8HWDNe0.js → get-simple-form-5c3qUHXR.js} +22 -16
- package/dist/index.d.ts +2 -10
- package/dist/index.js +12 -12
- package/dist/{base-CLqyTLv7.d.ts → markdown-Cpx6um-0.d.ts} +29 -2
- package/dist/{parse-tags-DMoo_pSD.js → parse-tags-CaW74X-R.js} +10 -13
- package/dist/ui/index.d.ts +4 -6
- package/dist/ui/index.js +4 -8
- package/package.json +12 -7
|
@@ -1,35 +1,42 @@
|
|
|
1
1
|
import { TypeFormatFlags } from "ts-morph";
|
|
2
|
-
|
|
3
2
|
//#region src/lib/get-simple-form.ts
|
|
4
|
-
function getSimpleForm(
|
|
3
|
+
function getSimpleForm(ctx, options = {}) {
|
|
4
|
+
const { type } = ctx;
|
|
5
|
+
const { override, shouldSimplify, noUndefined = false } = options;
|
|
5
6
|
if (type.isUndefined() && noUndefined) return "";
|
|
7
|
+
const overriden = override?.(ctx);
|
|
8
|
+
if (overriden) return overriden;
|
|
9
|
+
if (shouldSimplify && !shouldSimplify(ctx)) return type.getText(ctx.location, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
|
|
6
10
|
const alias = type.getAliasSymbol();
|
|
7
11
|
if (alias) {
|
|
8
12
|
const args = type.getAliasTypeArguments();
|
|
9
13
|
if (args.length === 0) return alias.getName();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
return types.length > 0 ? dedupe(types).join(" | ").replace("true | false", "boolean") : "never";
|
|
14
|
+
const nextOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
noUndefined: false
|
|
17
|
+
};
|
|
18
|
+
return `${alias.getName()}<${args.map((arg) => getSimpleForm({
|
|
19
|
+
...ctx,
|
|
20
|
+
type: arg
|
|
21
|
+
}, nextOptions)).join(", ")}>`;
|
|
19
22
|
}
|
|
23
|
+
if (type.isUnion()) return "union";
|
|
20
24
|
if (type.isIntersection()) {
|
|
21
25
|
const types = [];
|
|
22
26
|
for (const t of type.getIntersectionTypes()) {
|
|
23
|
-
const str = getSimpleForm(
|
|
27
|
+
const str = getSimpleForm({
|
|
28
|
+
...ctx,
|
|
29
|
+
type: t
|
|
30
|
+
}, options);
|
|
24
31
|
if (str.length > 0 && str !== "never") types.unshift(str);
|
|
25
32
|
}
|
|
26
33
|
return dedupe(types).join(" & ");
|
|
27
34
|
}
|
|
28
|
-
if (type.isTuple()) return
|
|
35
|
+
if (type.isTuple()) return "turple";
|
|
29
36
|
if (type.isArray() || type.isReadonlyArray()) return "array";
|
|
30
37
|
if (type.getCallSignatures().length > 0) return "function";
|
|
31
38
|
if (type.isClassOrInterface() || type.isObject()) return "object";
|
|
32
|
-
return type.getText(location, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
|
|
39
|
+
return type.getText(ctx.location, TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
|
|
33
40
|
}
|
|
34
41
|
function dedupe(arr) {
|
|
35
42
|
const dedupe = /* @__PURE__ */ new Set();
|
|
@@ -40,6 +47,5 @@ function dedupe(arr) {
|
|
|
40
47
|
}
|
|
41
48
|
return out;
|
|
42
49
|
}
|
|
43
|
-
|
|
44
50
|
//#endregion
|
|
45
|
-
export { getSimpleForm };
|
|
51
|
+
export { getSimpleForm };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { a as
|
|
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-Cpx6um-0.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?:
|
|
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-
|
|
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.
|
|
37
|
-
|
|
33
|
+
var version = "5.2.0";
|
|
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-
|
|
113
|
+
const { getSimpleForm } = await import("./get-simple-form-5c3qUHXR.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,14 @@ 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(
|
|
131
|
+
simplifiedType: getSimpleForm({
|
|
132
|
+
type: subType,
|
|
133
|
+
checker: program.getTypeChecker(),
|
|
134
|
+
location: context.declaration
|
|
135
|
+
}, {
|
|
136
|
+
...context.typeSimplifer,
|
|
137
|
+
noUndefined: isOptional
|
|
138
|
+
}),
|
|
136
139
|
required: !isOptional,
|
|
137
140
|
deprecated: false
|
|
138
141
|
};
|
|
@@ -159,7 +162,6 @@ async function getDocEntry(prop, context) {
|
|
|
159
162
|
transform?.call(context, entry, subType, prop);
|
|
160
163
|
return entry;
|
|
161
164
|
}
|
|
162
|
-
|
|
163
165
|
//#endregion
|
|
164
166
|
//#region src/lib/remark-auto-type-table.ts
|
|
165
167
|
function objectBuilder() {
|
|
@@ -319,7 +321,6 @@ function remarkAutoTypeTable(config = {}) {
|
|
|
319
321
|
await Promise.all(queue);
|
|
320
322
|
};
|
|
321
323
|
}
|
|
322
|
-
|
|
323
324
|
//#endregion
|
|
324
325
|
//#region src/cache/fs-cache.ts
|
|
325
326
|
function createFileSystemGeneratorCache(dir) {
|
|
@@ -339,6 +340,5 @@ function createFileSystemGeneratorCache(dir) {
|
|
|
339
340
|
}
|
|
340
341
|
};
|
|
341
342
|
}
|
|
342
|
-
|
|
343
343
|
//#endregion
|
|
344
|
-
export { createFileSystemGeneratorCache, createGenerator, createProject, generateHash, remarkAutoTypeTable };
|
|
344
|
+
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 simplifed names should be preferred over the type names.
|
|
61
|
+
*
|
|
62
|
+
* Default: always prefer simpliied 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
|
+
typeSimplifer?: 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
|
-
|
|
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 {
|
|
3
|
+
import { rehypeCode } from "fumadocs-core/mdx-plugins/rehype-code";
|
|
4
4
|
import remarkRehype from "remark-rehype";
|
|
5
|
-
import { highlightHast } from "fumadocs-core/highlight
|
|
6
|
-
import { configDefault } from "fumadocs-core/highlight";
|
|
7
|
-
|
|
5
|
+
import { highlightHast } from "fumadocs-core/highlight";
|
|
8
6
|
//#region src/markdown.ts
|
|
9
|
-
function markdownRenderer(
|
|
10
|
-
const processor = remark().use(remarkGfm).use(remarkRehype).use(
|
|
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 };
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as
|
|
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-Cpx6um-0.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?:
|
|
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<
|
|
24
|
+
}: AutoTypeTableProps): Promise<Promise<JsxRuntime.JSX.Element>[]>;
|
|
27
25
|
//#endregion
|
|
28
26
|
export { AutoTypeTable, AutoTypeTableProps };
|
package/dist/ui/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { n as markdownRenderer, t as parseTags } from "../parse-tags-
|
|
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
|
|
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
7
|
import "server-only";
|
|
8
|
-
|
|
9
8
|
//#region src/ui/auto-type-table.tsx
|
|
10
9
|
async function AutoTypeTable({ generator, options, renderType, renderMarkdown, shiki, name, path, type, ...props }) {
|
|
11
10
|
if (!renderType || !renderMarkdown) {
|
|
@@ -46,15 +45,12 @@ async function AutoTypeTable({ generator, options, renderType, renderMarkdown, s
|
|
|
46
45
|
}
|
|
47
46
|
function toJsx(hast) {
|
|
48
47
|
return toJsxRuntime(hast, {
|
|
49
|
-
|
|
50
|
-
jsx: runtime.jsx,
|
|
51
|
-
jsxs: runtime.jsxs,
|
|
48
|
+
...JsxRuntime,
|
|
52
49
|
components: {
|
|
53
50
|
...defaultMdxComponents,
|
|
54
51
|
img: void 0
|
|
55
52
|
}
|
|
56
53
|
});
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
//#endregion
|
|
60
|
-
export { AutoTypeTable };
|
|
56
|
+
export { AutoTypeTable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-typescript",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Typescript Integration for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -45,16 +45,17 @@
|
|
|
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.
|
|
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
|
-
"
|
|
52
|
+
"shiki": "^4.0.2",
|
|
53
|
+
"tsdown": "0.21.4",
|
|
53
54
|
"typescript": "^5.9.3",
|
|
54
55
|
"vfile": "^6.0.3",
|
|
55
56
|
"eslint-config-custom": "0.0.0",
|
|
56
|
-
"fumadocs-core": "16.
|
|
57
|
-
"fumadocs-ui": "16.
|
|
57
|
+
"fumadocs-core": "16.7.0",
|
|
58
|
+
"fumadocs-ui": "16.7.0",
|
|
58
59
|
"tsconfig": "0.0.0"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
@@ -62,12 +63,16 @@
|
|
|
62
63
|
"@types/hast": "*",
|
|
63
64
|
"@types/mdast": "*",
|
|
64
65
|
"@types/react": "*",
|
|
65
|
-
"fumadocs-core": "^16.
|
|
66
|
-
"fumadocs-ui": "^16.
|
|
66
|
+
"fumadocs-core": "^16.7.0",
|
|
67
|
+
"fumadocs-ui": "^16.7.0",
|
|
67
68
|
"react": "*",
|
|
69
|
+
"shiki": "*",
|
|
68
70
|
"typescript": "*"
|
|
69
71
|
},
|
|
70
72
|
"peerDependenciesMeta": {
|
|
73
|
+
"shiki": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
71
76
|
"@types/estree": {
|
|
72
77
|
"optional": true
|
|
73
78
|
},
|