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.
@@ -72,7 +72,7 @@ async function loadConfig(configPath, outDir, hash, build = false) {
72
72
  loaded
73
73
  );
74
74
  });
75
- cache = { config, hash };
75
+ if (hash) cache = { config, hash };
76
76
  return await config;
77
77
  }
78
78
  async function getConfigHash(configPath) {
@@ -0,0 +1,158 @@
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/vite/generate-glob.ts
42
+ function generateGlob(name, patterns, globOptions) {
43
+ const options = {
44
+ ...globOptions,
45
+ query: {
46
+ ...globOptions?.query,
47
+ collection: name
48
+ }
49
+ };
50
+ return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
51
+ }
52
+ function mapGlobPatterns(patterns) {
53
+ return patterns.map(enforceRelative);
54
+ }
55
+ function enforceRelative(file) {
56
+ if (file.startsWith("./")) return file;
57
+ if (file.startsWith("/")) return `.${file}`;
58
+ return `./${file}`;
59
+ }
60
+ function getGlobBase(collection) {
61
+ let dir = collection.dir;
62
+ if (Array.isArray(dir)) {
63
+ if (dir.length !== 1)
64
+ throw new Error(
65
+ `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
66
+ );
67
+ dir = dir[0];
68
+ }
69
+ return enforceRelative(dir);
70
+ }
71
+
72
+ // src/utils/collections.ts
73
+ function getSupportedFormats(collection) {
74
+ return {
75
+ doc: ["mdx", "md"],
76
+ meta: ["json", "yaml"]
77
+ }[collection.type];
78
+ }
79
+ function getGlobPatterns(collection) {
80
+ if (collection.files) return collection.files;
81
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
82
+ }
83
+ function isFileSupported(filePath, collection) {
84
+ for (const format of getSupportedFormats(collection)) {
85
+ if (filePath.endsWith(`.${format}`)) return true;
86
+ }
87
+ return false;
88
+ }
89
+
90
+ // src/vite/generate.ts
91
+ function docs(name, collection) {
92
+ const obj = [
93
+ ident(`doc: ${doc(name, collection.docs)}`),
94
+ ident(`meta: ${meta(name, collection.meta)}`)
95
+ ].join(",\n");
96
+ return `{
97
+ ${obj}
98
+ }`;
99
+ }
100
+ function doc(name, collection) {
101
+ const patterns = getGlobPatterns(collection);
102
+ const base = getGlobBase(collection);
103
+ const docGlob = generateGlob(name, patterns, {
104
+ base
105
+ });
106
+ if (collection.async) {
107
+ const headBlob = generateGlob(name, patterns, {
108
+ query: {
109
+ only: "frontmatter"
110
+ },
111
+ import: "frontmatter",
112
+ base
113
+ });
114
+ return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
115
+ }
116
+ return `create.doc("${name}", "${base}", ${docGlob})`;
117
+ }
118
+ function meta(name, collection) {
119
+ const patterns = getGlobPatterns(collection);
120
+ const base = getGlobBase(collection);
121
+ return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
122
+ import: "default",
123
+ base
124
+ })})`;
125
+ }
126
+ function entry(configPath, config, outDir, jsExtension) {
127
+ const lines = [
128
+ '/// <reference types="vite/client" />',
129
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
130
+ `import type * as Config from '${toImportPath(configPath, {
131
+ relativeTo: outDir,
132
+ jsExtension
133
+ })}';`,
134
+ "",
135
+ `export const create = fromConfig<typeof Config>();`
136
+ ];
137
+ for (const [name, collection] of config.collections.entries()) {
138
+ let body;
139
+ if (collection.type === "docs") {
140
+ body = docs(name, collection);
141
+ } else if (collection.type === "meta") {
142
+ body = meta(name, collection);
143
+ } else {
144
+ body = doc(name, collection);
145
+ }
146
+ lines.push("");
147
+ lines.push(`export const ${name} = ${body};`);
148
+ }
149
+ return lines.join("\n");
150
+ }
151
+
152
+ export {
153
+ getImportCode,
154
+ toImportPath,
155
+ getGlobPatterns,
156
+ isFileSupported,
157
+ entry
158
+ };
@@ -325,7 +325,7 @@ async function loadConfig(configPath, outDir, hash, build = false) {
325
325
  loaded
326
326
  );
327
327
  });
328
- cache = { config, hash };
328
+ if (hash) cache = { config, hash };
329
329
  return await config;
330
330
  }
331
331
  async function getConfigHash(configPath) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getConfigHash,
3
3
  loadConfig
4
- } from "./chunk-BWRDVK5L.js";
4
+ } from "./chunk-766EAFX6.js";
5
5
  import {
6
6
  countLines
7
7
  } from "./chunk-UCY7OBZG.js";
@@ -358,7 +358,7 @@ async function loadConfig(configPath, outDir, hash, build = false) {
358
358
  loaded
359
359
  );
360
360
  });
361
- cache = { config, hash };
361
+ if (hash) cache = { config, hash };
362
362
  return await config;
363
363
  }
364
364
  async function getConfigHash(configPath) {
@@ -514,6 +514,9 @@ function toImportPath(file, config) {
514
514
  }
515
515
  return importPath.replaceAll(import_node_path2.default.sep, "/");
516
516
  }
517
+ function ident(code, tab = 1) {
518
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
519
+ }
517
520
 
518
521
  // src/utils/collections.ts
519
522
  function getSupportedFormats(collection) {
@@ -634,18 +637,18 @@ async function generateJS(configPath, config, importPath, configHash = false) {
634
637
  }
635
638
  const declares = entries.map(async ([k, collection]) => {
636
639
  if (collection.type === "docs") {
637
- const docs = await getCollectionFiles(collection.docs);
640
+ const docs2 = await getCollectionFiles(collection.docs);
638
641
  const metas = await getCollectionFiles(collection.meta);
639
642
  const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
640
643
  ", "
641
644
  );
642
645
  if (collection.docs.async) {
643
- const docsEntries2 = (await getAsyncEntries(collection.docs, docs)).join(
646
+ const docsEntries2 = (await getAsyncEntries(collection.docs, docs2)).join(
644
647
  ", "
645
648
  );
646
649
  return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
647
650
  }
648
- const docsEntries = (await getDocEntries(k, docs)).join(", ");
651
+ const docsEntries = (await getDocEntries(k, docs2)).join(", ");
649
652
  return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
650
653
  }
651
654
  const files = await getCollectionFiles(collection);
@@ -764,11 +767,9 @@ function createMDX({
764
767
  configPath = findConfigFile(),
765
768
  outDir = ".source"
766
769
  } = {}) {
767
- const isDev = process.argv.includes("dev");
768
- const isBuild = process.argv.includes("build");
769
- if ((isDev || isBuild) && process.env._FUMADOCS_MDX !== "1") {
770
+ if (process.env._FUMADOCS_MDX !== "1") {
770
771
  process.env._FUMADOCS_MDX = "1";
771
- void start(isDev, configPath, outDir);
772
+ void start(process.env.NODE_ENV === "development", configPath, outDir);
772
773
  }
773
774
  return (nextConfig = {}) => {
774
775
  const mdxLoaderOptions = {
@@ -825,17 +826,129 @@ function createMDX({
825
826
  // src/postinstall.ts
826
827
  var path6 = __toESM(require("path"), 1);
827
828
  var fs4 = __toESM(require("fs/promises"), 1);
828
- async function postInstall(configPath = findConfigFile(), outDir = ".source") {
829
- const jsOut = path6.resolve(outDir, "index.ts");
829
+ var import_node_fs2 = require("fs");
830
+
831
+ // src/vite/generate-glob.ts
832
+ function generateGlob(name, patterns, globOptions) {
833
+ const options = {
834
+ ...globOptions,
835
+ query: {
836
+ ...globOptions?.query,
837
+ collection: name
838
+ }
839
+ };
840
+ return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
841
+ }
842
+ function mapGlobPatterns(patterns) {
843
+ return patterns.map(enforceRelative);
844
+ }
845
+ function enforceRelative(file) {
846
+ if (file.startsWith("./")) return file;
847
+ if (file.startsWith("/")) return `.${file}`;
848
+ return `./${file}`;
849
+ }
850
+ function getGlobBase(collection) {
851
+ let dir = collection.dir;
852
+ if (Array.isArray(dir)) {
853
+ if (dir.length !== 1)
854
+ throw new Error(
855
+ `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
856
+ );
857
+ dir = dir[0];
858
+ }
859
+ return enforceRelative(dir);
860
+ }
861
+
862
+ // src/vite/generate.ts
863
+ function docs(name, collection) {
864
+ const obj = [
865
+ ident(`doc: ${doc(name, collection.docs)}`),
866
+ ident(`meta: ${meta(name, collection.meta)}`)
867
+ ].join(",\n");
868
+ return `{
869
+ ${obj}
870
+ }`;
871
+ }
872
+ function doc(name, collection) {
873
+ const patterns = getGlobPatterns(collection);
874
+ const base = getGlobBase(collection);
875
+ const docGlob = generateGlob(name, patterns, {
876
+ base
877
+ });
878
+ if (collection.async) {
879
+ const headBlob = generateGlob(name, patterns, {
880
+ query: {
881
+ only: "frontmatter"
882
+ },
883
+ import: "frontmatter",
884
+ base
885
+ });
886
+ return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
887
+ }
888
+ return `create.doc("${name}", "${base}", ${docGlob})`;
889
+ }
890
+ function meta(name, collection) {
891
+ const patterns = getGlobPatterns(collection);
892
+ const base = getGlobBase(collection);
893
+ return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
894
+ import: "default",
895
+ base
896
+ })})`;
897
+ }
898
+ function entry(configPath, config, outDir, jsExtension) {
899
+ const lines = [
900
+ '/// <reference types="vite/client" />',
901
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
902
+ `import type * as Config from '${toImportPath(configPath, {
903
+ relativeTo: outDir,
904
+ jsExtension
905
+ })}';`,
906
+ "",
907
+ `export const create = fromConfig<typeof Config>();`
908
+ ];
909
+ for (const [name, collection] of config.collections.entries()) {
910
+ let body;
911
+ if (collection.type === "docs") {
912
+ body = docs(name, collection);
913
+ } else if (collection.type === "meta") {
914
+ body = meta(name, collection);
915
+ } else {
916
+ body = doc(name, collection);
917
+ }
918
+ lines.push("");
919
+ lines.push(`export const ${name} = ${body};`);
920
+ }
921
+ return lines.join("\n");
922
+ }
923
+
924
+ // src/postinstall.ts
925
+ async function postInstall(configPath = findConfigFile(), outDir) {
926
+ const isNext = (0, import_node_fs2.existsSync)("next.config.js") || (0, import_node_fs2.existsSync)("next.config.mjs") || (0, import_node_fs2.existsSync)("next.config.ts");
927
+ if (isNext) {
928
+ await onNext(configPath, outDir ?? ".source");
929
+ } else {
930
+ await onVite(configPath, outDir ?? process.cwd());
931
+ }
932
+ console.log("[MDX] types generated");
933
+ }
934
+ async function onNext(configPath, outDir) {
935
+ const config = await loadConfig(configPath, outDir, void 0, true);
936
+ const outPath = path6.join(outDir, "index.ts");
937
+ await fs4.rm(outDir, { recursive: true });
938
+ await fs4.mkdir(outDir, { recursive: true });
830
939
  const hash = await getConfigHash(configPath);
831
- const config = await loadConfig(configPath, outDir, hash, true);
832
- await fs4.rm(path6.dirname(jsOut), { recursive: true });
833
- await fs4.mkdir(path6.dirname(jsOut), { recursive: true });
834
940
  await fs4.writeFile(
835
- jsOut,
941
+ outPath,
836
942
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
837
943
  );
838
- console.log("[MDX] types generated");
944
+ }
945
+ async function onVite(configPath, outDir, addJsExtension) {
946
+ const config = await loadConfig(configPath, "node_modules", void 0, true);
947
+ const outFile = "source.generated.ts";
948
+ await fs4.writeFile(
949
+ path6.join(outDir, outFile),
950
+ entry(configPath, config, outDir, addJsExtension)
951
+ );
839
952
  }
840
953
  // Annotate the CommonJS export names for ESM import in node:
841
954
  0 && (module.exports = {
@@ -2,13 +2,14 @@ import {
2
2
  findConfigFile,
3
3
  getConfigHash,
4
4
  loadConfig
5
- } from "../chunk-BWRDVK5L.js";
5
+ } from "../chunk-766EAFX6.js";
6
6
  import {
7
+ entry,
7
8
  getGlobPatterns,
8
9
  getImportCode,
9
10
  isFileSupported,
10
11
  toImportPath
11
- } from "../chunk-6Y5JDZHD.js";
12
+ } from "../chunk-COQ4VMK2.js";
12
13
  import {
13
14
  ValidationError,
14
15
  getGitTimestamp,
@@ -280,11 +281,9 @@ function createMDX({
280
281
  configPath = findConfigFile(),
281
282
  outDir = ".source"
282
283
  } = {}) {
283
- const isDev = process.argv.includes("dev");
284
- const isBuild = process.argv.includes("build");
285
- if ((isDev || isBuild) && process.env._FUMADOCS_MDX !== "1") {
284
+ if (process.env._FUMADOCS_MDX !== "1") {
286
285
  process.env._FUMADOCS_MDX = "1";
287
- void start(isDev, configPath, outDir);
286
+ void start(process.env.NODE_ENV === "development", configPath, outDir);
288
287
  }
289
288
  return (nextConfig = {}) => {
290
289
  const mdxLoaderOptions = {
@@ -341,17 +340,34 @@ function createMDX({
341
340
  // src/postinstall.ts
342
341
  import * as path3 from "path";
343
342
  import * as fs3 from "fs/promises";
344
- async function postInstall(configPath = findConfigFile(), outDir = ".source") {
345
- const jsOut = path3.resolve(outDir, "index.ts");
343
+ import { existsSync } from "fs";
344
+ async function postInstall(configPath = findConfigFile(), outDir) {
345
+ const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.ts");
346
+ if (isNext) {
347
+ await onNext(configPath, outDir ?? ".source");
348
+ } else {
349
+ await onVite(configPath, outDir ?? process.cwd());
350
+ }
351
+ console.log("[MDX] types generated");
352
+ }
353
+ async function onNext(configPath, outDir) {
354
+ const config = await loadConfig(configPath, outDir, void 0, true);
355
+ const outPath = path3.join(outDir, "index.ts");
356
+ await fs3.rm(outDir, { recursive: true });
357
+ await fs3.mkdir(outDir, { recursive: true });
346
358
  const hash = await getConfigHash(configPath);
347
- const config = await loadConfig(configPath, outDir, hash, true);
348
- await fs3.rm(path3.dirname(jsOut), { recursive: true });
349
- await fs3.mkdir(path3.dirname(jsOut), { recursive: true });
350
359
  await fs3.writeFile(
351
- jsOut,
360
+ outPath,
352
361
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
353
362
  );
354
- console.log("[MDX] types generated");
363
+ }
364
+ async function onVite(configPath, outDir, addJsExtension) {
365
+ const config = await loadConfig(configPath, "node_modules", void 0, true);
366
+ const outFile = "source.generated.ts";
367
+ await fs3.writeFile(
368
+ path3.join(outDir, outFile),
369
+ entry(configPath, config, outDir, addJsExtension)
370
+ );
355
371
  }
356
372
  export {
357
373
  createMDX,
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/runtime/vite.ts
@@ -26,11 +36,13 @@ __export(vite_exports, {
26
36
  });
27
37
  module.exports = __toCommonJS(vite_exports);
28
38
  var import_react = require("react");
39
+ var import_node_path = __toESM(require("path"), 1);
29
40
  function fromConfig() {
30
- function normalize(entries) {
41
+ function normalize(entries, base) {
31
42
  const out = {};
32
43
  for (const k in entries) {
33
44
  const mappedK = k.startsWith("./") ? k.slice(2) : k;
45
+ if (base) Object.assign(entries[k], { base });
34
46
  out[mappedK] = entries[k];
35
47
  }
36
48
  return out;
@@ -57,14 +69,15 @@ function fromConfig() {
57
69
  };
58
70
  }
59
71
  return {
60
- doc(_, glob) {
61
- return normalize(glob);
72
+ doc(_, base, glob) {
73
+ return normalize(glob, base);
62
74
  },
63
- meta(_, glob) {
64
- return normalize(glob);
75
+ meta(_, base, glob) {
76
+ return normalize(glob, base);
65
77
  },
66
- docLazy(_, head, body) {
78
+ docLazy(_, base, head, body) {
67
79
  return {
80
+ base,
68
81
  head: normalize(head),
69
82
  body: normalize(body)
70
83
  };
@@ -75,6 +88,7 @@ function fromConfig() {
75
88
  return {
76
89
  type: "page",
77
90
  path: file,
91
+ absolutePath: import_node_path.default.join(content.base, file),
78
92
  data: mapPageData(await content())
79
93
  };
80
94
  }),
@@ -82,6 +96,7 @@ function fromConfig() {
82
96
  return {
83
97
  type: "meta",
84
98
  path: file,
99
+ absolutePath: import_node_path.default.join(content.base, file),
85
100
  data: await content()
86
101
  };
87
102
  })
@@ -94,6 +109,7 @@ function fromConfig() {
94
109
  return {
95
110
  type: "page",
96
111
  path: file,
112
+ absolutePath: import_node_path.default.join(doc.base, file),
97
113
  data: mapPageDataLazy(await frontmatter(), doc.body[file])
98
114
  };
99
115
  }),
@@ -101,6 +117,7 @@ function fromConfig() {
101
117
  return {
102
118
  type: "meta",
103
119
  path: file,
120
+ absolutePath: import_node_path.default.join(content.base, file),
104
121
  data: await content()
105
122
  };
106
123
  })
@@ -112,44 +129,41 @@ function fromConfig() {
112
129
  var loaderStore = /* @__PURE__ */ new Map();
113
130
  function createClientLoader(files, options) {
114
131
  const { id = "", component } = options;
132
+ let renderer;
115
133
  const store = loaderStore.get(id) ?? {
116
134
  preloaded: /* @__PURE__ */ new Map()
117
135
  };
118
136
  loaderStore.set(id, store);
119
- let renderer;
120
- return {
121
- async preload(path) {
122
- const loaded = await files[path]();
123
- store.preloaded.set(path, loaded);
124
- return loaded;
125
- },
126
- getComponent(path) {
127
- renderer ??= toClientRenderer(files, component, {
128
- cache: store.preloaded
137
+ function getRenderer() {
138
+ if (renderer) return renderer;
139
+ renderer = {};
140
+ for (const k in files) {
141
+ const OnDemand = (0, import_react.lazy)(async () => {
142
+ const loaded = await files[k]();
143
+ return { default: (props) => component(loaded, props) };
129
144
  });
130
- return renderer[path];
131
- }
132
- };
133
- }
134
- function toClientRenderer(files, component, options = {}) {
135
- const { cache } = options;
136
- const renderer = {};
137
- for (const k in files) {
138
- const OnDemand = (0, import_react.lazy)(async () => {
139
- const loaded = await files[k]();
140
- return { default: (props) => component(loaded, props) };
141
- });
142
- if (cache) {
143
145
  renderer[k] = (props) => {
144
- const cached = cache.get(k);
146
+ const cached = store.preloaded.get(k);
145
147
  if (!cached) return (0, import_react.createElement)(OnDemand, props);
146
148
  return component(cached, props);
147
149
  };
148
- } else {
149
- renderer[k] = OnDemand;
150
150
  }
151
+ return renderer;
151
152
  }
152
- return renderer;
153
+ return {
154
+ async preload(path2) {
155
+ const loaded = await files[path2]();
156
+ store.preloaded.set(path2, loaded);
157
+ return loaded;
158
+ },
159
+ getRenderer,
160
+ getComponent(path2) {
161
+ return getRenderer()[path2];
162
+ }
163
+ };
164
+ }
165
+ function toClientRenderer(files, component) {
166
+ return createClientLoader(files, { component }).getRenderer();
153
167
  }
154
168
  // Annotate the CommonJS export names for ESM import in node:
155
169
  0 && (module.exports = {
@@ -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 };