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_visit2.visit)(tree, ["heading", "link"], (node) => {
41
- if (node.type === "heading" && node.depth === 1) {
42
- title = flattenNode2(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 flattenNode2(node) {
62
- if ("children" in node)
63
- return node.children.map((child) => flattenNode2(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_visit2, 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_visit2 = 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,11 +110,65 @@ 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();
117
+ }
118
+ });
119
+
120
+ // src/config/build.ts
121
+ function buildConfig(config) {
122
+ const collections = /* @__PURE__ */ new Map();
123
+ let globalConfig = {};
124
+ for (const [k, v] of Object.entries(config)) {
125
+ if (!v) {
126
+ continue;
127
+ }
128
+ if (typeof v === "object" && "type" in v) {
129
+ if (v.type === "docs") {
130
+ collections.set(k, v);
131
+ continue;
132
+ }
133
+ if (v.type === "doc" || v.type === "meta") {
134
+ collections.set(k, v);
135
+ continue;
136
+ }
137
+ }
138
+ if (k === "default" && v) {
139
+ globalConfig = v;
140
+ continue;
141
+ }
142
+ throw new Error(
143
+ `Unknown export "${k}", you can only export collections from source configuration file.`
144
+ );
145
+ }
146
+ const mdxOptionsCache = /* @__PURE__ */ new Map();
147
+ return {
148
+ global: globalConfig,
149
+ collections,
150
+ async getDefaultMDXOptions(mode = "default") {
151
+ const cached = mdxOptionsCache.get(mode);
152
+ if (cached) return cached;
153
+ const input = this.global.mdxOptions;
154
+ async function uncached() {
155
+ const options = typeof input === "function" ? await input() : input;
156
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
157
+ if (options?.preset === "minimal") return options;
158
+ return getDefaultMDXOptions2({
159
+ ...options,
160
+ _withoutBundler: mode === "remote"
161
+ });
162
+ }
163
+ const result = uncached();
164
+ mdxOptionsCache.set(mode, result);
165
+ return result;
166
+ }
167
+ };
168
+ }
169
+ var init_build = __esm({
170
+ "src/config/build.ts"() {
171
+ "use strict";
197
172
  }
198
173
  });
199
174
 
@@ -281,19 +256,10 @@ async function getGitTimestamp(file) {
281
256
  }
282
257
  }
283
258
 
284
- // src/utils/count-lines.ts
285
- function countLines(s) {
286
- let num = 0;
287
- for (const c of s) {
288
- if (c === "\n") num++;
289
- }
290
- return num;
291
- }
292
-
293
- // src/utils/build-mdx.ts
259
+ // src/loaders/mdx/build-mdx.ts
294
260
  var import_mdx = require("@mdx-js/mdx");
295
261
 
296
- // src/mdx-plugins/remark-include.ts
262
+ // src/loaders/mdx/remark-include.ts
297
263
  var import_unified = require("unified");
298
264
  var import_unist_util_visit = require("unist-util-visit");
299
265
  var path2 = __toESM(require("path"), 1);
@@ -301,7 +267,28 @@ var fs = __toESM(require("fs/promises"), 1);
301
267
  var import_remark_parse = __toESM(require("remark-parse"), 1);
302
268
  var import_remark_mdx = __toESM(require("remark-mdx"), 1);
303
269
  var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
304
- var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
270
+ var ElementLikeTypes = [
271
+ "mdxJsxFlowElement",
272
+ "mdxJsxTextElement",
273
+ "containerDirective",
274
+ "textDirective",
275
+ "leafDirective"
276
+ ];
277
+ function isElementLike(node) {
278
+ return ElementLikeTypes.includes(node.type);
279
+ }
280
+ function parseElementAttributes(element) {
281
+ if (Array.isArray(element.attributes)) {
282
+ const attributes = {};
283
+ for (const attr of element.attributes) {
284
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
285
+ attributes[attr.name] = attr.value;
286
+ }
287
+ }
288
+ return attributes;
289
+ }
290
+ return element.attributes ?? {};
291
+ }
305
292
  function flattenNode(node) {
306
293
  if ("children" in node)
307
294
  return node.children.map((child) => flattenNode(child)).join("");
@@ -318,21 +305,31 @@ function parseSpecifier(specifier) {
318
305
  }
319
306
  function extractSection(root, section) {
320
307
  let nodes;
321
- for (const node of root.children) {
322
- if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
323
- (attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
324
- )) {
325
- nodes = node.children;
326
- break;
308
+ let capturingHeadingContent = false;
309
+ (0, import_unist_util_visit.visit)(root, (node) => {
310
+ if (node.type === "heading") {
311
+ if (capturingHeadingContent) {
312
+ return false;
313
+ }
314
+ if (node.data?.hProperties?.id === section) {
315
+ capturingHeadingContent = true;
316
+ nodes = [node];
317
+ return "skip";
318
+ }
319
+ return;
327
320
  }
328
- if (node.type === "heading" && node.data?.hProperties?.id === section) {
329
- nodes = [node];
330
- continue;
321
+ if (capturingHeadingContent) {
322
+ nodes?.push(node);
323
+ return "skip";
331
324
  }
332
- if (!nodes) continue;
333
- if (node.type === "heading") break;
334
- nodes.push(node);
335
- }
325
+ if (isElementLike(node) && node.name === "section") {
326
+ const attributes = parseElementAttributes(node);
327
+ if (attributes.id === section) {
328
+ nodes = node.children;
329
+ return false;
330
+ }
331
+ }
332
+ });
336
333
  if (nodes)
337
334
  return {
338
335
  type: "root",
@@ -364,55 +361,52 @@ ${e instanceof Error ? e.message : String(e)}`,
364
361
  data: {}
365
362
  };
366
363
  }
367
- const processor = (data._getProcessor ?? getDefaultProcessor)(
364
+ const parser = (data._getProcessor ?? getDefaultProcessor)(
368
365
  ext === ".mdx" ? "mdx" : "md"
369
366
  );
370
- let parsed = await baseProcessor.run(
371
- processor.parse(fumaMatter(content).content)
372
- );
367
+ const parsed = fumaMatter(content);
368
+ let mdast = parser.parse({
369
+ path: file,
370
+ value: parsed.content,
371
+ data: { frontmatter: parsed.data }
372
+ });
373
373
  if (heading) {
374
- const extracted = extractSection(parsed, heading);
374
+ const extracted = extractSection(
375
+ await (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading).run(mdast),
376
+ heading
377
+ );
375
378
  if (!extracted)
376
379
  throw new Error(
377
- `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
380
+ `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.`
378
381
  );
379
- parsed = extracted;
382
+ mdast = extracted;
380
383
  }
381
- await update(parsed, path2.dirname(file), data);
382
- return parsed;
384
+ await update(mdast, path2.dirname(file), data);
385
+ return mdast;
383
386
  }
384
387
  async function update(tree, directory, data) {
385
388
  const queue = [];
386
- (0, import_unist_util_visit.visit)(
387
- tree,
388
- ["mdxJsxFlowElement", "mdxJsxTextElement"],
389
- (_node, _, parent) => {
390
- const node = _node;
391
- if (node.name !== TagName) return;
392
- const params = {};
393
- const specifier = flattenNode(node);
394
- if (specifier.length === 0) return "skip";
395
- for (const attr of node.attributes) {
396
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
397
- params[attr.name] = attr.value;
398
- }
399
- }
400
- const { file: relativePath, section } = parseSpecifier(specifier);
401
- const file = path2.resolve(
402
- "cwd" in params ? process.cwd() : directory,
403
- relativePath
404
- );
405
- queue.push(
406
- embedContent(file, section, params, data).then((replace) => {
407
- Object.assign(
408
- parent && parent.type === "paragraph" ? parent : node,
409
- replace
410
- );
411
- })
412
- );
413
- return "skip";
414
- }
415
- );
389
+ (0, import_unist_util_visit.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
390
+ const node = _node;
391
+ if (node.name !== TagName) return;
392
+ const specifier = flattenNode(node);
393
+ if (specifier.length === 0) return "skip";
394
+ const attributes = parseElementAttributes(node);
395
+ const { file: relativePath, section } = parseSpecifier(specifier);
396
+ const file = path2.resolve(
397
+ "cwd" in attributes ? process.cwd() : directory,
398
+ relativePath
399
+ );
400
+ queue.push(
401
+ embedContent(file, section, attributes, data).then((replace) => {
402
+ Object.assign(
403
+ parent && parent.type === "paragraph" ? parent : node,
404
+ replace
405
+ );
406
+ })
407
+ );
408
+ return "skip";
409
+ });
416
410
  await Promise.all(queue);
417
411
  }
418
412
  return async (tree, file) => {
@@ -425,7 +419,90 @@ function getDefaultProcessor(format) {
425
419
  return mdProcessor.use(import_remark_mdx.default);
426
420
  }
427
421
 
428
- // src/utils/build-mdx.ts
422
+ // src/loaders/mdx/remark-postprocess.ts
423
+ var import_unist_util_visit2 = require("unist-util-visit");
424
+ var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
425
+ var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
426
+ function remarkPostprocess({
427
+ includeProcessedMarkdown = false,
428
+ valueToExport = []
429
+ } = {}) {
430
+ return (tree, file) => {
431
+ let title;
432
+ const urls = [];
433
+ (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
434
+ if (node.type === "heading" && node.depth === 1) {
435
+ title = flattenNode2(node);
436
+ }
437
+ if (node.type !== "link") return;
438
+ urls.push({
439
+ href: node.url
440
+ });
441
+ return "skip";
442
+ });
443
+ if (title) {
444
+ file.data.frontmatter ??= {};
445
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
446
+ }
447
+ file.data.extractedReferences = urls;
448
+ if (includeProcessedMarkdown) {
449
+ file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
450
+ ...this.data("settings"),
451
+ // from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
452
+ extensions: this.data("toMarkdownExtensions") || []
453
+ });
454
+ }
455
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
456
+ tree.children.unshift(getMdastExport(name, value));
457
+ }
458
+ for (const name of valueToExport) {
459
+ if (!(name in file.data)) continue;
460
+ tree.children.unshift(getMdastExport(name, file.data[name]));
461
+ }
462
+ };
463
+ }
464
+ function getMdastExport(name, value) {
465
+ return {
466
+ type: "mdxjsEsm",
467
+ value: "",
468
+ data: {
469
+ estree: {
470
+ type: "Program",
471
+ sourceType: "module",
472
+ body: [
473
+ {
474
+ type: "ExportNamedDeclaration",
475
+ attributes: [],
476
+ specifiers: [],
477
+ source: null,
478
+ declaration: {
479
+ type: "VariableDeclaration",
480
+ kind: "let",
481
+ declarations: [
482
+ {
483
+ type: "VariableDeclarator",
484
+ id: {
485
+ type: "Identifier",
486
+ name
487
+ },
488
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
489
+ }
490
+ ]
491
+ }
492
+ }
493
+ ]
494
+ }
495
+ }
496
+ };
497
+ }
498
+ function flattenNode2(node) {
499
+ if ("children" in node)
500
+ return node.children.map((child) => flattenNode2(child)).join("");
501
+ if ("value" in node) return node.value;
502
+ return "";
503
+ }
504
+
505
+ // src/loaders/mdx/build-mdx.ts
429
506
  var cache2 = /* @__PURE__ */ new Map();
430
507
  async function buildMDX(cacheKey, source, options) {
431
508
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
@@ -436,7 +513,24 @@ async function buildMDX(cacheKey, source, options) {
436
513
  processor = (0, import_mdx.createProcessor)({
437
514
  outputFormat: "program",
438
515
  ...rest,
439
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
516
+ remarkPlugins: [
517
+ remarkInclude,
518
+ ...rest.remarkPlugins ?? [],
519
+ [
520
+ remarkPostprocess,
521
+ {
522
+ ...options.postprocess,
523
+ valueToExport: [
524
+ ...options.postprocess?.valueToExport ?? [],
525
+ "structuredData",
526
+ "extractedReferences",
527
+ "frontmatter",
528
+ "lastModified",
529
+ "_markdown"
530
+ ]
531
+ }
532
+ ]
533
+ ],
440
534
  format
441
535
  });
442
536
  cache2.set(key, processor);
@@ -444,7 +538,7 @@ async function buildMDX(cacheKey, source, options) {
444
538
  return processor;
445
539
  }
446
540
  return getProcessor(
447
- options.format ?? filePath.endsWith(".mdx") ? "mdx" : "md"
541
+ options.format ?? (filePath.endsWith(".mdx") ? "mdx" : "md")
448
542
  ).process({
449
543
  value: source,
450
544
  path: filePath,
@@ -457,7 +551,7 @@ async function buildMDX(cacheKey, source, options) {
457
551
  });
458
552
  }
459
553
 
460
- // src/loaders/mdx.ts
554
+ // src/loaders/mdx/index.ts
461
555
  var import_zod = require("zod");
462
556
  var import_promises = __toESM(require("fs/promises"), 1);
463
557
  var import_node_path2 = __toESM(require("path"), 1);
@@ -492,21 +586,18 @@ function createMdxLoader(configLoader) {
492
586
  if (cached && cached.hash === generateCacheHash(value)) return cached;
493
587
  }
494
588
  const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
495
- let schema;
496
- let mdxOptions;
589
+ let docCollection;
497
590
  switch (collection?.type) {
498
591
  case "doc":
499
- mdxOptions = collection.mdxOptions;
500
- schema = collection.schema;
592
+ docCollection = collection;
501
593
  break;
502
594
  case "docs":
503
- mdxOptions = collection.docs.mdxOptions;
504
- schema = collection.docs.schema;
595
+ docCollection = collection.docs;
505
596
  break;
506
597
  }
507
- if (schema) {
598
+ if (docCollection?.schema) {
508
599
  matter.data = await validate(
509
- schema,
600
+ docCollection.schema,
510
601
  matter.data,
511
602
  {
512
603
  source: value,
@@ -531,7 +622,8 @@ function createMdxLoader(configLoader) {
531
622
  "\n".repeat(lineOffset) + matter.content,
532
623
  {
533
624
  development: isDevelopment,
534
- ...mdxOptions ?? await loaded.getDefaultMDXOptions(),
625
+ ...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
626
+ postprocess: docCollection?.postprocess,
535
627
  data,
536
628
  filePath,
537
629
  frontmatter: matter.data,
@@ -558,68 +650,19 @@ function createMdxLoader(configLoader) {
558
650
  function generateCacheHash(input) {
559
651
  return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
560
652
  }
561
-
562
- // src/utils/config.ts
563
- var fs3 = __toESM(require("fs/promises"), 1);
564
- var path4 = __toESM(require("path"), 1);
565
- var import_node_url = require("url");
566
-
567
- // src/config/build.ts
568
- function buildConfig(config) {
569
- const collections = /* @__PURE__ */ new Map();
570
- let globalConfig = {};
571
- for (const [k, v] of Object.entries(config)) {
572
- if (!v) {
573
- continue;
574
- }
575
- if (typeof v === "object" && "type" in v) {
576
- if (v.type === "docs") {
577
- collections.set(k, v);
578
- continue;
579
- }
580
- if (v.type === "doc" || v.type === "meta") {
581
- collections.set(k, v);
582
- continue;
583
- }
584
- }
585
- if (k === "default" && v) {
586
- globalConfig = v;
587
- continue;
588
- }
589
- throw new Error(
590
- `Unknown export "${k}", you can only export collections from source configuration file.`
591
- );
653
+ function countLines(s) {
654
+ let num = 0;
655
+ for (const c of s) {
656
+ if (c === "\n") num++;
592
657
  }
593
- const mdxOptionsCache = /* @__PURE__ */ new Map();
594
- return {
595
- global: globalConfig,
596
- collections,
597
- async getDefaultMDXOptions(mode = "default") {
598
- const cached = mdxOptionsCache.get(mode);
599
- if (cached) return cached;
600
- const input = this.global.mdxOptions;
601
- async function uncached() {
602
- const options = typeof input === "function" ? await input() : input;
603
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
604
- if (options?.preset === "minimal") return options;
605
- return getDefaultMDXOptions2({
606
- ...options,
607
- _withoutBundler: mode === "remote"
608
- });
609
- }
610
- const result = uncached();
611
- mdxOptionsCache.set(mode, result);
612
- return result;
613
- }
614
- };
658
+ return num;
615
659
  }
616
660
 
617
- // src/utils/config.ts
661
+ // src/loaders/config/index.ts
662
+ var import_node_path3 = __toESM(require("path"), 1);
618
663
  function findConfigFile() {
619
- return path4.resolve("source.config.ts");
664
+ return import_node_path3.default.resolve("source.config.ts");
620
665
  }
621
-
622
- // src/loaders/config-loader.ts
623
666
  function resolvedConfig(loaded) {
624
667
  return {
625
668
  getConfig() {
@@ -629,12 +672,13 @@ function resolvedConfig(loaded) {
629
672
  }
630
673
 
631
674
  // src/bun/index.ts
675
+ init_build();
632
676
  var import_node_querystring = require("querystring");
633
- var import_node_url2 = require("url");
677
+ var import_node_url = require("url");
634
678
  function createMdxPlugin(options = {}) {
635
679
  const { configPath = findConfigFile() } = options;
636
680
  async function getMdxLoader() {
637
- const importPath = (0, import_node_url2.pathToFileURL)(configPath).href;
681
+ const importPath = (0, import_node_url.pathToFileURL)(configPath).href;
638
682
  const out = buildConfig(await import(importPath));
639
683
  return createMdxLoader(resolvedConfig(out));
640
684
  }
package/dist/bun/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import {
2
- createMdxLoader,
3
- resolvedConfig
4
- } from "../chunk-QJCCVMBJ.js";
5
- import "../chunk-QQWCBFFE.js";
6
- import "../chunk-SVTXMVLQ.js";
2
+ createMdxLoader
3
+ } from "../chunk-SP7CHRTS.js";
7
4
  import "../chunk-IQAEAI4P.js";
8
5
  import {
9
- findConfigFile
10
- } from "../chunk-766EAFX6.js";
6
+ findConfigFile,
7
+ resolvedConfig
8
+ } from "../chunk-XMFLD5J6.js";
11
9
  import {
12
10
  buildConfig
13
- } from "../chunk-QVZ7JH4H.js";
11
+ } from "../chunk-U4MQ44TS.js";
12
+ import "../chunk-QAUWMR5D.js";
13
+ import "../chunk-LMG6UWCL.js";
14
14
  import "../chunk-VWJKRQZR.js";
15
15
 
16
16
  // src/bun/index.ts
@@ -0,0 +1,29 @@
1
+ // src/next/map/file-cache.ts
2
+ import { LRUCache } from "lru-cache";
3
+ import fs from "fs/promises";
4
+ import path from "path";
5
+ var map = new LRUCache({
6
+ max: 100
7
+ });
8
+ function toFullPath(file) {
9
+ if (path.isAbsolute(file)) {
10
+ return path.relative(process.cwd(), file);
11
+ }
12
+ return file;
13
+ }
14
+ async function readFileWithCache(file) {
15
+ const fullPath = toFullPath(file);
16
+ const cached = map.get(fullPath);
17
+ if (cached) return cached;
18
+ const read = fs.readFile(fullPath).then((s) => s.toString());
19
+ map.set(fullPath, read);
20
+ return read;
21
+ }
22
+ function removeFileCache(file) {
23
+ map.delete(toFullPath(file));
24
+ }
25
+
26
+ export {
27
+ readFileWithCache,
28
+ removeFileCache
29
+ };