fumadocs-mdx 11.10.1 → 12.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 (68) hide show
  1. package/dist/bin.cjs +126 -218
  2. package/dist/bin.js +1 -1
  3. package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
  4. package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
  5. package/dist/bun/index.cjs +274 -230
  6. package/dist/bun/index.js +8 -8
  7. package/dist/chunk-ADR6R7HM.js +29 -0
  8. package/dist/{chunk-UOOPSLFY.js → chunk-AUOOMFAI.js} +27 -21
  9. package/dist/chunk-FSZMKRVH.js +80 -0
  10. package/dist/{chunk-766EAFX6.js → chunk-LGYVNESJ.js} +2 -36
  11. package/dist/chunk-LMG6UWCL.js +167 -0
  12. package/dist/chunk-QAUWMR5D.js +142 -0
  13. package/dist/{chunk-QJCCVMBJ.js → chunk-SP7CHRTS.js} +17 -47
  14. package/dist/{chunk-QVZ7JH4H.js → chunk-U4MQ44TS.js} +1 -1
  15. package/dist/{chunk-CNKI574E.js → chunk-VXEBLM4X.js} +1 -1
  16. package/dist/chunk-XMFLD5J6.js +30 -0
  17. package/dist/chunk-ZLCSVXCD.js +10 -0
  18. package/dist/{chunk-XXSKWWMB.js → chunk-ZX7TM4AR.js} +4 -2
  19. package/dist/config/index.cjs +97 -148
  20. package/dist/config/index.d.cts +1 -1
  21. package/dist/config/index.d.ts +1 -1
  22. package/dist/config/index.js +48 -9
  23. package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.cts} +18 -3
  24. package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.ts} +18 -3
  25. package/dist/load-UUXLUBHL.js +9 -0
  26. package/dist/loader-mdx.cjs +336 -305
  27. package/dist/loader-mdx.js +8 -8
  28. package/dist/next/index.cjs +152 -242
  29. package/dist/next/index.js +52 -66
  30. package/dist/node/loader.cjs +274 -243
  31. package/dist/node/loader.js +7 -8
  32. package/dist/postinstall-SCSXM4IM.js +10 -0
  33. package/dist/{mdx-options-T73E4LQB.js → preset-ZMP6U62C.js} +1 -1
  34. package/dist/runtime/next/async.cjs +304 -204
  35. package/dist/runtime/next/async.d.cts +3 -3
  36. package/dist/runtime/next/async.d.ts +3 -3
  37. package/dist/runtime/next/async.js +59 -32
  38. package/dist/runtime/next/index.cjs +32 -21
  39. package/dist/runtime/next/index.d.cts +11 -7
  40. package/dist/runtime/next/index.d.ts +11 -7
  41. package/dist/runtime/next/index.js +2 -1
  42. package/dist/runtime/vite/browser.d.cts +2 -3
  43. package/dist/runtime/vite/browser.d.ts +2 -3
  44. package/dist/runtime/vite/server.cjs +67 -21
  45. package/dist/runtime/vite/server.d.cts +14 -28
  46. package/dist/runtime/vite/server.d.ts +14 -28
  47. package/dist/runtime/vite/server.js +61 -21
  48. package/dist/shared-0QIuV0XZ.d.ts +70 -0
  49. package/dist/shared-CqgMnt9h.d.cts +70 -0
  50. package/dist/{types-DN9KrG7R.d.ts → types-CFlQxTN8.d.ts} +10 -37
  51. package/dist/{types-DT83Ijs6.d.cts → types-DkGjw-Uo.d.cts} +10 -37
  52. package/dist/vite/index.cjs +299 -279
  53. package/dist/vite/index.d.cts +1 -0
  54. package/dist/vite/index.d.ts +1 -0
  55. package/dist/vite/index.js +15 -20
  56. package/dist/{watcher-4NDMOH4R.js → watcher-HGOH3APP.js} +1 -1
  57. package/package.json +16 -16
  58. package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
  59. package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
  60. package/dist/chunk-GBMFGEC7.js +0 -57
  61. package/dist/chunk-QQWCBFFE.js +0 -40
  62. package/dist/chunk-SMSNZ6N5.js +0 -155
  63. package/dist/chunk-SVTXMVLQ.js +0 -139
  64. package/dist/config/zod-3.cjs +0 -422
  65. package/dist/config/zod-3.d.cts +0 -53
  66. package/dist/config/zod-3.d.ts +0 -53
  67. package/dist/config/zod-3.js +0 -40
  68. package/dist/postinstall-XV4WSHZP.js +0 -9
@@ -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/loaders/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,26 +110,13 @@ 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/loaders/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
 
200
- // src/node/loader.ts
201
- var loader_exports = {};
202
- __export(loader_exports, {
203
- load: () => load2
204
- });
205
- module.exports = __toCommonJS(loader_exports);
206
-
207
- // src/utils/config.ts
208
- var fs = __toESM(require("fs/promises"), 1);
209
- var path = __toESM(require("path"), 1);
210
- var import_node_url = require("url");
211
-
212
120
  // src/config/build.ts
213
121
  function buildConfig(config) {
214
122
  const collections = /* @__PURE__ */ new Map();
@@ -245,7 +153,7 @@ function buildConfig(config) {
245
153
  const input = this.global.mdxOptions;
246
154
  async function uncached() {
247
155
  const options = typeof input === "function" ? await input() : input;
248
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
156
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
249
157
  if (options?.preset === "minimal") return options;
250
158
  return getDefaultMDXOptions2({
251
159
  ...options,
@@ -258,41 +166,18 @@ function buildConfig(config) {
258
166
  }
259
167
  };
260
168
  }
261
-
262
- // src/utils/config.ts
263
- function findConfigFile() {
264
- return path.resolve("source.config.ts");
265
- }
266
- 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;
169
+ var init_build = __esm({
170
+ "src/config/build.ts"() {
171
+ "use strict";
276
172
  }
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
- }
173
+ });
174
+
175
+ // src/loaders/config/load.ts
176
+ var load_exports = {};
177
+ __export(load_exports, {
178
+ getConfigHash: () => getConfigHash,
179
+ loadConfig: () => loadConfig
180
+ });
296
181
  async function compileConfig(configPath, outDir) {
297
182
  const { build } = await import("esbuild");
298
183
  const transformed = await build({
@@ -304,7 +189,6 @@ async function compileConfig(configPath, outDir) {
304
189
  platform: "node",
305
190
  format: "esm",
306
191
  packages: "external",
307
- plugins: [createCompatZodPlugin()],
308
192
  outExtension: {
309
193
  ".js": ".mjs"
310
194
  },
@@ -336,6 +220,42 @@ async function getConfigHash(configPath) {
336
220
  }
337
221
  throw new Error("Cannot find config file");
338
222
  }
223
+ var fs, path, import_node_url, cache;
224
+ var init_load = __esm({
225
+ "src/loaders/config/load.ts"() {
226
+ "use strict";
227
+ fs = __toESM(require("fs/promises"), 1);
228
+ path = __toESM(require("path"), 1);
229
+ import_node_url = require("url");
230
+ init_build();
231
+ cache = null;
232
+ }
233
+ });
234
+
235
+ // src/node/loader.ts
236
+ var loader_exports = {};
237
+ __export(loader_exports, {
238
+ load: () => load2
239
+ });
240
+ module.exports = __toCommonJS(loader_exports);
241
+
242
+ // src/loaders/config/index.ts
243
+ var import_node_path = __toESM(require("path"), 1);
244
+ function findConfigFile() {
245
+ return import_node_path.default.resolve("source.config.ts");
246
+ }
247
+ function dynamicConfig(configPath, outDir) {
248
+ return {
249
+ async getConfig(hash) {
250
+ const { loadConfig: loadConfig2, getConfigHash: getConfigHash2 } = await Promise.resolve().then(() => (init_load(), load_exports));
251
+ return loadConfig2(
252
+ configPath,
253
+ outDir,
254
+ hash ?? await getConfigHash2(configPath)
255
+ );
256
+ }
257
+ };
258
+ }
339
259
 
340
260
  // src/utils/fuma-matter.ts
341
261
  var import_js_yaml = require("js-yaml");
@@ -392,7 +312,7 @@ async function validate(schema, data, context, errorMessage) {
392
312
  }
393
313
 
394
314
  // src/utils/git-timestamp.ts
395
- var import_node_path = __toESM(require("path"), 1);
315
+ var import_node_path2 = __toESM(require("path"), 1);
396
316
  var import_tinyexec = require("tinyexec");
397
317
  var cache2 = /* @__PURE__ */ new Map();
398
318
  async function getGitTimestamp(file) {
@@ -401,7 +321,7 @@ async function getGitTimestamp(file) {
401
321
  try {
402
322
  const out = await (0, import_tinyexec.x)(
403
323
  "git",
404
- ["log", "-1", '--pretty="%ai"', import_node_path.default.relative(process.cwd(), file)],
324
+ ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
405
325
  {
406
326
  throwOnError: true
407
327
  }
@@ -414,30 +334,42 @@ async function getGitTimestamp(file) {
414
334
  }
415
335
  }
416
336
 
417
- // src/utils/count-lines.ts
418
- function countLines(s) {
419
- let num = 0;
420
- for (const c of s) {
421
- if (c === "\n") num++;
422
- }
423
- return num;
424
- }
425
-
426
- // src/utils/build-mdx.ts
337
+ // src/loaders/mdx/build-mdx.ts
427
338
  var import_mdx = require("@mdx-js/mdx");
428
339
 
429
- // src/mdx-plugins/remark-include.ts
340
+ // src/loaders/mdx/remark-include.ts
430
341
  var import_unified = require("unified");
431
- var import_unist_util_visit2 = require("unist-util-visit");
432
- var path3 = __toESM(require("path"), 1);
342
+ var import_unist_util_visit = require("unist-util-visit");
343
+ var path4 = __toESM(require("path"), 1);
433
344
  var fs2 = __toESM(require("fs/promises"), 1);
434
345
  var import_remark_parse = __toESM(require("remark-parse"), 1);
435
346
  var import_remark_mdx = __toESM(require("remark-mdx"), 1);
436
347
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
437
- var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
438
- function flattenNode2(node) {
348
+ var ElementLikeTypes = [
349
+ "mdxJsxFlowElement",
350
+ "mdxJsxTextElement",
351
+ "containerDirective",
352
+ "textDirective",
353
+ "leafDirective"
354
+ ];
355
+ function isElementLike(node) {
356
+ return ElementLikeTypes.includes(node.type);
357
+ }
358
+ function parseElementAttributes(element) {
359
+ if (Array.isArray(element.attributes)) {
360
+ const attributes = {};
361
+ for (const attr of element.attributes) {
362
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
363
+ attributes[attr.name] = attr.value;
364
+ }
365
+ }
366
+ return attributes;
367
+ }
368
+ return element.attributes ?? {};
369
+ }
370
+ function flattenNode(node) {
439
371
  if ("children" in node)
440
- return node.children.map((child) => flattenNode2(child)).join("");
372
+ return node.children.map((child) => flattenNode(child)).join("");
441
373
  if ("value" in node) return node.value;
442
374
  return "";
443
375
  }
@@ -451,21 +383,31 @@ function parseSpecifier(specifier) {
451
383
  }
452
384
  function extractSection(root, section) {
453
385
  let nodes;
454
- for (const node of root.children) {
455
- if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
456
- (attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
457
- )) {
458
- nodes = node.children;
459
- break;
386
+ let capturingHeadingContent = false;
387
+ (0, import_unist_util_visit.visit)(root, (node) => {
388
+ if (node.type === "heading") {
389
+ if (capturingHeadingContent) {
390
+ return false;
391
+ }
392
+ if (node.data?.hProperties?.id === section) {
393
+ capturingHeadingContent = true;
394
+ nodes = [node];
395
+ return "skip";
396
+ }
397
+ return;
460
398
  }
461
- if (node.type === "heading" && node.data?.hProperties?.id === section) {
462
- nodes = [node];
463
- continue;
399
+ if (capturingHeadingContent) {
400
+ nodes?.push(node);
401
+ return "skip";
464
402
  }
465
- if (!nodes) continue;
466
- if (node.type === "heading") break;
467
- nodes.push(node);
468
- }
403
+ if (isElementLike(node) && node.name === "section") {
404
+ const attributes = parseElementAttributes(node);
405
+ if (attributes.id === section) {
406
+ nodes = node.children;
407
+ return false;
408
+ }
409
+ }
410
+ });
469
411
  if (nodes)
470
412
  return {
471
413
  type: "root",
@@ -485,7 +427,7 @@ ${e instanceof Error ? e.message : String(e)}`,
485
427
  { cause: e }
486
428
  );
487
429
  }
488
- const ext = path3.extname(file);
430
+ const ext = path4.extname(file);
489
431
  data._compiler?.addDependency(file);
490
432
  if (params.lang || ext !== ".md" && ext !== ".mdx") {
491
433
  const lang = params.lang ?? ext.slice(1);
@@ -497,59 +439,56 @@ ${e instanceof Error ? e.message : String(e)}`,
497
439
  data: {}
498
440
  };
499
441
  }
500
- const processor = (data._getProcessor ?? getDefaultProcessor)(
442
+ const parser = (data._getProcessor ?? getDefaultProcessor)(
501
443
  ext === ".mdx" ? "mdx" : "md"
502
444
  );
503
- let parsed = await baseProcessor.run(
504
- processor.parse(fumaMatter(content).content)
505
- );
445
+ const parsed = fumaMatter(content);
446
+ let mdast = parser.parse({
447
+ path: file,
448
+ value: parsed.content,
449
+ data: { frontmatter: parsed.data }
450
+ });
506
451
  if (heading) {
507
- const extracted = extractSection(parsed, heading);
452
+ const extracted = extractSection(
453
+ await (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading).run(mdast),
454
+ heading
455
+ );
508
456
  if (!extracted)
509
457
  throw new Error(
510
- `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
458
+ `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
511
459
  );
512
- parsed = extracted;
460
+ mdast = extracted;
513
461
  }
514
- await update(parsed, path3.dirname(file), data);
515
- return parsed;
462
+ await update(mdast, path4.dirname(file), data);
463
+ return mdast;
516
464
  }
517
465
  async function update(tree, directory, data) {
518
466
  const queue = [];
519
- (0, import_unist_util_visit2.visit)(
520
- tree,
521
- ["mdxJsxFlowElement", "mdxJsxTextElement"],
522
- (_node, _, parent) => {
523
- const node = _node;
524
- if (node.name !== TagName) return;
525
- const params = {};
526
- const specifier = flattenNode2(node);
527
- if (specifier.length === 0) return "skip";
528
- for (const attr of node.attributes) {
529
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
530
- params[attr.name] = attr.value;
531
- }
532
- }
533
- const { file: relativePath, section } = parseSpecifier(specifier);
534
- const file = path3.resolve(
535
- "cwd" in params ? process.cwd() : directory,
536
- relativePath
537
- );
538
- queue.push(
539
- embedContent(file, section, params, data).then((replace) => {
540
- Object.assign(
541
- parent && parent.type === "paragraph" ? parent : node,
542
- replace
543
- );
544
- })
545
- );
546
- return "skip";
547
- }
548
- );
467
+ (0, import_unist_util_visit.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
468
+ const node = _node;
469
+ if (node.name !== TagName) return;
470
+ const specifier = flattenNode(node);
471
+ if (specifier.length === 0) return "skip";
472
+ const attributes = parseElementAttributes(node);
473
+ const { file: relativePath, section } = parseSpecifier(specifier);
474
+ const file = path4.resolve(
475
+ "cwd" in attributes ? process.cwd() : directory,
476
+ relativePath
477
+ );
478
+ queue.push(
479
+ embedContent(file, section, attributes, data).then((replace) => {
480
+ Object.assign(
481
+ parent && parent.type === "paragraph" ? parent : node,
482
+ replace
483
+ );
484
+ })
485
+ );
486
+ return "skip";
487
+ });
549
488
  await Promise.all(queue);
550
489
  }
551
490
  return async (tree, file) => {
552
- await update(tree, path3.dirname(file.path), file.data);
491
+ await update(tree, path4.dirname(file.path), file.data);
553
492
  };
554
493
  }
555
494
  function getDefaultProcessor(format) {
@@ -558,7 +497,90 @@ function getDefaultProcessor(format) {
558
497
  return mdProcessor.use(import_remark_mdx.default);
559
498
  }
560
499
 
561
- // src/utils/build-mdx.ts
500
+ // src/loaders/mdx/remark-postprocess.ts
501
+ var import_unist_util_visit2 = require("unist-util-visit");
502
+ var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
503
+ var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
504
+ function remarkPostprocess({
505
+ includeProcessedMarkdown = false,
506
+ valueToExport = []
507
+ } = {}) {
508
+ return (tree, file) => {
509
+ let title;
510
+ const urls = [];
511
+ (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
512
+ if (node.type === "heading" && node.depth === 1) {
513
+ title = flattenNode2(node);
514
+ }
515
+ if (node.type !== "link") return;
516
+ urls.push({
517
+ href: node.url
518
+ });
519
+ return "skip";
520
+ });
521
+ if (title) {
522
+ file.data.frontmatter ??= {};
523
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
524
+ }
525
+ file.data.extractedReferences = urls;
526
+ if (includeProcessedMarkdown) {
527
+ file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
528
+ ...this.data("settings"),
529
+ // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
530
+ extensions: this.data("toMarkdownExtensions") || []
531
+ });
532
+ }
533
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
534
+ tree.children.unshift(getMdastExport(name, value));
535
+ }
536
+ for (const name of valueToExport) {
537
+ if (!(name in file.data)) continue;
538
+ tree.children.unshift(getMdastExport(name, file.data[name]));
539
+ }
540
+ };
541
+ }
542
+ function getMdastExport(name, value) {
543
+ return {
544
+ type: "mdxjsEsm",
545
+ value: "",
546
+ data: {
547
+ estree: {
548
+ type: "Program",
549
+ sourceType: "module",
550
+ body: [
551
+ {
552
+ type: "ExportNamedDeclaration",
553
+ attributes: [],
554
+ specifiers: [],
555
+ source: null,
556
+ declaration: {
557
+ type: "VariableDeclaration",
558
+ kind: "let",
559
+ declarations: [
560
+ {
561
+ type: "VariableDeclarator",
562
+ id: {
563
+ type: "Identifier",
564
+ name
565
+ },
566
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
567
+ }
568
+ ]
569
+ }
570
+ }
571
+ ]
572
+ }
573
+ }
574
+ };
575
+ }
576
+ function flattenNode2(node) {
577
+ if ("children" in node)
578
+ return node.children.map((child) => flattenNode2(child)).join("");
579
+ if ("value" in node) return node.value;
580
+ return "";
581
+ }
582
+
583
+ // src/loaders/mdx/build-mdx.ts
562
584
  var cache3 = /* @__PURE__ */ new Map();
563
585
  async function buildMDX(cacheKey, source, options) {
564
586
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
@@ -569,7 +591,24 @@ async function buildMDX(cacheKey, source, options) {
569
591
  processor = (0, import_mdx.createProcessor)({
570
592
  outputFormat: "program",
571
593
  ...rest,
572
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
594
+ remarkPlugins: [
595
+ remarkInclude,
596
+ ...rest.remarkPlugins ?? [],
597
+ [
598
+ remarkPostprocess,
599
+ {
600
+ ...options.postprocess,
601
+ valueToExport: [
602
+ ...options.postprocess?.valueToExport ?? [],
603
+ "structuredData",
604
+ "extractedReferences",
605
+ "frontmatter",
606
+ "lastModified",
607
+ "_markdown"
608
+ ]
609
+ }
610
+ ]
611
+ ],
573
612
  format
574
613
  });
575
614
  cache3.set(key, processor);
@@ -577,7 +616,7 @@ async function buildMDX(cacheKey, source, options) {
577
616
  return processor;
578
617
  }
579
618
  return getProcessor(
580
- options.format ?? filePath.endsWith(".mdx") ? "mdx" : "md"
619
+ options.format ?? (filePath.endsWith(".mdx") ? "mdx" : "md")
581
620
  ).process({
582
621
  value: source,
583
622
  path: filePath,
@@ -590,10 +629,10 @@ async function buildMDX(cacheKey, source, options) {
590
629
  });
591
630
  }
592
631
 
593
- // src/loaders/mdx.ts
632
+ // src/loaders/mdx/index.ts
594
633
  var import_zod = require("zod");
595
634
  var import_promises = __toESM(require("fs/promises"), 1);
596
- var import_node_path2 = __toESM(require("path"), 1);
635
+ var import_node_path3 = __toESM(require("path"), 1);
597
636
  var import_node_crypto = require("crypto");
598
637
  var querySchema = import_zod.z.object({
599
638
  only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
@@ -621,25 +660,22 @@ function createMdxLoader(configLoader) {
621
660
  const cacheDir = isDevelopment ? void 0 : loaded.global.experimentalBuildCache;
622
661
  const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
623
662
  if (cacheDir) {
624
- const cached = await import_promises.default.readFile(import_node_path2.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
663
+ const cached = await import_promises.default.readFile(import_node_path3.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
625
664
  if (cached && cached.hash === generateCacheHash(value)) return cached;
626
665
  }
627
666
  const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
628
- let schema;
629
- let mdxOptions;
667
+ let docCollection;
630
668
  switch (collection?.type) {
631
669
  case "doc":
632
- mdxOptions = collection.mdxOptions;
633
- schema = collection.schema;
670
+ docCollection = collection;
634
671
  break;
635
672
  case "docs":
636
- mdxOptions = collection.docs.mdxOptions;
637
- schema = collection.docs.schema;
673
+ docCollection = collection.docs;
638
674
  break;
639
675
  }
640
- if (schema) {
676
+ if (docCollection?.schema) {
641
677
  matter.data = await validate(
642
- schema,
678
+ docCollection.schema,
643
679
  matter.data,
644
680
  {
645
681
  source: value,
@@ -664,7 +700,8 @@ function createMdxLoader(configLoader) {
664
700
  "\n".repeat(lineOffset) + matter.content,
665
701
  {
666
702
  development: isDevelopment,
667
- ...mdxOptions ?? await loaded.getDefaultMDXOptions(),
703
+ ...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
704
+ postprocess: docCollection?.postprocess,
668
705
  data,
669
706
  filePath,
670
707
  frontmatter: matter.data,
@@ -678,7 +715,7 @@ function createMdxLoader(configLoader) {
678
715
  if (cacheDir) {
679
716
  await import_promises.default.mkdir(cacheDir, { recursive: true });
680
717
  await import_promises.default.writeFile(
681
- import_node_path2.default.join(cacheDir, cacheKey),
718
+ import_node_path3.default.join(cacheDir, cacheKey),
682
719
  JSON.stringify({
683
720
  ...out,
684
721
  hash: generateCacheHash(value)
@@ -691,25 +728,19 @@ function createMdxLoader(configLoader) {
691
728
  function generateCacheHash(input) {
692
729
  return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
693
730
  }
694
-
695
- // src/loaders/config-loader.ts
696
- function dynamicConfig(configPath, outDir) {
697
- return {
698
- async getConfig(hash) {
699
- return loadConfig(
700
- configPath,
701
- outDir,
702
- hash ?? await getConfigHash(configPath)
703
- );
704
- }
705
- };
731
+ function countLines(s) {
732
+ let num = 0;
733
+ for (const c of s) {
734
+ if (c === "\n") num++;
735
+ }
736
+ return num;
706
737
  }
707
738
 
708
739
  // src/loaders/adapter.ts
709
740
  var import_node_url2 = require("url");
710
741
  var import_promises2 = __toESM(require("fs/promises"), 1);
711
742
  var import_node_querystring = require("querystring");
712
- var import_node_path3 = __toESM(require("path"), 1);
743
+ var import_node_path4 = __toESM(require("path"), 1);
713
744
  function toNode(loader, filterByPath) {
714
745
  return async (url, _context, nextLoad) => {
715
746
  if (!url.startsWith("file:///")) return nextLoad(url);