fumadocs-mdx 14.0.0 → 14.0.1

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.
Files changed (67) hide show
  1. package/dist/bin.cjs +270 -201
  2. package/dist/bun/index.cjs +63 -28
  3. package/dist/bun/index.d.cts +7 -1
  4. package/dist/bun/index.d.ts +7 -1
  5. package/dist/bun/index.js +6 -5
  6. package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
  7. package/dist/{chunk-XHJCLBZ4.js → chunk-7UKSZSPY.js} +87 -162
  8. package/dist/{chunk-7L2KNF6B.js → chunk-BEBCWQC7.js} +51 -7
  9. package/dist/{chunk-5UMZCWKV.js → chunk-IQGEFL2B.js} +1 -1
  10. package/dist/{chunk-SRSRFOVI.js → chunk-K6HCOGOX.js} +3 -3
  11. package/dist/{chunk-OXSRIWQW.js → chunk-MTTISKQJ.js} +3 -2
  12. package/dist/chunk-WBIHDYMN.js +126 -0
  13. package/dist/config/index.d.cts +6 -1
  14. package/dist/config/index.d.ts +6 -1
  15. package/dist/{index-D7JdSMpp.d.cts → core-B9ZoS6sA.d.ts} +73 -4
  16. package/dist/{index-D7JdSMpp.d.ts → core-DTuP23zu.d.cts} +73 -4
  17. package/dist/{index-BlVBvy-z.d.ts → index-BD8Woo4m.d.cts} +1 -1
  18. package/dist/{index-P2NNUkHn.d.cts → index-CNOvhtOn.d.ts} +1 -1
  19. package/dist/index.d.cts +56 -3
  20. package/dist/index.d.ts +56 -3
  21. package/dist/{load-from-file-I3ALLIVB.js → load-from-file-5HUQN36V.js} +1 -1
  22. package/dist/next/index.cjs +260 -192
  23. package/dist/next/index.d.cts +7 -2
  24. package/dist/next/index.d.ts +7 -2
  25. package/dist/next/index.js +10 -8
  26. package/dist/node/loader.cjs +72 -37
  27. package/dist/node/loader.js +3 -3
  28. package/dist/plugins/index-file.cjs +69 -45
  29. package/dist/plugins/index-file.d.cts +7 -22
  30. package/dist/plugins/index-file.d.ts +7 -22
  31. package/dist/plugins/index-file.js +2 -2
  32. package/dist/plugins/json-schema.d.cts +7 -1
  33. package/dist/plugins/json-schema.d.ts +7 -1
  34. package/dist/plugins/last-modified.cjs +41 -6
  35. package/dist/plugins/last-modified.d.cts +11 -1
  36. package/dist/plugins/last-modified.d.ts +11 -1
  37. package/dist/plugins/last-modified.js +34 -4
  38. package/dist/runtime/browser.cjs +7 -8
  39. package/dist/runtime/browser.d.cts +22 -19
  40. package/dist/runtime/browser.d.ts +22 -19
  41. package/dist/runtime/browser.js +5 -6
  42. package/dist/runtime/dynamic.cjs +81 -43
  43. package/dist/runtime/dynamic.d.cts +12 -12
  44. package/dist/runtime/dynamic.d.ts +12 -12
  45. package/dist/runtime/dynamic.js +9 -8
  46. package/dist/runtime/server.cjs +9 -6
  47. package/dist/runtime/server.d.cts +10 -157
  48. package/dist/runtime/server.d.ts +10 -157
  49. package/dist/runtime/server.js +3 -3
  50. package/dist/runtime/types.cjs +18 -0
  51. package/dist/runtime/types.d.cts +61 -0
  52. package/dist/runtime/types.d.ts +61 -0
  53. package/dist/runtime/types.js +0 -0
  54. package/dist/vite/index.cjs +257 -190
  55. package/dist/vite/index.d.cts +7 -2
  56. package/dist/vite/index.d.ts +7 -2
  57. package/dist/vite/index.js +7 -6
  58. package/dist/webpack/mdx.cjs +60 -25
  59. package/dist/webpack/mdx.d.cts +8 -2
  60. package/dist/webpack/mdx.d.ts +8 -2
  61. package/dist/webpack/mdx.js +4 -4
  62. package/dist/webpack/meta.cjs +60 -25
  63. package/dist/webpack/meta.d.cts +8 -2
  64. package/dist/webpack/meta.d.ts +8 -2
  65. package/dist/webpack/meta.js +4 -4
  66. package/package.json +2 -2
  67. package/dist/chunk-PKI7ZDA5.js +0 -29
@@ -763,24 +763,7 @@ var import_node_url2 = require("url");
763
763
 
764
764
  // src/core.ts
765
765
  var import_node_path3 = __toESM(require("path"), 1);
766
- var import_promises3 = __toESM(require("fs/promises"), 1);
767
-
768
- // src/utils/codegen/cache.ts
769
- var import_lru_cache = require("lru-cache");
770
766
  var import_promises2 = __toESM(require("fs/promises"), 1);
771
- var import_node_path2 = __toESM(require("path"), 1);
772
- var map = new import_lru_cache.LRUCache({
773
- max: 100
774
- });
775
- function toFullPath(file) {
776
- if (import_node_path2.default.isAbsolute(file)) {
777
- return import_node_path2.default.relative(process.cwd(), file);
778
- }
779
- return file;
780
- }
781
- function removeFileCache(file) {
782
- map.delete(toFullPath(file));
783
- }
784
767
 
785
768
  // src/utils/validation.ts
786
769
  var ValidationError = class extends Error {
@@ -820,6 +803,13 @@ async function validate(schema, data, context, errorMessage) {
820
803
  return data;
821
804
  }
822
805
 
806
+ // src/utils/codegen.ts
807
+ var import_node_path2 = __toESM(require("path"), 1);
808
+ var import_tinyglobby = require("tinyglobby");
809
+ function ident(code, tab = 1) {
810
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
811
+ }
812
+
823
813
  // src/core.ts
824
814
  var _Defaults = {
825
815
  configPath: "source.config.ts",
@@ -853,7 +843,6 @@ function createCore(options, defaultPlugins = []) {
853
843
  return data;
854
844
  }
855
845
  const core = {
856
- _options: options,
857
846
  /**
858
847
  * Convenient cache store, reset when config changes
859
848
  */
@@ -862,6 +851,7 @@ function createCore(options, defaultPlugins = []) {
862
851
  config = await newConfig;
863
852
  this.cache.clear();
864
853
  plugins = await getPlugins([
854
+ postprocessPlugin(),
865
855
  ...defaultPlugins,
866
856
  ...config.global.plugins ?? []
867
857
  ]);
@@ -869,7 +859,9 @@ function createCore(options, defaultPlugins = []) {
869
859
  const out = await plugin.config?.call(pluginContext, config);
870
860
  if (out) config = out;
871
861
  }
872
- return this;
862
+ },
863
+ getOptions() {
864
+ return options;
873
865
  },
874
866
  getConfig() {
875
867
  return config;
@@ -880,10 +872,13 @@ function createCore(options, defaultPlugins = []) {
880
872
  getCompiledConfigPath() {
881
873
  return import_node_path3.default.join(options.outDir, "source.config.mjs");
882
874
  },
875
+ getPlugins() {
876
+ return plugins;
877
+ },
878
+ getPluginContext() {
879
+ return pluginContext;
880
+ },
883
881
  async initServer(server) {
884
- server.watcher?.on("all", async (event, file) => {
885
- if (event === "change") removeFileCache(file);
886
- });
887
882
  for (const plugin of plugins) {
888
883
  await plugin.configureServer?.call(pluginContext, server);
889
884
  }
@@ -902,8 +897,8 @@ function createCore(options, defaultPlugins = []) {
902
897
  await Promise.all(
903
898
  out.map(async (entry) => {
904
899
  const file = import_node_path3.default.join(options.outDir, entry.path);
905
- await import_promises3.default.mkdir(import_node_path3.default.dirname(file), { recursive: true });
906
- await import_promises3.default.writeFile(file, entry.content);
900
+ await import_promises2.default.mkdir(import_node_path3.default.dirname(file), { recursive: true });
901
+ await import_promises2.default.writeFile(file, entry.content);
907
902
  })
908
903
  );
909
904
  console.log(`[MDX] generated files in ${performance.now() - start}ms`);
@@ -950,9 +945,48 @@ function createCore(options, defaultPlugins = []) {
950
945
  };
951
946
  return core;
952
947
  }
948
+ function postprocessPlugin() {
949
+ const LinkReferenceTypes = `{
950
+ /**
951
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
952
+ */
953
+ extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
954
+ }`;
955
+ return {
956
+ "index-file": {
957
+ generateTypeConfig() {
958
+ const lines = [];
959
+ lines.push("{");
960
+ lines.push(" DocData: {");
961
+ for (const collection of this.core.getConfig().collectionList) {
962
+ let postprocessOptions;
963
+ switch (collection.type) {
964
+ case "doc":
965
+ postprocessOptions = collection.postprocess;
966
+ break;
967
+ case "docs":
968
+ postprocessOptions = collection.docs.postprocess;
969
+ break;
970
+ }
971
+ if (postprocessOptions?.extractLinkReferences) {
972
+ lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
973
+ }
974
+ }
975
+ lines.push(" }");
976
+ lines.push("}");
977
+ return lines.join("\n");
978
+ },
979
+ serverOptions(options) {
980
+ options.doc ??= {};
981
+ options.doc.passthroughs ??= [];
982
+ options.doc.passthroughs.push("extractedReferences");
983
+ }
984
+ }
985
+ };
986
+ }
953
987
 
954
988
  // src/loaders/config.ts
955
- var import_promises4 = __toESM(require("fs/promises"), 1);
989
+ var import_promises3 = __toESM(require("fs/promises"), 1);
956
990
  function createIntegratedConfigLoader(core) {
957
991
  return {
958
992
  core,
@@ -1042,7 +1076,7 @@ function createMetaLoader(configLoader, resolve2 = {}) {
1042
1076
 
1043
1077
  // src/loaders/adapter.ts
1044
1078
  var import_node_url = require("url");
1045
- var import_promises5 = __toESM(require("fs/promises"), 1);
1079
+ var import_promises4 = __toESM(require("fs/promises"), 1);
1046
1080
  var import_node_querystring = require("querystring");
1047
1081
  var import_node_path4 = __toESM(require("path"), 1);
1048
1082
  var import_node_fs = require("fs");
@@ -1093,11 +1127,12 @@ function createMdxPlugin(options = {}) {
1093
1127
  name: "bun-plugin-fumadocs-mdx",
1094
1128
  async setup(build) {
1095
1129
  const importPath = (0, import_node_url2.pathToFileURL)(configPath).href;
1096
- const core = await createCore({
1130
+ const core = createCore({
1097
1131
  environment,
1098
1132
  outDir,
1099
1133
  configPath
1100
- }).init({
1134
+ });
1135
+ await core.init({
1101
1136
  config: buildConfig(await import(importPath))
1102
1137
  });
1103
1138
  const configLoader = createIntegratedConfigLoader(core);
@@ -1,5 +1,5 @@
1
1
  import { BunPlugin } from 'bun';
2
- import { C as CoreOptions } from '../index-D7JdSMpp.cjs';
2
+ import { i as CoreOptions } from '../core-DTuP23zu.cjs';
3
3
  import '@mdx-js/mdx';
4
4
  import '@standard-schema/spec';
5
5
  import 'unified';
@@ -7,6 +7,12 @@ import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
9
  import 'vfile';
10
+ import 'fumadocs-core/source';
11
+ import '../runtime/types.cjs';
12
+ import 'fumadocs-core/mdx-plugins/remark-structure';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdast';
15
+ import 'mdx/types';
10
16
 
11
17
  interface MdxPluginOptions extends Partial<CoreOptions> {
12
18
  /**
@@ -1,5 +1,5 @@
1
1
  import { BunPlugin } from 'bun';
2
- import { C as CoreOptions } from '../index-D7JdSMpp.js';
2
+ import { i as CoreOptions } from '../core-B9ZoS6sA.js';
3
3
  import '@mdx-js/mdx';
4
4
  import '@standard-schema/spec';
5
5
  import 'unified';
@@ -7,6 +7,12 @@ import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
9
  import 'vfile';
10
+ import 'fumadocs-core/source';
11
+ import '../runtime/types.js';
12
+ import 'fumadocs-core/mdx-plugins/remark-structure';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdast';
15
+ import 'mdx/types';
10
16
 
11
17
  interface MdxPluginOptions extends Partial<CoreOptions> {
12
18
  /**
package/dist/bun/index.js CHANGED
@@ -11,13 +11,13 @@ import {
11
11
  import {
12
12
  createIntegratedConfigLoader,
13
13
  toBun
14
- } from "../chunk-SRSRFOVI.js";
14
+ } from "../chunk-K6HCOGOX.js";
15
15
  import "../chunk-4JSFLXXT.js";
16
16
  import {
17
17
  _Defaults,
18
18
  createCore
19
- } from "../chunk-7L2KNF6B.js";
20
- import "../chunk-PKI7ZDA5.js";
19
+ } from "../chunk-BEBCWQC7.js";
20
+ import "../chunk-WBIHDYMN.js";
21
21
  import "../chunk-VWJKRQZR.js";
22
22
 
23
23
  // src/bun/index.ts
@@ -33,11 +33,12 @@ function createMdxPlugin(options = {}) {
33
33
  name: "bun-plugin-fumadocs-mdx",
34
34
  async setup(build) {
35
35
  const importPath = pathToFileURL(configPath).href;
36
- const core = await createCore({
36
+ const core = createCore({
37
37
  environment,
38
38
  outDir,
39
39
  configPath
40
- }).init({
40
+ });
41
+ await core.init({
41
42
  config: buildConfig(await import(importPath))
42
43
  });
43
44
  const configLoader = createIntegratedConfigLoader(core);
@@ -1,6 +1,7 @@
1
1
  // src/runtime/server.ts
2
2
  import * as path from "path";
3
- function fromConfig() {
3
+ function server(options = {}) {
4
+ const { doc: { passthroughs: docPassthroughs = [] } = {} } = options;
4
5
  function fileInfo(file, base) {
5
6
  if (file.startsWith("./")) {
6
7
  file = file.slice(2);
@@ -11,14 +12,16 @@ function fromConfig() {
11
12
  };
12
13
  }
13
14
  function mapDocData(entry) {
14
- return {
15
+ const data = {
15
16
  body: entry.default,
16
17
  toc: entry.toc,
17
- extractedReferences: entry.extractedReferences,
18
18
  structuredData: entry.structuredData,
19
- lastModified: entry.lastModified,
20
19
  _exports: entry
21
20
  };
21
+ for (const key of docPassthroughs) {
22
+ data[key] = entry[key];
23
+ }
24
+ return data;
22
25
  }
23
26
  return {
24
27
  async doc(_name, base, glob) {
@@ -133,6 +136,6 @@ function createDocMethods(info, load) {
133
136
  }
134
137
 
135
138
  export {
136
- fromConfig,
139
+ server,
137
140
  toFumadocsSource
138
141
  };
@@ -1,137 +1,41 @@
1
1
  import {
2
- readFileWithCache
3
- } from "./chunk-PKI7ZDA5.js";
2
+ createCodegen,
3
+ ident
4
+ } from "./chunk-WBIHDYMN.js";
4
5
  import {
5
6
  fumaMatter
6
7
  } from "./chunk-VWJKRQZR.js";
7
8
 
8
9
  // src/plugins/index-file.ts
9
10
  import path2 from "path";
11
+ import { glob } from "tinyglobby";
10
12
 
11
- // src/utils/codegen/index.ts
13
+ // src/utils/fs-cache.ts
14
+ import { LRUCache } from "lru-cache";
15
+ import fs from "fs/promises";
12
16
  import path from "path";
13
- import { glob } from "tinyglobby";
14
- function createCodegen({
15
- target = "default",
16
- outDir = "",
17
- jsExtension = false,
18
- globCache = /* @__PURE__ */ new Map()
19
- }) {
20
- let eagerImportId = 0;
21
- const banner = ["// @ts-nocheck"];
22
- if (target === "vite") {
23
- banner.push('/// <reference types="vite/client" />');
17
+ var map = new LRUCache({
18
+ max: 100
19
+ });
20
+ function toFullPath(file) {
21
+ if (path.isAbsolute(file)) {
22
+ return path.relative(process.cwd(), file);
24
23
  }
25
- return {
26
- options: {
27
- target,
28
- outDir
29
- },
30
- lines: [],
31
- addImport(statement) {
32
- this.lines.unshift(statement);
33
- },
34
- async pushAsync(insert) {
35
- for (const line of await Promise.all(insert)) {
36
- if (line === void 0) continue;
37
- this.lines.push(line);
38
- }
39
- },
40
- async generateGlobImport(patterns, options) {
41
- if (target === "vite") {
42
- return this.generateViteGlobImport(patterns, options);
43
- }
44
- return this.generateNodeGlobImport(patterns, options);
45
- },
46
- generateViteGlobImport(patterns, { base, ...rest }) {
47
- patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
48
- normalizeViteGlobPath
49
- );
50
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
51
- {
52
- base: normalizeViteGlobPath(path.relative(outDir, base)),
53
- ...rest
54
- },
55
- null,
56
- 2
57
- )})`;
58
- },
59
- async generateNodeGlobImport(patterns, {
60
- base,
61
- eager = false,
62
- query = {},
63
- import: importName
64
- }) {
65
- const cacheKey = JSON.stringify({ patterns, base });
66
- let files = globCache.get(cacheKey);
67
- if (!files) {
68
- files = glob(patterns, {
69
- cwd: base
70
- });
71
- globCache.set(cacheKey, files);
72
- }
73
- let code = "{";
74
- for (const item of await files) {
75
- const fullPath = path.join(base, item);
76
- const searchParams = new URLSearchParams();
77
- for (const [k, v] of Object.entries(query)) {
78
- searchParams.set(k, v);
79
- }
80
- const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
81
- if (eager) {
82
- const name = `__fd_glob_${eagerImportId++}`;
83
- this.lines.unshift(
84
- importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
85
- );
86
- code += `${JSON.stringify(item)}: ${name}, `;
87
- } else {
88
- let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
89
- if (importName) {
90
- line += `.then(mod => mod.${importName})`;
91
- }
92
- code += `${line}, `;
93
- }
94
- }
95
- code += "}";
96
- return code;
97
- },
98
- formatImportPath(file) {
99
- const ext = path.extname(file);
100
- let filename;
101
- if (ext === ".ts" && jsExtension) {
102
- filename = file.substring(0, file.length - ext.length) + ".js";
103
- } else if (ext === ".ts") {
104
- filename = file.substring(0, file.length - ext.length);
105
- } else {
106
- filename = file;
107
- }
108
- const importPath = slash(path.relative(outDir, filename));
109
- return importPath.startsWith(".") ? importPath : `./${importPath}`;
110
- },
111
- toString() {
112
- return [...banner, ...this.lines].join("\n");
113
- }
114
- };
24
+ return file;
115
25
  }
116
- function normalizeViteGlobPath(file) {
117
- file = slash(file);
118
- if (file.startsWith("./")) return file;
119
- if (file.startsWith("/")) return `.${file}`;
120
- return `./${file}`;
26
+ function readFileWithCache(file) {
27
+ const fullPath = toFullPath(file);
28
+ const cached = map.get(fullPath);
29
+ if (cached) return cached;
30
+ const read = fs.readFile(fullPath).then((s) => s.toString());
31
+ map.set(fullPath, read);
32
+ return read;
121
33
  }
122
- function slash(path3) {
123
- const isExtendedLengthPath = path3.startsWith("\\\\?\\");
124
- if (isExtendedLengthPath) {
125
- return path3;
126
- }
127
- return path3.replaceAll("\\", "/");
128
- }
129
- function ident(code, tab = 1) {
130
- return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
34
+ function removeFileCache(file) {
35
+ map.delete(toFullPath(file));
131
36
  }
132
37
 
133
38
  // src/plugins/index-file.ts
134
- import { glob as glob2 } from "tinyglobby";
135
39
  import { createHash } from "crypto";
136
40
  function indexFile(options = {}) {
137
41
  const {
@@ -145,6 +49,25 @@ function indexFile(options = {}) {
145
49
  function isDynamic(collection) {
146
50
  return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
147
51
  }
52
+ function generateConfigs(core) {
53
+ const serverOptions = {};
54
+ const typeConfigs = [];
55
+ const ctx = core.getPluginContext();
56
+ for (const plugin of core.getPlugins()) {
57
+ const indexFilePlugin = plugin["index-file"];
58
+ if (!indexFilePlugin) continue;
59
+ indexFilePlugin.serverOptions?.call(ctx, serverOptions);
60
+ const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
61
+ if (config2) typeConfigs.push(config2);
62
+ }
63
+ if (typeConfigs.length === 0) {
64
+ typeConfigs.push("{ DocData: {} }");
65
+ }
66
+ return {
67
+ serverOptions,
68
+ tc: typeConfigs.join(" & ")
69
+ };
70
+ }
148
71
  return {
149
72
  name: "index-file",
150
73
  config(v) {
@@ -154,6 +77,7 @@ function indexFile(options = {}) {
154
77
  configureServer(server) {
155
78
  if (!server.watcher) return;
156
79
  server.watcher.on("all", async (event, file) => {
80
+ removeFileCache(file);
157
81
  if (dynamicCollections.length === 0) {
158
82
  if (target === "vite") return;
159
83
  if (target === "default" && event === "change") return;
@@ -173,48 +97,47 @@ function indexFile(options = {}) {
173
97
  },
174
98
  async emit() {
175
99
  const globCache = /* @__PURE__ */ new Map();
176
- const makeCodeGen = () => createCodegen({
177
- target,
178
- outDir: this.outDir,
179
- jsExtension: addJsExtension,
180
- globCache
181
- });
182
- async function toEmitEntry(path3, content) {
100
+ const { serverOptions, tc } = generateConfigs(this.core);
101
+ const toEmitEntry = async (path3, content) => {
102
+ const codegen = createCodegen({
103
+ target,
104
+ outDir: this.outDir,
105
+ jsExtension: addJsExtension,
106
+ globCache
107
+ });
108
+ await content({
109
+ core: this.core,
110
+ codegen,
111
+ serverOptions,
112
+ tc
113
+ });
183
114
  return {
184
115
  path: path3,
185
- content: await content
116
+ content: codegen.toString()
186
117
  };
187
- }
118
+ };
188
119
  const out = [
189
- toEmitEntry(
190
- "server.ts",
191
- generateServerIndexFile(makeCodeGen(), config, this.configPath)
192
- )
120
+ toEmitEntry("server.ts", generateServerIndexFile)
193
121
  ];
194
122
  if (dynamic)
195
- out.push(
196
- toEmitEntry(
197
- "dynamic.ts",
198
- generateDynamicIndexFile(this.core, makeCodeGen())
199
- )
200
- );
123
+ out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
201
124
  if (browser)
202
- out.push(
203
- toEmitEntry(
204
- "browser.ts",
205
- generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
206
- )
207
- );
125
+ out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
208
126
  return await Promise.all(out);
209
127
  }
210
128
  };
211
129
  }
212
- async function generateServerIndexFile(codegen, config, configPath) {
130
+ async function generateServerIndexFile({
131
+ core,
132
+ codegen,
133
+ serverOptions,
134
+ tc
135
+ }) {
213
136
  codegen.lines.push(
214
- `import { fromConfig } from 'fumadocs-mdx/runtime/server';`,
215
- `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
137
+ `import { server } from 'fumadocs-mdx/runtime/server';`,
138
+ `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
216
139
  "",
217
- `const create = fromConfig<typeof Config>();`
140
+ `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
218
141
  );
219
142
  async function generateCollectionObject(collection) {
220
143
  switch (collection.type) {
@@ -261,22 +184,26 @@ async function generateServerIndexFile(codegen, config, configPath) {
261
184
  }
262
185
  }
263
186
  await codegen.pushAsync(
264
- config.collectionList.map(async (collection) => {
187
+ core.getConfig().collectionList.map(async (collection) => {
265
188
  const obj = await generateCollectionObject(collection);
266
189
  if (!obj) return;
267
190
  return `
268
191
  export const ${collection.name} = ${obj};`;
269
192
  })
270
193
  );
271
- return codegen.toString();
272
194
  }
273
- async function generateDynamicIndexFile(core, codegen) {
274
- const { configPath } = core._options;
195
+ async function generateDynamicIndexFile({
196
+ core,
197
+ codegen,
198
+ serverOptions,
199
+ tc
200
+ }) {
201
+ const { configPath } = core.getOptions();
275
202
  codegen.lines.push(
276
- `import { fromConfigDynamic } from 'fumadocs-mdx/runtime/dynamic';`,
203
+ `import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
277
204
  `import * as Config from '${codegen.formatImportPath(configPath)}';`,
278
205
  "",
279
- `const create = await fromConfigDynamic(Config);`
206
+ `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
280
207
  );
281
208
  async function generateCollectionObjectEntry(collection, file) {
282
209
  const fullPath = path2.join(collection.dir, file);
@@ -312,7 +239,7 @@ async function generateDynamicIndexFile(core, codegen) {
312
239
  if (parent.type === "doc") collection = parent;
313
240
  else if (parent.type === "docs") collection = parent.docs;
314
241
  if (!collection || !collection.dynamic) return;
315
- const files = await glob2(collection.patterns, {
242
+ const files = await glob(collection.patterns, {
316
243
  cwd: collection.dir
317
244
  });
318
245
  const entries = await Promise.all(
@@ -339,14 +266,13 @@ async function generateDynamicIndexFile(core, codegen) {
339
266
  export const ${collection.name} = ${obj};`;
340
267
  })
341
268
  );
342
- return codegen.toString();
343
269
  }
344
- async function generateBrowserIndexFile(codegen, config, configPath) {
270
+ async function generateBrowserIndexFile({ core, codegen, tc }) {
345
271
  codegen.lines.push(
346
- `import { fromConfig } from 'fumadocs-mdx/runtime/browser';`,
347
- `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
272
+ `import { browser } from 'fumadocs-mdx/runtime/browser';`,
273
+ `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
348
274
  "",
349
- `const create = fromConfig<typeof Config>();`
275
+ `const create = browser<typeof Config, ${tc}>();`
350
276
  );
351
277
  async function generateCollectionObject(collection) {
352
278
  switch (collection.type) {
@@ -361,14 +287,13 @@ async function generateBrowserIndexFile(codegen, config, configPath) {
361
287
  }
362
288
  codegen.lines.push("const browserCollections = {");
363
289
  await codegen.pushAsync(
364
- config.collectionList.map(async (collection) => {
290
+ core.getConfig().collectionList.map(async (collection) => {
365
291
  const obj = await generateCollectionObject(collection);
366
292
  if (!obj) return;
367
293
  return ident(`${collection.name}: ${obj},`);
368
294
  })
369
295
  );
370
296
  codegen.lines.push("};", "export default browserCollections;");
371
- return codegen.toString();
372
297
  }
373
298
  function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
374
299
  return codegen.generateGlobImport(collection.patterns, {