fumadocs-mdx 11.10.1 → 12.0.1

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 (68) hide show
  1. package/dist/bin.cjs +126 -218
  2. package/dist/bin.js +1 -1
  3. package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
  4. package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
  5. package/dist/bun/index.cjs +274 -230
  6. package/dist/bun/index.js +8 -8
  7. package/dist/chunk-ADR6R7HM.js +29 -0
  8. package/dist/{chunk-UOOPSLFY.js → chunk-AUOOMFAI.js} +27 -21
  9. package/dist/chunk-FSZMKRVH.js +80 -0
  10. package/dist/{chunk-766EAFX6.js → chunk-LGYVNESJ.js} +2 -36
  11. package/dist/chunk-LMG6UWCL.js +167 -0
  12. package/dist/chunk-QAUWMR5D.js +142 -0
  13. package/dist/{chunk-QJCCVMBJ.js → chunk-SP7CHRTS.js} +17 -47
  14. package/dist/{chunk-QVZ7JH4H.js → chunk-U4MQ44TS.js} +1 -1
  15. package/dist/{chunk-CNKI574E.js → chunk-VXEBLM4X.js} +1 -1
  16. package/dist/chunk-XMFLD5J6.js +30 -0
  17. package/dist/chunk-ZLCSVXCD.js +10 -0
  18. package/dist/{chunk-XXSKWWMB.js → chunk-ZX7TM4AR.js} +4 -2
  19. package/dist/config/index.cjs +97 -148
  20. package/dist/config/index.d.cts +1 -1
  21. package/dist/config/index.d.ts +1 -1
  22. package/dist/config/index.js +48 -9
  23. package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.cts} +18 -3
  24. package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.ts} +18 -3
  25. package/dist/load-UUXLUBHL.js +9 -0
  26. package/dist/loader-mdx.cjs +336 -305
  27. package/dist/loader-mdx.js +8 -8
  28. package/dist/next/index.cjs +152 -242
  29. package/dist/next/index.js +52 -66
  30. package/dist/node/loader.cjs +274 -243
  31. package/dist/node/loader.js +7 -8
  32. package/dist/postinstall-SCSXM4IM.js +10 -0
  33. package/dist/{mdx-options-T73E4LQB.js → preset-ZMP6U62C.js} +1 -1
  34. package/dist/runtime/next/async.cjs +304 -204
  35. package/dist/runtime/next/async.d.cts +3 -3
  36. package/dist/runtime/next/async.d.ts +3 -3
  37. package/dist/runtime/next/async.js +59 -32
  38. package/dist/runtime/next/index.cjs +32 -21
  39. package/dist/runtime/next/index.d.cts +11 -7
  40. package/dist/runtime/next/index.d.ts +11 -7
  41. package/dist/runtime/next/index.js +2 -1
  42. package/dist/runtime/vite/browser.d.cts +2 -3
  43. package/dist/runtime/vite/browser.d.ts +2 -3
  44. package/dist/runtime/vite/server.cjs +67 -21
  45. package/dist/runtime/vite/server.d.cts +14 -28
  46. package/dist/runtime/vite/server.d.ts +14 -28
  47. package/dist/runtime/vite/server.js +61 -21
  48. package/dist/shared-0QIuV0XZ.d.ts +70 -0
  49. package/dist/shared-CqgMnt9h.d.cts +70 -0
  50. package/dist/{types-DN9KrG7R.d.ts → types-CFlQxTN8.d.ts} +10 -37
  51. package/dist/{types-DT83Ijs6.d.cts → types-DkGjw-Uo.d.cts} +10 -37
  52. package/dist/vite/index.cjs +299 -279
  53. package/dist/vite/index.d.cts +1 -0
  54. package/dist/vite/index.d.ts +1 -0
  55. package/dist/vite/index.js +15 -20
  56. package/dist/{watcher-4NDMOH4R.js → watcher-HGOH3APP.js} +1 -1
  57. package/package.json +16 -16
  58. package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
  59. package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
  60. package/dist/chunk-GBMFGEC7.js +0 -57
  61. package/dist/chunk-QQWCBFFE.js +0 -40
  62. package/dist/chunk-SMSNZ6N5.js +0 -155
  63. package/dist/chunk-SVTXMVLQ.js +0 -139
  64. package/dist/config/zod-3.cjs +0 -422
  65. package/dist/config/zod-3.d.cts +0 -53
  66. package/dist/config/zod-3.d.ts +0 -53
  67. package/dist/config/zod-3.js +0 -40
  68. package/dist/postinstall-XV4WSHZP.js +0 -9
@@ -4,57 +4,36 @@ import {
4
4
  isFileSupported,
5
5
  toImportPath
6
6
  } from "../chunk-6Y5JDZHD.js";
7
+ import {
8
+ getConfigHash,
9
+ loadConfig
10
+ } from "../chunk-LGYVNESJ.js";
7
11
  import {
8
12
  ValidationError,
9
13
  getGitTimestamp,
10
14
  validate
11
15
  } from "../chunk-IQAEAI4P.js";
12
16
  import {
13
- findConfigFile,
14
- getConfigHash,
15
- loadConfig
16
- } from "../chunk-766EAFX6.js";
17
- import "../chunk-QVZ7JH4H.js";
17
+ findConfigFile
18
+ } from "../chunk-XMFLD5J6.js";
19
+ import {
20
+ readFileWithCache,
21
+ removeFileCache
22
+ } from "../chunk-ADR6R7HM.js";
23
+ import "../chunk-U4MQ44TS.js";
18
24
  import {
19
25
  fumaMatter
20
26
  } from "../chunk-VWJKRQZR.js";
21
27
 
22
28
  // src/next/index.ts
23
29
  import path3 from "path";
24
- import fs3 from "fs/promises";
30
+ import fs2 from "fs/promises";
25
31
 
26
- // src/map/generate.ts
32
+ // src/next/map/generate.ts
27
33
  import * as path from "path";
28
- import * as fs from "fs/promises";
34
+ import { createHash } from "crypto";
29
35
  import { glob } from "tinyglobby";
30
-
31
- // src/map/file-cache.ts
32
- import { LRUCache } from "lru-cache";
33
- var map = new LRUCache({
34
- max: 200
35
- });
36
- var fileCache = {
37
- read(namespace, path4) {
38
- return map.get(`${namespace}.${path4}`);
39
- },
40
- write(namespace, path4, data) {
41
- map.set(`${namespace}.${path4}`, data);
42
- },
43
- removeCache(path4) {
44
- for (const key of map.keys()) {
45
- const keyPath = key.slice(key.indexOf(".") + 1);
46
- if (keyPath === path4) map.delete(key);
47
- }
48
- }
49
- };
50
-
51
- // src/map/generate.ts
52
36
  import { load } from "js-yaml";
53
- async function readFileWithCache(file) {
54
- const cached = fileCache.read("read-file", file);
55
- if (cached) return cached;
56
- return (await fs.readFile(file)).toString();
57
- }
58
37
  async function generateJS(configPath, config, importPath, configHash = false) {
59
38
  let asyncInit = false;
60
39
  const lines = [
@@ -81,7 +60,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
81
60
  getImportCode({
82
61
  type: "namespace",
83
62
  name: importId,
84
- specifier: `${toImportPath(file.absolutePath, importPath)}?${params.join("&")}`
63
+ specifier: `${toImportPath(file.fullPath, importPath)}?${params.join("&")}`
85
64
  })
86
65
  );
87
66
  return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
@@ -90,17 +69,17 @@ async function generateJS(configPath, config, importPath, configHash = false) {
90
69
  }
91
70
  async function getMetaEntries(collection, files) {
92
71
  const items = files.map(async (file) => {
93
- const source = await readFileWithCache(file.absolutePath).catch(() => "");
94
- let data = source.length === 0 ? {} : parseMetaEntry(file.absolutePath, source);
72
+ const source = await readFileWithCache(file.fullPath).catch(() => "");
73
+ let data = source.length === 0 ? {} : parseMetaEntry(file.fullPath, source);
95
74
  if (collection?.schema) {
96
75
  data = await validate(
97
76
  collection.schema,
98
77
  data,
99
78
  {
100
79
  source,
101
- path: file.absolutePath
80
+ path: file.fullPath
102
81
  },
103
- `invalid data in ${file.absolutePath}`
82
+ `invalid data in ${file.fullPath}`
104
83
  );
105
84
  }
106
85
  return JSON.stringify({
@@ -118,33 +97,40 @@ async function generateJS(configPath, config, importPath, configHash = false) {
118
97
  specifier: "fumadocs-mdx/runtime/async",
119
98
  names: ["_runtimeAsync", "buildConfig"]
120
99
  }),
121
- "const _sourceConfig = buildConfig(_source)"
100
+ "const _sourceConfig = buildConfig(_source)",
101
+ getImportCode({
102
+ type: "default",
103
+ name: "path",
104
+ specifier: "node:path"
105
+ })
122
106
  );
123
107
  asyncInit = true;
124
108
  }
125
109
  const entries2 = files.map(async (file) => {
126
- const parsed = fumaMatter(
127
- await readFileWithCache(file.absolutePath).catch(() => "")
128
- );
110
+ const content = await readFileWithCache(file.fullPath).catch(() => "");
111
+ const parsed = fumaMatter(content);
129
112
  let data = parsed.data;
130
113
  if (collection.schema) {
131
114
  data = await validate(
132
115
  collection.schema,
133
116
  parsed.data,
134
- { path: file.absolutePath, source: parsed.content },
135
- `invalid frontmatter in ${file.absolutePath}`
117
+ { path: file.fullPath, source: parsed.content },
118
+ `invalid frontmatter in ${file.fullPath}`
136
119
  );
137
120
  }
138
121
  let lastModified;
139
122
  if (config.global?.lastModifiedTime === "git") {
140
- lastModified = await getGitTimestamp(file.absolutePath);
123
+ lastModified = await getGitTimestamp(file.fullPath);
141
124
  }
142
- return JSON.stringify({
143
- info: file,
144
- lastModified,
145
- data,
146
- content: { body: parsed.content, matter: parsed.matter }
147
- });
125
+ const hash = createHash("md5").update(content).digest("hex");
126
+ const infoStr = [];
127
+ for (const [k, v] of Object.entries({ ...file, hash })) {
128
+ infoStr.push(`${k}: ${JSON.stringify(v)}`);
129
+ }
130
+ infoStr.push(
131
+ `absolutePath: path.resolve(${JSON.stringify(file.fullPath)})`
132
+ );
133
+ return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
148
134
  });
149
135
  return Promise.all(entries2);
150
136
  }
@@ -184,14 +170,14 @@ async function getCollectionFiles(collection) {
184
170
  await Promise.all(
185
171
  dirs.map(async (dir) => {
186
172
  const result = await glob(patterns, {
187
- cwd: path.resolve(dir),
188
- absolute: true
173
+ cwd: path.resolve(dir)
189
174
  });
190
175
  for (const item of result) {
191
176
  if (!isFileSupported(item, collection)) continue;
192
- files.set(item, {
193
- path: path.relative(dir, item),
194
- absolutePath: item
177
+ const fullPath = path.join(dir, item);
178
+ files.set(fullPath, {
179
+ path: item,
180
+ fullPath
195
181
  });
196
182
  }
197
183
  })
@@ -211,9 +197,9 @@ function parseMetaEntry(file, content) {
211
197
  throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
212
198
  }
213
199
 
214
- // src/map/index.ts
200
+ // src/next/map/index.ts
215
201
  import * as path2 from "path";
216
- import * as fs2 from "fs/promises";
202
+ import * as fs from "fs/promises";
217
203
  async function start(dev, configPath, outDir) {
218
204
  let configHash = await getConfigHash(configPath);
219
205
  let config = await loadConfig(configPath, outDir, configHash, true);
@@ -221,7 +207,7 @@ async function start(dev, configPath, outDir) {
221
207
  async function updateMapFile() {
222
208
  const start2 = performance.now();
223
209
  try {
224
- await fs2.writeFile(
210
+ await fs.writeFile(
225
211
  outPath,
226
212
  await generateJS(
227
213
  configPath,
@@ -241,7 +227,7 @@ async function start(dev, configPath, outDir) {
241
227
  }
242
228
  await updateMapFile();
243
229
  if (dev) {
244
- const { watcher } = await import("../watcher-4NDMOH4R.js");
230
+ const { watcher } = await import("../watcher-HGOH3APP.js");
245
231
  const instance = watcher(configPath, config, [outPath]);
246
232
  instance.on("ready", () => {
247
233
  console.log("[MDX] started dev server");
@@ -255,7 +241,7 @@ async function start(dev, configPath, outDir) {
255
241
  configHash = await getConfigHash(configPath);
256
242
  config = await loadConfig(configPath, outDir, configHash, true);
257
243
  }
258
- if (event === "change") fileCache.removeCache(absolutePath);
244
+ if (event === "change") removeFileCache(absolutePath);
259
245
  await updateMapFile();
260
246
  };
261
247
  void onUpdate();
@@ -342,10 +328,10 @@ function createMDX({
342
328
  async function postInstall(configPath = findConfigFile(), outDir = ".source") {
343
329
  const config = await loadConfig(configPath, outDir, void 0, true);
344
330
  const outPath = path3.join(outDir, "index.ts");
345
- await fs3.rm(outDir, { recursive: true });
346
- await fs3.mkdir(outDir, { recursive: true });
331
+ await fs2.rm(outDir, { recursive: true });
332
+ await fs2.mkdir(outDir, { recursive: true });
347
333
  const hash = await getConfigHash(configPath);
348
- await fs3.writeFile(
334
+ await fs2.writeFile(
349
335
  outPath,
350
336
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
351
337
  );