fumadocs-mdx 14.0.0 → 14.0.2

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 (77) hide show
  1. package/dist/{build-mdx-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
  2. package/dist/bun/index.d.ts +7 -1
  3. package/dist/bun/index.js +9 -8
  4. package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
  5. package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
  6. package/dist/{chunk-XHJCLBZ4.js → chunk-ED3ON275.js} +86 -162
  7. package/dist/{chunk-7L2KNF6B.js → chunk-GB4W3YCZ.js} +51 -7
  8. package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
  9. package/dist/{chunk-OXSRIWQW.js → chunk-LPX7ZO66.js} +4 -3
  10. package/dist/{chunk-SRSRFOVI.js → chunk-OLL7FM7W.js} +3 -3
  11. package/dist/{chunk-5UMZCWKV.js → chunk-Q5OSGLJL.js} +1 -1
  12. package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
  13. package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
  14. package/dist/chunk-WBIHDYMN.js +126 -0
  15. package/dist/config/index.d.ts +6 -1
  16. package/dist/config/index.js +1 -1
  17. package/dist/{index-D7JdSMpp.d.cts → core-C3QZSdEx.d.ts} +73 -4
  18. package/dist/{index-BlVBvy-z.d.ts → index-RVIZxMZG.d.ts} +1 -1
  19. package/dist/index.d.ts +56 -3
  20. package/dist/load-from-file-OZ5N7DXU.js +8 -0
  21. package/dist/next/index.cjs +263 -193
  22. package/dist/next/index.d.ts +7 -2
  23. package/dist/next/index.js +12 -10
  24. package/dist/node/loader.js +4 -4
  25. package/dist/plugins/index-file.d.ts +7 -22
  26. package/dist/plugins/index-file.js +2 -2
  27. package/dist/plugins/json-schema.d.ts +7 -1
  28. package/dist/plugins/last-modified.d.ts +15 -2
  29. package/dist/plugins/last-modified.js +43 -6
  30. package/dist/runtime/browser.d.ts +22 -19
  31. package/dist/runtime/browser.js +5 -6
  32. package/dist/runtime/dynamic.d.ts +12 -12
  33. package/dist/runtime/dynamic.js +12 -11
  34. package/dist/runtime/server.d.ts +10 -157
  35. package/dist/runtime/server.js +3 -3
  36. package/dist/runtime/types.d.ts +61 -0
  37. package/dist/runtime/types.js +0 -0
  38. package/dist/vite/index.d.ts +7 -2
  39. package/dist/vite/index.js +10 -9
  40. package/dist/webpack/mdx.d.ts +8 -2
  41. package/dist/webpack/mdx.js +5 -5
  42. package/dist/webpack/meta.d.ts +8 -2
  43. package/dist/webpack/meta.js +4 -4
  44. package/package.json +4 -6
  45. package/dist/bin.cjs +0 -1889
  46. package/dist/bin.d.cts +0 -1
  47. package/dist/bun/index.cjs +0 -1112
  48. package/dist/bun/index.d.cts +0 -19
  49. package/dist/chunk-PKI7ZDA5.js +0 -29
  50. package/dist/config/index.cjs +0 -400
  51. package/dist/config/index.d.cts +0 -13
  52. package/dist/index-D7JdSMpp.d.ts +0 -272
  53. package/dist/index-P2NNUkHn.d.cts +0 -8
  54. package/dist/index.cjs +0 -18
  55. package/dist/index.d.cts +0 -8
  56. package/dist/load-from-file-I3ALLIVB.js +0 -8
  57. package/dist/next/index.d.cts +0 -28
  58. package/dist/node/loader.cjs +0 -1165
  59. package/dist/node/loader.d.cts +0 -5
  60. package/dist/plugins/index-file.cjs +0 -471
  61. package/dist/plugins/index-file.d.cts +0 -29
  62. package/dist/plugins/json-schema.cjs +0 -114
  63. package/dist/plugins/json-schema.d.cts +0 -25
  64. package/dist/plugins/last-modified.cjs +0 -75
  65. package/dist/plugins/last-modified.d.cts +0 -27
  66. package/dist/runtime/browser.cjs +0 -94
  67. package/dist/runtime/browser.d.cts +0 -50
  68. package/dist/runtime/dynamic.cjs +0 -985
  69. package/dist/runtime/dynamic.d.cts +0 -27
  70. package/dist/runtime/server.cjs +0 -173
  71. package/dist/runtime/server.d.cts +0 -161
  72. package/dist/vite/index.cjs +0 -1620
  73. package/dist/vite/index.d.cts +0 -39
  74. package/dist/webpack/mdx.cjs +0 -1089
  75. package/dist/webpack/mdx.d.cts +0 -14
  76. package/dist/webpack/meta.cjs +0 -649
  77. package/dist/webpack/meta.d.cts +0 -14
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildMDX
3
- } from "./chunk-SLY7WXTX.js";
3
+ } from "./chunk-KOPLIEVQ.js";
4
4
  import "./chunk-FBLMK4RS.js";
5
5
  import "./chunk-VWJKRQZR.js";
6
6
  export {
@@ -1,5 +1,5 @@
1
1
  import { BunPlugin } from 'bun';
2
- import { C as CoreOptions } from '../index-D7JdSMpp.js';
2
+ import { C as CoreOptions } from '../core-C3QZSdEx.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
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  buildConfig
3
- } from "../chunk-ZY6UZ7NH.js";
4
- import "../chunk-E5DJTSIM.js";
3
+ } from "../chunk-6RPNS75C.js";
4
+ import "../chunk-S7KOJHHO.js";
5
5
  import {
6
6
  createMdxLoader
7
- } from "../chunk-6NISOLQ6.js";
7
+ } from "../chunk-USWQVJWR.js";
8
8
  import {
9
9
  createMetaLoader
10
10
  } from "../chunk-TYJDYTKH.js";
11
11
  import {
12
12
  createIntegratedConfigLoader,
13
13
  toBun
14
- } from "../chunk-SRSRFOVI.js";
14
+ } from "../chunk-OLL7FM7W.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-GB4W3YCZ.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,6 +1,6 @@
1
1
  import {
2
2
  applyMdxPreset
3
- } from "./chunk-E5DJTSIM.js";
3
+ } from "./chunk-S7KOJHHO.js";
4
4
 
5
5
  // src/config/build.ts
6
6
  import picomatch from "picomatch";
@@ -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,24 @@ 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
+ 'import("fumadocs-mdx/runtime/types").InternalTypeConfig'
56
+ ];
57
+ const ctx = core.getPluginContext();
58
+ for (const plugin of core.getPlugins()) {
59
+ const indexFilePlugin = plugin["index-file"];
60
+ if (!indexFilePlugin) continue;
61
+ indexFilePlugin.serverOptions?.call(ctx, serverOptions);
62
+ const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
63
+ if (config2) typeConfigs.push(config2);
64
+ }
65
+ return {
66
+ serverOptions,
67
+ tc: typeConfigs.join(" & ")
68
+ };
69
+ }
148
70
  return {
149
71
  name: "index-file",
150
72
  config(v) {
@@ -154,6 +76,7 @@ function indexFile(options = {}) {
154
76
  configureServer(server) {
155
77
  if (!server.watcher) return;
156
78
  server.watcher.on("all", async (event, file) => {
79
+ removeFileCache(file);
157
80
  if (dynamicCollections.length === 0) {
158
81
  if (target === "vite") return;
159
82
  if (target === "default" && event === "change") return;
@@ -173,48 +96,47 @@ function indexFile(options = {}) {
173
96
  },
174
97
  async emit() {
175
98
  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) {
99
+ const { serverOptions, tc } = generateConfigs(this.core);
100
+ const toEmitEntry = async (path3, content) => {
101
+ const codegen = createCodegen({
102
+ target,
103
+ outDir: this.outDir,
104
+ jsExtension: addJsExtension,
105
+ globCache
106
+ });
107
+ await content({
108
+ core: this.core,
109
+ codegen,
110
+ serverOptions,
111
+ tc
112
+ });
183
113
  return {
184
114
  path: path3,
185
- content: await content
115
+ content: codegen.toString()
186
116
  };
187
- }
117
+ };
188
118
  const out = [
189
- toEmitEntry(
190
- "server.ts",
191
- generateServerIndexFile(makeCodeGen(), config, this.configPath)
192
- )
119
+ toEmitEntry("server.ts", generateServerIndexFile)
193
120
  ];
194
121
  if (dynamic)
195
- out.push(
196
- toEmitEntry(
197
- "dynamic.ts",
198
- generateDynamicIndexFile(this.core, makeCodeGen())
199
- )
200
- );
122
+ out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
201
123
  if (browser)
202
- out.push(
203
- toEmitEntry(
204
- "browser.ts",
205
- generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
206
- )
207
- );
124
+ out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
208
125
  return await Promise.all(out);
209
126
  }
210
127
  };
211
128
  }
212
- async function generateServerIndexFile(codegen, config, configPath) {
129
+ async function generateServerIndexFile({
130
+ core,
131
+ codegen,
132
+ serverOptions,
133
+ tc
134
+ }) {
213
135
  codegen.lines.push(
214
- `import { fromConfig } from 'fumadocs-mdx/runtime/server';`,
215
- `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
136
+ `import { server } from 'fumadocs-mdx/runtime/server';`,
137
+ `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
216
138
  "",
217
- `const create = fromConfig<typeof Config>();`
139
+ `const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
218
140
  );
219
141
  async function generateCollectionObject(collection) {
220
142
  switch (collection.type) {
@@ -261,22 +183,26 @@ async function generateServerIndexFile(codegen, config, configPath) {
261
183
  }
262
184
  }
263
185
  await codegen.pushAsync(
264
- config.collectionList.map(async (collection) => {
186
+ core.getConfig().collectionList.map(async (collection) => {
265
187
  const obj = await generateCollectionObject(collection);
266
188
  if (!obj) return;
267
189
  return `
268
190
  export const ${collection.name} = ${obj};`;
269
191
  })
270
192
  );
271
- return codegen.toString();
272
193
  }
273
- async function generateDynamicIndexFile(core, codegen) {
274
- const { configPath } = core._options;
194
+ async function generateDynamicIndexFile({
195
+ core,
196
+ codegen,
197
+ serverOptions,
198
+ tc
199
+ }) {
200
+ const { configPath } = core.getOptions();
275
201
  codegen.lines.push(
276
- `import { fromConfigDynamic } from 'fumadocs-mdx/runtime/dynamic';`,
202
+ `import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
277
203
  `import * as Config from '${codegen.formatImportPath(configPath)}';`,
278
204
  "",
279
- `const create = await fromConfigDynamic(Config);`
205
+ `const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
280
206
  );
281
207
  async function generateCollectionObjectEntry(collection, file) {
282
208
  const fullPath = path2.join(collection.dir, file);
@@ -312,7 +238,7 @@ async function generateDynamicIndexFile(core, codegen) {
312
238
  if (parent.type === "doc") collection = parent;
313
239
  else if (parent.type === "docs") collection = parent.docs;
314
240
  if (!collection || !collection.dynamic) return;
315
- const files = await glob2(collection.patterns, {
241
+ const files = await glob(collection.patterns, {
316
242
  cwd: collection.dir
317
243
  });
318
244
  const entries = await Promise.all(
@@ -339,14 +265,13 @@ async function generateDynamicIndexFile(core, codegen) {
339
265
  export const ${collection.name} = ${obj};`;
340
266
  })
341
267
  );
342
- return codegen.toString();
343
268
  }
344
- async function generateBrowserIndexFile(codegen, config, configPath) {
269
+ async function generateBrowserIndexFile({ core, codegen, tc }) {
345
270
  codegen.lines.push(
346
- `import { fromConfig } from 'fumadocs-mdx/runtime/browser';`,
347
- `import type * as Config from '${codegen.formatImportPath(configPath)}';`,
271
+ `import { browser } from 'fumadocs-mdx/runtime/browser';`,
272
+ `import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
348
273
  "",
349
- `const create = fromConfig<typeof Config>();`
274
+ `const create = browser<typeof Config, ${tc}>();`
350
275
  );
351
276
  async function generateCollectionObject(collection) {
352
277
  switch (collection.type) {
@@ -361,14 +286,13 @@ async function generateBrowserIndexFile(codegen, config, configPath) {
361
286
  }
362
287
  codegen.lines.push("const browserCollections = {");
363
288
  await codegen.pushAsync(
364
- config.collectionList.map(async (collection) => {
289
+ core.getConfig().collectionList.map(async (collection) => {
365
290
  const obj = await generateCollectionObject(collection);
366
291
  if (!obj) return;
367
292
  return ident(`${collection.name}: ${obj},`);
368
293
  })
369
294
  );
370
295
  codegen.lines.push("};", "export default browserCollections;");
371
- return codegen.toString();
372
296
  }
373
297
  function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
374
298
  return codegen.generateGlobImport(collection.patterns, {
@@ -1,6 +1,6 @@
1
1
  import {
2
- removeFileCache
3
- } from "./chunk-PKI7ZDA5.js";
2
+ ident
3
+ } from "./chunk-WBIHDYMN.js";
4
4
 
5
5
  // src/utils/validation.ts
6
6
  var ValidationError = class extends Error {
@@ -75,7 +75,6 @@ function createCore(options, defaultPlugins = []) {
75
75
  return data;
76
76
  }
77
77
  const core = {
78
- _options: options,
79
78
  /**
80
79
  * Convenient cache store, reset when config changes
81
80
  */
@@ -84,6 +83,7 @@ function createCore(options, defaultPlugins = []) {
84
83
  config = await newConfig;
85
84
  this.cache.clear();
86
85
  plugins = await getPlugins([
86
+ postprocessPlugin(),
87
87
  ...defaultPlugins,
88
88
  ...config.global.plugins ?? []
89
89
  ]);
@@ -91,7 +91,9 @@ function createCore(options, defaultPlugins = []) {
91
91
  const out = await plugin.config?.call(pluginContext, config);
92
92
  if (out) config = out;
93
93
  }
94
- return this;
94
+ },
95
+ getOptions() {
96
+ return options;
95
97
  },
96
98
  getConfig() {
97
99
  return config;
@@ -102,10 +104,13 @@ function createCore(options, defaultPlugins = []) {
102
104
  getCompiledConfigPath() {
103
105
  return path.join(options.outDir, "source.config.mjs");
104
106
  },
107
+ getPlugins() {
108
+ return plugins;
109
+ },
110
+ getPluginContext() {
111
+ return pluginContext;
112
+ },
105
113
  async initServer(server) {
106
- server.watcher?.on("all", async (event, file) => {
107
- if (event === "change") removeFileCache(file);
108
- });
109
114
  for (const plugin of plugins) {
110
115
  await plugin.configureServer?.call(pluginContext, server);
111
116
  }
@@ -172,6 +177,45 @@ function createCore(options, defaultPlugins = []) {
172
177
  };
173
178
  return core;
174
179
  }
180
+ function postprocessPlugin() {
181
+ const LinkReferenceTypes = `{
182
+ /**
183
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
184
+ */
185
+ extractedReferences: import("fumadocs-mdx").ExtractedReference[];
186
+ }`;
187
+ return {
188
+ "index-file": {
189
+ generateTypeConfig() {
190
+ const lines = [];
191
+ lines.push("{");
192
+ lines.push(" DocData: {");
193
+ for (const collection of this.core.getConfig().collectionList) {
194
+ let postprocessOptions;
195
+ switch (collection.type) {
196
+ case "doc":
197
+ postprocessOptions = collection.postprocess;
198
+ break;
199
+ case "docs":
200
+ postprocessOptions = collection.docs.postprocess;
201
+ break;
202
+ }
203
+ if (postprocessOptions?.extractLinkReferences) {
204
+ lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
205
+ }
206
+ }
207
+ lines.push(" }");
208
+ lines.push("}");
209
+ return lines.join("\n");
210
+ },
211
+ serverOptions(options) {
212
+ options.doc ??= {};
213
+ options.doc.passthroughs ??= [];
214
+ options.doc.passthroughs.push("extractedReferences");
215
+ }
216
+ }
217
+ };
218
+ }
175
219
 
176
220
  export {
177
221
  ValidationError,
@@ -38,6 +38,10 @@ function remarkPostprocess({
38
38
  });
39
39
  }
40
40
  file.data["mdx-export"] ??= [];
41
+ file.data["mdx-export"].push({
42
+ name: "frontmatter",
43
+ value: frontmatter
44
+ });
41
45
  if (extractLinkReferences) {
42
46
  const urls = [];
43
47
  visit(tree, "link", (node) => {
@@ -135,12 +139,7 @@ async function buildMDX(core, collection, {
135
139
  if (!processor) {
136
140
  const postprocessOptions = {
137
141
  _format: format,
138
- ...collection?.postprocess,
139
- valueToExport: [
140
- ...collection?.postprocess?.valueToExport ?? [],
141
- "structuredData",
142
- "frontmatter"
143
- ]
142
+ ...collection?.postprocess
144
143
  };
145
144
  processor = createProcessor({
146
145
  outputFormat: "program",
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  buildConfig
3
- } from "./chunk-ZY6UZ7NH.js";
3
+ } from "./chunk-6RPNS75C.js";
4
4
 
5
5
  // src/config/load-from-file.ts
6
6
  import { pathToFileURL } from "url";
7
7
  async function compileConfig(core) {
8
8
  const { build } = await import("esbuild");
9
+ const { configPath, outDir } = core.getOptions();
9
10
  const transformed = await build({
10
- entryPoints: [{ in: core._options.configPath, out: "source.config" }],
11
+ entryPoints: [{ in: configPath, out: "source.config" }],
11
12
  bundle: true,
12
- outdir: core._options.outDir,
13
+ outdir: outDir,
13
14
  target: "node20",
14
15
  write: true,
15
16
  platform: "node",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-7L2KNF6B.js";
3
+ } from "./chunk-GB4W3YCZ.js";
4
4
 
5
5
  // src/loaders/adapter.ts
6
6
  import { fileURLToPath } from "url";
@@ -137,13 +137,13 @@ function createStandaloneConfigLoader({
137
137
  let loaded;
138
138
  async function getConfigHash() {
139
139
  if (mode === "production") return "static";
140
- const stats = await fs2.stat(core._options.configPath).catch(() => {
140
+ const stats = await fs2.stat(core.getOptions().configPath).catch(() => {
141
141
  throw new Error("Cannot find config file");
142
142
  });
143
143
  return stats.mtime.getTime().toString();
144
144
  }
145
145
  async function newConfig() {
146
- const { loadConfig } = await import("./load-from-file-I3ALLIVB.js");
146
+ const { loadConfig } = await import("./load-from-file-OZ5N7DXU.js");
147
147
  await core.init({
148
148
  config: loadConfig(core, buildConfig)
149
149
  });
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createCore
3
- } from "./chunk-7L2KNF6B.js";
3
+ } from "./chunk-GB4W3YCZ.js";
4
4
 
5
5
  // src/webpack/index.ts
6
6
  var core;
@@ -47,7 +47,10 @@ function applyMdxPreset(options = {}) {
47
47
  ...v,
48
48
  remarkStructureOptions !== false && [
49
49
  plugins.remarkStructure,
50
- remarkStructureOptions
50
+ {
51
+ exportAs: "structuredData",
52
+ ...remarkStructureOptions
53
+ }
51
54
  ],
52
55
  valueToExport.length > 0 && (() => {
53
56
  return (_, file) => {
@@ -73,7 +73,7 @@ function createMdxLoader(configLoader) {
73
73
  };
74
74
  }
75
75
  const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
76
- const { buildMDX } = await import("./build-mdx-6UAK5FF5.js");
76
+ const { buildMDX } = await import("./build-mdx-W3233QBZ.js");
77
77
  const compiled = await buildMDX(configLoader.core, docCollection, {
78
78
  isDevelopment,
79
79
  source: "\n".repeat(lineOffset) + matter.content,