fumadocs-typescript 4.0.3 → 4.0.5

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
  /**
@@ -80,7 +80,16 @@ interface GenerateOptions {
80
80
  transform?: Transformer;
81
81
  }
82
82
  type Generator = ReturnType<typeof createGenerator>;
83
- 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): {
84
93
  generateDocumentation(file: {
85
94
  path: string;
86
95
  content?: string;
@@ -100,4 +109,4 @@ declare function generateDocumentation(file: string, name: string | undefined, c
100
109
  project?: Project;
101
110
  }): GeneratedDoc[];
102
111
 
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 };
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,6 +1,6 @@
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
- import fg from 'fast-glob';
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
+ import { GlobOptions } from 'tinyglobby';
4
4
  import { Nodes } from 'hast';
5
5
  import { Root } from 'mdast';
6
6
  import { Transformer } from 'unified';
@@ -25,7 +25,7 @@ interface GenerateFilesOptions {
25
25
  * Output directory, or a function that returns the output path
26
26
  */
27
27
  output: string | ((inputPath: string) => string);
28
- globOptions?: fg.Options;
28
+ globOptions?: GlobOptions;
29
29
  options?: GenerateMDXOptions;
30
30
  /**
31
31
  * @returns New content
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,11 +23,11 @@ function getProject(options = {}) {
23
23
  }
24
24
 
25
25
  // src/lib/base.ts
26
- import fs2 from "node:fs";
26
+ import fs3 from "fs";
27
27
 
28
28
  // src/lib/type-table.ts
29
- import * as fs from "node:fs/promises";
30
- import { join } from "node:path";
29
+ import * as fs from "fs/promises";
30
+ import { join } from "path";
31
31
  function getTypeTableOutput(gen, _a, options) {
32
32
  return __async(this, null, function* () {
33
33
  var _b = _a, { name, type } = _b, props = __objRest(_b, ["name", "type"]);
@@ -56,19 +56,61 @@ export type ${typeName} = ${type}`;
56
56
  });
57
57
  }
58
58
 
59
+ // src/lib/cache.ts
60
+ import fs2 from "fs";
61
+ import { createHash } from "crypto";
62
+ import path from "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 "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,
@@ -149,7 +192,7 @@ function getDocEntry(prop, context) {
149
192
  }
150
193
 
151
194
  // src/lib/mdx.ts
152
- import * as path from "node:path";
195
+ import * as path3 from "path";
153
196
  var regex = new RegExp("^---type-table---\\r?\\n(?<file>.+?)(?:#(?<name>.+))?\\r?\\n---end---$", "gm");
154
197
  var defaultTemplates = {
155
198
  block: (doc, c) => `### ${doc.name}
@@ -176,7 +219,7 @@ function generateMDX(generator, source, _a = {}) {
176
219
  const templates = __spreadValues(__spreadValues({}, defaultTemplates), overrides);
177
220
  return source.replace(regex, (...args) => {
178
221
  const groups = args[args.length - 1];
179
- const file = path.resolve(basePath, groups.file);
222
+ const file = path3.resolve(basePath, groups.file);
180
223
  const docs = generator.generateDocumentation(
181
224
  { path: file },
182
225
  groups.name,
@@ -192,21 +235,21 @@ function replaceJsDocLinks(md) {
192
235
  }
193
236
 
194
237
  // src/lib/file.ts
195
- import * as path2 from "node:path";
196
- import { mkdir, writeFile, readFile as readFile2 } from "node:fs/promises";
197
- import fg from "fast-glob";
238
+ import * as path4 from "path";
239
+ import { mkdir, writeFile, readFile as readFile2 } from "fs/promises";
240
+ import { glob } from "tinyglobby";
198
241
  function generateFiles(generator, options) {
199
242
  return __async(this, null, function* () {
200
- const files = yield fg(options.input, options.globOptions);
201
- const produce = files.map((file) => __async(this, null, function* () {
202
- const absolutePath = path2.resolve(file);
203
- const outputPath = typeof options.output === "function" ? options.output(file) : path2.resolve(
243
+ const files = yield glob(options.input, options.globOptions);
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(
204
247
  options.output,
205
- `${path2.basename(file, path2.extname(file))}.mdx`
248
+ `${path4.basename(file, path4.extname(file))}.mdx`
206
249
  );
207
250
  const content = (yield readFile2(absolutePath)).toString();
208
251
  let result = generateMDX(generator, content, __spreadValues({
209
- basePath: path2.dirname(absolutePath)
252
+ basePath: path4.dirname(absolutePath)
210
253
  }, options.options));
211
254
  if (options.transformOutput) {
212
255
  result = options.transformOutput(outputPath, result);
@@ -219,7 +262,7 @@ function generateFiles(generator, options) {
219
262
  }
220
263
  function write(file, content) {
221
264
  return __async(this, null, function* () {
222
- yield mkdir(path2.dirname(file), { recursive: true });
265
+ yield mkdir(path4.dirname(file), { recursive: true });
223
266
  yield writeFile(file, content);
224
267
  });
225
268
  }
@@ -228,7 +271,7 @@ function write(file, content) {
228
271
  import { valueToEstree } from "estree-util-value-to-estree";
229
272
  import { visit } from "unist-util-visit";
230
273
  import { toEstree } from "hast-util-to-estree";
231
- import { dirname as dirname2 } from "node:path";
274
+ import { dirname as dirname2 } from "path";
232
275
  function mapProperty(entry, renderMarkdown) {
233
276
  return __async(this, null, function* () {
234
277
  const value = valueToEstree({
@@ -259,8 +302,8 @@ function mapProperty(entry, renderMarkdown) {
259
302
  shorthand: false,
260
303
  computed: false,
261
304
  key: {
262
- type: "Identifier",
263
- name: entry.name
305
+ type: "Literal",
306
+ value: entry.name
264
307
  },
265
308
  kind: "init",
266
309
  value
@@ -275,7 +318,7 @@ function remarkAutoTypeTable({
275
318
  remarkStringify = true,
276
319
  generator = createGenerator()
277
320
  } = {}) {
278
- return (tree, file) => __async(this, null, function* () {
321
+ return (tree, file) => __async(null, null, function* () {
279
322
  const queue = [];
280
323
  let basePath = options == null ? void 0 : options.basePath;
281
324
  if (!basePath && file.path) basePath = dirname2(file.path);
@@ -297,7 +340,7 @@ function remarkAutoTypeTable({
297
340
  basePath
298
341
  })
299
342
  );
300
- const rendered = output.map((doc) => __async(this, null, function* () {
343
+ const rendered = output.map((doc) => __async(null, null, function* () {
301
344
  const properties = yield Promise.all(
302
345
  doc.entries.map((entry) => mapProperty(entry, renderMarkdown))
303
346
  );
@@ -347,10 +390,10 @@ function remarkAutoTypeTable({
347
390
  }
348
391
  export {
349
392
  createGenerator,
393
+ createProject,
350
394
  generateDocumentation,
351
395
  generateFiles,
352
396
  generateMDX,
353
- getProject,
354
397
  remarkAutoTypeTable,
355
398
  renderMarkdownToHast
356
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-Xy2dq1Yw.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,9 +25,9 @@ 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
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-typescript",
3
- "version": "4.0.3",
3
+ "version": "4.0.5",
4
4
  "description": "Typescript Integration for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -28,14 +28,14 @@
28
28
  "dist/*"
29
29
  ],
30
30
  "dependencies": {
31
- "estree-util-value-to-estree": "^3.3.3",
32
- "fast-glob": "^3.3.3",
31
+ "estree-util-value-to-estree": "^3.4.0",
33
32
  "hast-util-to-estree": "^3.1.3",
34
33
  "hast-util-to-jsx-runtime": "^2.3.6",
35
34
  "remark": "^15.0.1",
36
35
  "remark-rehype": "^11.1.2",
37
- "shiki": "^3.3.0",
38
- "ts-morph": "^25.0.1",
36
+ "shiki": "^3.4.2",
37
+ "tinyglobby": "^0.2.13",
38
+ "ts-morph": "^26.0.0",
39
39
  "unist-util-visit": "^5.0.0"
40
40
  },
41
41
  "devDependencies": {
@@ -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.1",
47
- "@types/react": "19.1.2",
48
- "@types/react-dom": "19.1.2",
46
+ "@types/node": "22.15.19",
47
+ "@types/react": "19.1.4",
48
+ "@types/react-dom": "19.1.5",
49
49
  "typescript": "^5.8.3",
50
50
  "unified": "^11.0.5",
51
51
  "eslint-config-custom": "0.0.0",
52
- "fumadocs-core": "15.2.10",
53
- "fumadocs-ui": "15.2.10",
52
+ "fumadocs-ui": "15.3.4",
53
+ "fumadocs-core": "15.3.4",
54
54
  "tsconfig": "0.0.0"
55
55
  },
56
56
  "peerDependencies": {