fumadocs-mdx 11.8.2 → 11.9.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.
@@ -25,19 +25,26 @@ type MDXFileToPageDataLazy<Frontmatter> = Override<Frontmatter, {
25
25
  body: FC<MDXProps>;
26
26
  }>;
27
27
  }>;
28
+ type DocMap<Frontmatter> = Record<string, (() => Promise<CompiledMDXFile<Frontmatter>>) & {
29
+ base: string;
30
+ }>;
31
+ type MetaMap<Data> = Record<string, (() => Promise<Data>) & {
32
+ base: string;
33
+ }>;
28
34
  interface LazyDocMap<Frontmatter> {
35
+ base: string;
29
36
  head: Record<string, () => Promise<Frontmatter>>;
30
37
  body: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
31
38
  }
32
39
  declare function fromConfig<Config>(): {
33
- doc: <Name extends keyof Config>(name: Name, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? Record<string, () => Promise<CompiledMDXFile<StandardSchemaV1.InferOutput<Schema>>>> : never;
34
- docLazy: <Name extends keyof Config>(name: Name, headGlob: Record<string, () => Promise<unknown>>, bodyGlob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? LazyDocMap<StandardSchemaV1.InferOutput<Schema>> : never;
35
- meta: <Name extends keyof Config>(name: Name, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends MetaCollection<infer Schema> | DocsCollection<StandardSchemaV1, infer Schema> ? Record<string, () => Promise<StandardSchemaV1.InferOutput<Schema>>> : never;
36
- sourceAsync: <DocOut extends PageData, MetaOut extends MetaData>(doc: Record<string, () => Promise<CompiledMDXFile<DocOut>>>, meta: Record<string, () => Promise<MetaOut>>) => Promise<Source<{
40
+ doc: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocMap<StandardSchemaV1.InferOutput<Schema>> : never;
41
+ docLazy: <Name extends keyof Config>(name: Name, base: string, headGlob: Record<string, () => Promise<unknown>>, bodyGlob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? LazyDocMap<StandardSchemaV1.InferOutput<Schema>> : never;
42
+ meta: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends MetaCollection<infer Schema> | DocsCollection<StandardSchemaV1, infer Schema> ? MetaMap<StandardSchemaV1.InferOutput<Schema>> : never;
43
+ sourceAsync: <DocOut extends PageData, MetaOut extends MetaData>(doc: DocMap<DocOut>, meta: MetaMap<MetaOut>) => Promise<Source<{
37
44
  pageData: MDXFileToPageData<DocOut>;
38
45
  metaData: MetaOut;
39
46
  }>>;
40
- sourceLazy: <DocOut extends PageData, MetaOut extends MetaData>(doc: LazyDocMap<DocOut>, meta: Record<string, () => Promise<MetaOut>>) => Promise<Source<{
47
+ sourceLazy: <DocOut extends PageData, MetaOut extends MetaData>(doc: LazyDocMap<DocOut>, meta: MetaMap<MetaOut>) => Promise<Source<{
41
48
  pageData: MDXFileToPageDataLazy<DocOut>;
42
49
  metaData: MetaOut;
43
50
  }>>;
@@ -55,18 +62,16 @@ interface ClientLoaderOptions<Frontmatter, Props> {
55
62
  id?: string;
56
63
  component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
57
64
  }
65
+ type ClientRenderer<Props> = Record<string, FC<Props>>;
58
66
  interface ClientLoader<Frontmatter, Props> {
59
67
  preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
60
68
  /**
61
69
  * Get a component that renders content with `React.lazy`
62
70
  */
63
71
  getComponent: (path: string) => FC<Props>;
72
+ getRenderer: () => ClientRenderer<Props>;
64
73
  }
65
74
  declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
66
- interface ClientRendererOptions<Frontmatter> {
67
- cache?: Map<string, CompiledMDXFile<Frontmatter>>;
68
- }
69
- type ClientRenderer<Props> = Record<string, FC<Props>>;
70
- declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode, options?: ClientRendererOptions<Frontmatter>): ClientRenderer<Props>;
75
+ declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode): ClientRenderer<Props>;
71
76
 
72
- export { type ClientLoader, type ClientLoaderOptions, type ClientRendererOptions, type CompiledMDXFile, createClientLoader, fromConfig, toClientRenderer };
77
+ export { type ClientLoader, type ClientLoaderOptions, type CompiledMDXFile, createClientLoader, fromConfig, toClientRenderer };
@@ -1,10 +1,12 @@
1
1
  // src/runtime/vite.ts
2
2
  import { createElement, lazy } from "react";
3
+ import path from "path";
3
4
  function fromConfig() {
4
- function normalize(entries) {
5
+ function normalize(entries, base) {
5
6
  const out = {};
6
7
  for (const k in entries) {
7
8
  const mappedK = k.startsWith("./") ? k.slice(2) : k;
9
+ if (base) Object.assign(entries[k], { base });
8
10
  out[mappedK] = entries[k];
9
11
  }
10
12
  return out;
@@ -31,14 +33,15 @@ function fromConfig() {
31
33
  };
32
34
  }
33
35
  return {
34
- doc(_, glob) {
35
- return normalize(glob);
36
+ doc(_, base, glob) {
37
+ return normalize(glob, base);
36
38
  },
37
- meta(_, glob) {
38
- return normalize(glob);
39
+ meta(_, base, glob) {
40
+ return normalize(glob, base);
39
41
  },
40
- docLazy(_, head, body) {
42
+ docLazy(_, base, head, body) {
41
43
  return {
44
+ base,
42
45
  head: normalize(head),
43
46
  body: normalize(body)
44
47
  };
@@ -49,6 +52,7 @@ function fromConfig() {
49
52
  return {
50
53
  type: "page",
51
54
  path: file,
55
+ absolutePath: path.join(content.base, file),
52
56
  data: mapPageData(await content())
53
57
  };
54
58
  }),
@@ -56,6 +60,7 @@ function fromConfig() {
56
60
  return {
57
61
  type: "meta",
58
62
  path: file,
63
+ absolutePath: path.join(content.base, file),
59
64
  data: await content()
60
65
  };
61
66
  })
@@ -68,6 +73,7 @@ function fromConfig() {
68
73
  return {
69
74
  type: "page",
70
75
  path: file,
76
+ absolutePath: path.join(doc.base, file),
71
77
  data: mapPageDataLazy(await frontmatter(), doc.body[file])
72
78
  };
73
79
  }),
@@ -75,6 +81,7 @@ function fromConfig() {
75
81
  return {
76
82
  type: "meta",
77
83
  path: file,
84
+ absolutePath: path.join(content.base, file),
78
85
  data: await content()
79
86
  };
80
87
  })
@@ -86,44 +93,41 @@ function fromConfig() {
86
93
  var loaderStore = /* @__PURE__ */ new Map();
87
94
  function createClientLoader(files, options) {
88
95
  const { id = "", component } = options;
96
+ let renderer;
89
97
  const store = loaderStore.get(id) ?? {
90
98
  preloaded: /* @__PURE__ */ new Map()
91
99
  };
92
100
  loaderStore.set(id, store);
93
- let renderer;
94
- return {
95
- async preload(path) {
96
- const loaded = await files[path]();
97
- store.preloaded.set(path, loaded);
98
- return loaded;
99
- },
100
- getComponent(path) {
101
- renderer ??= toClientRenderer(files, component, {
102
- cache: store.preloaded
101
+ function getRenderer() {
102
+ if (renderer) return renderer;
103
+ renderer = {};
104
+ for (const k in files) {
105
+ const OnDemand = lazy(async () => {
106
+ const loaded = await files[k]();
107
+ return { default: (props) => component(loaded, props) };
103
108
  });
104
- return renderer[path];
105
- }
106
- };
107
- }
108
- function toClientRenderer(files, component, options = {}) {
109
- const { cache } = options;
110
- const renderer = {};
111
- for (const k in files) {
112
- const OnDemand = lazy(async () => {
113
- const loaded = await files[k]();
114
- return { default: (props) => component(loaded, props) };
115
- });
116
- if (cache) {
117
109
  renderer[k] = (props) => {
118
- const cached = cache.get(k);
110
+ const cached = store.preloaded.get(k);
119
111
  if (!cached) return createElement(OnDemand, props);
120
112
  return component(cached, props);
121
113
  };
122
- } else {
123
- renderer[k] = OnDemand;
124
114
  }
115
+ return renderer;
125
116
  }
126
- return renderer;
117
+ return {
118
+ async preload(path2) {
119
+ const loaded = await files[path2]();
120
+ store.preloaded.set(path2, loaded);
121
+ return loaded;
122
+ },
123
+ getRenderer,
124
+ getComponent(path2) {
125
+ return getRenderer()[path2];
126
+ }
127
+ };
128
+ }
129
+ function toClientRenderer(files, component) {
130
+ return createClientLoader(files, { component }).getRenderer();
127
131
  }
128
132
  export {
129
133
  createClientLoader,
@@ -203,6 +203,7 @@ __export(vite_exports, {
203
203
  default: () => mdx
204
204
  });
205
205
  module.exports = __toCommonJS(vite_exports);
206
+ var import_vite = require("vite");
206
207
 
207
208
  // src/config/build.ts
208
209
  function buildConfig(config) {
@@ -491,41 +492,12 @@ async function validate(schema, data, context, errorMessage) {
491
492
 
492
493
  // src/vite/index.ts
493
494
  var import_zod = require("zod");
494
-
495
- // src/utils/import-formatter.ts
496
- var import_node_path = __toESM(require("path"), 1);
497
- function toImportPath(file, config) {
498
- const ext = import_node_path.default.extname(file);
499
- let filename;
500
- if (ext === ".ts" && config.jsExtension) {
501
- filename = file.substring(0, file.length - ext.length) + ".js";
502
- } else if (ext === ".ts") {
503
- filename = file.substring(0, file.length - ext.length);
504
- } else {
505
- filename = file;
506
- }
507
- let importPath;
508
- if ("relativeTo" in config) {
509
- importPath = import_node_path.default.relative(config.relativeTo, filename);
510
- if (!import_node_path.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
511
- importPath = `./${importPath}`;
512
- }
513
- } else {
514
- importPath = import_node_path.default.resolve(filename);
515
- }
516
- return importPath.replaceAll(import_node_path.default.sep, "/");
517
- }
518
- function ident(code, tab = 1) {
519
- return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
520
- }
521
-
522
- // src/vite/index.ts
523
495
  var fs2 = __toESM(require("fs/promises"), 1);
524
496
  var path4 = __toESM(require("path"), 1);
525
497
  var import_js_yaml2 = require("js-yaml");
526
498
 
527
499
  // src/utils/git-timestamp.ts
528
- var import_node_path2 = __toESM(require("path"), 1);
500
+ var import_node_path = __toESM(require("path"), 1);
529
501
  var import_tinyexec = require("tinyexec");
530
502
  var cache2 = /* @__PURE__ */ new Map();
531
503
  async function getGitTimestamp(file) {
@@ -534,7 +506,7 @@ async function getGitTimestamp(file) {
534
506
  try {
535
507
  const out = await (0, import_tinyexec.x)(
536
508
  "git",
537
- ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
509
+ ["log", "-1", '--pretty="%ai"', import_node_path.default.relative(process.cwd(), file)],
538
510
  {
539
511
  throwOnError: true
540
512
  }
@@ -547,37 +519,51 @@ async function getGitTimestamp(file) {
547
519
  }
548
520
  }
549
521
 
550
- // src/utils/collections.ts
551
- function getSupportedFormats(collection) {
552
- return {
553
- doc: ["mdx", "md"],
554
- meta: ["json", "yaml"]
555
- }[collection.type];
522
+ // src/utils/import-formatter.ts
523
+ var import_node_path2 = __toESM(require("path"), 1);
524
+ function toImportPath(file, config) {
525
+ const ext = import_node_path2.default.extname(file);
526
+ let filename;
527
+ if (ext === ".ts" && config.jsExtension) {
528
+ filename = file.substring(0, file.length - ext.length) + ".js";
529
+ } else if (ext === ".ts") {
530
+ filename = file.substring(0, file.length - ext.length);
531
+ } else {
532
+ filename = file;
533
+ }
534
+ let importPath;
535
+ if ("relativeTo" in config) {
536
+ importPath = import_node_path2.default.relative(config.relativeTo, filename);
537
+ if (!import_node_path2.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
538
+ importPath = `./${importPath}`;
539
+ }
540
+ } else {
541
+ importPath = import_node_path2.default.resolve(filename);
542
+ }
543
+ return importPath.replaceAll(import_node_path2.default.sep, "/");
556
544
  }
557
- function getGlobPatterns(collection) {
558
- if (collection.files) return collection.files;
559
- return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
545
+ function ident(code, tab = 1) {
546
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
560
547
  }
561
548
 
562
549
  // src/vite/generate-glob.ts
563
- function generateGlob(name, collection, globOptions) {
564
- const patterns = mapGlobPatterns(getGlobPatterns(collection));
550
+ function generateGlob(name, patterns, globOptions) {
565
551
  const options = {
566
552
  ...globOptions,
567
553
  query: {
568
554
  ...globOptions?.query,
569
555
  collection: name
570
- },
571
- base: getGlobBase(collection)
556
+ }
572
557
  };
573
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(options, null, 2)})`;
558
+ return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
574
559
  }
575
560
  function mapGlobPatterns(patterns) {
576
- return patterns.map((file) => {
577
- if (file.startsWith("./")) return file;
578
- if (file.startsWith("/")) return `.${file}`;
579
- return `./${file}`;
580
- });
561
+ return patterns.map(enforceRelative);
562
+ }
563
+ function enforceRelative(file) {
564
+ if (file.startsWith("./")) return file;
565
+ if (file.startsWith("/")) return `.${file}`;
566
+ return `./${file}`;
581
567
  }
582
568
  function getGlobBase(collection) {
583
569
  let dir = collection.dir;
@@ -588,10 +574,19 @@ function getGlobBase(collection) {
588
574
  );
589
575
  dir = dir[0];
590
576
  }
591
- if (!dir.startsWith("./") && !dir.startsWith("/")) {
592
- return "/" + dir;
593
- }
594
- return dir;
577
+ return enforceRelative(dir);
578
+ }
579
+
580
+ // src/utils/collections.ts
581
+ function getSupportedFormats(collection) {
582
+ return {
583
+ doc: ["mdx", "md"],
584
+ meta: ["json", "yaml"]
585
+ }[collection.type];
586
+ }
587
+ function getGlobPatterns(collection) {
588
+ if (collection.files) return collection.files;
589
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
595
590
  }
596
591
 
597
592
  // src/vite/generate.ts
@@ -605,23 +600,59 @@ ${obj}
605
600
  }`;
606
601
  }
607
602
  function doc(name, collection) {
603
+ const patterns = getGlobPatterns(collection);
604
+ const base = getGlobBase(collection);
605
+ const docGlob = generateGlob(name, patterns, {
606
+ base
607
+ });
608
608
  if (collection.async) {
609
- return `create.docLazy("${name}", ${generateGlob(name, collection, {
609
+ const headBlob = generateGlob(name, patterns, {
610
610
  query: {
611
611
  only: "frontmatter"
612
612
  },
613
- import: "frontmatter"
614
- })}, ${generateGlob(name, collection)})`;
613
+ import: "frontmatter",
614
+ base
615
+ });
616
+ return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
615
617
  }
616
- return `create.doc("${name}", ${generateGlob(name, collection)})`;
618
+ return `create.doc("${name}", "${base}", ${docGlob})`;
617
619
  }
618
620
  function meta(name, collection) {
619
- return `create.meta("${name}", ${generateGlob(name, collection, {
620
- import: "default"
621
+ const patterns = getGlobPatterns(collection);
622
+ const base = getGlobBase(collection);
623
+ return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
624
+ import: "default",
625
+ base
621
626
  })})`;
622
627
  }
628
+ function entry(configPath, config, outDir, jsExtension) {
629
+ const lines = [
630
+ '/// <reference types="vite/client" />',
631
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
632
+ `import type * as Config from '${toImportPath(configPath, {
633
+ relativeTo: outDir,
634
+ jsExtension
635
+ })}';`,
636
+ "",
637
+ `export const create = fromConfig<typeof Config>();`
638
+ ];
639
+ for (const [name, collection] of config.collections.entries()) {
640
+ let body;
641
+ if (collection.type === "docs") {
642
+ body = docs(name, collection);
643
+ } else if (collection.type === "meta") {
644
+ body = meta(name, collection);
645
+ } else {
646
+ body = doc(name, collection);
647
+ }
648
+ lines.push("");
649
+ lines.push(`export const ${name} = ${body};`);
650
+ }
651
+ return lines.join("\n");
652
+ }
623
653
 
624
654
  // src/vite/index.ts
655
+ var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
625
656
  var querySchema = import_zod.z.object({
626
657
  only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
627
658
  collection: import_zod.z.string().optional()
@@ -726,34 +757,31 @@ function mdx(config, options = {}) {
726
757
  name: "fumadocs-mdx",
727
758
  // needed, otherwise other plugins will be executed before our `transform`.
728
759
  enforce: "pre",
760
+ config(config2) {
761
+ return (0, import_vite.mergeConfig)(config2, {
762
+ optimizeDeps: {
763
+ exclude: FumadocsDeps
764
+ },
765
+ resolve: {
766
+ noExternal: FumadocsDeps,
767
+ dedupe: FumadocsDeps
768
+ }
769
+ });
770
+ },
729
771
  async buildStart() {
730
772
  if (!generateIndexFile) return;
731
773
  console.log("[Fumadocs MDX] Generating index files");
732
- const outdir = process.cwd();
774
+ const outDir = process.cwd();
733
775
  const outFile = "source.generated.ts";
734
- const lines = [
735
- '/// <reference types="vite/client" />',
736
- `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
737
- `import type * as Config from '${toImportPath(configPath, {
738
- relativeTo: outdir,
739
- jsExtension: typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
740
- })}';`,
741
- "",
742
- `export const create = fromConfig<typeof Config>();`
743
- ];
744
- for (const [name, collection] of loaded.collections.entries()) {
745
- let body;
746
- if (collection.type === "docs") {
747
- body = docs(name, collection);
748
- } else if (collection.type === "meta") {
749
- body = meta(name, collection);
750
- } else {
751
- body = doc(name, collection);
752
- }
753
- lines.push("");
754
- lines.push(`export const ${name} = ${body};`);
755
- }
756
- await fs2.writeFile(path4.join(outdir, outFile), lines.join("\n"));
776
+ await fs2.writeFile(
777
+ path4.join(outDir, outFile),
778
+ entry(
779
+ configPath,
780
+ loaded,
781
+ outDir,
782
+ typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
783
+ )
784
+ );
757
785
  },
758
786
  async transform(value, id) {
759
787
  const [file, query = ""] = id.split("?");
@@ -2,10 +2,8 @@ import {
2
2
  countLines
3
3
  } from "../chunk-UCY7OBZG.js";
4
4
  import {
5
- getGlobPatterns,
6
- ident,
7
- toImportPath
8
- } from "../chunk-6Y5JDZHD.js";
5
+ entry
6
+ } from "../chunk-COQ4VMK2.js";
9
7
  import {
10
8
  ValidationError,
11
9
  getGitTimestamp,
@@ -23,75 +21,15 @@ import {
23
21
  } from "../chunk-VWJKRQZR.js";
24
22
 
25
23
  // src/vite/index.ts
24
+ import {
25
+ mergeConfig
26
+ } from "vite";
26
27
  import { parse } from "querystring";
27
28
  import { z } from "zod";
28
29
  import * as fs from "fs/promises";
29
30
  import * as path from "path";
30
31
  import { load } from "js-yaml";
31
-
32
- // src/vite/generate-glob.ts
33
- function generateGlob(name, collection, globOptions) {
34
- const patterns = mapGlobPatterns(getGlobPatterns(collection));
35
- const options = {
36
- ...globOptions,
37
- query: {
38
- ...globOptions?.query,
39
- collection: name
40
- },
41
- base: getGlobBase(collection)
42
- };
43
- return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(options, null, 2)})`;
44
- }
45
- function mapGlobPatterns(patterns) {
46
- return patterns.map((file) => {
47
- if (file.startsWith("./")) return file;
48
- if (file.startsWith("/")) return `.${file}`;
49
- return `./${file}`;
50
- });
51
- }
52
- function getGlobBase(collection) {
53
- let dir = collection.dir;
54
- if (Array.isArray(dir)) {
55
- if (dir.length !== 1)
56
- throw new Error(
57
- `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
58
- );
59
- dir = dir[0];
60
- }
61
- if (!dir.startsWith("./") && !dir.startsWith("/")) {
62
- return "/" + dir;
63
- }
64
- return dir;
65
- }
66
-
67
- // src/vite/generate.ts
68
- function docs(name, collection) {
69
- const obj = [
70
- ident(`doc: ${doc(name, collection.docs)}`),
71
- ident(`meta: ${meta(name, collection.meta)}`)
72
- ].join(",\n");
73
- return `{
74
- ${obj}
75
- }`;
76
- }
77
- function doc(name, collection) {
78
- if (collection.async) {
79
- return `create.docLazy("${name}", ${generateGlob(name, collection, {
80
- query: {
81
- only: "frontmatter"
82
- },
83
- import: "frontmatter"
84
- })}, ${generateGlob(name, collection)})`;
85
- }
86
- return `create.doc("${name}", ${generateGlob(name, collection)})`;
87
- }
88
- function meta(name, collection) {
89
- return `create.meta("${name}", ${generateGlob(name, collection, {
90
- import: "default"
91
- })})`;
92
- }
93
-
94
- // src/vite/index.ts
32
+ var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
95
33
  var querySchema = z.object({
96
34
  only: z.literal(["frontmatter", "all"]).default("all"),
97
35
  collection: z.string().optional()
@@ -196,34 +134,31 @@ function mdx(config, options = {}) {
196
134
  name: "fumadocs-mdx",
197
135
  // needed, otherwise other plugins will be executed before our `transform`.
198
136
  enforce: "pre",
137
+ config(config2) {
138
+ return mergeConfig(config2, {
139
+ optimizeDeps: {
140
+ exclude: FumadocsDeps
141
+ },
142
+ resolve: {
143
+ noExternal: FumadocsDeps,
144
+ dedupe: FumadocsDeps
145
+ }
146
+ });
147
+ },
199
148
  async buildStart() {
200
149
  if (!generateIndexFile) return;
201
150
  console.log("[Fumadocs MDX] Generating index files");
202
- const outdir = process.cwd();
151
+ const outDir = process.cwd();
203
152
  const outFile = "source.generated.ts";
204
- const lines = [
205
- '/// <reference types="vite/client" />',
206
- `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
207
- `import type * as Config from '${toImportPath(configPath, {
208
- relativeTo: outdir,
209
- jsExtension: typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
210
- })}';`,
211
- "",
212
- `export const create = fromConfig<typeof Config>();`
213
- ];
214
- for (const [name, collection] of loaded.collections.entries()) {
215
- let body;
216
- if (collection.type === "docs") {
217
- body = docs(name, collection);
218
- } else if (collection.type === "meta") {
219
- body = meta(name, collection);
220
- } else {
221
- body = doc(name, collection);
222
- }
223
- lines.push("");
224
- lines.push(`export const ${name} = ${body};`);
225
- }
226
- await fs.writeFile(path.join(outdir, outFile), lines.join("\n"));
153
+ await fs.writeFile(
154
+ path.join(outDir, outFile),
155
+ entry(
156
+ configPath,
157
+ loaded,
158
+ outDir,
159
+ typeof generateIndexFile === "object" ? generateIndexFile.addJsExtension : void 0
160
+ )
161
+ );
227
162
  },
228
163
  async transform(value, id) {
229
164
  const [file, query = ""] = id.split("?");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.8.2",
3
+ "version": "11.9.0",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -56,38 +56,38 @@
56
56
  "bin.js"
57
57
  ],
58
58
  "dependencies": {
59
- "unified": "^11.0.5",
60
- "@mdx-js/mdx": "^3.1.0",
59
+ "@mdx-js/mdx": "^3.1.1",
61
60
  "@standard-schema/spec": "^1.0.0",
62
61
  "chokidar": "^4.0.3",
63
62
  "esbuild": "^0.25.9",
64
63
  "estree-util-value-to-estree": "^3.4.0",
65
64
  "js-yaml": "^4.1.0",
66
- "lru-cache": "^11.1.0",
65
+ "lru-cache": "^11.2.1",
67
66
  "picocolors": "^1.1.1",
68
- "remark-mdx": "^3.1.0",
67
+ "remark-mdx": "^3.1.1",
69
68
  "remark-parse": "^11.0.0",
70
69
  "tinyexec": "^1.0.1",
71
70
  "tinyglobby": "^0.2.14",
71
+ "unified": "^11.0.5",
72
72
  "unist-util-visit": "^5.0.0",
73
- "zod": "^4.1.4"
73
+ "zod": "^4.1.5"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/js-yaml": "^4.0.9",
77
77
  "@types/mdast": "^4.0.3",
78
78
  "@types/mdx": "^2.0.13",
79
- "@types/node": "^24.3.0",
79
+ "@types/node": "^24.3.1",
80
80
  "@types/react": "^19.1.12",
81
81
  "mdast-util-mdx-jsx": "^3.2.0",
82
82
  "next": "^15.5.2",
83
83
  "react": "^19.1.1",
84
- "rollup": "^4.49.0",
84
+ "rollup": "^4.50.0",
85
85
  "vfile": "^6.0.3",
86
- "vite": "^7.1.3",
86
+ "vite": "^7.1.4",
87
87
  "webpack": "^5.101.3",
88
88
  "@fumadocs/mdx-remote": "1.4.0",
89
89
  "eslint-config-custom": "0.0.0",
90
- "fumadocs-core": "15.7.6",
90
+ "fumadocs-core": "15.7.10",
91
91
  "tsconfig": "0.0.0"
92
92
  },
93
93
  "peerDependencies": {