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
  };
@@ -191,20 +199,26 @@ function buildConfig(config) {
191
199
  `Unknown export "${k}", you can only export collections from source configuration file.`
192
200
  );
193
201
  }
194
- let cachedMdxOptions;
202
+ const mdxOptionsCache = /* @__PURE__ */ new Map();
195
203
  return {
196
204
  global: globalConfig,
197
205
  collections,
198
- async getDefaultMDXOptions() {
199
- if (cachedMdxOptions) return cachedMdxOptions;
206
+ async getDefaultMDXOptions(mode = "default") {
207
+ const cached = mdxOptionsCache.get(mode);
208
+ if (cached) return cached;
200
209
  const input = this.global.mdxOptions;
201
210
  async function uncached() {
202
211
  const options = typeof input === "function" ? await input() : input;
203
212
  const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
204
213
  if (options?.preset === "minimal") return options;
205
- return getDefaultMDXOptions2(options ?? {});
214
+ return getDefaultMDXOptions2({
215
+ ...options,
216
+ _withoutBundler: mode === "remote"
217
+ });
206
218
  }
207
- return cachedMdxOptions = uncached();
219
+ const result = uncached();
220
+ mdxOptionsCache.set(mode, result);
221
+ return result;
208
222
  }
209
223
  };
210
224
  }
@@ -240,9 +254,29 @@ function flattenNode(node) {
240
254
  if ("value" in node) return node.value;
241
255
  return "";
242
256
  }
257
+ function parseSpecifier(specifier) {
258
+ const idx = specifier.lastIndexOf("#");
259
+ if (idx === -1) return { file: specifier };
260
+ return {
261
+ file: specifier.slice(0, idx),
262
+ section: specifier.slice(idx + 1)
263
+ };
264
+ }
265
+ function extractSection(root, section) {
266
+ for (const node of root.children) {
267
+ if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
268
+ (attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
269
+ )) {
270
+ return {
271
+ type: "root",
272
+ children: node.children
273
+ };
274
+ }
275
+ }
276
+ }
243
277
  function remarkInclude() {
244
278
  const TagName = "include";
245
- async function update(tree, file, processor, compiler) {
279
+ async function update(tree, directory, data) {
246
280
  const queue = [];
247
281
  (0, import_unist_util_visit.visit)(
248
282
  tree,
@@ -262,27 +296,44 @@ function remarkInclude() {
262
296
  }
263
297
  }
264
298
  if (!specifier) return;
299
+ const { file, section } = parseSpecifier(specifier);
265
300
  const targetPath = path.resolve(
266
- "cwd" in params ? process.cwd() : path.dirname(file),
267
- specifier
301
+ "cwd" in params ? process.cwd() : directory,
302
+ file
268
303
  );
269
- const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
304
+ const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
270
305
  queue.push(
271
306
  fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
272
- compiler?.addDependency(targetPath);
307
+ data._compiler?.addDependency(targetPath);
273
308
  if (asCode) {
274
- const lang = params.lang ?? path.extname(specifier).slice(1);
309
+ const lang = params.lang ?? path.extname(file).slice(1);
275
310
  Object.assign(node, {
276
311
  type: "code",
277
312
  lang,
278
313
  meta: params.meta,
279
- value: content.toString(),
314
+ value: content,
280
315
  data: {}
281
316
  });
282
317
  return;
283
318
  }
284
- const parsed = processor.parse(fumaMatter(content).content);
285
- await update(parsed, targetPath, processor, compiler);
319
+ const processor = data._processor ? data._processor.getProcessor(
320
+ targetPath.endsWith(".md") ? "md" : "mdx"
321
+ ) : this;
322
+ let parsed = processor.parse(fumaMatter(content).content);
323
+ if (section) {
324
+ const extracted = extractSection(parsed, section);
325
+ if (!extracted)
326
+ throw new Error(
327
+ `Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
328
+ );
329
+ parsed = extracted;
330
+ }
331
+ await update.call(
332
+ processor,
333
+ parsed,
334
+ path.dirname(targetPath),
335
+ data
336
+ );
286
337
  Object.assign(
287
338
  parent && parent.type === "paragraph" ? parent : node,
288
339
  parsed
@@ -290,7 +341,8 @@ function remarkInclude() {
290
341
  }).catch((e) => {
291
342
  throw new Error(
292
343
  `failed to read file ${targetPath}
293
- ${e instanceof Error ? e.message : String(e)}`
344
+ ${e instanceof Error ? e.message : String(e)}`,
345
+ { cause: e }
294
346
  );
295
347
  })
296
348
  );
@@ -300,7 +352,7 @@ ${e instanceof Error ? e.message : String(e)}`
300
352
  await Promise.all(queue);
301
353
  }
302
354
  return async (tree, file) => {
303
- await update(tree, file.path, this, file.data._compiler);
355
+ await update.call(this, tree, path.dirname(file.path), file.data);
304
356
  };
305
357
  }
306
358
 
@@ -308,29 +360,32 @@ ${e instanceof Error ? e.message : String(e)}`
308
360
  var cache = /* @__PURE__ */ new Map();
309
361
  async function buildMDX(cacheKey, source, options) {
310
362
  const { filePath, frontmatter, data, _compiler, ...rest } = options;
311
- let format = options.format;
312
- if (filePath) {
313
- format ??= filePath.endsWith(".mdx") ? "mdx" : "md";
314
- }
315
- format ??= "mdx";
316
- const key = `${cacheKey}:${format}`;
317
- let cached = cache.get(key);
318
- if (!cached) {
319
- cached = (0, import_mdx.createProcessor)({
320
- outputFormat: "program",
321
- ...rest,
322
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
323
- format
324
- });
325
- cache.set(key, cached);
363
+ function getProcessor(format) {
364
+ const key = `${cacheKey}:${format}`;
365
+ let processor = cache.get(key);
366
+ if (!processor) {
367
+ processor = (0, import_mdx.createProcessor)({
368
+ outputFormat: "program",
369
+ ...rest,
370
+ remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
371
+ format
372
+ });
373
+ cache.set(key, processor);
374
+ }
375
+ return processor;
326
376
  }
327
- return cached.process({
377
+ return getProcessor(
378
+ options.format ?? filePath.endsWith(".mdx") ? "mdx" : "md"
379
+ ).process({
328
380
  value: source,
329
381
  path: filePath,
330
382
  data: {
331
383
  ...data,
332
384
  frontmatter,
333
- _compiler
385
+ _compiler,
386
+ _processor: {
387
+ getProcessor
388
+ }
334
389
  }
335
390
  });
336
391
  }
@@ -347,25 +402,8 @@ function countLines(s) {
347
402
  return num;
348
403
  }
349
404
 
350
- // src/utils/schema.ts
351
- var import_zod = require("zod");
405
+ // src/utils/validation.ts
352
406
  var import_picocolors = __toESM(require("picocolors"), 1);
353
- var metaSchema = import_zod.z.object({
354
- title: import_zod.z.string().optional(),
355
- pages: import_zod.z.array(import_zod.z.string()).optional(),
356
- description: import_zod.z.string().optional(),
357
- root: import_zod.z.boolean().optional(),
358
- defaultOpen: import_zod.z.boolean().optional(),
359
- icon: import_zod.z.string().optional()
360
- });
361
- var frontmatterSchema = import_zod.z.object({
362
- title: import_zod.z.string(),
363
- description: import_zod.z.string().optional(),
364
- icon: import_zod.z.string().optional(),
365
- full: import_zod.z.boolean().optional(),
366
- // Fumadocs OpenAPI generated
367
- _openapi: import_zod.z.looseObject({}).optional()
368
- });
369
407
  var ValidationError = class extends Error {
370
408
  constructor(message, issues) {
371
409
  super(
@@ -403,7 +441,7 @@ async function validate(schema, data, context, errorMessage) {
403
441
  }
404
442
 
405
443
  // src/vite/index.ts
406
- var import_zod2 = require("zod");
444
+ var import_zod = require("zod");
407
445
 
408
446
  // src/utils/import-formatter.ts
409
447
  var import_node_path = __toESM(require("path"), 1);
@@ -502,7 +540,7 @@ async function getGitTimestamp(file) {
502
540
  }
503
541
 
504
542
  // src/vite/index.ts
505
- var onlySchema = import_zod2.z.literal(["frontmatter", "all"]);
543
+ var onlySchema = import_zod.z.literal(["frontmatter", "all"]);
506
544
  function mdx(config, options = {}) {
507
545
  const { generateIndexFile = true, configPath = "source.config.ts" } = options;
508
546
  const loaded = buildConfig(config);
@@ -1,23 +1,23 @@
1
1
  import {
2
- buildMDX,
3
2
  countLines
4
- } from "../chunk-C5INPAZJ.js";
3
+ } from "../chunk-UCY7OBZG.js";
4
+ import {
5
+ buildMDX
6
+ } from "../chunk-HWSF4OGZ.js";
7
+ import "../chunk-3XN4P23K.js";
5
8
  import {
6
9
  getGlobPatterns,
7
10
  ident,
8
11
  toImportPath
9
12
  } from "../chunk-OWZSTKKX.js";
10
- import {
11
- getGitTimestamp
12
- } from "../chunk-VUEZTR2H.js";
13
13
  import {
14
14
  ValidationError,
15
+ getGitTimestamp,
15
16
  validate
16
- } from "../chunk-ZOWJF3OH.js";
17
- import "../chunk-AVMO2SRO.js";
17
+ } from "../chunk-GX3THK2Q.js";
18
18
  import {
19
19
  buildConfig
20
- } from "../chunk-JFNBRKRV.js";
20
+ } from "../chunk-XVL4ZQFK.js";
21
21
  import {
22
22
  fumaMatter
23
23
  } from "../chunk-KVWX6THC.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.7.3",
3
+ "version": "11.7.5",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -18,6 +18,11 @@
18
18
  "types": "./dist/config/index.d.ts",
19
19
  "require": "./dist/config/index.cjs"
20
20
  },
21
+ "./config/zod-3": {
22
+ "import": "./dist/config/zod-3.js",
23
+ "types": "./dist/config/zod-3.d.ts",
24
+ "require": "./dist/config/zod-3.cjs"
25
+ },
21
26
  "./next": {
22
27
  "import": "./dist/next/index.js",
23
28
  "types": "./dist/next/index.d.ts",
@@ -62,25 +67,25 @@
62
67
  "tinyexec": "^1.0.1",
63
68
  "tinyglobby": "^0.2.14",
64
69
  "unist-util-visit": "^5.0.0",
65
- "zod": "^4.0.14"
70
+ "zod": "^4.0.17"
66
71
  },
67
72
  "devDependencies": {
68
73
  "@types/js-yaml": "^4.0.9",
69
74
  "@types/mdast": "^4.0.3",
70
75
  "@types/mdx": "^2.0.13",
71
- "@types/node": "^24.1.0",
76
+ "@types/node": "^24.2.1",
72
77
  "@types/react": "^19.1.9",
73
78
  "mdast-util-mdx-jsx": "^3.2.0",
74
- "next": "^15.4.5",
79
+ "next": "^15.4.6",
75
80
  "react": "^19.1.1",
76
81
  "rollup": "^4.46.2",
77
82
  "unified": "^11.0.5",
78
83
  "vfile": "^6.0.3",
79
- "vite": "^7.0.5",
84
+ "vite": "^7.1.1",
80
85
  "webpack": "^5.101.0",
81
- "@fumadocs/mdx-remote": "1.4.0",
86
+ "fumadocs-core": "15.6.10",
82
87
  "eslint-config-custom": "0.0.0",
83
- "fumadocs-core": "15.6.7",
88
+ "@fumadocs/mdx-remote": "1.4.0",
84
89
  "tsconfig": "0.0.0"
85
90
  },
86
91
  "peerDependencies": {
@@ -1,49 +0,0 @@
1
- import {
2
- remarkInclude
3
- } from "./chunk-AVMO2SRO.js";
4
-
5
- // src/utils/build-mdx.ts
6
- import { createProcessor } from "@mdx-js/mdx";
7
- var cache = /* @__PURE__ */ new Map();
8
- async function buildMDX(cacheKey, source, options) {
9
- const { filePath, frontmatter, data, _compiler, ...rest } = options;
10
- let format = options.format;
11
- if (filePath) {
12
- format ??= filePath.endsWith(".mdx") ? "mdx" : "md";
13
- }
14
- format ??= "mdx";
15
- const key = `${cacheKey}:${format}`;
16
- let cached = cache.get(key);
17
- if (!cached) {
18
- cached = createProcessor({
19
- outputFormat: "program",
20
- ...rest,
21
- remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
22
- format
23
- });
24
- cache.set(key, cached);
25
- }
26
- return cached.process({
27
- value: source,
28
- path: filePath,
29
- data: {
30
- ...data,
31
- frontmatter,
32
- _compiler
33
- }
34
- });
35
- }
36
-
37
- // src/utils/count-lines.ts
38
- function countLines(s) {
39
- let num = 0;
40
- for (const c of s) {
41
- if (c === "\n") num++;
42
- }
43
- return num;
44
- }
45
-
46
- export {
47
- buildMDX,
48
- countLines
49
- };
@@ -1,26 +0,0 @@
1
- // src/utils/git-timestamp.ts
2
- import path from "path";
3
- import { x } from "tinyexec";
4
- var cache = /* @__PURE__ */ new Map();
5
- async function getGitTimestamp(file) {
6
- const cached = cache.get(file);
7
- if (cached) return cached;
8
- try {
9
- const out = await x(
10
- "git",
11
- ["log", "-1", '--pretty="%ai"', path.relative(process.cwd(), file)],
12
- {
13
- throwOnError: true
14
- }
15
- );
16
- const time = new Date(out.stdout);
17
- cache.set(file, time);
18
- return time;
19
- } catch {
20
- return;
21
- }
22
- }
23
-
24
- export {
25
- getGitTimestamp
26
- };