fumadocs-mdx 11.10.0 → 12.0.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.
Files changed (71) hide show
  1. package/dist/bin.cjs +953 -0
  2. package/dist/bin.d.cts +1 -0
  3. package/dist/bin.d.ts +1 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
  6. package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
  7. package/dist/bun/index.cjs +129 -109
  8. package/dist/bun/index.js +9 -6
  9. package/dist/chunk-3M4SHY6K.js +80 -0
  10. package/dist/chunk-6Y5JDZHD.js +65 -0
  11. package/dist/{chunk-NUDEC6C5.js → chunk-AUOOMFAI.js} +28 -22
  12. package/dist/chunk-IQAEAI4P.js +66 -0
  13. package/dist/{chunk-5XJM5RPV.js → chunk-KGUBBRL6.js} +13 -13
  14. package/dist/{chunk-SVTXMVLQ.js → chunk-KTDVTBMH.js} +1 -1
  15. package/dist/chunk-POXTQZ4D.js +60 -0
  16. package/dist/chunk-SWNOXPYJ.js +142 -0
  17. package/dist/{chunk-COQ4VMK2.js → chunk-TLD6JMT6.js} +28 -61
  18. package/dist/{chunk-NVX3U5YE.js → chunk-VXEBLM4X.js} +2 -2
  19. package/dist/{chunk-QVZ7JH4H.js → chunk-YC25YEBF.js} +1 -1
  20. package/dist/chunk-ZLCSVXCD.js +10 -0
  21. package/dist/config/index.cjs +18 -97
  22. package/dist/config/index.d.cts +1 -1
  23. package/dist/config/index.d.ts +1 -1
  24. package/dist/config/index.js +48 -9
  25. package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.cts} +18 -3
  26. package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.ts} +18 -3
  27. package/dist/loader-mdx.cjs +127 -139
  28. package/dist/loader-mdx.js +7 -6
  29. package/dist/next/index.cjs +44 -269
  30. package/dist/next/index.js +30 -46
  31. package/dist/node/loader.cjs +131 -143
  32. package/dist/node/loader.js +7 -6
  33. package/dist/postinstall-U7VROOY7.js +9 -0
  34. package/dist/{mdx-options-T73E4LQB.js → preset-WFEORCAB.js} +1 -1
  35. package/dist/runtime/{async.cjs → next/async.cjs} +202 -154
  36. package/dist/runtime/{async.d.cts → next/async.d.cts} +3 -3
  37. package/dist/runtime/{async.d.ts → next/async.d.ts} +3 -3
  38. package/dist/runtime/next/async.js +92 -0
  39. package/dist/{index.cjs → runtime/next/index.cjs} +35 -26
  40. package/dist/runtime/next/index.d.cts +30 -0
  41. package/dist/runtime/next/index.d.ts +30 -0
  42. package/dist/{index.js → runtime/next/index.js} +2 -1
  43. package/dist/runtime/vite/browser.d.cts +2 -3
  44. package/dist/runtime/vite/browser.d.ts +2 -3
  45. package/dist/runtime/vite/server.cjs +67 -21
  46. package/dist/runtime/vite/server.d.cts +14 -28
  47. package/dist/runtime/vite/server.d.ts +14 -28
  48. package/dist/runtime/vite/server.js +61 -21
  49. package/dist/shared-0QIuV0XZ.d.ts +70 -0
  50. package/dist/shared-CqgMnt9h.d.cts +70 -0
  51. package/dist/{types-DN9KrG7R.d.ts → types-DLIAvrgC.d.ts} +6 -32
  52. package/dist/{types-DT83Ijs6.d.cts → types-Dl8HLbm5.d.cts} +6 -32
  53. package/dist/vite/index.cjs +201 -123
  54. package/dist/vite/index.d.cts +4 -1
  55. package/dist/vite/index.d.ts +4 -1
  56. package/dist/vite/index.js +13 -9
  57. package/package.json +11 -17
  58. package/bin.js +0 -5
  59. package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
  60. package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
  61. package/dist/chunk-2HKRTQYP.js +0 -154
  62. package/dist/chunk-GBMFGEC7.js +0 -57
  63. package/dist/chunk-QQWCBFFE.js +0 -40
  64. package/dist/chunk-SMSNZ6N5.js +0 -155
  65. package/dist/config/zod-3.cjs +0 -422
  66. package/dist/config/zod-3.d.cts +0 -53
  67. package/dist/config/zod-3.d.ts +0 -53
  68. package/dist/config/zod-3.js +0 -40
  69. package/dist/index.d.cts +0 -26
  70. package/dist/index.d.ts +0 -26
  71. package/dist/runtime/async.js +0 -72
@@ -30,86 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // src/mdx-plugins/remark-postprocess.ts
34
- function remarkPostprocess({
35
- injectExports
36
- }) {
37
- return (tree, file) => {
38
- let title;
39
- const urls = [];
40
- (0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
41
- if (node.type === "heading" && node.depth === 1) {
42
- title = flattenNode(node);
43
- }
44
- if (node.type !== "link") return;
45
- urls.push({
46
- href: node.url
47
- });
48
- return "skip";
49
- });
50
- if (title) {
51
- file.data.frontmatter ??= {};
52
- if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
53
- }
54
- file.data.extractedReferences = urls;
55
- for (const name of injectExports) {
56
- if (!(name in file.data)) continue;
57
- tree.children.unshift(getMdastExport(name, file.data[name]));
58
- }
59
- };
60
- }
61
- function flattenNode(node) {
62
- if ("children" in node)
63
- return node.children.map((child) => flattenNode(child)).join("");
64
- if ("value" in node) return node.value;
65
- return "";
66
- }
67
- function getMdastExport(name, value) {
68
- return {
69
- type: "mdxjsEsm",
70
- value: "",
71
- data: {
72
- estree: {
73
- type: "Program",
74
- sourceType: "module",
75
- body: [
76
- {
77
- type: "ExportNamedDeclaration",
78
- attributes: [],
79
- specifiers: [],
80
- source: null,
81
- declaration: {
82
- type: "VariableDeclaration",
83
- kind: "let",
84
- declarations: [
85
- {
86
- type: "VariableDeclarator",
87
- id: {
88
- type: "Identifier",
89
- name
90
- },
91
- init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
92
- }
93
- ]
94
- }
95
- }
96
- ]
97
- }
98
- }
99
- };
100
- }
101
- var import_unist_util_visit, import_estree_util_value_to_estree;
102
- var init_remark_postprocess = __esm({
103
- "src/mdx-plugins/remark-postprocess.ts"() {
104
- "use strict";
105
- import_unist_util_visit = require("unist-util-visit");
106
- import_estree_util_value_to_estree = require("estree-util-value-to-estree");
107
- }
108
- });
109
-
110
- // src/utils/mdx-options.ts
111
- var mdx_options_exports = {};
112
- __export(mdx_options_exports, {
33
+ // src/mdx/preset.ts
34
+ var preset_exports = {};
35
+ __export(preset_exports, {
113
36
  getDefaultMDXOptions: () => getDefaultMDXOptions
114
37
  });
115
38
  function pluginOption(def, options = []) {
@@ -132,13 +55,6 @@ function getDefaultMDXOptions({
132
55
  _withoutBundler = false,
133
56
  ...mdxOptions
134
57
  }) {
135
- const mdxExports = [
136
- "structuredData",
137
- "extractedReferences",
138
- "frontmatter",
139
- "lastModified",
140
- ...valueToExport
141
- ];
142
58
  const remarkPlugins = pluginOption(
143
59
  (v) => [
144
60
  plugins.remarkGfm,
@@ -166,10 +82,15 @@ function getDefaultMDXOptions({
166
82
  plugins.remarkStructure,
167
83
  remarkStructureOptions
168
84
  ],
169
- [
170
- remarkPostprocess,
171
- { injectExports: mdxExports }
172
- ]
85
+ () => {
86
+ return (_, file) => {
87
+ file.data["mdx-export"] ??= [];
88
+ for (const name of valueToExport) {
89
+ if (name in file.data)
90
+ file.data["mdx-export"].push({ name, value: file.data[name] });
91
+ }
92
+ };
93
+ }
173
94
  ],
174
95
  mdxOptions.remarkPlugins
175
96
  );
@@ -189,11 +110,10 @@ function getDefaultMDXOptions({
189
110
  };
190
111
  }
191
112
  var plugins;
192
- var init_mdx_options = __esm({
193
- "src/utils/mdx-options.ts"() {
113
+ var init_preset = __esm({
114
+ "src/mdx/preset.ts"() {
194
115
  "use strict";
195
116
  plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
196
- init_remark_postprocess();
197
117
  }
198
118
  });
199
119
 
@@ -245,7 +165,7 @@ function buildConfig(config) {
245
165
  const input = this.global.mdxOptions;
246
166
  async function uncached() {
247
167
  const options = typeof input === "function" ? await input() : input;
248
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
168
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
249
169
  if (options?.preset === "minimal") return options;
250
170
  return getDefaultMDXOptions2({
251
171
  ...options,
@@ -264,35 +184,6 @@ function findConfigFile() {
264
184
  return path.resolve("source.config.ts");
265
185
  }
266
186
  var cache = null;
267
- async function isZod3() {
268
- try {
269
- const content = JSON.parse(
270
- (await fs.readFile("node_modules/zod/package.json")).toString()
271
- );
272
- const version = content.version;
273
- return typeof version === "string" && version.startsWith("3.");
274
- } catch {
275
- return false;
276
- }
277
- }
278
- function createCompatZodPlugin() {
279
- return {
280
- name: "replace-zod-import",
281
- async setup(build) {
282
- const usingZod3 = await isZod3();
283
- if (!usingZod3) return;
284
- console.warn(
285
- "[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
286
- );
287
- build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
288
- return {
289
- path: "fumadocs-mdx/config/zod-3",
290
- external: true
291
- };
292
- });
293
- }
294
- };
295
- }
296
187
  async function compileConfig(configPath, outDir) {
297
188
  const { build } = await import("esbuild");
298
189
  const transformed = await build({
@@ -304,7 +195,6 @@ async function compileConfig(configPath, outDir) {
304
195
  platform: "node",
305
196
  format: "esm",
306
197
  packages: "external",
307
- plugins: [createCompatZodPlugin()],
308
198
  outExtension: {
309
199
  ".js": ".mjs"
310
200
  },
@@ -423,21 +313,21 @@ function countLines(s) {
423
313
  return num;
424
314
  }
425
315
 
426
- // src/utils/build-mdx.ts
316
+ // src/mdx/build-mdx.ts
427
317
  var import_mdx = require("@mdx-js/mdx");
428
318
 
429
- // src/mdx-plugins/remark-include.ts
319
+ // src/mdx/remark-include.ts
430
320
  var import_unified = require("unified");
431
- var import_unist_util_visit2 = require("unist-util-visit");
321
+ var import_unist_util_visit = require("unist-util-visit");
432
322
  var path3 = __toESM(require("path"), 1);
433
323
  var fs2 = __toESM(require("fs/promises"), 1);
434
324
  var import_remark_parse = __toESM(require("remark-parse"), 1);
435
325
  var import_remark_mdx = __toESM(require("remark-mdx"), 1);
436
326
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
437
327
  var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
438
- function flattenNode2(node) {
328
+ function flattenNode(node) {
439
329
  if ("children" in node)
440
- return node.children.map((child) => flattenNode2(child)).join("");
330
+ return node.children.map((child) => flattenNode(child)).join("");
441
331
  if ("value" in node) return node.value;
442
332
  return "";
443
333
  }
@@ -516,14 +406,14 @@ ${e instanceof Error ? e.message : String(e)}`,
516
406
  }
517
407
  async function update(tree, directory, data) {
518
408
  const queue = [];
519
- (0, import_unist_util_visit2.visit)(
409
+ (0, import_unist_util_visit.visit)(
520
410
  tree,
521
411
  ["mdxJsxFlowElement", "mdxJsxTextElement"],
522
412
  (_node, _, parent) => {
523
413
  const node = _node;
524
414
  if (node.name !== TagName) return;
525
415
  const params = {};
526
- const specifier = flattenNode2(node);
416
+ const specifier = flattenNode(node);
527
417
  if (specifier.length === 0) return "skip";
528
418
  for (const attr of node.attributes) {
529
419
  if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
@@ -558,7 +448,90 @@ function getDefaultProcessor(format) {
558
448
  return mdProcessor.use(import_remark_mdx.default);
559
449
  }
560
450
 
561
- // src/utils/build-mdx.ts
451
+ // src/mdx/remark-postprocess.ts
452
+ var import_unist_util_visit2 = require("unist-util-visit");
453
+ var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
454
+ var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
455
+ function remarkPostprocess({
456
+ includeProcessedMarkdown = false,
457
+ valueToExport = []
458
+ } = {}) {
459
+ return (tree, file) => {
460
+ let title;
461
+ const urls = [];
462
+ (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
463
+ if (node.type === "heading" && node.depth === 1) {
464
+ title = flattenNode2(node);
465
+ }
466
+ if (node.type !== "link") return;
467
+ urls.push({
468
+ href: node.url
469
+ });
470
+ return "skip";
471
+ });
472
+ if (title) {
473
+ file.data.frontmatter ??= {};
474
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
475
+ }
476
+ file.data.extractedReferences = urls;
477
+ if (includeProcessedMarkdown) {
478
+ file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
479
+ ...this.data("settings"),
480
+ // @ts-expect-error - from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
481
+ extensions: this.data("toMarkdownExtensions") || []
482
+ });
483
+ }
484
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
485
+ tree.children.unshift(getMdastExport(name, value));
486
+ }
487
+ for (const name of valueToExport) {
488
+ if (!(name in file.data)) continue;
489
+ tree.children.unshift(getMdastExport(name, file.data[name]));
490
+ }
491
+ };
492
+ }
493
+ function getMdastExport(name, value) {
494
+ return {
495
+ type: "mdxjsEsm",
496
+ value: "",
497
+ data: {
498
+ estree: {
499
+ type: "Program",
500
+ sourceType: "module",
501
+ body: [
502
+ {
503
+ type: "ExportNamedDeclaration",
504
+ attributes: [],
505
+ specifiers: [],
506
+ source: null,
507
+ declaration: {
508
+ type: "VariableDeclaration",
509
+ kind: "let",
510
+ declarations: [
511
+ {
512
+ type: "VariableDeclarator",
513
+ id: {
514
+ type: "Identifier",
515
+ name
516
+ },
517
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
518
+ }
519
+ ]
520
+ }
521
+ }
522
+ ]
523
+ }
524
+ }
525
+ };
526
+ }
527
+ function flattenNode2(node) {
528
+ if ("children" in node)
529
+ return node.children.map((child) => flattenNode2(child)).join("");
530
+ if ("value" in node) return node.value;
531
+ return "";
532
+ }
533
+
534
+ // src/mdx/build-mdx.ts
562
535
  var cache3 = /* @__PURE__ */ new Map();
563
536
  async function buildMDX(cacheKey, source, options) {
564
537
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
@@ -569,7 +542,24 @@ async function buildMDX(cacheKey, source, options) {
569
542
  processor = (0, import_mdx.createProcessor)({
570
543
  outputFormat: "program",
571
544
  ...rest,
572
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
545
+ remarkPlugins: [
546
+ remarkInclude,
547
+ ...rest.remarkPlugins ?? [],
548
+ [
549
+ remarkPostprocess,
550
+ {
551
+ ...options.postprocess,
552
+ valueToExport: [
553
+ ...options.postprocess?.valueToExport ?? [],
554
+ "structuredData",
555
+ "extractedReferences",
556
+ "frontmatter",
557
+ "lastModified",
558
+ "_markdown"
559
+ ]
560
+ }
561
+ ]
562
+ ],
573
563
  format
574
564
  });
575
565
  cache3.set(key, processor);
@@ -625,21 +615,18 @@ function createMdxLoader(configLoader) {
625
615
  if (cached && cached.hash === generateCacheHash(value)) return cached;
626
616
  }
627
617
  const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
628
- let schema;
629
- let mdxOptions;
618
+ let docCollection;
630
619
  switch (collection?.type) {
631
620
  case "doc":
632
- mdxOptions = collection.mdxOptions;
633
- schema = collection.schema;
621
+ docCollection = collection;
634
622
  break;
635
623
  case "docs":
636
- mdxOptions = collection.docs.mdxOptions;
637
- schema = collection.docs.schema;
624
+ docCollection = collection.docs;
638
625
  break;
639
626
  }
640
- if (schema) {
627
+ if (docCollection?.schema) {
641
628
  matter.data = await validate(
642
- schema,
629
+ docCollection.schema,
643
630
  matter.data,
644
631
  {
645
632
  source: value,
@@ -664,7 +651,8 @@ function createMdxLoader(configLoader) {
664
651
  "\n".repeat(lineOffset) + matter.content,
665
652
  {
666
653
  development: isDevelopment,
667
- ...mdxOptions ?? await loaded.getDefaultMDXOptions(),
654
+ ...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
655
+ postprocess: docCollection?.postprocess,
668
656
  data,
669
657
  filePath,
670
658
  frontmatter: matter.data,
@@ -1,16 +1,17 @@
1
1
  import {
2
2
  toNode
3
- } from "../chunk-NVX3U5YE.js";
3
+ } from "../chunk-VXEBLM4X.js";
4
4
  import {
5
5
  createMdxLoader,
6
6
  dynamicConfig
7
- } from "../chunk-5XJM5RPV.js";
7
+ } from "../chunk-KGUBBRL6.js";
8
+ import "../chunk-IQAEAI4P.js";
8
9
  import {
9
10
  findConfigFile
10
- } from "../chunk-2HKRTQYP.js";
11
- import "../chunk-QQWCBFFE.js";
12
- import "../chunk-SVTXMVLQ.js";
13
- import "../chunk-QVZ7JH4H.js";
11
+ } from "../chunk-POXTQZ4D.js";
12
+ import "../chunk-SWNOXPYJ.js";
13
+ import "../chunk-KTDVTBMH.js";
14
+ import "../chunk-YC25YEBF.js";
14
15
  import "../chunk-VWJKRQZR.js";
15
16
 
16
17
  // src/node/loader.ts
@@ -0,0 +1,9 @@
1
+ import {
2
+ postInstall
3
+ } from "./chunk-TLD6JMT6.js";
4
+ import "./chunk-6Y5JDZHD.js";
5
+ import "./chunk-POXTQZ4D.js";
6
+ import "./chunk-YC25YEBF.js";
7
+ export {
8
+ postInstall
9
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getDefaultMDXOptions
3
- } from "./chunk-SMSNZ6N5.js";
3
+ } from "./chunk-3M4SHY6K.js";
4
4
  export {
5
5
  getDefaultMDXOptions
6
6
  };