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
package/dist/bin.d.cts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/bin.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/bin.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/bin.ts
4
+ import { existsSync } from "fs";
5
+ async function start() {
6
+ const args = process.argv.slice(2);
7
+ const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.ts");
8
+ if (isNext) {
9
+ const { postInstall } = await import("./next/index.js");
10
+ await postInstall(...args);
11
+ } else {
12
+ const { postInstall } = await import("./postinstall-U7VROOY7.js");
13
+ await postInstall(...args);
14
+ }
15
+ }
16
+ void start();
@@ -1,8 +1,55 @@
1
- import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.cjs';
2
- import { ReactNode, FC } from 'react';
3
- import { a as DocCollection, b as DocsCollection, M as MetaCollection } from './define-BH4bnHQl.cjs';
1
+ import { createProcessor } from '@mdx-js/mdx';
2
+ import { StructuredData } from 'fumadocs-core/mdx-plugins';
3
+ import { TableOfContents } from 'fumadocs-core/server';
4
+ import { FC, ReactNode } from 'react';
5
+ import { MDXProps } from 'mdx/types';
6
+ import { E as ExtractedReference, a as DocCollection, b as DocsCollection, M as MetaCollection } from './define--6HQ1ehX.js';
4
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
5
8
 
9
+ type Processor = ReturnType<typeof createProcessor>;
10
+ interface CompilerOptions {
11
+ addDependency: (file: string) => void;
12
+ }
13
+ interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
14
+ frontmatter: Frontmatter;
15
+ structuredData: StructuredData;
16
+ toc: TableOfContents;
17
+ default: FC<MDXProps>;
18
+ /**
19
+ * Only available when `lastModifiedTime` is enabled on MDX loader
20
+ */
21
+ lastModified?: Date;
22
+ extractedReferences?: ExtractedReference[];
23
+ _markdown?: string;
24
+ }
25
+ interface FumadocsDataMap {
26
+ /**
27
+ * [Fumadocs MDX] raw frontmatter, you can modify it
28
+ */
29
+ frontmatter?: Record<string, unknown>;
30
+ /**
31
+ * [Fumadocs MDX] additional ESM exports to write
32
+ */
33
+ 'mdx-export'?: {
34
+ name: string;
35
+ value: unknown;
36
+ }[];
37
+ extractedReferences: ExtractedReference[];
38
+ /**
39
+ * [Fumadocs MDX] The compiler object from loader
40
+ */
41
+ _compiler?: CompilerOptions;
42
+ _getProcessor?: (format: 'md' | 'mdx') => Processor;
43
+ /**
44
+ * [Fumadocs MDX] Processed Markdown content before `remark-rehype`.
45
+ */
46
+ _markdown?: string;
47
+ }
48
+ declare module 'vfile' {
49
+ interface DataMap extends FumadocsDataMap {
50
+ }
51
+ }
52
+
6
53
  type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
7
54
  type DocMap<Frontmatter> = Record<string, (() => Promise<CompiledMDXFile<Frontmatter>>) & {
8
55
  base: string;
@@ -48,4 +95,4 @@ interface ClientLoader<Frontmatter, Props> {
48
95
  declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
49
96
  declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode): ClientRenderer<Props>;
50
97
 
51
- export { type BaseCreate as B, type CompiledMDXFile as C, type DocMap as D, type LazyDocMap as L, type MetaMap as M, type ClientLoader as a, type ClientLoaderOptions as b, createClientLoader as c, fromConfigBase as f, toClientRenderer as t };
98
+ export { type BaseCreate as B, type ClientLoader as C, type DocMap as D, type LazyDocMap as L, type MetaMap as M, type ClientLoaderOptions as a, type CompiledMDXFile as b, createClientLoader as c, fromConfigBase as f, toClientRenderer as t };
@@ -1,8 +1,55 @@
1
- import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.js';
2
- import { ReactNode, FC } from 'react';
3
- import { a as DocCollection, b as DocsCollection, M as MetaCollection } from './define-BH4bnHQl.js';
1
+ import { createProcessor } from '@mdx-js/mdx';
2
+ import { StructuredData } from 'fumadocs-core/mdx-plugins';
3
+ import { TableOfContents } from 'fumadocs-core/server';
4
+ import { FC, ReactNode } from 'react';
5
+ import { MDXProps } from 'mdx/types';
6
+ import { E as ExtractedReference, a as DocCollection, b as DocsCollection, M as MetaCollection } from './define--6HQ1ehX.cjs';
4
7
  import { StandardSchemaV1 } from '@standard-schema/spec';
5
8
 
9
+ type Processor = ReturnType<typeof createProcessor>;
10
+ interface CompilerOptions {
11
+ addDependency: (file: string) => void;
12
+ }
13
+ interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
14
+ frontmatter: Frontmatter;
15
+ structuredData: StructuredData;
16
+ toc: TableOfContents;
17
+ default: FC<MDXProps>;
18
+ /**
19
+ * Only available when `lastModifiedTime` is enabled on MDX loader
20
+ */
21
+ lastModified?: Date;
22
+ extractedReferences?: ExtractedReference[];
23
+ _markdown?: string;
24
+ }
25
+ interface FumadocsDataMap {
26
+ /**
27
+ * [Fumadocs MDX] raw frontmatter, you can modify it
28
+ */
29
+ frontmatter?: Record<string, unknown>;
30
+ /**
31
+ * [Fumadocs MDX] additional ESM exports to write
32
+ */
33
+ 'mdx-export'?: {
34
+ name: string;
35
+ value: unknown;
36
+ }[];
37
+ extractedReferences: ExtractedReference[];
38
+ /**
39
+ * [Fumadocs MDX] The compiler object from loader
40
+ */
41
+ _compiler?: CompilerOptions;
42
+ _getProcessor?: (format: 'md' | 'mdx') => Processor;
43
+ /**
44
+ * [Fumadocs MDX] Processed Markdown content before `remark-rehype`.
45
+ */
46
+ _markdown?: string;
47
+ }
48
+ declare module 'vfile' {
49
+ interface DataMap extends FumadocsDataMap {
50
+ }
51
+ }
52
+
6
53
  type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
7
54
  type DocMap<Frontmatter> = Record<string, (() => Promise<CompiledMDXFile<Frontmatter>>) & {
8
55
  base: string;
@@ -48,4 +95,4 @@ interface ClientLoader<Frontmatter, Props> {
48
95
  declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
49
96
  declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode): ClientRenderer<Props>;
50
97
 
51
- export { type BaseCreate as B, type CompiledMDXFile as C, type DocMap as D, type LazyDocMap as L, type MetaMap as M, type ClientLoader as a, type ClientLoaderOptions as b, createClientLoader as c, fromConfigBase as f, toClientRenderer as t };
98
+ export { type BaseCreate as B, type ClientLoader as C, type DocMap as D, type LazyDocMap as L, type MetaMap as M, type ClientLoaderOptions as a, type CompiledMDXFile as b, createClientLoader as c, fromConfigBase as f, toClientRenderer as t };
@@ -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/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
 
@@ -290,10 +210,10 @@ function countLines(s) {
290
210
  return num;
291
211
  }
292
212
 
293
- // src/utils/build-mdx.ts
213
+ // src/mdx/build-mdx.ts
294
214
  var import_mdx = require("@mdx-js/mdx");
295
215
 
296
- // src/mdx-plugins/remark-include.ts
216
+ // src/mdx/remark-include.ts
297
217
  var import_unified = require("unified");
298
218
  var import_unist_util_visit = require("unist-util-visit");
299
219
  var path2 = __toESM(require("path"), 1);
@@ -425,7 +345,90 @@ function getDefaultProcessor(format) {
425
345
  return mdProcessor.use(import_remark_mdx.default);
426
346
  }
427
347
 
428
- // src/utils/build-mdx.ts
348
+ // src/mdx/remark-postprocess.ts
349
+ var import_unist_util_visit2 = require("unist-util-visit");
350
+ var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
351
+ var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
352
+ function remarkPostprocess({
353
+ includeProcessedMarkdown = false,
354
+ valueToExport = []
355
+ } = {}) {
356
+ return (tree, file) => {
357
+ let title;
358
+ const urls = [];
359
+ (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
360
+ if (node.type === "heading" && node.depth === 1) {
361
+ title = flattenNode2(node);
362
+ }
363
+ if (node.type !== "link") return;
364
+ urls.push({
365
+ href: node.url
366
+ });
367
+ return "skip";
368
+ });
369
+ if (title) {
370
+ file.data.frontmatter ??= {};
371
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
372
+ }
373
+ file.data.extractedReferences = urls;
374
+ if (includeProcessedMarkdown) {
375
+ file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
376
+ ...this.data("settings"),
377
+ // @ts-expect-error - from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
378
+ extensions: this.data("toMarkdownExtensions") || []
379
+ });
380
+ }
381
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
382
+ tree.children.unshift(getMdastExport(name, value));
383
+ }
384
+ for (const name of valueToExport) {
385
+ if (!(name in file.data)) continue;
386
+ tree.children.unshift(getMdastExport(name, file.data[name]));
387
+ }
388
+ };
389
+ }
390
+ function getMdastExport(name, value) {
391
+ return {
392
+ type: "mdxjsEsm",
393
+ value: "",
394
+ data: {
395
+ estree: {
396
+ type: "Program",
397
+ sourceType: "module",
398
+ body: [
399
+ {
400
+ type: "ExportNamedDeclaration",
401
+ attributes: [],
402
+ specifiers: [],
403
+ source: null,
404
+ declaration: {
405
+ type: "VariableDeclaration",
406
+ kind: "let",
407
+ declarations: [
408
+ {
409
+ type: "VariableDeclarator",
410
+ id: {
411
+ type: "Identifier",
412
+ name
413
+ },
414
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
415
+ }
416
+ ]
417
+ }
418
+ }
419
+ ]
420
+ }
421
+ }
422
+ };
423
+ }
424
+ function flattenNode2(node) {
425
+ if ("children" in node)
426
+ return node.children.map((child) => flattenNode2(child)).join("");
427
+ if ("value" in node) return node.value;
428
+ return "";
429
+ }
430
+
431
+ // src/mdx/build-mdx.ts
429
432
  var cache2 = /* @__PURE__ */ new Map();
430
433
  async function buildMDX(cacheKey, source, options) {
431
434
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
@@ -436,7 +439,24 @@ async function buildMDX(cacheKey, source, options) {
436
439
  processor = (0, import_mdx.createProcessor)({
437
440
  outputFormat: "program",
438
441
  ...rest,
439
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
442
+ remarkPlugins: [
443
+ remarkInclude,
444
+ ...rest.remarkPlugins ?? [],
445
+ [
446
+ remarkPostprocess,
447
+ {
448
+ ...options.postprocess,
449
+ valueToExport: [
450
+ ...options.postprocess?.valueToExport ?? [],
451
+ "structuredData",
452
+ "extractedReferences",
453
+ "frontmatter",
454
+ "lastModified",
455
+ "_markdown"
456
+ ]
457
+ }
458
+ ]
459
+ ],
440
460
  format
441
461
  });
442
462
  cache2.set(key, processor);
@@ -492,21 +512,18 @@ function createMdxLoader(configLoader) {
492
512
  if (cached && cached.hash === generateCacheHash(value)) return cached;
493
513
  }
494
514
  const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
495
- let schema;
496
- let mdxOptions;
515
+ let docCollection;
497
516
  switch (collection?.type) {
498
517
  case "doc":
499
- mdxOptions = collection.mdxOptions;
500
- schema = collection.schema;
518
+ docCollection = collection;
501
519
  break;
502
520
  case "docs":
503
- mdxOptions = collection.docs.mdxOptions;
504
- schema = collection.docs.schema;
521
+ docCollection = collection.docs;
505
522
  break;
506
523
  }
507
- if (schema) {
524
+ if (docCollection?.schema) {
508
525
  matter.data = await validate(
509
- schema,
526
+ docCollection.schema,
510
527
  matter.data,
511
528
  {
512
529
  source: value,
@@ -531,7 +548,8 @@ function createMdxLoader(configLoader) {
531
548
  "\n".repeat(lineOffset) + matter.content,
532
549
  {
533
550
  development: isDevelopment,
534
- ...mdxOptions ?? await loaded.getDefaultMDXOptions(),
551
+ ...docCollection?.mdxOptions ?? await loaded.getDefaultMDXOptions(),
552
+ postprocess: docCollection?.postprocess,
535
553
  data,
536
554
  filePath,
537
555
  frontmatter: matter.data,
@@ -600,7 +618,7 @@ function buildConfig(config) {
600
618
  const input = this.global.mdxOptions;
601
619
  async function uncached() {
602
620
  const options = typeof input === "function" ? await input() : input;
603
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
621
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
604
622
  if (options?.preset === "minimal") return options;
605
623
  return getDefaultMDXOptions2({
606
624
  ...options,
@@ -630,10 +648,12 @@ function resolvedConfig(loaded) {
630
648
 
631
649
  // src/bun/index.ts
632
650
  var import_node_querystring = require("querystring");
651
+ var import_node_url2 = require("url");
633
652
  function createMdxPlugin(options = {}) {
634
653
  const { configPath = findConfigFile() } = options;
635
654
  async function getMdxLoader() {
636
- const out = buildConfig(await import(configPath));
655
+ const importPath = (0, import_node_url2.pathToFileURL)(configPath).href;
656
+ const out = buildConfig(await import(importPath));
637
657
  return createMdxLoader(resolvedConfig(out));
638
658
  }
639
659
  return {
package/dist/bun/index.js CHANGED
@@ -1,23 +1,26 @@
1
1
  import {
2
2
  createMdxLoader,
3
3
  resolvedConfig
4
- } from "../chunk-5XJM5RPV.js";
4
+ } from "../chunk-KGUBBRL6.js";
5
+ import "../chunk-IQAEAI4P.js";
5
6
  import {
6
7
  findConfigFile
7
- } from "../chunk-2HKRTQYP.js";
8
- import "../chunk-QQWCBFFE.js";
9
- import "../chunk-SVTXMVLQ.js";
8
+ } from "../chunk-POXTQZ4D.js";
9
+ import "../chunk-SWNOXPYJ.js";
10
+ import "../chunk-KTDVTBMH.js";
10
11
  import {
11
12
  buildConfig
12
- } from "../chunk-QVZ7JH4H.js";
13
+ } from "../chunk-YC25YEBF.js";
13
14
  import "../chunk-VWJKRQZR.js";
14
15
 
15
16
  // src/bun/index.ts
16
17
  import { parse } from "querystring";
18
+ import { pathToFileURL } from "url";
17
19
  function createMdxPlugin(options = {}) {
18
20
  const { configPath = findConfigFile() } = options;
19
21
  async function getMdxLoader() {
20
- const out = buildConfig(await import(configPath));
22
+ const importPath = pathToFileURL(configPath).href;
23
+ const out = buildConfig(await import(importPath));
21
24
  return createMdxLoader(resolvedConfig(out));
22
25
  }
23
26
  return {
@@ -0,0 +1,80 @@
1
+ // src/mdx/preset.ts
2
+ import * as plugins from "fumadocs-core/mdx-plugins";
3
+ function pluginOption(def, options = []) {
4
+ const list = def(Array.isArray(options) ? options : []).filter(
5
+ Boolean
6
+ );
7
+ if (typeof options === "function") {
8
+ return options(list);
9
+ }
10
+ return list;
11
+ }
12
+ function getDefaultMDXOptions({
13
+ valueToExport = [],
14
+ rehypeCodeOptions,
15
+ remarkImageOptions,
16
+ remarkHeadingOptions,
17
+ remarkStructureOptions,
18
+ remarkCodeTabOptions,
19
+ remarkNpmOptions,
20
+ _withoutBundler = false,
21
+ ...mdxOptions
22
+ }) {
23
+ const remarkPlugins = pluginOption(
24
+ (v) => [
25
+ plugins.remarkGfm,
26
+ [
27
+ plugins.remarkHeading,
28
+ {
29
+ generateToc: false,
30
+ ...remarkHeadingOptions
31
+ }
32
+ ],
33
+ remarkImageOptions !== false && [
34
+ plugins.remarkImage,
35
+ {
36
+ ...remarkImageOptions,
37
+ useImport: _withoutBundler ? false : remarkImageOptions?.useImport
38
+ }
39
+ ],
40
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
41
+ plugins.remarkCodeTab,
42
+ remarkCodeTabOptions
43
+ ],
44
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
45
+ ...v,
46
+ remarkStructureOptions !== false && [
47
+ plugins.remarkStructure,
48
+ remarkStructureOptions
49
+ ],
50
+ () => {
51
+ return (_, file) => {
52
+ file.data["mdx-export"] ??= [];
53
+ for (const name of valueToExport) {
54
+ if (name in file.data)
55
+ file.data["mdx-export"].push({ name, value: file.data[name] });
56
+ }
57
+ };
58
+ }
59
+ ],
60
+ mdxOptions.remarkPlugins
61
+ );
62
+ const rehypePlugins = pluginOption(
63
+ (v) => [
64
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
65
+ ...v,
66
+ plugins.rehypeToc
67
+ ],
68
+ mdxOptions.rehypePlugins
69
+ );
70
+ return {
71
+ ...mdxOptions,
72
+ outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
73
+ remarkPlugins,
74
+ rehypePlugins
75
+ };
76
+ }
77
+
78
+ export {
79
+ getDefaultMDXOptions
80
+ };
@@ -0,0 +1,65 @@
1
+ // src/utils/import-formatter.ts
2
+ import path from "path";
3
+ function getImportCode(info) {
4
+ const specifier = JSON.stringify(info.specifier);
5
+ if (info.type === "default") return `import ${info.name} from ${specifier}`;
6
+ if (info.type === "namespace")
7
+ return `import * as ${info.name} from ${specifier}`;
8
+ if (info.type === "named") {
9
+ const names = info.names.map(
10
+ (name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
11
+ );
12
+ return `import { ${names.join(", ")} } from ${specifier}`;
13
+ }
14
+ return `import ${specifier}`;
15
+ }
16
+ function toImportPath(file, config) {
17
+ const ext = path.extname(file);
18
+ let filename;
19
+ if (ext === ".ts" && config.jsExtension) {
20
+ filename = file.substring(0, file.length - ext.length) + ".js";
21
+ } else if (ext === ".ts") {
22
+ filename = file.substring(0, file.length - ext.length);
23
+ } else {
24
+ filename = file;
25
+ }
26
+ let importPath;
27
+ if ("relativeTo" in config) {
28
+ importPath = path.relative(config.relativeTo, filename);
29
+ if (!path.isAbsolute(importPath) && !importPath.startsWith(".")) {
30
+ importPath = `./${importPath}`;
31
+ }
32
+ } else {
33
+ importPath = path.resolve(filename);
34
+ }
35
+ return importPath.replaceAll(path.sep, "/");
36
+ }
37
+ function ident(code, tab = 1) {
38
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
39
+ }
40
+
41
+ // src/utils/collections.ts
42
+ function getSupportedFormats(collection) {
43
+ return {
44
+ doc: ["mdx", "md"],
45
+ meta: ["json", "yaml"]
46
+ }[collection.type];
47
+ }
48
+ function getGlobPatterns(collection) {
49
+ if (collection.files) return collection.files;
50
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
51
+ }
52
+ function isFileSupported(filePath, collection) {
53
+ for (const format of getSupportedFormats(collection)) {
54
+ if (filePath.endsWith(`.${format}`)) return true;
55
+ }
56
+ return false;
57
+ }
58
+
59
+ export {
60
+ getImportCode,
61
+ toImportPath,
62
+ ident,
63
+ getGlobPatterns,
64
+ isFileSupported
65
+ };