fumadocs-mdx 11.9.1 → 11.10.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.
Files changed (37) hide show
  1. package/dist/{browser-CyU2Yl7A.d.cts → browser-B2G8uAF2.d.cts} +1 -1
  2. package/dist/{browser-DEsQvNRx.d.ts → browser-DrH7tKRi.d.ts} +1 -1
  3. package/dist/bun/index.cjs +667 -0
  4. package/dist/bun/index.d.cts +8 -0
  5. package/dist/bun/index.d.ts +8 -0
  6. package/dist/bun/index.js +50 -0
  7. package/dist/{chunk-766EAFX6.js → chunk-2HKRTQYP.js} +64 -0
  8. package/dist/chunk-5XJM5RPV.js +149 -0
  9. package/dist/chunk-NVX3U5YE.js +82 -0
  10. package/dist/config/index.d.cts +1 -1
  11. package/dist/config/index.d.ts +1 -1
  12. package/dist/config/zod-3.d.cts +1 -1
  13. package/dist/config/zod-3.d.ts +1 -1
  14. package/dist/{define-DnJzAZrj.d.cts → define-BH4bnHQl.d.cts} +6 -0
  15. package/dist/{define-DnJzAZrj.d.ts → define-BH4bnHQl.d.ts} +6 -0
  16. package/dist/index.d.cts +2 -2
  17. package/dist/index.d.ts +2 -2
  18. package/dist/loader-mdx.cjs +345 -265
  19. package/dist/loader-mdx.js +11 -80
  20. package/dist/next/index.js +4 -6
  21. package/dist/node/loader.cjs +748 -0
  22. package/dist/node/loader.d.cts +5 -0
  23. package/dist/node/loader.d.ts +5 -0
  24. package/dist/node/loader.js +23 -0
  25. package/dist/runtime/async.d.cts +2 -2
  26. package/dist/runtime/async.d.ts +2 -2
  27. package/dist/runtime/vite/browser.d.cts +2 -2
  28. package/dist/runtime/vite/browser.d.ts +2 -2
  29. package/dist/runtime/vite/server.d.cts +3 -3
  30. package/dist/runtime/vite/server.d.ts +3 -3
  31. package/dist/{types-WSHJKA8L.d.ts → types-DN9KrG7R.d.ts} +1 -1
  32. package/dist/{types-BmVgoqsr.d.cts → types-DT83Ijs6.d.cts} +1 -1
  33. package/dist/vite/index.cjs +356 -282
  34. package/dist/vite/index.js +12 -78
  35. package/package.json +17 -8
  36. package/dist/chunk-GX3THK2Q.js +0 -66
  37. package/dist/chunk-UCY7OBZG.js +0 -12
@@ -1,42 +1,37 @@
1
- import {
2
- countLines
3
- } from "../chunk-UCY7OBZG.js";
4
1
  import {
5
2
  entry
6
3
  } from "../chunk-COQ4VMK2.js";
4
+ import {
5
+ toVite
6
+ } from "../chunk-NVX3U5YE.js";
7
+ import {
8
+ createMdxLoader,
9
+ resolvedConfig
10
+ } from "../chunk-5XJM5RPV.js";
7
11
  import {
8
12
  ValidationError,
9
- getGitTimestamp,
10
13
  validate
11
- } from "../chunk-GX3THK2Q.js";
12
- import {
13
- buildMDX
14
- } from "../chunk-QQWCBFFE.js";
14
+ } from "../chunk-2HKRTQYP.js";
15
+ import "../chunk-QQWCBFFE.js";
15
16
  import "../chunk-SVTXMVLQ.js";
16
17
  import {
17
18
  buildConfig
18
19
  } from "../chunk-QVZ7JH4H.js";
19
- import {
20
- fumaMatter
21
- } from "../chunk-VWJKRQZR.js";
20
+ import "../chunk-VWJKRQZR.js";
22
21
 
23
22
  // src/vite/index.ts
24
23
  import {
25
24
  mergeConfig
26
25
  } from "vite";
27
26
  import { parse } from "querystring";
28
- import { z } from "zod";
29
27
  import * as fs from "fs/promises";
30
28
  import * as path from "path";
31
29
  import { load } from "js-yaml";
32
30
  var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
33
- var querySchema = z.object({
34
- only: z.literal(["frontmatter", "all"]).default("all"),
35
- collection: z.string().optional()
36
- }).loose();
37
31
  function mdx(config, options = {}) {
38
32
  const { generateIndexFile = true, configPath = "source.config.ts" } = options;
39
33
  const loaded = buildConfig(config);
34
+ const mdxLoader = toVite(createMdxLoader(resolvedConfig(loaded)));
40
35
  async function transformMeta(path2, query, value) {
41
36
  const isJson = path2.endsWith(".json");
42
37
  const parsed = parse(query);
@@ -69,67 +64,6 @@ function mdx(config, options = {}) {
69
64
  map: null
70
65
  };
71
66
  }
72
- async function transformContent(file, query, value) {
73
- const matter = fumaMatter(value);
74
- const isDevelopment = this.environment.mode === "dev";
75
- const parsed = querySchema.parse(parse(query));
76
- const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
77
- let schema;
78
- let mdxOptions;
79
- switch (collection?.type) {
80
- case "doc":
81
- mdxOptions = collection.mdxOptions;
82
- schema = collection.schema;
83
- break;
84
- case "docs":
85
- mdxOptions = collection.docs.mdxOptions;
86
- schema = collection.docs.schema;
87
- break;
88
- }
89
- if (schema) {
90
- matter.data = await validate(
91
- schema,
92
- matter.data,
93
- {
94
- source: value,
95
- path: file
96
- },
97
- `invalid frontmatter in ${file}`
98
- );
99
- }
100
- if (parsed.only === "frontmatter") {
101
- return {
102
- code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
103
- map: null
104
- };
105
- }
106
- const data = {};
107
- if (loaded.global.lastModifiedTime === "git") {
108
- data.lastModified = (await getGitTimestamp(file))?.getTime();
109
- }
110
- mdxOptions ??= await loaded.getDefaultMDXOptions();
111
- const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
112
- const compiled = await buildMDX(
113
- parsed.collection ?? "global",
114
- "\n".repeat(lineOffset) + matter.content,
115
- {
116
- development: isDevelopment,
117
- ...mdxOptions,
118
- data,
119
- filePath: file,
120
- frontmatter: matter.data,
121
- _compiler: {
122
- addDependency: (file2) => {
123
- this.addWatchFile(file2);
124
- }
125
- }
126
- }
127
- );
128
- return {
129
- code: String(compiled.value),
130
- map: compiled.map
131
- };
132
- }
133
67
  return {
134
68
  name: "fumadocs-mdx",
135
69
  // needed, otherwise other plugins will be executed before our `transform`.
@@ -167,7 +101,7 @@ function mdx(config, options = {}) {
167
101
  if ([".yaml", ".json"].includes(ext))
168
102
  return await transformMeta(file, query, value);
169
103
  if ([".md", ".mdx"].includes(ext))
170
- return await transformContent.call(this, file, query, value);
104
+ return await mdxLoader.call(this, file, query, value);
171
105
  } catch (e) {
172
106
  if (e instanceof ValidationError) {
173
107
  throw new Error(e.toStringFormatted());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.9.1",
3
+ "version": "11.10.0",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -42,6 +42,14 @@
42
42
  "import": "./dist/runtime/vite/server.js",
43
43
  "types": "./dist/runtime/vite/server.d.ts"
44
44
  },
45
+ "./node/loader": {
46
+ "import": "./dist/node/loader.js",
47
+ "types": "./dist/node/loader.d.ts"
48
+ },
49
+ "./bun": {
50
+ "import": "./dist/bun/index.js",
51
+ "types": "./dist/bun/index.d.ts"
52
+ },
45
53
  ".": {
46
54
  "import": "./dist/index.js",
47
55
  "types": "./dist/index.d.ts",
@@ -71,25 +79,26 @@
71
79
  "tinyglobby": "^0.2.15",
72
80
  "unified": "^11.0.5",
73
81
  "unist-util-visit": "^5.0.0",
74
- "zod": "^4.1.5"
82
+ "zod": "^4.1.8"
75
83
  },
76
84
  "devDependencies": {
85
+ "@types/bun": "^1.2.21",
77
86
  "@types/js-yaml": "^4.0.9",
78
87
  "@types/mdast": "^4.0.3",
79
88
  "@types/mdx": "^2.0.13",
80
- "@types/node": "^24.3.1",
81
- "@types/react": "^19.1.12",
89
+ "@types/node": "^24.3.3",
90
+ "@types/react": "^19.1.13",
82
91
  "mdast-util-mdx-jsx": "^3.2.0",
83
- "next": "^15.5.2",
92
+ "next": "^15.5.3",
84
93
  "react": "^19.1.1",
85
94
  "rollup": "^4.50.1",
86
95
  "vfile": "^6.0.3",
87
96
  "vite": "^7.1.5",
88
97
  "webpack": "^5.101.3",
89
- "tsconfig": "0.0.0",
90
- "eslint-config-custom": "0.0.0",
91
98
  "@fumadocs/mdx-remote": "1.4.0",
92
- "fumadocs-core": "15.7.11"
99
+ "eslint-config-custom": "0.0.0",
100
+ "fumadocs-core": "15.7.12",
101
+ "tsconfig": "0.0.0"
93
102
  },
94
103
  "peerDependencies": {
95
104
  "@fumadocs/mdx-remote": "^1.4.0",
@@ -1,66 +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
- // src/utils/validation.ts
25
- import picocolors from "picocolors";
26
- var ValidationError = class extends Error {
27
- constructor(message, issues) {
28
- super(
29
- `${message}:
30
- ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
31
- );
32
- this.title = message;
33
- this.issues = issues;
34
- }
35
- toStringFormatted() {
36
- return [
37
- picocolors.bold(`[MDX] ${this.title}:`),
38
- ...this.issues.map(
39
- (issue) => picocolors.redBright(
40
- `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
41
- )
42
- )
43
- ].join("\n");
44
- }
45
- };
46
- async function validate(schema, data, context, errorMessage) {
47
- if (typeof schema === "function" && !("~standard" in schema)) {
48
- schema = schema(context);
49
- }
50
- if ("~standard" in schema) {
51
- const result = await schema["~standard"].validate(
52
- data
53
- );
54
- if (result.issues) {
55
- throw new ValidationError(errorMessage, result.issues);
56
- }
57
- return result.value;
58
- }
59
- return data;
60
- }
61
-
62
- export {
63
- getGitTimestamp,
64
- ValidationError,
65
- validate
66
- };
@@ -1,12 +0,0 @@
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
- };