fumadocs-typescript 2.0.0 → 2.1.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.
@@ -10,6 +10,7 @@ interface TypescriptConfig {
10
10
  */
11
11
  getDefaultLibLocation?: (() => string) | 'default';
12
12
  }
13
+ declare function getProgram(options?: TypescriptConfig): ts.Program;
13
14
 
14
15
  interface GeneratedDoc {
15
16
  name: string;
@@ -46,7 +47,9 @@ interface GenerateDocumentationOptions extends GenerateOptions {
46
47
  /**
47
48
  * Typescript configurations
48
49
  */
49
- config?: TypescriptConfig;
50
+ config?: TypescriptConfig | {
51
+ program: ts.Program;
52
+ };
50
53
  }
51
54
  /**
52
55
  * Generate documentation for properties in an exported type/interface
@@ -54,4 +57,4 @@ interface GenerateDocumentationOptions extends GenerateOptions {
54
57
  declare function generateDocumentation(file: string, name: string, options?: GenerateDocumentationOptions): GeneratedDoc | undefined;
55
58
  declare function generate(program: ts.Program, symbol: ts.Symbol, { allowInternal, transform }: GenerateOptions): GeneratedDoc;
56
59
 
57
- export { type DocEntry as D, type GenerateOptions as G, type TypescriptConfig as T, type GeneratedDoc as a, type GenerateDocumentationOptions as b, generate as c, generateDocumentation as g };
60
+ export { type DocEntry as D, type GenerateOptions as G, type TypescriptConfig as T, type GeneratedDoc as a, type GenerateDocumentationOptions as b, generateDocumentation as c, generate as d, getProgram as g };
@@ -47,26 +47,17 @@ var __async = (__this, __arguments, generator) => {
47
47
  });
48
48
  };
49
49
 
50
- // src/generate/base.ts
51
- import ts2 from "typescript";
52
-
53
50
  // src/program.ts
54
51
  import * as path from "path";
55
52
  import ts from "typescript";
56
- var cache = /* @__PURE__ */ new Map();
57
53
  function getFileSymbol(file, program) {
58
54
  const checker = program.getTypeChecker();
59
55
  const sourceFile = program.getSourceFile(file);
60
- if (!sourceFile)
61
- return;
56
+ if (!sourceFile) return;
62
57
  return checker.getSymbolAtLocation(sourceFile);
63
58
  }
64
59
  function getProgram(options = {}) {
65
60
  var _a, _b, _c, _d;
66
- const key = JSON.stringify(options);
67
- const cached = cache.get(key);
68
- if (cached)
69
- return cached;
70
61
  const configFile = ts.readJsonConfigFile(
71
62
  (_a = options.tsconfigPath) != null ? _a : "./tsconfig.json",
72
63
  (p) => ts.sys.readFile(p)
@@ -81,26 +72,23 @@ function getProgram(options = {}) {
81
72
  if (options.getDefaultLibLocation !== "default") {
82
73
  host.getDefaultLibLocation = (_c = options.getDefaultLibLocation) != null ? _c : () => path.resolve("./node_modules/typescript/lib");
83
74
  }
84
- const program = ts.createProgram({
75
+ return ts.createProgram({
85
76
  rootNames: (_d = options.files) != null ? _d : parsed.fileNames,
86
77
  host,
87
78
  options: parsed.options,
88
79
  configFileParsingDiagnostics: parsed.errors,
89
80
  projectReferences: parsed.projectReferences
90
81
  });
91
- cache.set(key, program);
92
- return program;
93
82
  }
94
83
 
95
84
  // src/generate/base.ts
85
+ import ts2 from "typescript";
96
86
  function generateDocumentation(file, name, options = {}) {
97
- const program = getProgram(options.config);
87
+ const program = options.config && "program" in options.config ? options.config.program : getProgram(options.config);
98
88
  const fileSymbol = getFileSymbol(file, program);
99
- if (!fileSymbol)
100
- return;
89
+ if (!fileSymbol) return;
101
90
  const symbol = program.getTypeChecker().getExportsOfModule(fileSymbol).find((e) => e.getEscapedName().toString() === name);
102
- if (!symbol)
103
- return;
91
+ if (!symbol) return;
104
92
  return generate(program, symbol, options);
105
93
  }
106
94
  function generate(program, symbol, { allowInternal = false, transform }) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { G as GenerateOptions, T as TypescriptConfig, a as GeneratedDoc, D as DocEntry } from './base-3iGxlbJG.js';
2
- export { b as GenerateDocumentationOptions, c as generate, g as generateDocumentation } from './base-3iGxlbJG.js';
1
+ import { G as GenerateOptions, T as TypescriptConfig, a as GeneratedDoc, D as DocEntry } from './base-CqMIWAcs.js';
2
+ export { b as GenerateDocumentationOptions, d as generate, c as generateDocumentation, g as getProgram } from './base-CqMIWAcs.js';
3
3
  import fg from 'fast-glob';
4
4
  import { Nodes } from 'hast';
5
5
  import 'typescript';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  getFileSymbol,
8
8
  getProgram,
9
9
  renderMarkdownToHast
10
- } from "./chunk-ESYFMJFA.js";
10
+ } from "./chunk-HGR3BUTN.js";
11
11
 
12
12
  // src/generate/mdx.ts
13
13
  import * as path from "path";
@@ -18,11 +18,11 @@ var defaultTemplates = {
18
18
  ${doc.description}
19
19
 
20
20
  <div className='*:border-b [&>*:last-child]:border-b-0'>${c}</div>`,
21
- property: (c) => `<div className='text-sm text-muted-foreground py-4'>
21
+ property: (c) => `<div className='text-sm text-fd-muted-foreground py-4'>
22
22
 
23
23
  <div className="flex flex-row items-center gap-4">
24
24
  <code className="text-sm">${c.name}</code>
25
- <code className="text-muted-foreground">{${JSON.stringify(c.type)}}</code>
25
+ <code className="text-fd-muted-foreground">{${JSON.stringify(c.type)}}</code>
26
26
  </div>
27
27
 
28
28
  ${c.description || "No Description"}
@@ -48,15 +48,13 @@ function generateMDX(source, _a = {}) {
48
48
  const groups = args[args.length - 1];
49
49
  const file = path.resolve(basePath, groups.file);
50
50
  const fileSymbol = getFileSymbol(file, program);
51
- if (!fileSymbol)
52
- throw new Error(`${file} doesn't exist`);
51
+ if (!fileSymbol) throw new Error(`${file} doesn't exist`);
53
52
  let docs;
54
53
  if (!groups.name) {
55
54
  docs = program.getTypeChecker().getExportsOfModule(fileSymbol).map((symbol) => generate(program, symbol, rest));
56
55
  } else {
57
56
  const symbol = program.getTypeChecker().getExportsOfModule(fileSymbol).find((s) => s.getEscapedName().toString() === groups.name);
58
- if (!symbol)
59
- throw new Error(`Type ${groups.name} doesn't exist`);
57
+ if (!symbol) throw new Error(`Type ${groups.name} doesn't exist`);
60
58
  docs = [generate(program, symbol, rest)];
61
59
  }
62
60
  return docs.map(
@@ -105,5 +103,6 @@ export {
105
103
  generateDocumentation,
106
104
  generateFiles,
107
105
  generateMDX,
106
+ getProgram,
108
107
  renderMarkdownToHast
109
108
  };
@@ -1,4 +1,4 @@
1
- import { G as GenerateOptions } from '../base-3iGxlbJG.js';
1
+ import { G as GenerateOptions } from '../base-CqMIWAcs.js';
2
2
  import 'typescript';
3
3
 
4
4
  /**
package/dist/ui/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  generateDocumentation,
3
3
  renderMarkdownToHast
4
- } from "../chunk-ESYFMJFA.js";
4
+ } from "../chunk-HGR3BUTN.js";
5
5
 
6
6
  // src/ui/auto-type-table.tsx
7
7
  import { TypeTable } from "fumadocs-ui/components/type-table";
@@ -15,8 +15,7 @@ function AutoTypeTable({
15
15
  options
16
16
  }) {
17
17
  const output = generateDocumentation(path, name, options);
18
- if (!output)
19
- throw new Error(`${name} in ${path} doesn't exist`);
18
+ if (!output) throw new Error(`${name} in ${path} doesn't exist`);
20
19
  return /* @__PURE__ */ jsx2(
21
20
  TypeTable,
22
21
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-typescript",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Typescript Integration for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -37,18 +37,19 @@
37
37
  "dependencies": {
38
38
  "fast-glob": "^3.3.1",
39
39
  "hast-util-to-jsx-runtime": "^2.3.0",
40
- "mdast-util-from-markdown": "^2.0.0",
40
+ "mdast-util-from-markdown": "^2.0.1",
41
41
  "mdast-util-gfm": "^3.0.0",
42
- "mdast-util-to-hast": "^13.1.0"
42
+ "mdast-util-to-hast": "^13.2.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/estree": "^1.0.5",
46
46
  "@types/hast": "^3.0.4",
47
47
  "@types/mdast": "^4.0.3",
48
- "@types/react": "18.2.67",
49
- "@types/react-dom": "18.2.22",
48
+ "@types/react": "18.3.5",
49
+ "@types/react-dom": "18.3.0",
50
+ "typescript": "^5.5.4",
50
51
  "eslint-config-custom": "0.0.0",
51
- "fumadocs-ui": "11.0.0",
52
+ "fumadocs-ui": "13.4.2",
52
53
  "tsconfig": "0.0.0"
53
54
  },
54
55
  "peerDependencies": {