fumadocs-mdx 11.7.4 → 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-PQCNPAD3.js → chunk-3XN4P23K.js} +9 -6
  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 +19 -9
  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 +81 -48
  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 +162 -124
  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 +52 -49
  35. package/dist/vite/index.js +8 -8
  36. package/package.json +12 -7
  37. package/dist/chunk-2K55VKP6.js +0 -49
  38. package/dist/chunk-VUEZTR2H.js +0 -26
@@ -34,7 +34,7 @@ function extractSection(root, section) {
34
34
  }
35
35
  function remarkInclude() {
36
36
  const TagName = "include";
37
- async function update(tree, directory, processor, compiler) {
37
+ async function update(tree, directory, data) {
38
38
  const queue = [];
39
39
  visit(
40
40
  tree,
@@ -62,7 +62,7 @@ function remarkInclude() {
62
62
  const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
63
63
  queue.push(
64
64
  fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
65
- compiler?.addDependency(targetPath);
65
+ data._compiler?.addDependency(targetPath);
66
66
  if (asCode) {
67
67
  const lang = params.lang ?? path.extname(file).slice(1);
68
68
  Object.assign(node, {
@@ -74,6 +74,9 @@ function remarkInclude() {
74
74
  });
75
75
  return;
76
76
  }
77
+ const processor = data._processor ? data._processor.getProcessor(
78
+ targetPath.endsWith(".md") ? "md" : "mdx"
79
+ ) : this;
77
80
  let parsed = processor.parse(fumaMatter(content).content);
78
81
  if (section) {
79
82
  const extracted = extractSection(parsed, section);
@@ -83,11 +86,11 @@ function remarkInclude() {
83
86
  );
84
87
  parsed = extracted;
85
88
  }
86
- await update(
89
+ await update.call(
90
+ processor,
87
91
  parsed,
88
92
  path.dirname(targetPath),
89
- processor,
90
- compiler
93
+ data
91
94
  );
92
95
  Object.assign(
93
96
  parent && parent.type === "paragraph" ? parent : node,
@@ -107,7 +110,7 @@ ${e instanceof Error ? e.message : String(e)}`,
107
110
  await Promise.all(queue);
108
111
  }
109
112
  return async (tree, file) => {
110
- await update(tree, path.dirname(file.path), this, file.data._compiler);
113
+ await update.call(this, tree, path.dirname(file.path), file.data);
111
114
  };
112
115
  }
113
116
 
@@ -0,0 +1,57 @@
1
+ // src/config/zod-4.ts
2
+ import { z } from "zod";
3
+ var metaSchema = z.object({
4
+ title: z.string().optional(),
5
+ pages: z.array(z.string()).optional(),
6
+ description: z.string().optional(),
7
+ root: z.boolean().optional(),
8
+ defaultOpen: z.boolean().optional(),
9
+ icon: z.string().optional()
10
+ });
11
+ var frontmatterSchema = z.object({
12
+ title: z.string(),
13
+ description: z.string().optional(),
14
+ icon: z.string().optional(),
15
+ full: z.boolean().optional(),
16
+ // Fumadocs OpenAPI generated
17
+ _openapi: z.looseObject({}).optional()
18
+ });
19
+
20
+ // src/config/define.ts
21
+ function defineCollections(options) {
22
+ return options;
23
+ }
24
+ function defineDocs(options) {
25
+ if (!options)
26
+ console.warn(
27
+ "[`source.config.ts`] Deprecated: please pass options to `defineDocs()` and specify a `dir`."
28
+ );
29
+ const dir = options?.dir ?? "content/docs";
30
+ return {
31
+ type: "docs",
32
+ dir,
33
+ docs: defineCollections({
34
+ type: "doc",
35
+ dir,
36
+ schema: frontmatterSchema,
37
+ ...options?.docs
38
+ }),
39
+ meta: defineCollections({
40
+ type: "meta",
41
+ dir,
42
+ schema: metaSchema,
43
+ ...options?.meta
44
+ })
45
+ };
46
+ }
47
+ function defineConfig(config = {}) {
48
+ return config;
49
+ }
50
+
51
+ export {
52
+ metaSchema,
53
+ frontmatterSchema,
54
+ defineCollections,
55
+ defineDocs,
56
+ defineConfig
57
+ };
@@ -1,22 +1,28 @@
1
- // src/utils/schema.ts
2
- import { z } from "zod";
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
+ // src/utils/validation.ts
3
25
  import picocolors from "picocolors";
4
- var metaSchema = z.object({
5
- title: z.string().optional(),
6
- pages: z.array(z.string()).optional(),
7
- description: z.string().optional(),
8
- root: z.boolean().optional(),
9
- defaultOpen: z.boolean().optional(),
10
- icon: z.string().optional()
11
- });
12
- var frontmatterSchema = z.object({
13
- title: z.string(),
14
- description: z.string().optional(),
15
- icon: z.string().optional(),
16
- full: z.boolean().optional(),
17
- // Fumadocs OpenAPI generated
18
- _openapi: z.looseObject({}).optional()
19
- });
20
26
  var ValidationError = class extends Error {
21
27
  constructor(message, issues) {
22
28
  super(
@@ -54,8 +60,7 @@ async function validate(schema, data, context, errorMessage) {
54
60
  }
55
61
 
56
62
  export {
57
- metaSchema,
58
- frontmatterSchema,
63
+ getGitTimestamp,
59
64
  ValidationError,
60
65
  validate
61
66
  };
@@ -63,6 +63,7 @@ function getDefaultMDXOptions({
63
63
  remarkStructureOptions,
64
64
  remarkCodeTabOptions,
65
65
  remarkNpmOptions,
66
+ _withoutBundler = false,
66
67
  ...mdxOptions
67
68
  }) {
68
69
  const mdxExports = [
@@ -81,7 +82,13 @@ function getDefaultMDXOptions({
81
82
  ...remarkHeadingOptions
82
83
  }
83
84
  ],
84
- remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
85
+ remarkImageOptions !== false && [
86
+ plugins.remarkImage,
87
+ {
88
+ ...remarkImageOptions,
89
+ useImport: _withoutBundler ? false : remarkImageOptions?.useImport
90
+ }
91
+ ],
85
92
  "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
86
93
  plugins.remarkCodeTab,
87
94
  remarkCodeTabOptions
@@ -106,6 +113,7 @@ function getDefaultMDXOptions({
106
113
  );
107
114
  return {
108
115
  ...mdxOptions,
116
+ outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
109
117
  remarkPlugins,
110
118
  rehypePlugins
111
119
  };
@@ -0,0 +1,42 @@
1
+ import {
2
+ remarkInclude
3
+ } from "./chunk-3XN4P23K.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
+ function getProcessor(format) {
11
+ const key = `${cacheKey}:${format}`;
12
+ let processor = cache.get(key);
13
+ if (!processor) {
14
+ processor = createProcessor({
15
+ outputFormat: "program",
16
+ ...rest,
17
+ remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
18
+ format
19
+ });
20
+ cache.set(key, processor);
21
+ }
22
+ return processor;
23
+ }
24
+ return getProcessor(
25
+ options.format ?? filePath.endsWith(".mdx") ? "mdx" : "md"
26
+ ).process({
27
+ value: source,
28
+ path: filePath,
29
+ data: {
30
+ ...data,
31
+ frontmatter,
32
+ _compiler,
33
+ _processor: {
34
+ getProcessor
35
+ }
36
+ }
37
+ });
38
+ }
39
+
40
+ export {
41
+ buildMDX
42
+ };
@@ -0,0 +1,12 @@
1
+ // src/utils/count-lines.ts
2
+ function countLines(s) {
3
+ let num = 0;
4
+ for (const c of s) {
5
+ if (c === "\n") num++;
6
+ }
7
+ return num;
8
+ }
9
+
10
+ export {
11
+ countLines
12
+ };
@@ -24,20 +24,26 @@ function buildConfig(config) {
24
24
  `Unknown export "${k}", you can only export collections from source configuration file.`
25
25
  );
26
26
  }
27
- let cachedMdxOptions;
27
+ const mdxOptionsCache = /* @__PURE__ */ new Map();
28
28
  return {
29
29
  global: globalConfig,
30
30
  collections,
31
- async getDefaultMDXOptions() {
32
- if (cachedMdxOptions) return cachedMdxOptions;
31
+ async getDefaultMDXOptions(mode = "default") {
32
+ const cached = mdxOptionsCache.get(mode);
33
+ if (cached) return cached;
33
34
  const input = this.global.mdxOptions;
34
35
  async function uncached() {
35
36
  const options = typeof input === "function" ? await input() : input;
36
- const { getDefaultMDXOptions } = await import("./mdx-options-UDV5WEFU.js");
37
+ const { getDefaultMDXOptions } = await import("./mdx-options-3NB74EMB.js");
37
38
  if (options?.preset === "minimal") return options;
38
- return getDefaultMDXOptions(options ?? {});
39
+ return getDefaultMDXOptions({
40
+ ...options,
41
+ _withoutBundler: mode === "remote"
42
+ });
39
43
  }
40
- return cachedMdxOptions = uncached();
44
+ const result = uncached();
45
+ mdxOptionsCache.set(mode, result);
46
+ return result;
41
47
  }
42
48
  };
43
49
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildConfig
3
- } from "./chunk-JFNBRKRV.js";
3
+ } from "./chunk-XVL4ZQFK.js";
4
4
 
5
5
  // src/utils/config.ts
6
6
  import * as fs from "fs/promises";
@@ -10,17 +10,47 @@ function findConfigFile() {
10
10
  return path.resolve("source.config.ts");
11
11
  }
12
12
  var cache = null;
13
+ async function isZod3() {
14
+ try {
15
+ const content = JSON.parse(
16
+ (await fs.readFile("node_modules/zod/package.json")).toString()
17
+ );
18
+ const version = content.version;
19
+ return typeof version === "string" && version.startsWith("3.");
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+ function createCompatZodPlugin() {
25
+ return {
26
+ name: "replace-zod-import",
27
+ async setup(build) {
28
+ const usingZod3 = await isZod3();
29
+ if (!usingZod3) return;
30
+ console.warn(
31
+ "[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
32
+ );
33
+ build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
34
+ return {
35
+ path: "fumadocs-mdx/config/zod-3",
36
+ external: true
37
+ };
38
+ });
39
+ }
40
+ };
41
+ }
13
42
  async function compileConfig(configPath, outDir) {
14
43
  const { build } = await import("esbuild");
15
44
  const transformed = await build({
16
45
  entryPoints: [{ in: configPath, out: "source.config" }],
17
46
  bundle: true,
18
47
  outdir: outDir,
19
- target: "node18",
48
+ target: "node20",
20
49
  write: true,
21
50
  platform: "node",
22
51
  format: "esm",
23
52
  packages: "external",
53
+ plugins: [createCompatZodPlugin()],
24
54
  outExtension: {
25
55
  ".js": ".mjs"
26
56
  },
@@ -40,9 +40,8 @@ __export(config_exports, {
40
40
  });
41
41
  module.exports = __toCommonJS(config_exports);
42
42
 
43
- // src/utils/schema.ts
43
+ // src/config/zod-4.ts
44
44
  var import_zod = require("zod");
45
- var import_picocolors = __toESM(require("picocolors"), 1);
46
45
  var metaSchema = import_zod.z.object({
47
46
  title: import_zod.z.string().optional(),
48
47
  pages: import_zod.z.array(import_zod.z.string()).optional(),
@@ -156,6 +155,7 @@ function getDefaultMDXOptions({
156
155
  remarkStructureOptions,
157
156
  remarkCodeTabOptions,
158
157
  remarkNpmOptions,
158
+ _withoutBundler = false,
159
159
  ...mdxOptions
160
160
  }) {
161
161
  const mdxExports = [
@@ -174,7 +174,13 @@ function getDefaultMDXOptions({
174
174
  ...remarkHeadingOptions
175
175
  }
176
176
  ],
177
- remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
177
+ remarkImageOptions !== false && [
178
+ plugins.remarkImage,
179
+ {
180
+ ...remarkImageOptions,
181
+ useImport: _withoutBundler ? false : remarkImageOptions?.useImport
182
+ }
183
+ ],
178
184
  "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
179
185
  plugins.remarkCodeTab,
180
186
  remarkCodeTabOptions
@@ -199,6 +205,7 @@ function getDefaultMDXOptions({
199
205
  );
200
206
  return {
201
207
  ...mdxOptions,
208
+ outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
202
209
  remarkPlugins,
203
210
  rehypePlugins
204
211
  };
@@ -254,7 +261,7 @@ function extractSection(root, section) {
254
261
  }
255
262
  function remarkInclude() {
256
263
  const TagName = "include";
257
- async function update(tree, directory, processor, compiler) {
264
+ async function update(tree, directory, data) {
258
265
  const queue = [];
259
266
  (0, import_unist_util_visit.visit)(
260
267
  tree,
@@ -282,7 +289,7 @@ function remarkInclude() {
282
289
  const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
283
290
  queue.push(
284
291
  fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
285
- compiler?.addDependency(targetPath);
292
+ data._compiler?.addDependency(targetPath);
286
293
  if (asCode) {
287
294
  const lang = params.lang ?? path.extname(file).slice(1);
288
295
  Object.assign(node, {
@@ -294,6 +301,9 @@ function remarkInclude() {
294
301
  });
295
302
  return;
296
303
  }
304
+ const processor = data._processor ? data._processor.getProcessor(
305
+ targetPath.endsWith(".md") ? "md" : "mdx"
306
+ ) : this;
297
307
  let parsed = processor.parse(fumaMatter(content).content);
298
308
  if (section) {
299
309
  const extracted = extractSection(parsed, section);
@@ -303,11 +313,11 @@ function remarkInclude() {
303
313
  );
304
314
  parsed = extracted;
305
315
  }
306
- await update(
316
+ await update.call(
317
+ processor,
307
318
  parsed,
308
319
  path.dirname(targetPath),
309
- processor,
310
- compiler
320
+ data
311
321
  );
312
322
  Object.assign(
313
323
  parent && parent.type === "paragraph" ? parent : node,
@@ -327,7 +337,7 @@ ${e instanceof Error ? e.message : String(e)}`,
327
337
  await Promise.all(queue);
328
338
  }
329
339
  return async (tree, file) => {
330
- await update(tree, path.dirname(file.path), this, file.data._compiler);
340
+ await update.call(this, tree, path.dirname(file.path), file.data);
331
341
  };
332
342
  }
333
343
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,10 +1,10 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-E6TRBwBQ.cjs';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DnJzAZrj.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
- import 'zod';
5
4
  import '@standard-schema/spec';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import '@mdx-js/mdx';
7
+ import 'zod';
8
8
 
9
9
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
10
10
 
@@ -1,10 +1,10 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-E6TRBwBQ.js';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-DnJzAZrj.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
- import 'zod';
5
4
  import '@standard-schema/spec';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import '@mdx-js/mdx';
7
+ import 'zod';
8
8
 
9
9
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
10
10
 
@@ -1,45 +1,17 @@
1
1
  import {
2
+ defineCollections,
3
+ defineConfig,
4
+ defineDocs,
2
5
  frontmatterSchema,
3
6
  metaSchema
4
- } from "../chunk-ZOWJF3OH.js";
7
+ } from "../chunk-GBMFGEC7.js";
8
+ import {
9
+ getDefaultMDXOptions
10
+ } from "../chunk-GYWPPGFD.js";
5
11
  import {
6
12
  remarkInclude
7
- } from "../chunk-PQCNPAD3.js";
13
+ } from "../chunk-3XN4P23K.js";
8
14
  import "../chunk-KVWX6THC.js";
9
- import {
10
- getDefaultMDXOptions
11
- } from "../chunk-2CSSQTP6.js";
12
-
13
- // src/config/define.ts
14
- function defineCollections(options) {
15
- return options;
16
- }
17
- function defineDocs(options) {
18
- if (!options)
19
- console.warn(
20
- "[`source.config.ts`] Deprecated: please pass options to `defineDocs()` and specify a `dir`."
21
- );
22
- const dir = options?.dir ?? "content/docs";
23
- return {
24
- type: "docs",
25
- dir,
26
- docs: defineCollections({
27
- type: "doc",
28
- dir,
29
- schema: frontmatterSchema,
30
- ...options?.docs
31
- }),
32
- meta: defineCollections({
33
- type: "meta",
34
- dir,
35
- schema: metaSchema,
36
- ...options?.meta
37
- })
38
- };
39
- }
40
- function defineConfig(config = {}) {
41
- return config;
42
- }
43
15
  export {
44
16
  defineCollections,
45
17
  defineConfig,