fumadocs-typescript 4.0.1 → 4.0.3

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.
@@ -8,6 +8,45 @@ interface TypescriptConfig {
8
8
  }
9
9
  declare function getProject(options?: TypescriptConfig): Project;
10
10
 
11
+ interface BaseTypeTableProps {
12
+ /**
13
+ * The path to source TypeScript file.
14
+ */
15
+ path?: string;
16
+ /**
17
+ * Exported type name to generate from.
18
+ */
19
+ name?: string;
20
+ /**
21
+ * Set the type to generate from.
22
+ *
23
+ * When used with `name`, it generates the type with `name` as export name.
24
+ *
25
+ * ```ts
26
+ * export const myName = MyType;
27
+ * ```
28
+ *
29
+ * When `type` contains multiple lines, `export const` is not added.
30
+ * You need to export it manually, and specify the type name with `name`.
31
+ *
32
+ * ```tsx
33
+ * <AutoTypeTable
34
+ * path="./file.ts"
35
+ * type={`import { ReactNode } from "react"
36
+ * export const MyName = ReactNode`}
37
+ * name="MyName"
38
+ * />
39
+ * ```
40
+ */
41
+ type?: string;
42
+ }
43
+ interface GenerateTypeTableOptions extends GenerateOptions {
44
+ /**
45
+ * base path to resolve `path` prop
46
+ */
47
+ basePath?: string;
48
+ }
49
+
11
50
  interface GeneratedDoc {
12
51
  name: string;
13
52
  description: string;
@@ -19,6 +58,7 @@ interface DocEntry {
19
58
  type: string;
20
59
  tags: Record<string, string>;
21
60
  required: boolean;
61
+ deprecated: boolean;
22
62
  }
23
63
  interface EntryContext {
24
64
  program: Project;
@@ -45,6 +85,7 @@ declare function createGenerator(config?: TypescriptConfig | Project): {
45
85
  path: string;
46
86
  content?: string;
47
87
  }, name: string | undefined, options?: GenerateOptions): GeneratedDoc[];
88
+ generateTypeTable(props: BaseTypeTableProps, options?: GenerateTypeTableOptions): Promise<GeneratedDoc[]>;
48
89
  };
49
90
  /**
50
91
  * Generate documentation for properties in an exported type/interface
@@ -59,43 +100,4 @@ declare function generateDocumentation(file: string, name: string | undefined, c
59
100
  project?: Project;
60
101
  }): GeneratedDoc[];
61
102
 
62
- interface BaseTypeTableProps {
63
- /**
64
- * The path to source TypeScript file.
65
- */
66
- path?: string;
67
- /**
68
- * Exported type name to generate from.
69
- */
70
- name?: string;
71
- /**
72
- * Set the type to generate from.
73
- *
74
- * When used with `name`, it generates the type with `name` as export name.
75
- *
76
- * ```ts
77
- * export const myName = MyType;
78
- * ```
79
- *
80
- * When `type` contains multiple lines, `export const` is not added.
81
- * You need to export it manually, and specify the type name with `name`.
82
- *
83
- * ```tsx
84
- * <AutoTypeTable
85
- * path="./file.ts"
86
- * type={`import { ReactNode } from "react"
87
- * export const MyName = ReactNode`}
88
- * name="MyName"
89
- * />
90
- * ```
91
- */
92
- type?: string;
93
- }
94
- interface GenerateTypeTableOptions extends GenerateOptions {
95
- /**
96
- * base path to resolve `path` prop
97
- */
98
- basePath?: string;
99
- }
100
-
101
103
  export { type BaseTypeTableProps as B, type DocEntry as D, type GenerateOptions as G, type GeneratedDoc as a, type Generator as b, type GenerateTypeTableOptions as c, createGenerator as d, generateDocumentation as e, getProject as g };
@@ -77,42 +77,10 @@ function renderMarkdownToHast(md) {
77
77
  });
78
78
  }
79
79
 
80
- // src/utils/type-table.ts
81
- import * as fs from "node:fs/promises";
82
- import { join } from "node:path";
83
- function getTypeTableOutput(gen, _a, options) {
84
- return __async(this, null, function* () {
85
- var _b = _a, { name, type } = _b, props = __objRest(_b, ["name", "type"]);
86
- const file = props.path && (options == null ? void 0 : options.basePath) ? join(options.basePath, props.path) : props.path;
87
- let typeName = name;
88
- let content = "";
89
- if (file) {
90
- content = (yield fs.readFile(file)).toString();
91
- }
92
- if (type && type.split("\n").length > 1) {
93
- content += `
94
- ${type}`;
95
- } else if (type) {
96
- typeName != null ? typeName : typeName = "$Fumadocs";
97
- content += `
98
- export type ${typeName} = ${type}`;
99
- }
100
- const output = gen.generateDocumentation(
101
- { path: file != null ? file : "temp.ts", content },
102
- typeName,
103
- options
104
- );
105
- if (name && output.length === 0)
106
- throw new Error(`${name} in ${file != null ? file : "empty file"} doesn't exist`);
107
- return output;
108
- });
109
- }
110
-
111
80
  export {
112
81
  __spreadValues,
113
82
  __spreadProps,
114
83
  __objRest,
115
84
  __async,
116
- renderMarkdownToHast,
117
- getTypeTableOutput
85
+ renderMarkdownToHast
118
86
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { G as GenerateOptions, a as GeneratedDoc, D as DocEntry, b as Generator, c as GenerateTypeTableOptions } from './type-table-Duzly_SK.js';
2
- export { d as createGenerator, e as generateDocumentation, g as getProject } from './type-table-Duzly_SK.js';
1
+ import { G as GenerateOptions, a as GeneratedDoc, D as DocEntry, b as Generator, c as GenerateTypeTableOptions } from './base-Xy2dq1Yw.js';
2
+ export { d as createGenerator, e as generateDocumentation, g as getProject } from './base-Xy2dq1Yw.js';
3
3
  import fg from 'fast-glob';
4
4
  import { Nodes } from 'hast';
5
5
  import { Root } from 'mdast';
package/dist/index.js CHANGED
@@ -3,9 +3,8 @@ import {
3
3
  __objRest,
4
4
  __spreadProps,
5
5
  __spreadValues,
6
- getTypeTableOutput,
7
6
  renderMarkdownToHast
8
- } from "./chunk-2WGVCLFC.js";
7
+ } from "./chunk-B4VUDCYC.js";
9
8
 
10
9
  // src/lib/base.ts
11
10
  import {
@@ -24,7 +23,40 @@ function getProject(options = {}) {
24
23
  }
25
24
 
26
25
  // src/lib/base.ts
27
- import fs from "node:fs";
26
+ import fs2 from "node:fs";
27
+
28
+ // src/lib/type-table.ts
29
+ import * as fs from "node:fs/promises";
30
+ import { join } from "node:path";
31
+ function getTypeTableOutput(gen, _a, options) {
32
+ return __async(this, null, function* () {
33
+ var _b = _a, { name, type } = _b, props = __objRest(_b, ["name", "type"]);
34
+ const file = props.path && (options == null ? void 0 : options.basePath) ? join(options.basePath, props.path) : props.path;
35
+ let typeName = name;
36
+ let content = "";
37
+ if (file) {
38
+ content = (yield fs.readFile(file)).toString();
39
+ }
40
+ if (type && type.split("\n").length > 1) {
41
+ content += `
42
+ ${type}`;
43
+ } else if (type) {
44
+ typeName != null ? typeName : typeName = "$Fumadocs";
45
+ content += `
46
+ export type ${typeName} = ${type}`;
47
+ }
48
+ const output = gen.generateDocumentation(
49
+ { path: file != null ? file : "temp.ts", content },
50
+ typeName,
51
+ options
52
+ );
53
+ if (name && output.length === 0)
54
+ throw new Error(`${name} in ${file != null ? file : "empty file"} doesn't exist`);
55
+ return output;
56
+ });
57
+ }
58
+
59
+ // src/lib/base.ts
28
60
  function createGenerator(config) {
29
61
  const project = config instanceof Project2 ? config : getProject(config);
30
62
  return {
@@ -32,7 +64,7 @@ function createGenerator(config) {
32
64
  var _a;
33
65
  const sourceFile = project.createSourceFile(
34
66
  file.path,
35
- (_a = file.content) != null ? _a : fs.readFileSync(file.path).toString(),
67
+ (_a = file.content) != null ? _a : fs2.readFileSync(file.path).toString(),
36
68
  {
37
69
  overwrite: true
38
70
  }
@@ -47,6 +79,9 @@ function createGenerator(config) {
47
79
  out.push(generate(project, k, d[0], options));
48
80
  }
49
81
  return out;
82
+ },
83
+ generateTypeTable(props, options) {
84
+ return getTypeTableOutput(this, props, options);
50
85
  }
51
86
  };
52
87
  }
@@ -84,10 +119,16 @@ function getDocEntry(prop, context) {
84
119
  const tags = Object.fromEntries(
85
120
  prop.getJsDocTags().map((tag) => [tag.getName(), ts.displayPartsToString(tag.getText())])
86
121
  );
87
- let typeName = subType.getNonNullableType().getText(void 0, ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope);
122
+ let typeName = subType.getText(
123
+ void 0,
124
+ ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
125
+ );
88
126
  if (subType.getAliasSymbol() && subType.getAliasTypeArguments().length === 0) {
89
127
  typeName = (_b = (_a = subType.getAliasSymbol()) == null ? void 0 : _a.getEscapedName()) != null ? _b : typeName;
90
128
  }
129
+ if (prop.isOptional() && typeName.endsWith("| undefined")) {
130
+ typeName = typeName.slice(0, typeName.length - "| undefined".length).trimEnd();
131
+ }
91
132
  if ("remarks" in tags) {
92
133
  typeName = (_d = (_c = new RegExp("^`(?<name>.+)`").exec(tags.remarks)) == null ? void 0 : _c[1]) != null ? _d : typeName;
93
134
  }
@@ -100,7 +141,8 @@ function getDocEntry(prop, context) {
100
141
  ),
101
142
  tags,
102
143
  type: typeName,
103
- required: !prop.isOptional()
144
+ required: !prop.isOptional(),
145
+ deprecated: prop.getJsDocTags().some((tag) => tag.getName() === "deprecated")
104
146
  };
105
147
  transform == null ? void 0 : transform.call(context, entry, subType, prop);
106
148
  return entry;
@@ -151,7 +193,7 @@ function replaceJsDocLinks(md) {
151
193
 
152
194
  // src/lib/file.ts
153
195
  import * as path2 from "node:path";
154
- import { mkdir, writeFile, readFile } from "node:fs/promises";
196
+ import { mkdir, writeFile, readFile as readFile2 } from "node:fs/promises";
155
197
  import fg from "fast-glob";
156
198
  function generateFiles(generator, options) {
157
199
  return __async(this, null, function* () {
@@ -162,7 +204,7 @@ function generateFiles(generator, options) {
162
204
  options.output,
163
205
  `${path2.basename(file, path2.extname(file))}.mdx`
164
206
  );
165
- const content = (yield readFile(absolutePath)).toString();
207
+ const content = (yield readFile2(absolutePath)).toString();
166
208
  let result = generateMDX(generator, content, __spreadValues({
167
209
  basePath: path2.dirname(absolutePath)
168
210
  }, options.options));
@@ -249,8 +291,7 @@ function remarkAutoTypeTable({
249
291
  }
250
292
  function run() {
251
293
  return __async(this, null, function* () {
252
- const output = yield getTypeTableOutput(
253
- generator,
294
+ const output = yield generator.generateTypeTable(
254
295
  props,
255
296
  __spreadProps(__spreadValues({}, options), {
256
297
  basePath
@@ -1,6 +1,6 @@
1
1
  import * as runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { B as BaseTypeTableProps, b as Generator, c as GenerateTypeTableOptions } from '../type-table-Duzly_SK.js';
3
+ import { B as BaseTypeTableProps, b as Generator, c as GenerateTypeTableOptions } from '../base-Xy2dq1Yw.js';
4
4
  import 'ts-morph';
5
5
 
6
6
  type AutoTypeTableProps = BaseTypeTableProps;
package/dist/ui/index.js CHANGED
@@ -3,9 +3,8 @@ import {
3
3
  __objRest,
4
4
  __spreadProps,
5
5
  __spreadValues,
6
- getTypeTableOutput,
7
6
  renderMarkdownToHast
8
- } from "../chunk-2WGVCLFC.js";
7
+ } from "../chunk-B4VUDCYC.js";
9
8
 
10
9
  // src/ui/auto-type-table.tsx
11
10
  import { TypeTable } from "fumadocs-ui/components/type-table";
@@ -25,7 +24,7 @@ function AutoTypeTable(_a) {
25
24
  "options",
26
25
  "renderMarkdown"
27
26
  ]);
28
- const output = yield getTypeTableOutput(generator, props, options);
27
+ const output = yield generator.generateTypeTable(props, options);
29
28
  return output.map((item) => __async(this, null, function* () {
30
29
  const entries = item.entries.map(
31
30
  (entry) => __async(this, null, function* () {
@@ -35,7 +34,8 @@ function AutoTypeTable(_a) {
35
34
  type: entry.type,
36
35
  description: yield renderMarkdown(entry.description),
37
36
  default: entry.tags.default || entry.tags.defaultValue,
38
- required: entry.required
37
+ required: entry.required,
38
+ deprecated: entry.deprecated
39
39
  }
40
40
  ];
41
41
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-typescript",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Typescript Integration for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -28,13 +28,13 @@
28
28
  "dist/*"
29
29
  ],
30
30
  "dependencies": {
31
- "estree-util-value-to-estree": "^3.3.2",
31
+ "estree-util-value-to-estree": "^3.3.3",
32
32
  "fast-glob": "^3.3.3",
33
33
  "hast-util-to-estree": "^3.1.3",
34
34
  "hast-util-to-jsx-runtime": "^2.3.6",
35
35
  "remark": "^15.0.1",
36
- "remark-rehype": "^11.1.1",
37
- "shiki": "^3.2.1",
36
+ "remark-rehype": "^11.1.2",
37
+ "shiki": "^3.3.0",
38
38
  "ts-morph": "^25.0.1",
39
39
  "unist-util-visit": "^5.0.0"
40
40
  },
@@ -43,15 +43,15 @@
43
43
  "@types/estree": "^1.0.7",
44
44
  "@types/hast": "^3.0.4",
45
45
  "@types/mdast": "^4.0.3",
46
- "@types/node": "22.13.14",
47
- "@types/react": "19.0.12",
48
- "@types/react-dom": "19.0.4",
49
- "typescript": "^5.8.2",
46
+ "@types/node": "22.14.1",
47
+ "@types/react": "19.1.2",
48
+ "@types/react-dom": "19.1.2",
49
+ "typescript": "^5.8.3",
50
50
  "unified": "^11.0.5",
51
51
  "eslint-config-custom": "0.0.0",
52
- "fumadocs-ui": "15.2.1",
53
- "tsconfig": "0.0.0",
54
- "fumadocs-core": "15.2.1"
52
+ "fumadocs-core": "15.2.10",
53
+ "fumadocs-ui": "15.2.10",
54
+ "tsconfig": "0.0.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "typescript": "*"