fumadocs-mdx 11.7.3 → 11.7.5

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 (38) hide show
  1. package/dist/{chunk-AVMO2SRO.js → chunk-3XN4P23K.js} +49 -11
  2. package/dist/chunk-GBMFGEC7.js +57 -0
  3. package/dist/{chunk-ZOWJF3OH.js → chunk-GX3THK2Q.js} +25 -20
  4. package/dist/{chunk-2CSSQTP6.js → chunk-GYWPPGFD.js} +9 -1
  5. package/dist/chunk-HWSF4OGZ.js +42 -0
  6. package/dist/chunk-UCY7OBZG.js +12 -0
  7. package/dist/{chunk-JFNBRKRV.js → chunk-XVL4ZQFK.js} +12 -6
  8. package/dist/{chunk-4CGSOZUZ.js → chunk-XZR5QXVY.js} +32 -2
  9. package/dist/config/index.cjs +59 -14
  10. package/dist/config/index.d.cts +2 -2
  11. package/dist/config/index.d.ts +2 -2
  12. package/dist/config/index.js +8 -36
  13. package/dist/config/zod-3.cjs +371 -0
  14. package/dist/config/zod-3.d.cts +53 -0
  15. package/dist/config/zod-3.d.ts +53 -0
  16. package/dist/config/zod-3.js +40 -0
  17. package/dist/{define-E6TRBwBQ.d.cts → define-DnJzAZrj.d.cts} +3 -2
  18. package/dist/{define-E6TRBwBQ.d.ts → define-DnJzAZrj.d.ts} +3 -2
  19. package/dist/index.d.cts +3 -3
  20. package/dist/index.d.ts +3 -3
  21. package/dist/loader-mdx.cjs +121 -53
  22. package/dist/loader-mdx.js +8 -8
  23. package/dist/{mdx-options-UDV5WEFU.js → mdx-options-3NB74EMB.js} +1 -1
  24. package/dist/next/index.cjs +52 -25
  25. package/dist/next/index.js +4 -6
  26. package/dist/runtime/async.cjs +202 -129
  27. package/dist/runtime/async.d.cts +3 -3
  28. package/dist/runtime/async.d.ts +3 -3
  29. package/dist/runtime/async.js +26 -43
  30. package/dist/runtime/vite.d.cts +2 -2
  31. package/dist/runtime/vite.d.ts +2 -2
  32. package/dist/{types-DiL328cG.d.ts → types-C-WXTx1W.d.cts} +2 -2
  33. package/dist/{types-Lh_-Uuix.d.cts → types-CU9nn_je.d.ts} +2 -2
  34. package/dist/vite/index.cjs +92 -54
  35. package/dist/vite/index.js +8 -8
  36. package/package.json +12 -7
  37. package/dist/chunk-C5INPAZJ.js +0 -49
  38. package/dist/chunk-VUEZTR2H.js +0 -26
@@ -102,6 +102,7 @@ function getDefaultMDXOptions({
102
102
  remarkStructureOptions,
103
103
  remarkCodeTabOptions,
104
104
  remarkNpmOptions,
105
+ _withoutBundler = false,
105
106
  ...mdxOptions
106
107
  }) {
107
108
  const mdxExports = [
@@ -120,7 +121,13 @@ function getDefaultMDXOptions({
120
121
  ...remarkHeadingOptions
121
122
  }
122
123
  ],
123
- remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
124
+ remarkImageOptions !== false && [
125
+ plugins.remarkImage,
126
+ {
127
+ ...remarkImageOptions,
128
+ useImport: _withoutBundler ? false : remarkImageOptions?.useImport
129
+ }
130
+ ],
124
131
  "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
125
132
  plugins.remarkCodeTab,
126
133
  remarkCodeTabOptions
@@ -145,6 +152,7 @@ function getDefaultMDXOptions({
145
152
  );
146
153
  return {
147
154
  ...mdxOptions,
155
+ outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
148
156
  remarkPlugins,
149
157
  rehypePlugins
150
158
  };
@@ -198,37 +206,73 @@ function buildConfig(config) {
198
206
  `Unknown export "${k}", you can only export collections from source configuration file.`
199
207
  );
200
208
  }
201
- let cachedMdxOptions;
209
+ const mdxOptionsCache = /* @__PURE__ */ new Map();
202
210
  return {
203
211
  global: globalConfig,
204
212
  collections,
205
- async getDefaultMDXOptions() {
206
- if (cachedMdxOptions) return cachedMdxOptions;
213
+ async getDefaultMDXOptions(mode = "default") {
214
+ const cached = mdxOptionsCache.get(mode);
215
+ if (cached) return cached;
207
216
  const input = this.global.mdxOptions;
208
217
  async function uncached() {
209
218
  const options = typeof input === "function" ? await input() : input;
210
219
  const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
211
220
  if (options?.preset === "minimal") return options;
212
- return getDefaultMDXOptions2(options ?? {});
221
+ return getDefaultMDXOptions2({
222
+ ...options,
223
+ _withoutBundler: mode === "remote"
224
+ });
213
225
  }
214
- return cachedMdxOptions = uncached();
226
+ const result = uncached();
227
+ mdxOptionsCache.set(mode, result);
228
+ return result;
215
229
  }
216
230
  };
217
231
  }
218
232
 
219
233
  // src/utils/config.ts
220
234
  var cache = null;
235
+ async function isZod3() {
236
+ try {
237
+ const content = JSON.parse(
238
+ (await fs.readFile("node_modules/zod/package.json")).toString()
239
+ );
240
+ const version = content.version;
241
+ return typeof version === "string" && version.startsWith("3.");
242
+ } catch {
243
+ return false;
244
+ }
245
+ }
246
+ function createCompatZodPlugin() {
247
+ return {
248
+ name: "replace-zod-import",
249
+ async setup(build) {
250
+ const usingZod3 = await isZod3();
251
+ if (!usingZod3) return;
252
+ console.warn(
253
+ "[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
254
+ );
255
+ build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
256
+ return {
257
+ path: "fumadocs-mdx/config/zod-3",
258
+ external: true
259
+ };
260
+ });
261
+ }
262
+ };
263
+ }
221
264
  async function compileConfig(configPath, outDir) {
222
265
  const { build } = await import("esbuild");
223
266
  const transformed = await build({
224
267
  entryPoints: [{ in: configPath, out: "source.config" }],
225
268
  bundle: true,
226
269
  outdir: outDir,
227
- target: "node18",
270
+ target: "node20",
228
271
  write: true,
229
272
  platform: "node",
230
273
  format: "esm",
231
274
  packages: "external",
275
+ plugins: [createCompatZodPlugin()],
232
276
  outExtension: {
233
277
  ".js": ".mjs"
234
278
  },
@@ -292,9 +336,29 @@ function flattenNode(node) {
292
336
  if ("value" in node) return node.value;
293
337
  return "";
294
338
  }
339
+ function parseSpecifier(specifier) {
340
+ const idx = specifier.lastIndexOf("#");
341
+ if (idx === -1) return { file: specifier };
342
+ return {
343
+ file: specifier.slice(0, idx),
344
+ section: specifier.slice(idx + 1)
345
+ };
346
+ }
347
+ function extractSection(root, section) {
348
+ for (const node of root.children) {
349
+ if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
350
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
351
+ )) {
352
+ return {
353
+ type: "root",
354
+ children: node.children
355
+ };
356
+ }
357
+ }
358
+ }
295
359
  function remarkInclude() {
296
360
  const TagName = "include";
297
- async function update(tree, file, processor, compiler) {
361
+ async function update(tree, directory, data) {
298
362
  const queue = [];
299
363
  (0, import_unist_util_visit.visit)(
300
364
  tree,
@@ -314,27 +378,44 @@ function remarkInclude() {
314
378
  }
315
379
  }
316
380
  if (!specifier) return;
381
+ const { file, section } = parseSpecifier(specifier);
317
382
  const targetPath = path2.resolve(
318
- "cwd" in params ? process.cwd() : path2.dirname(file),
319
- specifier
383
+ "cwd" in params ? process.cwd() : directory,
384
+ file
320
385
  );
321
- const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
386
+ const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
322
387
  queue.push(
323
388
  fs2.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
324
- compiler?.addDependency(targetPath);
389
+ data._compiler?.addDependency(targetPath);
325
390
  if (asCode) {
326
- const lang = params.lang ?? path2.extname(specifier).slice(1);
391
+ const lang = params.lang ?? path2.extname(file).slice(1);
327
392
  Object.assign(node, {
328
393
  type: "code",
329
394
  lang,
330
395
  meta: params.meta,
331
- value: content.toString(),
396
+ value: content,
332
397
  data: {}
333
398
  });
334
399
  return;
335
400
  }
336
- const parsed = processor.parse(fumaMatter(content).content);
337
- await update(parsed, targetPath, processor, compiler);
401
+ const processor = data._processor ? data._processor.getProcessor(
402
+ targetPath.endsWith(".md") ? "md" : "mdx"
403
+ ) : this;
404
+ let parsed = processor.parse(fumaMatter(content).content);
405
+ if (section) {
406
+ const extracted = extractSection(parsed, section);
407
+ if (!extracted)
408
+ throw new Error(
409
+ `Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
410
+ );
411
+ parsed = extracted;
412
+ }
413
+ await update.call(
414
+ processor,
415
+ parsed,
416
+ path2.dirname(targetPath),
417
+ data
418
+ );
338
419
  Object.assign(
339
420
  parent && parent.type === "paragraph" ? parent : node,
340
421
  parsed
@@ -342,7 +423,8 @@ function remarkInclude() {
342
423
  }).catch((e) => {
343
424
  throw new Error(
344
425
  `failed to read file ${targetPath}
345
- ${e instanceof Error ? e.message : String(e)}`
426
+ ${e instanceof Error ? e.message : String(e)}`,
427
+ { cause: e }
346
428
  );
347
429
  })
348
430
  );
@@ -352,7 +434,7 @@ ${e instanceof Error ? e.message : String(e)}`
352
434
  await Promise.all(queue);
353
435
  }
354
436
  return async (tree, file) => {
355
- await update(tree, file.path, this, file.data._compiler);
437
+ await update.call(this, tree, path2.dirname(file.path), file.data);
356
438
  };
357
439
  }
358
440
 
@@ -360,29 +442,32 @@ ${e instanceof Error ? e.message : String(e)}`
360
442
  var cache2 = /* @__PURE__ */ new Map();
361
443
  async function buildMDX(cacheKey, source, options) {
362
444
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
363
- let format = options.format;
364
- if (filePath) {
365
- format ??= filePath.endsWith(".mdx") ? "mdx" : "md";
366
- }
367
- format ??= "mdx";
368
- const key = `${cacheKey}:${format}`;
369
- let cached = cache2.get(key);
370
- if (!cached) {
371
- cached = (0, import_mdx.createProcessor)({
372
- outputFormat: "program",
373
- ...rest,
374
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
375
- format
376
- });
377
- cache2.set(key, cached);
445
+ function getProcessor(format) {
446
+ const key = `${cacheKey}:${format}`;
447
+ let processor = cache2.get(key);
448
+ if (!processor) {
449
+ processor = (0, import_mdx.createProcessor)({
450
+ outputFormat: "program",
451
+ ...rest,
452
+ remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
453
+ format
454
+ });
455
+ cache2.set(key, processor);
456
+ }
457
+ return processor;
378
458
  }
379
- return cached.process({
459
+ return getProcessor(
460
+ options.format ?? filePath.endsWith(".mdx") ? "mdx" : "md"
461
+ ).process({
380
462
  value: source,
381
463
  path: filePath,
382
464
  data: {
383
465
  ...data,
384
466
  frontmatter,
385
- _compiler
467
+ _compiler,
468
+ _processor: {
469
+ getProcessor
470
+ }
386
471
  }
387
472
  });
388
473
  }
@@ -410,25 +495,8 @@ async function getGitTimestamp(file) {
410
495
  }
411
496
  }
412
497
 
413
- // src/utils/schema.ts
414
- var import_zod = require("zod");
498
+ // src/utils/validation.ts
415
499
  var import_picocolors = __toESM(require("picocolors"), 1);
416
- var metaSchema = import_zod.z.object({
417
- title: import_zod.z.string().optional(),
418
- pages: import_zod.z.array(import_zod.z.string()).optional(),
419
- description: import_zod.z.string().optional(),
420
- root: import_zod.z.boolean().optional(),
421
- defaultOpen: import_zod.z.boolean().optional(),
422
- icon: import_zod.z.string().optional()
423
- });
424
- var frontmatterSchema = import_zod.z.object({
425
- title: import_zod.z.string(),
426
- description: import_zod.z.string().optional(),
427
- icon: import_zod.z.string().optional(),
428
- full: import_zod.z.boolean().optional(),
429
- // Fumadocs OpenAPI generated
430
- _openapi: import_zod.z.looseObject({}).optional()
431
- });
432
500
  var ValidationError = class extends Error {
433
501
  constructor(message, issues) {
434
502
  super(
@@ -1,20 +1,20 @@
1
1
  import {
2
2
  getConfigHash,
3
3
  loadConfig
4
- } from "./chunk-4CGSOZUZ.js";
4
+ } from "./chunk-XZR5QXVY.js";
5
5
  import {
6
- buildMDX,
7
6
  countLines
8
- } from "./chunk-C5INPAZJ.js";
7
+ } from "./chunk-UCY7OBZG.js";
9
8
  import {
10
- getGitTimestamp
11
- } from "./chunk-VUEZTR2H.js";
9
+ buildMDX
10
+ } from "./chunk-HWSF4OGZ.js";
11
+ import "./chunk-3XN4P23K.js";
12
12
  import {
13
13
  ValidationError,
14
+ getGitTimestamp,
14
15
  validate
15
- } from "./chunk-ZOWJF3OH.js";
16
- import "./chunk-AVMO2SRO.js";
17
- import "./chunk-JFNBRKRV.js";
16
+ } from "./chunk-GX3THK2Q.js";
17
+ import "./chunk-XVL4ZQFK.js";
18
18
  import {
19
19
  fumaMatter
20
20
  } from "./chunk-KVWX6THC.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getDefaultMDXOptions
3
- } from "./chunk-2CSSQTP6.js";
3
+ } from "./chunk-GYWPPGFD.js";
4
4
  export {
5
5
  getDefaultMDXOptions
6
6
  };
@@ -102,6 +102,7 @@ function getDefaultMDXOptions({
102
102
  remarkStructureOptions,
103
103
  remarkCodeTabOptions,
104
104
  remarkNpmOptions,
105
+ _withoutBundler = false,
105
106
  ...mdxOptions
106
107
  }) {
107
108
  const mdxExports = [
@@ -120,7 +121,13 @@ function getDefaultMDXOptions({
120
121
  ...remarkHeadingOptions
121
122
  }
122
123
  ],
123
- remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
124
+ remarkImageOptions !== false && [
125
+ plugins.remarkImage,
126
+ {
127
+ ...remarkImageOptions,
128
+ useImport: _withoutBundler ? false : remarkImageOptions?.useImport
129
+ }
130
+ ],
124
131
  "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
125
132
  plugins.remarkCodeTab,
126
133
  remarkCodeTabOptions
@@ -145,6 +152,7 @@ function getDefaultMDXOptions({
145
152
  );
146
153
  return {
147
154
  ...mdxOptions,
155
+ outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
148
156
  remarkPlugins,
149
157
  rehypePlugins
150
158
  };
@@ -228,20 +236,26 @@ function buildConfig(config) {
228
236
  `Unknown export "${k}", you can only export collections from source configuration file.`
229
237
  );
230
238
  }
231
- let cachedMdxOptions;
239
+ const mdxOptionsCache = /* @__PURE__ */ new Map();
232
240
  return {
233
241
  global: globalConfig,
234
242
  collections,
235
- async getDefaultMDXOptions() {
236
- if (cachedMdxOptions) return cachedMdxOptions;
243
+ async getDefaultMDXOptions(mode = "default") {
244
+ const cached = mdxOptionsCache.get(mode);
245
+ if (cached) return cached;
237
246
  const input = this.global.mdxOptions;
238
247
  async function uncached() {
239
248
  const options = typeof input === "function" ? await input() : input;
240
249
  const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
241
250
  if (options?.preset === "minimal") return options;
242
- return getDefaultMDXOptions2(options ?? {});
251
+ return getDefaultMDXOptions2({
252
+ ...options,
253
+ _withoutBundler: mode === "remote"
254
+ });
243
255
  }
244
- return cachedMdxOptions = uncached();
256
+ const result = uncached();
257
+ mdxOptionsCache.set(mode, result);
258
+ return result;
245
259
  }
246
260
  };
247
261
  }
@@ -251,17 +265,47 @@ function findConfigFile() {
251
265
  return path.resolve("source.config.ts");
252
266
  }
253
267
  var cache = null;
268
+ async function isZod3() {
269
+ try {
270
+ const content = JSON.parse(
271
+ (await fs.readFile("node_modules/zod/package.json")).toString()
272
+ );
273
+ const version = content.version;
274
+ return typeof version === "string" && version.startsWith("3.");
275
+ } catch {
276
+ return false;
277
+ }
278
+ }
279
+ function createCompatZodPlugin() {
280
+ return {
281
+ name: "replace-zod-import",
282
+ async setup(build) {
283
+ const usingZod3 = await isZod3();
284
+ if (!usingZod3) return;
285
+ console.warn(
286
+ "[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
287
+ );
288
+ build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
289
+ return {
290
+ path: "fumadocs-mdx/config/zod-3",
291
+ external: true
292
+ };
293
+ });
294
+ }
295
+ };
296
+ }
254
297
  async function compileConfig(configPath, outDir) {
255
298
  const { build } = await import("esbuild");
256
299
  const transformed = await build({
257
300
  entryPoints: [{ in: configPath, out: "source.config" }],
258
301
  bundle: true,
259
302
  outdir: outDir,
260
- target: "node18",
303
+ target: "node20",
261
304
  write: true,
262
305
  platform: "node",
263
306
  format: "esm",
264
307
  packages: "external",
308
+ plugins: [createCompatZodPlugin()],
265
309
  outExtension: {
266
310
  ".js": ".mjs"
267
311
  },
@@ -303,25 +347,8 @@ var path4 = __toESM(require("path"), 1);
303
347
  var fs2 = __toESM(require("fs/promises"), 1);
304
348
  var import_tinyglobby = require("tinyglobby");
305
349
 
306
- // src/utils/schema.ts
307
- var import_zod = require("zod");
350
+ // src/utils/validation.ts
308
351
  var import_picocolors = __toESM(require("picocolors"), 1);
309
- var metaSchema = import_zod.z.object({
310
- title: import_zod.z.string().optional(),
311
- pages: import_zod.z.array(import_zod.z.string()).optional(),
312
- description: import_zod.z.string().optional(),
313
- root: import_zod.z.boolean().optional(),
314
- defaultOpen: import_zod.z.boolean().optional(),
315
- icon: import_zod.z.string().optional()
316
- });
317
- var frontmatterSchema = import_zod.z.object({
318
- title: import_zod.z.string(),
319
- description: import_zod.z.string().optional(),
320
- icon: import_zod.z.string().optional(),
321
- full: import_zod.z.boolean().optional(),
322
- // Fumadocs OpenAPI generated
323
- _openapi: import_zod.z.looseObject({}).optional()
324
- });
325
352
  var ValidationError = class extends Error {
326
353
  constructor(message, issues) {
327
354
  super(
@@ -2,21 +2,19 @@ import {
2
2
  findConfigFile,
3
3
  getConfigHash,
4
4
  loadConfig
5
- } from "../chunk-4CGSOZUZ.js";
5
+ } from "../chunk-XZR5QXVY.js";
6
6
  import {
7
7
  getGlobPatterns,
8
8
  getImportCode,
9
9
  isFileSupported,
10
10
  toImportPath
11
11
  } from "../chunk-OWZSTKKX.js";
12
- import {
13
- getGitTimestamp
14
- } from "../chunk-VUEZTR2H.js";
15
12
  import {
16
13
  ValidationError,
14
+ getGitTimestamp,
17
15
  validate
18
- } from "../chunk-ZOWJF3OH.js";
19
- import "../chunk-JFNBRKRV.js";
16
+ } from "../chunk-GX3THK2Q.js";
17
+ import "../chunk-XVL4ZQFK.js";
20
18
  import {
21
19
  fumaMatter
22
20
  } from "../chunk-KVWX6THC.js";