fumadocs-mdx 11.10.1 → 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 (61) hide show
  1. package/dist/bin.cjs +29 -139
  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 +126 -108
  6. package/dist/bun/index.js +5 -5
  7. package/dist/chunk-3M4SHY6K.js +80 -0
  8. package/dist/{chunk-UOOPSLFY.js → chunk-AUOOMFAI.js} +27 -21
  9. package/dist/{chunk-QJCCVMBJ.js → chunk-KGUBBRL6.js} +11 -13
  10. package/dist/{chunk-SVTXMVLQ.js → chunk-KTDVTBMH.js} +1 -1
  11. package/dist/{chunk-766EAFX6.js → chunk-POXTQZ4D.js} +1 -31
  12. package/dist/chunk-SWNOXPYJ.js +142 -0
  13. package/dist/{chunk-XXSKWWMB.js → chunk-TLD6JMT6.js} +1 -1
  14. package/dist/{chunk-CNKI574E.js → chunk-VXEBLM4X.js} +1 -1
  15. package/dist/{chunk-QVZ7JH4H.js → chunk-YC25YEBF.js} +1 -1
  16. package/dist/chunk-ZLCSVXCD.js +10 -0
  17. package/dist/config/index.cjs +18 -97
  18. package/dist/config/index.d.cts +1 -1
  19. package/dist/config/index.d.ts +1 -1
  20. package/dist/config/index.js +48 -9
  21. package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.cts} +18 -3
  22. package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.ts} +18 -3
  23. package/dist/loader-mdx.cjs +127 -139
  24. package/dist/loader-mdx.js +6 -6
  25. package/dist/next/index.cjs +29 -139
  26. package/dist/next/index.js +16 -16
  27. package/dist/node/loader.cjs +131 -143
  28. package/dist/node/loader.js +6 -6
  29. package/dist/postinstall-U7VROOY7.js +9 -0
  30. package/dist/{mdx-options-T73E4LQB.js → preset-WFEORCAB.js} +1 -1
  31. package/dist/runtime/next/async.cjs +198 -150
  32. package/dist/runtime/next/async.d.cts +3 -3
  33. package/dist/runtime/next/async.d.ts +3 -3
  34. package/dist/runtime/next/async.js +50 -30
  35. package/dist/runtime/next/index.cjs +32 -21
  36. package/dist/runtime/next/index.d.cts +11 -7
  37. package/dist/runtime/next/index.d.ts +11 -7
  38. package/dist/runtime/next/index.js +2 -1
  39. package/dist/runtime/vite/browser.d.cts +2 -3
  40. package/dist/runtime/vite/browser.d.ts +2 -3
  41. package/dist/runtime/vite/server.cjs +67 -21
  42. package/dist/runtime/vite/server.d.cts +14 -28
  43. package/dist/runtime/vite/server.d.ts +14 -28
  44. package/dist/runtime/vite/server.js +61 -21
  45. package/dist/shared-0QIuV0XZ.d.ts +70 -0
  46. package/dist/shared-CqgMnt9h.d.cts +70 -0
  47. package/dist/{types-DN9KrG7R.d.ts → types-DLIAvrgC.d.ts} +6 -32
  48. package/dist/{types-DT83Ijs6.d.cts → types-Dl8HLbm5.d.cts} +6 -32
  49. package/dist/vite/index.cjs +131 -143
  50. package/dist/vite/index.js +7 -7
  51. package/package.json +2 -6
  52. package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
  53. package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
  54. package/dist/chunk-GBMFGEC7.js +0 -57
  55. package/dist/chunk-QQWCBFFE.js +0 -40
  56. package/dist/chunk-SMSNZ6N5.js +0 -155
  57. package/dist/config/zod-3.cjs +0 -422
  58. package/dist/config/zod-3.d.cts +0 -53
  59. package/dist/config/zod-3.d.ts +0 -53
  60. package/dist/config/zod-3.js +0 -40
  61. package/dist/postinstall-XV4WSHZP.js +0 -9
package/dist/bin.cjs CHANGED
@@ -30,86 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
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
 
@@ -233,7 +153,7 @@ function buildConfig(config) {
233
153
  const input = this.global.mdxOptions;
234
154
  async function uncached() {
235
155
  const options = typeof input === "function" ? await input() : input;
236
- 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));
237
157
  if (options?.preset === "minimal") return options;
238
158
  return getDefaultMDXOptions2({
239
159
  ...options,
@@ -256,35 +176,6 @@ var init_build = __esm({
256
176
  function findConfigFile() {
257
177
  return path.resolve("source.config.ts");
258
178
  }
259
- async function isZod3() {
260
- try {
261
- const content = JSON.parse(
262
- (await fs.readFile("node_modules/zod/package.json")).toString()
263
- );
264
- const version = content.version;
265
- return typeof version === "string" && version.startsWith("3.");
266
- } catch {
267
- return false;
268
- }
269
- }
270
- function createCompatZodPlugin() {
271
- return {
272
- name: "replace-zod-import",
273
- async setup(build) {
274
- const usingZod3 = await isZod3();
275
- if (!usingZod3) return;
276
- console.warn(
277
- "[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
278
- );
279
- build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
280
- return {
281
- path: "fumadocs-mdx/config/zod-3",
282
- external: true
283
- };
284
- });
285
- }
286
- };
287
- }
288
179
  async function compileConfig(configPath, outDir) {
289
180
  const { build } = await import("esbuild");
290
181
  const transformed = await build({
@@ -296,7 +187,6 @@ async function compileConfig(configPath, outDir) {
296
187
  platform: "node",
297
188
  format: "esm",
298
189
  packages: "external",
299
- plugins: [createCompatZodPlugin()],
300
190
  outExtension: {
301
191
  ".js": ".mjs"
302
192
  },
@@ -562,7 +452,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
562
452
  getImportCode({
563
453
  type: "namespace",
564
454
  name: importId,
565
- specifier: `${toImportPath(file.absolutePath, importPath)}?${params.join("&")}`
455
+ specifier: `${toImportPath(file.fullPath, importPath)}?${params.join("&")}`
566
456
  })
567
457
  );
568
458
  return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
@@ -571,17 +461,17 @@ async function generateJS(configPath, config, importPath, configHash = false) {
571
461
  }
572
462
  async function getMetaEntries(collection, files) {
573
463
  const items = files.map(async (file) => {
574
- const source = await readFileWithCache(file.absolutePath).catch(() => "");
575
- let data = source.length === 0 ? {} : parseMetaEntry(file.absolutePath, source);
464
+ const source = await readFileWithCache(file.fullPath).catch(() => "");
465
+ let data = source.length === 0 ? {} : parseMetaEntry(file.fullPath, source);
576
466
  if (collection?.schema) {
577
467
  data = await validate(
578
468
  collection.schema,
579
469
  data,
580
470
  {
581
471
  source,
582
- path: file.absolutePath
472
+ path: file.fullPath
583
473
  },
584
- `invalid data in ${file.absolutePath}`
474
+ `invalid data in ${file.fullPath}`
585
475
  );
586
476
  }
587
477
  return JSON.stringify({
@@ -605,20 +495,20 @@ async function generateJS(configPath, config, importPath, configHash = false) {
605
495
  }
606
496
  const entries2 = files.map(async (file) => {
607
497
  const parsed = fumaMatter(
608
- await readFileWithCache(file.absolutePath).catch(() => "")
498
+ await readFileWithCache(file.fullPath).catch(() => "")
609
499
  );
610
500
  let data = parsed.data;
611
501
  if (collection.schema) {
612
502
  data = await validate(
613
503
  collection.schema,
614
504
  parsed.data,
615
- { path: file.absolutePath, source: parsed.content },
616
- `invalid frontmatter in ${file.absolutePath}`
505
+ { path: file.fullPath, source: parsed.content },
506
+ `invalid frontmatter in ${file.fullPath}`
617
507
  );
618
508
  }
619
509
  let lastModified;
620
510
  if (config.global?.lastModifiedTime === "git") {
621
- lastModified = await getGitTimestamp(file.absolutePath);
511
+ lastModified = await getGitTimestamp(file.fullPath);
622
512
  }
623
513
  return JSON.stringify({
624
514
  info: file,
@@ -665,14 +555,14 @@ async function getCollectionFiles(collection) {
665
555
  await Promise.all(
666
556
  dirs.map(async (dir) => {
667
557
  const result = await (0, import_tinyglobby.glob)(patterns, {
668
- cwd: path4.resolve(dir),
669
- absolute: true
558
+ cwd: path4.resolve(dir)
670
559
  });
671
560
  for (const item of result) {
672
561
  if (!isFileSupported(item, collection)) continue;
673
- files.set(item, {
674
- path: path4.relative(dir, item),
675
- absolutePath: item
562
+ const fullPath = path4.join(dir, item);
563
+ files.set(fullPath, {
564
+ path: item,
565
+ fullPath
676
566
  });
677
567
  }
678
568
  })
package/dist/bin.js CHANGED
@@ -9,7 +9,7 @@ async function start() {
9
9
  const { postInstall } = await import("./next/index.js");
10
10
  await postInstall(...args);
11
11
  } else {
12
- const { postInstall } = await import("./postinstall-XV4WSHZP.js");
12
+ const { postInstall } = await import("./postinstall-U7VROOY7.js");
13
13
  await postInstall(...args);
14
14
  }
15
15
  }
@@ -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 };