fumadocs-typescript 4.0.2 → 4.0.4

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.
@@ -6,7 +6,7 @@ interface TypescriptConfig {
6
6
  /** A root directory to resolve relative path entries in the config file to. e.g. outDir */
7
7
  basePath?: string;
8
8
  }
9
- declare function getProject(options?: TypescriptConfig): Project;
9
+ declare function createProject(options?: TypescriptConfig): Project;
10
10
 
11
11
  interface BaseTypeTableProps {
12
12
  /**
@@ -58,6 +58,7 @@ interface DocEntry {
58
58
  type: string;
59
59
  tags: Record<string, string>;
60
60
  required: boolean;
61
+ deprecated: boolean;
61
62
  }
62
63
  interface EntryContext {
63
64
  program: Project;
@@ -79,7 +80,16 @@ interface GenerateOptions {
79
80
  transform?: Transformer;
80
81
  }
81
82
  type Generator = ReturnType<typeof createGenerator>;
82
- declare function createGenerator(config?: TypescriptConfig | Project): {
83
+ interface GeneratorOptions extends TypescriptConfig {
84
+ /**
85
+ * cache results, note that some options are not marked as dependency.
86
+ *
87
+ * @defaultValue fs
88
+ */
89
+ cache?: 'fs' | false;
90
+ project?: Project;
91
+ }
92
+ declare function createGenerator(config?: GeneratorOptions | Project): {
83
93
  generateDocumentation(file: {
84
94
  path: string;
85
95
  content?: string;
@@ -99,4 +109,4 @@ declare function generateDocumentation(file: string, name: string | undefined, c
99
109
  project?: Project;
100
110
  }): GeneratedDoc[];
101
111
 
102
- 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 };
112
+ 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, createProject as d, type GeneratorOptions as e, createGenerator as f, generateDocumentation as g };
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 './base-ze7ajmJT.js';
2
- export { d as createGenerator, e as generateDocumentation, g as getProject } from './base-ze7ajmJT.js';
1
+ import { G as GenerateOptions, a as GeneratedDoc, D as DocEntry, b as Generator, c as GenerateTypeTableOptions } from './base-CDpZg096.js';
2
+ export { e as GeneratorOptions, f as createGenerator, d as createProject, g as generateDocumentation } from './base-CDpZg096.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
@@ -12,9 +12,9 @@ import {
12
12
  ts
13
13
  } from "ts-morph";
14
14
 
15
- // src/get-project.ts
15
+ // src/create-project.ts
16
16
  import { Project } from "ts-morph";
17
- function getProject(options = {}) {
17
+ function createProject(options = {}) {
18
18
  var _a;
19
19
  return new Project({
20
20
  tsConfigFilePath: (_a = options.tsconfigPath) != null ? _a : "./tsconfig.json",
@@ -23,7 +23,7 @@ function getProject(options = {}) {
23
23
  }
24
24
 
25
25
  // src/lib/base.ts
26
- import fs2 from "node:fs";
26
+ import fs3 from "node:fs";
27
27
 
28
28
  // src/lib/type-table.ts
29
29
  import * as fs from "node:fs/promises";
@@ -56,19 +56,61 @@ export type ${typeName} = ${type}`;
56
56
  });
57
57
  }
58
58
 
59
+ // src/lib/cache.ts
60
+ import fs2 from "node:fs";
61
+ import { createHash } from "node:crypto";
62
+ import path from "node:path";
63
+ function createCache() {
64
+ const dir = path.join(process.cwd(), ".next/fumadocs-typescript");
65
+ try {
66
+ fs2.mkdirSync(dir, { recursive: true });
67
+ } catch (e) {
68
+ }
69
+ return {
70
+ write(input, data) {
71
+ const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
72
+ fs2.writeFileSync(path.join(dir, `${hash}.json`), JSON.stringify(data));
73
+ },
74
+ read(input) {
75
+ const hash = createHash("SHA256").update(input).digest("hex").slice(0, 12);
76
+ try {
77
+ return JSON.parse(
78
+ fs2.readFileSync(path.join(dir, `${hash}.json`)).toString()
79
+ );
80
+ } catch (e) {
81
+ return;
82
+ }
83
+ }
84
+ };
85
+ }
86
+
59
87
  // src/lib/base.ts
88
+ import path2 from "node:path";
60
89
  function createGenerator(config) {
61
- const project = config instanceof Project2 ? config : getProject(config);
90
+ var _a;
91
+ const options = config instanceof Project2 ? {
92
+ project: config
93
+ } : config;
94
+ const cacheType = (_a = options == null ? void 0 : options.cache) != null ? _a : "fs";
95
+ const cache = cacheType === "fs" ? createCache() : null;
96
+ let instance;
97
+ function getProject() {
98
+ var _a2;
99
+ instance != null ? instance : instance = (_a2 = options == null ? void 0 : options.project) != null ? _a2 : createProject(options);
100
+ return instance;
101
+ }
62
102
  return {
63
- generateDocumentation(file, name, options = {}) {
64
- var _a;
65
- const sourceFile = project.createSourceFile(
66
- file.path,
67
- (_a = file.content) != null ? _a : fs2.readFileSync(file.path).toString(),
68
- {
69
- overwrite: true
70
- }
71
- );
103
+ generateDocumentation(file, name, options2) {
104
+ var _a2;
105
+ const content = (_a2 = file.content) != null ? _a2 : fs3.readFileSync(path2.resolve(file.path)).toString();
106
+ const cacheKey = `${file.path}:${name}:${content}`;
107
+ if (cache) {
108
+ const cached = cache.read(cacheKey);
109
+ if (cached) return cached;
110
+ }
111
+ const sourceFile = getProject().createSourceFile(file.path, content, {
112
+ overwrite: true
113
+ });
72
114
  const out = [];
73
115
  for (const [k, d] of sourceFile.getExportedDeclarations()) {
74
116
  if (name && name !== k) continue;
@@ -76,12 +118,13 @@ function createGenerator(config) {
76
118
  console.warn(
77
119
  `export ${k} should not have more than one type declaration.`
78
120
  );
79
- out.push(generate(project, k, d[0], options));
121
+ out.push(generate(getProject(), k, d[0], options2));
80
122
  }
123
+ cache == null ? void 0 : cache.write(cacheKey, out);
81
124
  return out;
82
125
  },
83
- generateTypeTable(props, options) {
84
- return getTypeTableOutput(this, props, options);
126
+ generateTypeTable(props, options2) {
127
+ return getTypeTableOutput(this, props, options2);
85
128
  }
86
129
  };
87
130
  }
@@ -90,7 +133,7 @@ function generateDocumentation(file, name, content, options = {}) {
90
133
  const gen = createGenerator((_a = options.project) != null ? _a : options.config);
91
134
  return gen.generateDocumentation({ path: file, content }, name, options);
92
135
  }
93
- function generate(program, name, declaration, { allowInternal = false, transform }) {
136
+ function generate(program, name, declaration, { allowInternal = false, transform } = {}) {
94
137
  var _a;
95
138
  const entryContext = {
96
139
  transform,
@@ -141,14 +184,15 @@ function getDocEntry(prop, context) {
141
184
  ),
142
185
  tags,
143
186
  type: typeName,
144
- required: !prop.isOptional()
187
+ required: !prop.isOptional(),
188
+ deprecated: prop.getJsDocTags().some((tag) => tag.getName() === "deprecated")
145
189
  };
146
190
  transform == null ? void 0 : transform.call(context, entry, subType, prop);
147
191
  return entry;
148
192
  }
149
193
 
150
194
  // src/lib/mdx.ts
151
- import * as path from "node:path";
195
+ import * as path3 from "node:path";
152
196
  var regex = new RegExp("^---type-table---\\r?\\n(?<file>.+?)(?:#(?<name>.+))?\\r?\\n---end---$", "gm");
153
197
  var defaultTemplates = {
154
198
  block: (doc, c) => `### ${doc.name}
@@ -175,7 +219,7 @@ function generateMDX(generator, source, _a = {}) {
175
219
  const templates = __spreadValues(__spreadValues({}, defaultTemplates), overrides);
176
220
  return source.replace(regex, (...args) => {
177
221
  const groups = args[args.length - 1];
178
- const file = path.resolve(basePath, groups.file);
222
+ const file = path3.resolve(basePath, groups.file);
179
223
  const docs = generator.generateDocumentation(
180
224
  { path: file },
181
225
  groups.name,
@@ -191,21 +235,21 @@ function replaceJsDocLinks(md) {
191
235
  }
192
236
 
193
237
  // src/lib/file.ts
194
- import * as path2 from "node:path";
238
+ import * as path4 from "node:path";
195
239
  import { mkdir, writeFile, readFile as readFile2 } from "node:fs/promises";
196
240
  import fg from "fast-glob";
197
241
  function generateFiles(generator, options) {
198
242
  return __async(this, null, function* () {
199
243
  const files = yield fg(options.input, options.globOptions);
200
- const produce = files.map((file) => __async(this, null, function* () {
201
- const absolutePath = path2.resolve(file);
202
- const outputPath = typeof options.output === "function" ? options.output(file) : path2.resolve(
244
+ const produce = files.map((file) => __async(null, null, function* () {
245
+ const absolutePath = path4.resolve(file);
246
+ const outputPath = typeof options.output === "function" ? options.output(file) : path4.resolve(
203
247
  options.output,
204
- `${path2.basename(file, path2.extname(file))}.mdx`
248
+ `${path4.basename(file, path4.extname(file))}.mdx`
205
249
  );
206
250
  const content = (yield readFile2(absolutePath)).toString();
207
251
  let result = generateMDX(generator, content, __spreadValues({
208
- basePath: path2.dirname(absolutePath)
252
+ basePath: path4.dirname(absolutePath)
209
253
  }, options.options));
210
254
  if (options.transformOutput) {
211
255
  result = options.transformOutput(outputPath, result);
@@ -218,7 +262,7 @@ function generateFiles(generator, options) {
218
262
  }
219
263
  function write(file, content) {
220
264
  return __async(this, null, function* () {
221
- yield mkdir(path2.dirname(file), { recursive: true });
265
+ yield mkdir(path4.dirname(file), { recursive: true });
222
266
  yield writeFile(file, content);
223
267
  });
224
268
  }
@@ -258,8 +302,8 @@ function mapProperty(entry, renderMarkdown) {
258
302
  shorthand: false,
259
303
  computed: false,
260
304
  key: {
261
- type: "Identifier",
262
- name: entry.name
305
+ type: "Literal",
306
+ value: entry.name
263
307
  },
264
308
  kind: "init",
265
309
  value
@@ -274,7 +318,7 @@ function remarkAutoTypeTable({
274
318
  remarkStringify = true,
275
319
  generator = createGenerator()
276
320
  } = {}) {
277
- return (tree, file) => __async(this, null, function* () {
321
+ return (tree, file) => __async(null, null, function* () {
278
322
  const queue = [];
279
323
  let basePath = options == null ? void 0 : options.basePath;
280
324
  if (!basePath && file.path) basePath = dirname2(file.path);
@@ -296,7 +340,7 @@ function remarkAutoTypeTable({
296
340
  basePath
297
341
  })
298
342
  );
299
- const rendered = output.map((doc) => __async(this, null, function* () {
343
+ const rendered = output.map((doc) => __async(null, null, function* () {
300
344
  const properties = yield Promise.all(
301
345
  doc.entries.map((entry) => mapProperty(entry, renderMarkdown))
302
346
  );
@@ -346,10 +390,10 @@ function remarkAutoTypeTable({
346
390
  }
347
391
  export {
348
392
  createGenerator,
393
+ createProject,
349
394
  generateDocumentation,
350
395
  generateFiles,
351
396
  generateMDX,
352
- getProject,
353
397
  remarkAutoTypeTable,
354
398
  renderMarkdownToHast
355
399
  };
@@ -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 '../base-ze7ajmJT.js';
3
+ import { B as BaseTypeTableProps, b as Generator, c as GenerateTypeTableOptions } from '../base-CDpZg096.js';
4
4
  import 'ts-morph';
5
5
 
6
6
  type AutoTypeTableProps = BaseTypeTableProps;
package/dist/ui/index.js CHANGED
@@ -25,16 +25,17 @@ function AutoTypeTable(_a) {
25
25
  "renderMarkdown"
26
26
  ]);
27
27
  const output = yield generator.generateTypeTable(props, options);
28
- return output.map((item) => __async(this, null, function* () {
28
+ return output.map((item) => __async(null, null, function* () {
29
29
  const entries = item.entries.map(
30
- (entry) => __async(this, null, function* () {
30
+ (entry) => __async(null, null, function* () {
31
31
  return [
32
32
  entry.name,
33
33
  {
34
34
  type: entry.type,
35
35
  description: yield renderMarkdown(entry.description),
36
36
  default: entry.tags.default || entry.tags.defaultValue,
37
- required: entry.required
37
+ required: entry.required,
38
+ deprecated: entry.deprecated
38
39
  }
39
40
  ];
40
41
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-typescript",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
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
36
  "remark-rehype": "^11.1.2",
37
- "shiki": "^3.2.1",
37
+ "shiki": "^3.4.0",
38
38
  "ts-morph": "^25.0.1",
39
39
  "unist-util-visit": "^5.0.0"
40
40
  },
@@ -43,14 +43,14 @@
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.14.0",
47
- "@types/react": "19.1.0",
48
- "@types/react-dom": "19.1.1",
49
- "typescript": "^5.8.2",
46
+ "@types/node": "22.15.12",
47
+ "@types/react": "19.1.3",
48
+ "@types/react-dom": "19.1.3",
49
+ "typescript": "^5.8.3",
50
50
  "unified": "^11.0.5",
51
51
  "eslint-config-custom": "0.0.0",
52
- "fumadocs-core": "15.2.2",
53
- "fumadocs-ui": "15.2.2",
52
+ "fumadocs-core": "15.3.1",
53
+ "fumadocs-ui": "15.3.1",
54
54
  "tsconfig": "0.0.0"
55
55
  },
56
56
  "peerDependencies": {