fumadocs-mdx 12.0.0 → 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 (40) hide show
  1. package/dist/bin.cjs +102 -84
  2. package/dist/bin.js +1 -1
  3. package/dist/bun/index.cjs +156 -130
  4. package/dist/bun/index.js +8 -8
  5. package/dist/chunk-ADR6R7HM.js +29 -0
  6. package/dist/{chunk-3M4SHY6K.js → chunk-FSZMKRVH.js} +1 -1
  7. package/dist/{chunk-POXTQZ4D.js → chunk-LGYVNESJ.js} +2 -6
  8. package/dist/chunk-LMG6UWCL.js +167 -0
  9. package/dist/{chunk-SWNOXPYJ.js → chunk-QAUWMR5D.js} +6 -6
  10. package/dist/{chunk-KGUBBRL6.js → chunk-SP7CHRTS.js} +9 -37
  11. package/dist/{chunk-YC25YEBF.js → chunk-U4MQ44TS.js} +1 -1
  12. package/dist/chunk-XMFLD5J6.js +30 -0
  13. package/dist/{chunk-TLD6JMT6.js → chunk-ZX7TM4AR.js} +4 -2
  14. package/dist/config/index.cjs +84 -56
  15. package/dist/config/index.js +2 -2
  16. package/dist/load-UUXLUBHL.js +9 -0
  17. package/dist/loader-mdx.cjs +217 -174
  18. package/dist/loader-mdx.js +7 -7
  19. package/dist/next/index.cjs +128 -108
  20. package/dist/next/index.js +39 -53
  21. package/dist/node/loader.cjs +152 -109
  22. package/dist/node/loader.js +6 -7
  23. package/dist/postinstall-SCSXM4IM.js +10 -0
  24. package/dist/{preset-WFEORCAB.js → preset-ZMP6U62C.js} +1 -1
  25. package/dist/runtime/next/async.cjs +117 -65
  26. package/dist/runtime/next/async.d.cts +1 -1
  27. package/dist/runtime/next/async.d.ts +1 -1
  28. package/dist/runtime/next/async.js +15 -8
  29. package/dist/runtime/next/index.d.cts +2 -2
  30. package/dist/runtime/next/index.d.ts +2 -2
  31. package/dist/{types-DLIAvrgC.d.ts → types-CFlQxTN8.d.ts} +4 -5
  32. package/dist/{types-Dl8HLbm5.d.cts → types-DkGjw-Uo.d.cts} +4 -5
  33. package/dist/vite/index.cjs +177 -145
  34. package/dist/vite/index.d.cts +1 -0
  35. package/dist/vite/index.d.ts +1 -0
  36. package/dist/vite/index.js +14 -19
  37. package/dist/{watcher-4NDMOH4R.js → watcher-HGOH3APP.js} +1 -1
  38. package/package.json +15 -11
  39. package/dist/chunk-KTDVTBMH.js +0 -139
  40. package/dist/postinstall-U7VROOY7.js +0 -9
package/dist/bin.cjs CHANGED
@@ -30,7 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
- // src/mdx/preset.ts
33
+ // src/loaders/mdx/preset.ts
34
34
  var preset_exports = {};
35
35
  __export(preset_exports, {
36
36
  getDefaultMDXOptions: () => getDefaultMDXOptions
@@ -111,7 +111,7 @@ function getDefaultMDXOptions({
111
111
  }
112
112
  var plugins;
113
113
  var init_preset = __esm({
114
- "src/mdx/preset.ts"() {
114
+ "src/loaders/mdx/preset.ts"() {
115
115
  "use strict";
116
116
  plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
117
117
  }
@@ -172,10 +172,7 @@ var init_build = __esm({
172
172
  }
173
173
  });
174
174
 
175
- // src/utils/config.ts
176
- function findConfigFile() {
177
- return path.resolve("source.config.ts");
178
- }
175
+ // src/loaders/config/load.ts
179
176
  async function compileConfig(configPath, outDir) {
180
177
  const { build } = await import("esbuild");
181
178
  const transformed = await build({
@@ -219,8 +216,8 @@ async function getConfigHash(configPath) {
219
216
  throw new Error("Cannot find config file");
220
217
  }
221
218
  var fs, path, import_node_url, cache;
222
- var init_config = __esm({
223
- "src/utils/config.ts"() {
219
+ var init_load = __esm({
220
+ "src/loaders/config/load.ts"() {
224
221
  "use strict";
225
222
  fs = __toESM(require("fs/promises"), 1);
226
223
  path = __toESM(require("path"), 1);
@@ -274,29 +271,34 @@ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
274
271
  }
275
272
  });
276
273
 
277
- // src/map/file-cache.ts
278
- var import_lru_cache, map, fileCache;
274
+ // src/next/map/file-cache.ts
275
+ function toFullPath(file) {
276
+ if (import_node_path.default.isAbsolute(file)) {
277
+ return import_node_path.default.relative(process.cwd(), file);
278
+ }
279
+ return file;
280
+ }
281
+ async function readFileWithCache(file) {
282
+ const fullPath = toFullPath(file);
283
+ const cached = map.get(fullPath);
284
+ if (cached) return cached;
285
+ const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
286
+ map.set(fullPath, read);
287
+ return read;
288
+ }
289
+ function removeFileCache(file) {
290
+ map.delete(toFullPath(file));
291
+ }
292
+ var import_lru_cache, import_promises, import_node_path, map;
279
293
  var init_file_cache = __esm({
280
- "src/map/file-cache.ts"() {
294
+ "src/next/map/file-cache.ts"() {
281
295
  "use strict";
282
296
  import_lru_cache = require("lru-cache");
297
+ import_promises = __toESM(require("fs/promises"), 1);
298
+ import_node_path = __toESM(require("path"), 1);
283
299
  map = new import_lru_cache.LRUCache({
284
- max: 200
300
+ max: 100
285
301
  });
286
- fileCache = {
287
- read(namespace, path8) {
288
- return map.get(`${namespace}.${path8}`);
289
- },
290
- write(namespace, path8, data) {
291
- map.set(`${namespace}.${path8}`, data);
292
- },
293
- removeCache(path8) {
294
- for (const key of map.keys()) {
295
- const keyPath = key.slice(key.indexOf(".") + 1);
296
- if (keyPath === path8) map.delete(key);
297
- }
298
- }
299
- };
300
302
  }
301
303
  });
302
304
 
@@ -307,7 +309,7 @@ async function getGitTimestamp(file) {
307
309
  try {
308
310
  const out = await (0, import_tinyexec.x)(
309
311
  "git",
310
- ["log", "-1", '--pretty="%ai"', import_node_path.default.relative(process.cwd(), file)],
312
+ ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
311
313
  {
312
314
  throwOnError: true
313
315
  }
@@ -319,11 +321,11 @@ async function getGitTimestamp(file) {
319
321
  return;
320
322
  }
321
323
  }
322
- var import_node_path, import_tinyexec, cache2;
324
+ var import_node_path2, import_tinyexec, cache2;
323
325
  var init_git_timestamp = __esm({
324
326
  "src/utils/git-timestamp.ts"() {
325
327
  "use strict";
326
- import_node_path = __toESM(require("path"), 1);
328
+ import_node_path2 = __toESM(require("path"), 1);
327
329
  import_tinyexec = require("tinyexec");
328
330
  cache2 = /* @__PURE__ */ new Map();
329
331
  }
@@ -366,7 +368,7 @@ function getImportCode(info) {
366
368
  return `import ${specifier}`;
367
369
  }
368
370
  function toImportPath(file, config) {
369
- const ext = import_node_path2.default.extname(file);
371
+ const ext = import_node_path3.default.extname(file);
370
372
  let filename;
371
373
  if (ext === ".ts" && config.jsExtension) {
372
374
  filename = file.substring(0, file.length - ext.length) + ".js";
@@ -377,23 +379,23 @@ function toImportPath(file, config) {
377
379
  }
378
380
  let importPath;
379
381
  if ("relativeTo" in config) {
380
- importPath = import_node_path2.default.relative(config.relativeTo, filename);
381
- if (!import_node_path2.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
382
+ importPath = import_node_path3.default.relative(config.relativeTo, filename);
383
+ if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
382
384
  importPath = `./${importPath}`;
383
385
  }
384
386
  } else {
385
- importPath = import_node_path2.default.resolve(filename);
387
+ importPath = import_node_path3.default.resolve(filename);
386
388
  }
387
- return importPath.replaceAll(import_node_path2.default.sep, "/");
389
+ return importPath.replaceAll(import_node_path3.default.sep, "/");
388
390
  }
389
391
  function ident(code, tab = 1) {
390
392
  return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
391
393
  }
392
- var import_node_path2;
394
+ var import_node_path3;
393
395
  var init_import_formatter = __esm({
394
396
  "src/utils/import-formatter.ts"() {
395
397
  "use strict";
396
- import_node_path2 = __toESM(require("path"), 1);
398
+ import_node_path3 = __toESM(require("path"), 1);
397
399
  }
398
400
  });
399
401
 
@@ -420,12 +422,7 @@ var init_collections = __esm({
420
422
  }
421
423
  });
422
424
 
423
- // src/map/generate.ts
424
- async function readFileWithCache(file) {
425
- const cached = fileCache.read("read-file", file);
426
- if (cached) return cached;
427
- return (await fs2.readFile(file)).toString();
428
- }
425
+ // src/next/map/generate.ts
429
426
  async function generateJS(configPath, config, importPath, configHash = false) {
430
427
  let asyncInit = false;
431
428
  const lines = [
@@ -489,14 +486,18 @@ async function generateJS(configPath, config, importPath, configHash = false) {
489
486
  specifier: "fumadocs-mdx/runtime/async",
490
487
  names: ["_runtimeAsync", "buildConfig"]
491
488
  }),
492
- "const _sourceConfig = buildConfig(_source)"
489
+ "const _sourceConfig = buildConfig(_source)",
490
+ getImportCode({
491
+ type: "default",
492
+ name: "path",
493
+ specifier: "node:path"
494
+ })
493
495
  );
494
496
  asyncInit = true;
495
497
  }
496
498
  const entries2 = files.map(async (file) => {
497
- const parsed = fumaMatter(
498
- await readFileWithCache(file.fullPath).catch(() => "")
499
- );
499
+ const content = await readFileWithCache(file.fullPath).catch(() => "");
500
+ const parsed = fumaMatter(content);
500
501
  let data = parsed.data;
501
502
  if (collection.schema) {
502
503
  data = await validate(
@@ -510,12 +511,15 @@ async function generateJS(configPath, config, importPath, configHash = false) {
510
511
  if (config.global?.lastModifiedTime === "git") {
511
512
  lastModified = await getGitTimestamp(file.fullPath);
512
513
  }
513
- return JSON.stringify({
514
- info: file,
515
- lastModified,
516
- data,
517
- content: { body: parsed.content, matter: parsed.matter }
518
- });
514
+ const hash = (0, import_node_crypto.createHash)("md5").update(content).digest("hex");
515
+ const infoStr = [];
516
+ for (const [k, v] of Object.entries({ ...file, hash })) {
517
+ infoStr.push(`${k}: ${JSON.stringify(v)}`);
518
+ }
519
+ infoStr.push(
520
+ `absolutePath: path.resolve(${JSON.stringify(file.fullPath)})`
521
+ );
522
+ return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
519
523
  });
520
524
  return Promise.all(entries2);
521
525
  }
@@ -555,11 +559,11 @@ async function getCollectionFiles(collection) {
555
559
  await Promise.all(
556
560
  dirs.map(async (dir) => {
557
561
  const result = await (0, import_tinyglobby.glob)(patterns, {
558
- cwd: path4.resolve(dir)
562
+ cwd: path5.resolve(dir)
559
563
  });
560
564
  for (const item of result) {
561
565
  if (!isFileSupported(item, collection)) continue;
562
- const fullPath = path4.join(dir, item);
566
+ const fullPath = path5.join(dir, item);
563
567
  files.set(fullPath, {
564
568
  path: item,
565
569
  fullPath
@@ -570,7 +574,7 @@ async function getCollectionFiles(collection) {
570
574
  return Array.from(files.values());
571
575
  }
572
576
  function parseMetaEntry(file, content) {
573
- const extname2 = path4.extname(file);
577
+ const extname2 = path5.extname(file);
574
578
  try {
575
579
  if (extname2 === ".json") return JSON.parse(content);
576
580
  if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
@@ -581,12 +585,12 @@ function parseMetaEntry(file, content) {
581
585
  }
582
586
  throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
583
587
  }
584
- var path4, fs2, import_tinyglobby, import_js_yaml2;
588
+ var path5, import_node_crypto, import_tinyglobby, import_js_yaml2;
585
589
  var init_generate = __esm({
586
- "src/map/generate.ts"() {
590
+ "src/next/map/generate.ts"() {
587
591
  "use strict";
588
- path4 = __toESM(require("path"), 1);
589
- fs2 = __toESM(require("fs/promises"), 1);
592
+ path5 = __toESM(require("path"), 1);
593
+ import_node_crypto = require("crypto");
590
594
  import_tinyglobby = require("tinyglobby");
591
595
  init_validation();
592
596
  init_file_cache();
@@ -598,7 +602,19 @@ var init_generate = __esm({
598
602
  }
599
603
  });
600
604
 
601
- // src/map/watcher.ts
605
+ // src/loaders/config/index.ts
606
+ function findConfigFile() {
607
+ return import_node_path4.default.resolve("source.config.ts");
608
+ }
609
+ var import_node_path4;
610
+ var init_config = __esm({
611
+ "src/loaders/config/index.ts"() {
612
+ "use strict";
613
+ import_node_path4 = __toESM(require("path"), 1);
614
+ }
615
+ });
616
+
617
+ // src/next/map/watcher.ts
602
618
  var watcher_exports = {};
603
619
  __export(watcher_exports, {
604
620
  watcher: () => watcher
@@ -622,17 +638,17 @@ function watcher(configPath, config, ignored) {
622
638
  }
623
639
  var import_chokidar;
624
640
  var init_watcher = __esm({
625
- "src/map/watcher.ts"() {
641
+ "src/next/map/watcher.ts"() {
626
642
  "use strict";
627
643
  import_chokidar = require("chokidar");
628
644
  }
629
645
  });
630
646
 
631
- // src/map/index.ts
647
+ // src/next/map/index.ts
632
648
  async function start(dev, configPath, outDir) {
633
649
  let configHash = await getConfigHash(configPath);
634
650
  let config = await loadConfig(configPath, outDir, configHash, true);
635
- const outPath = path5.resolve(outDir, `index.ts`);
651
+ const outPath = path7.resolve(outDir, `index.ts`);
636
652
  async function updateMapFile() {
637
653
  const start3 = performance.now();
638
654
  try {
@@ -663,14 +679,14 @@ async function start(dev, configPath, outDir) {
663
679
  });
664
680
  instance.on("all", (event, file) => {
665
681
  if (typeof file !== "string") return;
666
- const absolutePath = path5.resolve(file);
682
+ const absolutePath = path7.resolve(file);
667
683
  const onUpdate = async () => {
668
684
  const isConfigFile = absolutePath === configPath;
669
685
  if (isConfigFile) {
670
686
  configHash = await getConfigHash(configPath);
671
687
  config = await loadConfig(configPath, outDir, configHash, true);
672
688
  }
673
- if (event === "change") fileCache.removeCache(absolutePath);
689
+ if (event === "change") removeFileCache(absolutePath);
674
690
  await updateMapFile();
675
691
  };
676
692
  void onUpdate();
@@ -681,13 +697,13 @@ async function start(dev, configPath, outDir) {
681
697
  });
682
698
  }
683
699
  }
684
- var path5, fs3;
700
+ var path7, fs3;
685
701
  var init_map = __esm({
686
- "src/map/index.ts"() {
702
+ "src/next/map/index.ts"() {
687
703
  "use strict";
688
- path5 = __toESM(require("path"), 1);
704
+ path7 = __toESM(require("path"), 1);
689
705
  fs3 = __toESM(require("fs/promises"), 1);
690
- init_config();
706
+ init_load();
691
707
  init_generate();
692
708
  init_file_cache();
693
709
  init_validation();
@@ -781,24 +797,25 @@ __export(next_exports, {
781
797
  });
782
798
  async function postInstall(configPath = findConfigFile(), outDir = ".source") {
783
799
  const config = await loadConfig(configPath, outDir, void 0, true);
784
- const outPath = import_node_path3.default.join(outDir, "index.ts");
785
- await import_promises.default.rm(outDir, { recursive: true });
786
- await import_promises.default.mkdir(outDir, { recursive: true });
800
+ const outPath = import_node_path5.default.join(outDir, "index.ts");
801
+ await import_promises2.default.rm(outDir, { recursive: true });
802
+ await import_promises2.default.mkdir(outDir, { recursive: true });
787
803
  const hash = await getConfigHash(configPath);
788
- await import_promises.default.writeFile(
804
+ await import_promises2.default.writeFile(
789
805
  outPath,
790
806
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
791
807
  );
792
808
  console.log("[MDX] types generated");
793
809
  }
794
- var import_node_path3, import_promises;
810
+ var import_node_path5, import_promises2;
795
811
  var init_next = __esm({
796
812
  "src/next/index.ts"() {
797
813
  "use strict";
798
- init_config();
799
- import_node_path3 = __toESM(require("path"), 1);
800
- import_promises = __toESM(require("fs/promises"), 1);
814
+ init_load();
815
+ import_node_path5 = __toESM(require("path"), 1);
816
+ import_promises2 = __toESM(require("fs/promises"), 1);
801
817
  init_generate();
818
+ init_config();
802
819
  init_create();
803
820
  }
804
821
  });
@@ -918,22 +935,23 @@ async function postInstall2(configPath = findConfigFile(), outDir, addJsExtensio
918
935
  const config = await loadConfig(configPath, "node_modules", void 0, true);
919
936
  const outFile = "source.generated.ts";
920
937
  if (outDir) {
921
- await import_promises2.default.mkdir(outDir, { recursive: true });
938
+ await import_promises3.default.mkdir(outDir, { recursive: true });
922
939
  }
923
- await import_promises2.default.writeFile(
924
- outDir ? import_node_path4.default.join(outDir, outFile) : outFile,
940
+ await import_promises3.default.writeFile(
941
+ outDir ? import_node_path6.default.join(outDir, outFile) : outFile,
925
942
  entry(configPath, config, outDir ?? process.cwd(), addJsExtension)
926
943
  );
927
944
  console.log("[MDX] types generated");
928
945
  }
929
- var import_promises2, import_node_path4;
946
+ var import_promises3, import_node_path6;
930
947
  var init_postinstall = __esm({
931
948
  "src/vite/postinstall.ts"() {
932
949
  "use strict";
933
- init_config();
934
- import_promises2 = __toESM(require("fs/promises"), 1);
935
- import_node_path4 = __toESM(require("path"), 1);
950
+ init_load();
951
+ import_promises3 = __toESM(require("fs/promises"), 1);
952
+ import_node_path6 = __toESM(require("path"), 1);
936
953
  init_generate2();
954
+ init_config();
937
955
  }
938
956
  });
939
957
 
package/dist/bin.js CHANGED
@@ -9,7 +9,7 @@ async function start() {
9
9
  const { postInstall } = await import("./next/index.js");
10
10
  await postInstall(...args);
11
11
  } else {
12
- const { postInstall } = await import("./postinstall-U7VROOY7.js");
12
+ const { postInstall } = await import("./postinstall-SCSXM4IM.js");
13
13
  await postInstall(...args);
14
14
  }
15
15
  }