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
@@ -3,50 +3,88 @@ import {
3
3
  fromConfigBase,
4
4
  toClientRenderer
5
5
  } from "../../chunk-46UPKP5R.js";
6
+ import {
7
+ missingProcessedMarkdown
8
+ } from "../../chunk-ZLCSVXCD.js";
6
9
 
7
10
  // src/runtime/vite/server.ts
8
11
  import * as path from "path";
12
+ import fs from "fs/promises";
9
13
  function fromConfig() {
10
14
  const base = fromConfigBase();
11
- function mapPageData(entry) {
12
- const { toc, structuredData, lastModified, frontmatter } = entry;
15
+ function fileInfo(file, base2) {
16
+ return {
17
+ path: file,
18
+ fullPath: path.join(base2, file)
19
+ };
20
+ }
21
+ function mapDocData(entry) {
13
22
  return {
14
- ...frontmatter,
15
- default: entry.default,
16
23
  body: entry.default,
17
- toc,
18
- structuredData,
19
- lastModified,
24
+ toc: entry.toc,
25
+ extractedReferences: entry.extractedReferences,
26
+ structuredData: entry.structuredData,
27
+ lastModified: entry.lastModified,
20
28
  _exports: entry
21
29
  };
22
30
  }
23
- function mapPageDataLazy(head, content) {
31
+ function mapPageData(info, entry) {
32
+ return {
33
+ ...mapDocData(entry),
34
+ info,
35
+ async getText(type) {
36
+ if (type === "raw") {
37
+ return (await fs.readFile(info.fullPath)).toString();
38
+ }
39
+ if (typeof entry._markdown !== "string") missingProcessedMarkdown();
40
+ return entry._markdown;
41
+ },
42
+ ...entry.frontmatter
43
+ };
44
+ }
45
+ function mapPageDataLazy(info, head, content) {
24
46
  return {
25
47
  ...head,
48
+ info,
26
49
  async load() {
27
- const { default: body, ...rest } = await content();
28
- return { body, ...rest };
50
+ return mapDocData(await content());
51
+ },
52
+ async getText(type) {
53
+ if (type === "raw") {
54
+ return (await fs.readFile(info.fullPath)).toString();
55
+ }
56
+ const entry = await content();
57
+ if (typeof entry._markdown !== "string") missingProcessedMarkdown();
58
+ return entry._markdown;
29
59
  }
30
60
  };
31
61
  }
62
+ function mapMetaData(info, content) {
63
+ return {
64
+ info,
65
+ ...content
66
+ };
67
+ }
32
68
  return {
33
69
  ...base,
34
70
  async sourceAsync(doc, meta) {
35
71
  const virtualFiles = [
36
72
  ...Object.entries(doc).map(async ([file, content]) => {
73
+ const info = fileInfo(file, content.base);
37
74
  return {
38
75
  type: "page",
39
76
  path: file,
40
- absolutePath: path.join(content.base, file),
41
- data: mapPageData(await content())
77
+ absolutePath: info.fullPath,
78
+ data: mapPageData(info, await content())
42
79
  };
43
80
  }),
44
81
  ...Object.entries(meta).map(async ([file, content]) => {
82
+ const info = fileInfo(file, content.base);
45
83
  return {
46
84
  type: "meta",
47
- path: file,
48
- absolutePath: path.join(content.base, file),
49
- data: await content()
85
+ path: info.path,
86
+ absolutePath: info.fullPath,
87
+ data: mapMetaData(info, await content())
50
88
  };
51
89
  })
52
90
  ];
@@ -55,19 +93,21 @@ function fromConfig() {
55
93
  async sourceLazy(doc, meta) {
56
94
  const virtualFiles = [
57
95
  ...Object.entries(doc.head).map(async ([file, frontmatter]) => {
96
+ const info = fileInfo(file, doc.base);
58
97
  return {
59
98
  type: "page",
60
- path: file,
61
- absolutePath: path.join(doc.base, file),
62
- data: mapPageDataLazy(await frontmatter(), doc.body[file])
99
+ path: info.path,
100
+ absolutePath: info.fullPath,
101
+ data: mapPageDataLazy(info, await frontmatter(), doc.body[file])
63
102
  };
64
103
  }),
65
104
  ...Object.entries(meta).map(async ([file, content]) => {
105
+ const info = fileInfo(file, content.base);
66
106
  return {
67
107
  type: "meta",
68
- path: file,
69
- absolutePath: path.join(content.base, file),
70
- data: await content()
108
+ path: info.path,
109
+ absolutePath: info.fullPath,
110
+ data: mapMetaData(info, await content())
71
111
  };
72
112
  })
73
113
  ];
@@ -0,0 +1,70 @@
1
+ import { StructuredData } from 'fumadocs-core/mdx-plugins';
2
+ import { TableOfContents } from 'fumadocs-core/server';
3
+ import { FC } from 'react';
4
+ import { MDXProps } from 'mdx/types';
5
+ import { E as ExtractedReference } from './define--6HQ1ehX.js';
6
+
7
+ interface FileInfo {
8
+ /**
9
+ * virtualized path for Source API
10
+ */
11
+ path: string;
12
+ /**
13
+ * the file path in file system
14
+ */
15
+ fullPath: string;
16
+ }
17
+ interface DocData {
18
+ /**
19
+ * Compiled MDX content (as component)
20
+ */
21
+ body: FC<MDXProps>;
22
+ /**
23
+ * table of contents generated from content.
24
+ */
25
+ toc: TableOfContents;
26
+ /**
27
+ * structured data for document search indexing.
28
+ */
29
+ structuredData: StructuredData;
30
+ /**
31
+ * Raw exports from the compiled MDX file.
32
+ */
33
+ _exports: Record<string, unknown>;
34
+ /**
35
+ * Last modified date of document file, obtained from version control.
36
+ *
37
+ * Only available when `lastModifiedTime` is enabled on global config.
38
+ */
39
+ lastModified?: Date;
40
+ /**
41
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
42
+ */
43
+ extractedReferences?: ExtractedReference[];
44
+ }
45
+ interface DocMethods {
46
+ /**
47
+ * file info
48
+ */
49
+ info: FileInfo;
50
+ /**
51
+ * get document as text.
52
+ *
53
+ * - `type: raw` - read the original content from file system.
54
+ * - `type: processed` - get the processed Markdown content, only available when `includeProcessedMarkdown` is enabled on collection config.
55
+ */
56
+ getText: (type: 'raw' | 'processed') => Promise<string>;
57
+ }
58
+ type MetaCollectionEntry<Data> = Data & {
59
+ /**
60
+ * file info
61
+ */
62
+ info: FileInfo;
63
+ };
64
+ type DocCollectionEntry<Frontmatter> = Override<DocData & DocMethods, Frontmatter>;
65
+ type AsyncDocCollectionEntry<Frontmatter> = Override<DocMethods & {
66
+ load: () => Promise<DocData>;
67
+ }, Frontmatter>;
68
+ type Override<A, B> = Omit<A, keyof B> & B;
69
+
70
+ export type { AsyncDocCollectionEntry as A, DocCollectionEntry as D, FileInfo as F, MetaCollectionEntry as M };
@@ -0,0 +1,70 @@
1
+ import { StructuredData } from 'fumadocs-core/mdx-plugins';
2
+ import { TableOfContents } from 'fumadocs-core/server';
3
+ import { FC } from 'react';
4
+ import { MDXProps } from 'mdx/types';
5
+ import { E as ExtractedReference } from './define--6HQ1ehX.cjs';
6
+
7
+ interface FileInfo {
8
+ /**
9
+ * virtualized path for Source API
10
+ */
11
+ path: string;
12
+ /**
13
+ * the file path in file system
14
+ */
15
+ fullPath: string;
16
+ }
17
+ interface DocData {
18
+ /**
19
+ * Compiled MDX content (as component)
20
+ */
21
+ body: FC<MDXProps>;
22
+ /**
23
+ * table of contents generated from content.
24
+ */
25
+ toc: TableOfContents;
26
+ /**
27
+ * structured data for document search indexing.
28
+ */
29
+ structuredData: StructuredData;
30
+ /**
31
+ * Raw exports from the compiled MDX file.
32
+ */
33
+ _exports: Record<string, unknown>;
34
+ /**
35
+ * Last modified date of document file, obtained from version control.
36
+ *
37
+ * Only available when `lastModifiedTime` is enabled on global config.
38
+ */
39
+ lastModified?: Date;
40
+ /**
41
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
42
+ */
43
+ extractedReferences?: ExtractedReference[];
44
+ }
45
+ interface DocMethods {
46
+ /**
47
+ * file info
48
+ */
49
+ info: FileInfo;
50
+ /**
51
+ * get document as text.
52
+ *
53
+ * - `type: raw` - read the original content from file system.
54
+ * - `type: processed` - get the processed Markdown content, only available when `includeProcessedMarkdown` is enabled on collection config.
55
+ */
56
+ getText: (type: 'raw' | 'processed') => Promise<string>;
57
+ }
58
+ type MetaCollectionEntry<Data> = Data & {
59
+ /**
60
+ * file info
61
+ */
62
+ info: FileInfo;
63
+ };
64
+ type DocCollectionEntry<Frontmatter> = Override<DocData & DocMethods, Frontmatter>;
65
+ type AsyncDocCollectionEntry<Frontmatter> = Override<DocMethods & {
66
+ load: () => Promise<DocData>;
67
+ }, Frontmatter>;
68
+ type Override<A, B> = Omit<A, keyof B> & B;
69
+
70
+ export type { AsyncDocCollectionEntry as A, DocCollectionEntry as D, FileInfo as F, MetaCollectionEntry as M };
@@ -1,8 +1,8 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
3
- import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-BH4bnHQl.js';
3
+ import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define--6HQ1ehX.js';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
5
- import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.js';
5
+ import { F as FileInfo, A as AsyncDocCollectionEntry, M as MetaCollectionEntry, D as DocCollectionEntry } from './shared-0QIuV0XZ.js';
6
6
 
7
7
  interface LoadedConfig {
8
8
  collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
@@ -10,44 +10,20 @@ interface LoadedConfig {
10
10
  getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
11
11
  }
12
12
 
13
- interface BaseCollectionEntry {
14
- /**
15
- * Raw file path of collection entry, including absolute path (not normalized).
16
- */
17
- _file: FileInfo;
18
- }
19
- interface FileInfo {
20
- path: string;
21
- absolutePath: string;
22
- }
23
- interface MarkdownProps extends Omit<CompiledMDXProperties, 'frontmatter' | 'default'> {
24
- body: CompiledMDXProperties['default'];
25
- }
26
13
  interface RuntimeFile {
27
14
  info: FileInfo;
28
15
  data: Record<string, unknown>;
29
16
  }
30
17
  interface AsyncRuntimeFile {
31
- info: FileInfo;
32
- data: Record<string, unknown>;
33
- content: {
34
- matter: string;
35
- body: string;
18
+ info: FileInfo & {
19
+ hash?: string;
20
+ absolutePath?: string;
36
21
  };
22
+ data: Record<string, unknown>;
37
23
  lastModified?: Date;
38
24
  }
39
- type DocOut<Schema extends StandardSchemaV1> = Override<MarkdownProps & {
40
- /**
41
- * Other exports in the compiled Markdown/MDX file
42
- */
43
- _exports: Record<string, unknown>;
44
- /**
45
- * Read the original content of file from file system.
46
- */
47
- get content(): string;
48
- }, StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry>;
49
- type Override<A, B> = Omit<A, keyof B> & B;
50
- type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
25
+ type DocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = DocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
26
+ type MetaOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = MetaCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
51
27
  interface Runtime {
52
28
  doc: <C>(files: RuntimeFile[]) => C extends DocCollection<infer Schema, false> ? DocOut<Schema>[] : never;
53
29
  meta: <C>(files: RuntimeFile[]) => C extends MetaCollection<infer Schema> ? MetaOut<Schema>[] : never;
@@ -60,10 +36,7 @@ interface Runtime {
60
36
  }>;
61
37
  } : never;
62
38
  }
63
- type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
64
- content: string;
65
- load: () => Promise<MarkdownProps & Record<string, unknown>>;
66
- };
39
+ type AsyncDocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = AsyncDocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
67
40
  interface RuntimeAsync {
68
41
  doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends DocCollection<infer Schema, true> ? AsyncDocOut<Schema>[] : never;
69
42
  docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends DocsCollection<infer DocSchema, infer MetaSchema, true> ? {
@@ -76,4 +49,4 @@ interface RuntimeAsync {
76
49
  } : never;
77
50
  }
78
51
 
79
- export type { BaseCollectionEntry as B, LoadedConfig as L, Runtime as R, RuntimeAsync as a };
52
+ export type { AsyncRuntimeFile as A, DocOut as D, LoadedConfig as L, MetaOut as M, Runtime as R, RuntimeFile as a, AsyncDocOut as b, RuntimeAsync as c };
@@ -1,8 +1,8 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
3
- import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-BH4bnHQl.cjs';
3
+ import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define--6HQ1ehX.cjs';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
5
- import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.cjs';
5
+ import { F as FileInfo, A as AsyncDocCollectionEntry, M as MetaCollectionEntry, D as DocCollectionEntry } from './shared-CqgMnt9h.cjs';
6
6
 
7
7
  interface LoadedConfig {
8
8
  collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
@@ -10,44 +10,20 @@ interface LoadedConfig {
10
10
  getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
11
11
  }
12
12
 
13
- interface BaseCollectionEntry {
14
- /**
15
- * Raw file path of collection entry, including absolute path (not normalized).
16
- */
17
- _file: FileInfo;
18
- }
19
- interface FileInfo {
20
- path: string;
21
- absolutePath: string;
22
- }
23
- interface MarkdownProps extends Omit<CompiledMDXProperties, 'frontmatter' | 'default'> {
24
- body: CompiledMDXProperties['default'];
25
- }
26
13
  interface RuntimeFile {
27
14
  info: FileInfo;
28
15
  data: Record<string, unknown>;
29
16
  }
30
17
  interface AsyncRuntimeFile {
31
- info: FileInfo;
32
- data: Record<string, unknown>;
33
- content: {
34
- matter: string;
35
- body: string;
18
+ info: FileInfo & {
19
+ hash?: string;
20
+ absolutePath?: string;
36
21
  };
22
+ data: Record<string, unknown>;
37
23
  lastModified?: Date;
38
24
  }
39
- type DocOut<Schema extends StandardSchemaV1> = Override<MarkdownProps & {
40
- /**
41
- * Other exports in the compiled Markdown/MDX file
42
- */
43
- _exports: Record<string, unknown>;
44
- /**
45
- * Read the original content of file from file system.
46
- */
47
- get content(): string;
48
- }, StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry>;
49
- type Override<A, B> = Omit<A, keyof B> & B;
50
- type MetaOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
25
+ type DocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = DocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
26
+ type MetaOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = MetaCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
51
27
  interface Runtime {
52
28
  doc: <C>(files: RuntimeFile[]) => C extends DocCollection<infer Schema, false> ? DocOut<Schema>[] : never;
53
29
  meta: <C>(files: RuntimeFile[]) => C extends MetaCollection<infer Schema> ? MetaOut<Schema>[] : never;
@@ -60,10 +36,7 @@ interface Runtime {
60
36
  }>;
61
37
  } : never;
62
38
  }
63
- type AsyncDocOut<Schema extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry & {
64
- content: string;
65
- load: () => Promise<MarkdownProps & Record<string, unknown>>;
66
- };
39
+ type AsyncDocOut<Schema extends StandardSchemaV1 = StandardSchemaV1> = AsyncDocCollectionEntry<StandardSchemaV1.InferOutput<Schema>>;
67
40
  interface RuntimeAsync {
68
41
  doc: <C>(files: AsyncRuntimeFile[], collection: string, config: LoadedConfig) => C extends DocCollection<infer Schema, true> ? AsyncDocOut<Schema>[] : never;
69
42
  docs: <C>(docs: AsyncRuntimeFile[], metas: RuntimeFile[], collection: string, config: LoadedConfig) => C extends DocsCollection<infer DocSchema, infer MetaSchema, true> ? {
@@ -76,4 +49,4 @@ interface RuntimeAsync {
76
49
  } : never;
77
50
  }
78
51
 
79
- export type { BaseCollectionEntry as B, LoadedConfig as L, Runtime as R, RuntimeAsync as a };
52
+ export type { AsyncRuntimeFile as A, DocOut as D, LoadedConfig as L, MetaOut as M, Runtime as R, RuntimeFile as a, AsyncDocOut as b, RuntimeAsync as c };