fumadocs-mdx 11.9.1 → 11.10.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 (52) hide show
  1. package/dist/bin.cjs +1063 -0
  2. package/dist/bin.d.cts +1 -0
  3. package/dist/bin.d.ts +1 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/{browser-CyU2Yl7A.d.cts → browser-B2G8uAF2.d.cts} +1 -1
  6. package/dist/{browser-DEsQvNRx.d.ts → browser-DrH7tKRi.d.ts} +1 -1
  7. package/dist/bun/index.cjs +669 -0
  8. package/dist/bun/index.d.cts +8 -0
  9. package/dist/bun/index.d.ts +8 -0
  10. package/dist/bun/index.js +53 -0
  11. package/dist/chunk-6Y5JDZHD.js +65 -0
  12. package/dist/chunk-CNKI574E.js +82 -0
  13. package/dist/{chunk-GX3THK2Q.js → chunk-IQAEAI4P.js} +25 -25
  14. package/dist/chunk-QJCCVMBJ.js +151 -0
  15. package/dist/{chunk-NUDEC6C5.js → chunk-UOOPSLFY.js} +1 -1
  16. package/dist/{chunk-COQ4VMK2.js → chunk-XXSKWWMB.js} +28 -61
  17. package/dist/config/index.d.cts +1 -1
  18. package/dist/config/index.d.ts +1 -1
  19. package/dist/config/zod-3.d.cts +1 -1
  20. package/dist/config/zod-3.d.ts +1 -1
  21. package/dist/{define-DnJzAZrj.d.cts → define-BH4bnHQl.d.cts} +6 -0
  22. package/dist/{define-DnJzAZrj.d.ts → define-BH4bnHQl.d.ts} +6 -0
  23. package/dist/loader-mdx.cjs +345 -265
  24. package/dist/loader-mdx.js +12 -80
  25. package/dist/next/index.cjs +15 -130
  26. package/dist/next/index.js +15 -33
  27. package/dist/node/loader.cjs +748 -0
  28. package/dist/node/loader.d.cts +5 -0
  29. package/dist/node/loader.d.ts +5 -0
  30. package/dist/node/loader.js +24 -0
  31. package/dist/postinstall-XV4WSHZP.js +9 -0
  32. package/dist/runtime/{async.cjs → next/async.cjs} +4 -4
  33. package/dist/runtime/{async.d.cts → next/async.d.cts} +3 -3
  34. package/dist/runtime/{async.d.ts → next/async.d.ts} +3 -3
  35. package/dist/runtime/{async.js → next/async.js} +6 -6
  36. package/dist/{index.cjs → runtime/next/index.cjs} +4 -6
  37. package/dist/{index.d.cts → runtime/next/index.d.cts} +3 -3
  38. package/dist/{index.d.ts → runtime/next/index.d.ts} +3 -3
  39. package/dist/{index.js → runtime/next/index.js} +1 -1
  40. package/dist/runtime/vite/browser.d.cts +2 -2
  41. package/dist/runtime/vite/browser.d.ts +2 -2
  42. package/dist/runtime/vite/server.d.cts +3 -3
  43. package/dist/runtime/vite/server.d.ts +3 -3
  44. package/dist/{types-WSHJKA8L.d.ts → types-DN9KrG7R.d.ts} +1 -1
  45. package/dist/{types-BmVgoqsr.d.cts → types-DT83Ijs6.d.cts} +1 -1
  46. package/dist/vite/index.cjs +440 -276
  47. package/dist/vite/index.d.cts +4 -1
  48. package/dist/vite/index.d.ts +4 -1
  49. package/dist/vite/index.js +19 -81
  50. package/package.json +24 -17
  51. package/bin.js +0 -5
  52. package/dist/chunk-UCY7OBZG.js +0 -12
@@ -1,92 +1,24 @@
1
1
  import {
2
- getConfigHash,
3
- loadConfig
4
- } from "./chunk-766EAFX6.js";
2
+ toWebpack
3
+ } from "./chunk-CNKI574E.js";
5
4
  import {
6
- countLines
7
- } from "./chunk-UCY7OBZG.js";
8
- import {
9
- ValidationError,
10
- getGitTimestamp,
11
- validate
12
- } from "./chunk-GX3THK2Q.js";
13
- import {
14
- buildMDX
15
- } from "./chunk-QQWCBFFE.js";
5
+ createMdxLoader,
6
+ dynamicConfig
7
+ } from "./chunk-QJCCVMBJ.js";
8
+ import "./chunk-QQWCBFFE.js";
16
9
  import "./chunk-SVTXMVLQ.js";
10
+ import "./chunk-IQAEAI4P.js";
11
+ import "./chunk-766EAFX6.js";
17
12
  import "./chunk-QVZ7JH4H.js";
18
- import {
19
- fumaMatter
20
- } from "./chunk-VWJKRQZR.js";
13
+ import "./chunk-VWJKRQZR.js";
21
14
 
22
15
  // src/loader-mdx.ts
23
- import * as path from "path";
24
- import { parse } from "querystring";
16
+ var instance;
25
17
  async function loader(source, callback) {
26
18
  this.cacheable(true);
27
- const context = this.context;
28
- const filePath = this.resourcePath;
29
19
  const { configPath, outDir } = this.getOptions();
30
- const matter = fumaMatter(source);
31
- const {
32
- hash: configHash = await getConfigHash(configPath),
33
- collection: collectionId
34
- } = parse(this.resourceQuery.slice(1));
35
- const config = await loadConfig(configPath, outDir, configHash);
36
- let collection = collectionId !== void 0 ? config.collections.get(collectionId) : void 0;
37
- if (collection && collection.type === "docs") collection = collection.docs;
38
- if (collection && collection.type !== "doc") {
39
- collection = void 0;
40
- }
41
- let frontmatter = matter.data;
42
- const mdxOptions = collection?.mdxOptions ?? await config.getDefaultMDXOptions();
43
- if (collection?.schema) {
44
- try {
45
- frontmatter = await validate(
46
- collection.schema,
47
- frontmatter,
48
- {
49
- source,
50
- path: filePath
51
- },
52
- `invalid frontmatter in ${filePath}`
53
- );
54
- } catch (e) {
55
- if (e instanceof ValidationError) {
56
- return callback(new Error(e.toStringFormatted()));
57
- }
58
- return callback(e);
59
- }
60
- }
61
- let timestamp;
62
- if (config.global?.lastModifiedTime === "git") {
63
- timestamp = (await getGitTimestamp(filePath))?.getTime();
64
- }
65
- try {
66
- const lineOffset = "\n".repeat(
67
- this.mode === "development" ? countLines(matter.matter) : 0
68
- );
69
- const file = await buildMDX(
70
- `${configHash}:${collectionId ?? "global"}`,
71
- lineOffset + matter.content,
72
- {
73
- development: this.mode === "development",
74
- ...mdxOptions,
75
- filePath,
76
- frontmatter,
77
- data: {
78
- lastModified: timestamp
79
- },
80
- _compiler: this
81
- }
82
- );
83
- callback(void 0, String(file.value), file.map ?? void 0);
84
- } catch (error) {
85
- if (!(error instanceof Error)) throw error;
86
- const fpath = path.relative(context, filePath);
87
- error.message = `${fpath}:${error.name}: ${error.message}`;
88
- callback(error);
89
- }
20
+ instance ??= toWebpack(createMdxLoader(dynamicConfig(configPath, outDir)));
21
+ await instance.call(this, source, callback);
90
22
  }
91
23
  export {
92
24
  loader as default
@@ -369,9 +369,9 @@ async function getConfigHash(configPath) {
369
369
  throw new Error("Cannot find config file");
370
370
  }
371
371
 
372
- // src/map/index.ts
373
- var path5 = __toESM(require("path"), 1);
374
- var fs3 = __toESM(require("fs/promises"), 1);
372
+ // src/next/index.ts
373
+ var import_node_path3 = __toESM(require("path"), 1);
374
+ var import_promises = __toESM(require("fs/promises"), 1);
375
375
 
376
376
  // src/map/generate.ts
377
377
  var path4 = __toESM(require("path"), 1);
@@ -514,9 +514,6 @@ function toImportPath(file, config) {
514
514
  }
515
515
  return importPath.replaceAll(import_node_path2.default.sep, "/");
516
516
  }
517
- function ident(code, tab = 1) {
518
- return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
519
- }
520
517
 
521
518
  // src/utils/collections.ts
522
519
  function getSupportedFormats(collection) {
@@ -637,18 +634,18 @@ async function generateJS(configPath, config, importPath, configHash = false) {
637
634
  }
638
635
  const declares = entries.map(async ([k, collection]) => {
639
636
  if (collection.type === "docs") {
640
- const docs2 = await getCollectionFiles(collection.docs);
637
+ const docs = await getCollectionFiles(collection.docs);
641
638
  const metas = await getCollectionFiles(collection.meta);
642
639
  const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
643
640
  ", "
644
641
  );
645
642
  if (collection.docs.async) {
646
- const docsEntries2 = (await getAsyncEntries(collection.docs, docs2)).join(
643
+ const docsEntries2 = (await getAsyncEntries(collection.docs, docs)).join(
647
644
  ", "
648
645
  );
649
646
  return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
650
647
  }
651
- const docsEntries = (await getDocEntries(k, docs2)).join(", ");
648
+ const docsEntries = (await getDocEntries(k, docs)).join(", ");
652
649
  return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
653
650
  }
654
651
  const files = await getCollectionFiles(collection);
@@ -699,6 +696,8 @@ function parseMetaEntry(file, content) {
699
696
  }
700
697
 
701
698
  // src/map/index.ts
699
+ var path5 = __toESM(require("path"), 1);
700
+ var fs3 = __toESM(require("fs/promises"), 1);
702
701
  async function start(dev, configPath, outDir) {
703
702
  let configHash = await getConfigHash(configPath);
704
703
  let config = await loadConfig(configPath, outDir, configHash, true);
@@ -823,132 +822,18 @@ function createMDX({
823
822
  };
824
823
  }
825
824
 
826
- // src/postinstall.ts
827
- var path6 = __toESM(require("path"), 1);
828
- var fs4 = __toESM(require("fs/promises"), 1);
829
- var import_node_fs2 = require("fs");
830
-
831
- // src/vite/generate-glob.ts
832
- function generateGlob(name, patterns, globOptions) {
833
- const options = {
834
- ...globOptions,
835
- query: {
836
- ...globOptions?.query,
837
- collection: name
838
- }
839
- };
840
- return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
841
- }
842
- function mapGlobPatterns(patterns) {
843
- return patterns.map(enforceRelative);
844
- }
845
- function enforceRelative(file) {
846
- if (file.startsWith("./")) return file;
847
- if (file.startsWith("/")) return `.${file}`;
848
- return `./${file}`;
849
- }
850
- function getGlobBase(collection) {
851
- let dir = collection.dir;
852
- if (Array.isArray(dir)) {
853
- if (dir.length !== 1)
854
- throw new Error(
855
- `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
856
- );
857
- dir = dir[0];
858
- }
859
- return enforceRelative(dir);
860
- }
861
-
862
- // src/vite/generate.ts
863
- function docs(name, collection) {
864
- const obj = [
865
- ident(`doc: ${doc(name, collection.docs)}`),
866
- ident(`meta: ${meta(name, collection.meta)}`)
867
- ].join(",\n");
868
- return `{
869
- ${obj}
870
- }`;
871
- }
872
- function doc(name, collection) {
873
- const patterns = getGlobPatterns(collection);
874
- const base = getGlobBase(collection);
875
- const docGlob = generateGlob(name, patterns, {
876
- base
877
- });
878
- if (collection.async) {
879
- const headBlob = generateGlob(name, patterns, {
880
- query: {
881
- only: "frontmatter"
882
- },
883
- import: "frontmatter",
884
- base
885
- });
886
- return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
887
- }
888
- return `create.doc("${name}", "${base}", ${docGlob})`;
889
- }
890
- function meta(name, collection) {
891
- const patterns = getGlobPatterns(collection);
892
- const base = getGlobBase(collection);
893
- return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
894
- import: "default",
895
- base
896
- })})`;
897
- }
898
- function entry(configPath, config, outDir, jsExtension) {
899
- const lines = [
900
- '/// <reference types="vite/client" />',
901
- `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
902
- `import type * as Config from '${toImportPath(configPath, {
903
- relativeTo: outDir,
904
- jsExtension
905
- })}';`,
906
- "",
907
- `export const create = fromConfig<typeof Config>();`
908
- ];
909
- for (const [name, collection] of config.collections.entries()) {
910
- let body;
911
- if (collection.type === "docs") {
912
- body = docs(name, collection);
913
- } else if (collection.type === "meta") {
914
- body = meta(name, collection);
915
- } else {
916
- body = doc(name, collection);
917
- }
918
- lines.push("");
919
- lines.push(`export const ${name} = ${body};`);
920
- }
921
- return lines.join("\n");
922
- }
923
-
924
- // src/postinstall.ts
925
- async function postInstall(configPath = findConfigFile(), outDir) {
926
- const isNext = (0, import_node_fs2.existsSync)("next.config.js") || (0, import_node_fs2.existsSync)("next.config.mjs") || (0, import_node_fs2.existsSync)("next.config.ts");
927
- if (isNext) {
928
- await onNext(configPath, outDir ?? ".source");
929
- } else {
930
- await onVite(configPath, outDir ?? process.cwd());
931
- }
932
- console.log("[MDX] types generated");
933
- }
934
- async function onNext(configPath, outDir) {
825
+ // src/next/index.ts
826
+ async function postInstall(configPath = findConfigFile(), outDir = ".source") {
935
827
  const config = await loadConfig(configPath, outDir, void 0, true);
936
- const outPath = path6.join(outDir, "index.ts");
937
- await fs4.rm(outDir, { recursive: true });
938
- await fs4.mkdir(outDir, { recursive: true });
828
+ const outPath = import_node_path3.default.join(outDir, "index.ts");
829
+ await import_promises.default.rm(outDir, { recursive: true });
830
+ await import_promises.default.mkdir(outDir, { recursive: true });
939
831
  const hash = await getConfigHash(configPath);
940
- await fs4.writeFile(
832
+ await import_promises.default.writeFile(
941
833
  outPath,
942
834
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
943
835
  );
944
- }
945
- async function onVite(configPath, outDir, addJsExtension) {
946
- const config = await loadConfig(configPath, "node_modules", void 0, true);
947
- const outFile = "source.generated.ts";
948
- await fs4.writeFile(
949
- path6.join(outDir, outFile),
950
- entry(configPath, config, outDir, addJsExtension)
951
- );
836
+ console.log("[MDX] types generated");
952
837
  }
953
838
  // Annotate the CommonJS export names for ESM import in node:
954
839
  0 && (module.exports = {
@@ -1,28 +1,27 @@
1
1
  import {
2
- findConfigFile,
3
- getConfigHash,
4
- loadConfig
5
- } from "../chunk-766EAFX6.js";
6
- import {
7
- entry,
8
2
  getGlobPatterns,
9
3
  getImportCode,
10
4
  isFileSupported,
11
5
  toImportPath
12
- } from "../chunk-COQ4VMK2.js";
6
+ } from "../chunk-6Y5JDZHD.js";
13
7
  import {
14
8
  ValidationError,
15
9
  getGitTimestamp,
16
10
  validate
17
- } from "../chunk-GX3THK2Q.js";
11
+ } from "../chunk-IQAEAI4P.js";
12
+ import {
13
+ findConfigFile,
14
+ getConfigHash,
15
+ loadConfig
16
+ } from "../chunk-766EAFX6.js";
18
17
  import "../chunk-QVZ7JH4H.js";
19
18
  import {
20
19
  fumaMatter
21
20
  } from "../chunk-VWJKRQZR.js";
22
21
 
23
- // src/map/index.ts
24
- import * as path2 from "path";
25
- import * as fs2 from "fs/promises";
22
+ // src/next/index.ts
23
+ import path3 from "path";
24
+ import fs3 from "fs/promises";
26
25
 
27
26
  // src/map/generate.ts
28
27
  import * as path from "path";
@@ -213,6 +212,8 @@ function parseMetaEntry(file, content) {
213
212
  }
214
213
 
215
214
  // src/map/index.ts
215
+ import * as path2 from "path";
216
+ import * as fs2 from "fs/promises";
216
217
  async function start(dev, configPath, outDir) {
217
218
  let configHash = await getConfigHash(configPath);
218
219
  let config = await loadConfig(configPath, outDir, configHash, true);
@@ -337,20 +338,8 @@ function createMDX({
337
338
  };
338
339
  }
339
340
 
340
- // src/postinstall.ts
341
- import * as path3 from "path";
342
- import * as fs3 from "fs/promises";
343
- import { existsSync } from "fs";
344
- async function postInstall(configPath = findConfigFile(), outDir) {
345
- const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.ts");
346
- if (isNext) {
347
- await onNext(configPath, outDir ?? ".source");
348
- } else {
349
- await onVite(configPath, outDir ?? process.cwd());
350
- }
351
- console.log("[MDX] types generated");
352
- }
353
- async function onNext(configPath, outDir) {
341
+ // src/next/index.ts
342
+ async function postInstall(configPath = findConfigFile(), outDir = ".source") {
354
343
  const config = await loadConfig(configPath, outDir, void 0, true);
355
344
  const outPath = path3.join(outDir, "index.ts");
356
345
  await fs3.rm(outDir, { recursive: true });
@@ -360,14 +349,7 @@ async function onNext(configPath, outDir) {
360
349
  outPath,
361
350
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
362
351
  );
363
- }
364
- async function onVite(configPath, outDir, addJsExtension) {
365
- const config = await loadConfig(configPath, "node_modules", void 0, true);
366
- const outFile = "source.generated.ts";
367
- await fs3.writeFile(
368
- path3.join(outDir, outFile),
369
- entry(configPath, config, outDir, addJsExtension)
370
- );
352
+ console.log("[MDX] types generated");
371
353
  }
372
354
  export {
373
355
  createMDX,