fumadocs-mdx 13.0.8 → 14.0.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 (104) hide show
  1. package/dist/bin.cjs +924 -901
  2. package/dist/bin.js +3 -3
  3. package/dist/build-mdx-6UAK5FF5.js +8 -0
  4. package/dist/bun/index.cjs +578 -471
  5. package/dist/bun/index.d.cts +3 -2
  6. package/dist/bun/index.d.ts +3 -2
  7. package/dist/bun/index.js +12 -12
  8. package/dist/chunk-4JSFLXXT.js +8 -0
  9. package/dist/chunk-5UMZCWKV.js +17 -0
  10. package/dist/chunk-5YXP7JLN.js +138 -0
  11. package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
  12. package/dist/chunk-7L2KNF6B.js +180 -0
  13. package/dist/chunk-E5DJTSIM.js +86 -0
  14. package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
  15. package/dist/{chunk-QXHN25N3.js → chunk-OXSRIWQW.js} +7 -8
  16. package/dist/chunk-PKI7ZDA5.js +29 -0
  17. package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
  18. package/dist/{chunk-5FTSWCB4.js → chunk-SRSRFOVI.js} +8 -10
  19. package/dist/chunk-TYJDYTKH.js +85 -0
  20. package/dist/chunk-XHJCLBZ4.js +406 -0
  21. package/dist/{chunk-2HXTGJBI.js → chunk-ZY6UZ7NH.js} +22 -19
  22. package/dist/config/index.cjs +79 -71
  23. package/dist/config/index.d.cts +2 -1
  24. package/dist/config/index.d.ts +2 -1
  25. package/dist/config/index.js +5 -5
  26. package/dist/index-BlVBvy-z.d.ts +8 -0
  27. package/dist/{core-DB7TdlyC.d.cts → index-D7JdSMpp.d.cts} +99 -61
  28. package/dist/{core-DB7TdlyC.d.ts → index-D7JdSMpp.d.ts} +99 -61
  29. package/dist/index-P2NNUkHn.d.cts +8 -0
  30. package/dist/index.d.cts +3 -74
  31. package/dist/index.d.ts +3 -74
  32. package/dist/load-from-file-I3ALLIVB.js +8 -0
  33. package/dist/next/index.cjs +698 -476
  34. package/dist/next/index.d.cts +11 -1
  35. package/dist/next/index.d.ts +11 -1
  36. package/dist/next/index.js +78 -281
  37. package/dist/node/loader.cjs +704 -602
  38. package/dist/node/loader.js +10 -11
  39. package/dist/plugins/index-file.cjs +471 -0
  40. package/dist/plugins/index-file.d.cts +29 -0
  41. package/dist/plugins/index-file.d.ts +29 -0
  42. package/dist/plugins/index-file.js +8 -0
  43. package/dist/plugins/json-schema.d.cts +3 -2
  44. package/dist/plugins/json-schema.d.ts +3 -2
  45. package/dist/plugins/last-modified.cjs +75 -0
  46. package/dist/plugins/last-modified.d.cts +27 -0
  47. package/dist/plugins/last-modified.d.ts +27 -0
  48. package/dist/plugins/last-modified.js +44 -0
  49. package/dist/runtime/{vite/browser.cjs → browser.cjs} +40 -53
  50. package/dist/runtime/browser.d.cts +50 -0
  51. package/dist/runtime/browser.d.ts +50 -0
  52. package/dist/runtime/browser.js +68 -0
  53. package/dist/runtime/dynamic.cjs +985 -0
  54. package/dist/runtime/dynamic.d.cts +27 -0
  55. package/dist/runtime/dynamic.d.ts +27 -0
  56. package/dist/runtime/dynamic.js +78 -0
  57. package/dist/runtime/server.cjs +173 -0
  58. package/dist/runtime/server.d.cts +161 -0
  59. package/dist/runtime/server.d.ts +161 -0
  60. package/dist/runtime/server.js +8 -0
  61. package/dist/vite/index.cjs +934 -638
  62. package/dist/vite/index.d.cts +12 -22
  63. package/dist/vite/index.d.ts +12 -22
  64. package/dist/vite/index.js +30 -221
  65. package/dist/webpack/mdx.cjs +613 -515
  66. package/dist/webpack/mdx.d.cts +9 -1
  67. package/dist/webpack/mdx.d.ts +9 -1
  68. package/dist/webpack/mdx.js +12 -17
  69. package/dist/webpack/meta.cjs +327 -233
  70. package/dist/webpack/meta.d.cts +9 -1
  71. package/dist/webpack/meta.d.ts +9 -1
  72. package/dist/webpack/meta.js +13 -15
  73. package/package.json +15 -32
  74. package/dist/build-mdx-BjXOmv0b.d.cts +0 -53
  75. package/dist/build-mdx-CY5UldCO.d.ts +0 -53
  76. package/dist/chunk-2AQRQXSO.js +0 -119
  77. package/dist/chunk-CXA4JO4Z.js +0 -45
  78. package/dist/chunk-DMJ6I4C3.js +0 -76
  79. package/dist/chunk-FSZMKRVH.js +0 -80
  80. package/dist/chunk-II3H5ZVZ.js +0 -77
  81. package/dist/chunk-KILFIBVW.js +0 -75
  82. package/dist/chunk-NVRDCY6Z.js +0 -30
  83. package/dist/chunk-VUEZTR2H.js +0 -26
  84. package/dist/index-D7s7kCc2.d.cts +0 -7
  85. package/dist/index-D7s7kCc2.d.ts +0 -7
  86. package/dist/load-from-file-AVYOFOI7.js +0 -7
  87. package/dist/preset-ZMP6U62C.js +0 -6
  88. package/dist/runtime/next/async.cjs +0 -760
  89. package/dist/runtime/next/async.d.cts +0 -19
  90. package/dist/runtime/next/async.d.ts +0 -19
  91. package/dist/runtime/next/async.js +0 -86
  92. package/dist/runtime/next/index.cjs +0 -136
  93. package/dist/runtime/next/index.d.cts +0 -33
  94. package/dist/runtime/next/index.d.ts +0 -33
  95. package/dist/runtime/next/index.js +0 -11
  96. package/dist/runtime/vite/browser.d.cts +0 -59
  97. package/dist/runtime/vite/browser.d.ts +0 -59
  98. package/dist/runtime/vite/browser.js +0 -11
  99. package/dist/runtime/vite/server.cjs +0 -243
  100. package/dist/runtime/vite/server.d.cts +0 -30
  101. package/dist/runtime/vite/server.d.ts +0 -30
  102. package/dist/runtime/vite/server.js +0 -111
  103. package/dist/types-Bnh9n7mj.d.cts +0 -45
  104. package/dist/types-ey1AZqrg.d.ts +0 -45
@@ -1,4 +1,4 @@
1
- export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, D as DefaultMDXOptions, b as DocCollection, c as DocsCollection, G as GlobalConfig, M as MetaCollection, P as PostprocessOptions, d as defineCollections, f as defineConfig, e as defineDocs, h as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../core-DB7TdlyC.js';
1
+ export { A as AnyCollection, B as BaseCollection, a as CollectionSchema, f as DefaultMDXOptions, D as DocCollection, b as DocsCollection, G as GlobalConfig, g as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, h as applyMdxPreset, d as defineCollections, e as defineConfig, c as defineDocs, i as frontmatterSchema, m as metaSchema } from '../index-D7JdSMpp.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -6,6 +6,7 @@ import '@standard-schema/spec';
6
6
  import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
+ import 'vfile';
9
10
 
10
11
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
11
12
 
@@ -1,9 +1,9 @@
1
- import {
2
- getDefaultMDXOptions
3
- } from "../chunk-FSZMKRVH.js";
4
1
  import {
5
2
  remarkInclude
6
- } from "../chunk-K5ZLPEIQ.js";
3
+ } from "../chunk-FBLMK4RS.js";
4
+ import {
5
+ applyMdxPreset
6
+ } from "../chunk-E5DJTSIM.js";
7
7
  import "../chunk-VWJKRQZR.js";
8
8
 
9
9
  // src/config/zod-4.ts
@@ -52,11 +52,11 @@ function defineConfig(config = {}) {
52
52
  return config;
53
53
  }
54
54
  export {
55
+ applyMdxPreset,
55
56
  defineCollections,
56
57
  defineConfig,
57
58
  defineDocs,
58
59
  frontmatterSchema,
59
- getDefaultMDXOptions,
60
60
  metaSchema,
61
61
  remarkInclude
62
62
  };
@@ -0,0 +1,8 @@
1
+ import { C as CoreOptions } from './index-D7JdSMpp.js';
2
+
3
+ interface WebpackLoaderOptions extends CoreOptions {
4
+ compiledConfigPath: string;
5
+ isDev: boolean;
6
+ }
7
+
8
+ export type { WebpackLoaderOptions as W };
@@ -1,30 +1,10 @@
1
1
  import { ProcessorOptions } from '@mdx-js/mdx';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import * as plugins from 'fumadocs-core/mdx-plugins';
4
3
  import { Pluggable } from 'unified';
4
+ import * as Plugins from 'fumadocs-core/mdx-plugins';
5
5
  import { z } from 'zod';
6
6
  import { FSWatcher } from 'chokidar';
7
-
8
- interface ExtractedReference {
9
- href: string;
10
- }
11
- interface PostprocessOptions {
12
- _format: 'md' | 'mdx';
13
- /**
14
- * Properties to export from `vfile.data`
15
- */
16
- valueToExport?: string[];
17
- /**
18
- * stringify MDAST and export via `_markdown`.
19
- */
20
- includeProcessedMarkdown?: boolean;
21
- /**
22
- * store MDAST and export via `_mdast`.
23
- */
24
- includeMDAST?: boolean | {
25
- removePosition?: boolean;
26
- };
27
- }
7
+ import { VFile } from 'vfile';
28
8
 
29
9
  type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
30
10
  type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
@@ -34,15 +14,22 @@ type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | '
34
14
  * Properties to export from `vfile.data`
35
15
  */
36
16
  valueToExport?: string[];
37
- remarkStructureOptions?: plugins.StructureOptions | false;
38
- remarkHeadingOptions?: plugins.RemarkHeadingOptions;
39
- remarkImageOptions?: plugins.RemarkImageOptions | false;
40
- remarkCodeTabOptions?: plugins.RemarkCodeTabOptions | false;
41
- remarkNpmOptions?: plugins.RemarkNpmOptions | false;
42
- rehypeCodeOptions?: plugins.RehypeCodeOptions | false;
43
- _withoutBundler?: boolean;
17
+ remarkStructureOptions?: Plugins.StructureOptions | false;
18
+ remarkHeadingOptions?: Plugins.RemarkHeadingOptions;
19
+ remarkImageOptions?: Plugins.RemarkImageOptions | false;
20
+ remarkCodeTabOptions?: Plugins.RemarkCodeTabOptions | false;
21
+ remarkNpmOptions?: Plugins.RemarkNpmOptions | false;
22
+ rehypeCodeOptions?: Plugins.RehypeCodeOptions | false;
44
23
  };
45
- declare function getDefaultMDXOptions({ valueToExport, rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, remarkCodeTabOptions, remarkNpmOptions, _withoutBundler, ...mdxOptions }: DefaultMDXOptions): ProcessorOptions;
24
+ type MDXPresetOptions = ({
25
+ preset?: 'fumadocs';
26
+ } & DefaultMDXOptions) | ({
27
+ preset: 'minimal';
28
+ } & ProcessorOptions);
29
+ /**
30
+ * apply MDX processor presets
31
+ */
32
+ declare function applyMdxPreset(options?: MDXPresetOptions): (environment: BuildEnvironment) => Promise<ProcessorOptions>;
46
33
 
47
34
  /**
48
35
  * Zod 4 schema
@@ -66,13 +53,38 @@ declare const frontmatterSchema: z.ZodObject<{
66
53
  _openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
67
54
  }, z.core.$strip>;
68
55
 
56
+ interface ExtractedReference {
57
+ href: string;
58
+ }
59
+ interface PostprocessOptions {
60
+ _format: 'md' | 'mdx';
61
+ /**
62
+ * Properties to export from `vfile.data`
63
+ */
64
+ valueToExport?: string[];
65
+ /**
66
+ * stringify MDAST and export via `_markdown`.
67
+ */
68
+ includeProcessedMarkdown?: boolean;
69
+ /**
70
+ * extract link references, export via `extractedReferences`.
71
+ */
72
+ extractLinkReferences?: boolean;
73
+ /**
74
+ * store MDAST and export via `_mdast`.
75
+ */
76
+ includeMDAST?: boolean | {
77
+ removePosition?: boolean;
78
+ };
79
+ }
80
+
69
81
  type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
70
82
  type AnyCollection = DocsCollection | DocCollection | MetaCollection;
71
83
  interface BaseCollection {
72
84
  /**
73
- * Directories to scan
85
+ * Directory to scan
74
86
  */
75
- dir: string | string[];
87
+ dir: string;
76
88
  /**
77
89
  * what files to include/exclude (glob patterns)
78
90
  *
@@ -87,44 +99,37 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
87
99
  source: string;
88
100
  }>;
89
101
  }
90
- interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
102
+ interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> extends BaseCollection {
91
103
  type: 'doc';
92
104
  postprocess?: Partial<PostprocessOptions>;
93
- mdxOptions?: ProcessorOptions;
105
+ mdxOptions?: ProcessorOptions | ((environment: BuildEnvironment) => Promise<ProcessorOptions>);
94
106
  /**
95
107
  * Load files with async
96
108
  */
97
- async?: Async;
109
+ async?: boolean;
110
+ /**
111
+ * Compile files on-demand
112
+ */
113
+ dynamic?: boolean;
98
114
  schema?: CollectionSchema<Schema, {
99
115
  path: string;
100
116
  source: string;
101
117
  }>;
102
118
  }
103
- interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1, MetaSchema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> {
119
+ interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1, MetaSchema extends StandardSchemaV1 = StandardSchemaV1> {
104
120
  type: 'docs';
105
121
  dir: string;
106
- docs: DocCollection<DocSchema, Async>;
122
+ docs: DocCollection<DocSchema>;
107
123
  meta: MetaCollection<MetaSchema>;
108
124
  }
109
- type GlobalConfigMDXOptions = ({
110
- preset?: 'fumadocs';
111
- } & DefaultMDXOptions) | ({
112
- preset: 'minimal';
113
- } & ProcessorOptions);
114
125
  interface GlobalConfig {
115
- collections?: Record<string, AnyCollection>;
116
126
  plugins?: PluginOption[];
117
127
  /**
118
128
  * Configure global MDX options
119
129
  *
120
- * @remarks `GlobalConfigMDXOptions`
121
- */
122
- mdxOptions?: GlobalConfigMDXOptions | (() => Promise<GlobalConfigMDXOptions>);
123
- /**
124
- * Fetch last modified time with specified version control
125
- * @defaultValue 'none'
130
+ * @remarks `MDXPresetOptions`
126
131
  */
127
- lastModifiedTime?: 'git' | 'none';
132
+ mdxOptions?: MDXPresetOptions | (() => Promise<MDXPresetOptions>);
128
133
  /**
129
134
  * specify a directory to access & store cache (disabled during development mode).
130
135
  *
@@ -132,25 +137,26 @@ interface GlobalConfig {
132
137
  */
133
138
  experimentalBuildCache?: string;
134
139
  }
135
- declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: DocCollection<Schema, Async>): DocCollection<Schema, Async>;
140
+ declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: DocCollection<Schema>): DocCollection<Schema>;
136
141
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: MetaCollection<Schema>): MetaCollection<Schema>;
137
- declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema, Async extends boolean = false>(options: {
142
+ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema>(options: {
138
143
  /**
139
144
  * The content directory to scan files
140
145
  *
141
146
  * @defaultValue 'content/docs'
142
147
  */
143
148
  dir?: string;
144
- docs?: Omit<DocCollection<DocSchema, Async>, 'dir' | 'type'>;
149
+ docs?: Omit<DocCollection<DocSchema>, 'dir' | 'type'>;
145
150
  meta?: Omit<MetaCollection<MetaSchema>, 'dir' | 'type'>;
146
- }): DocsCollection<DocSchema, MetaSchema, Async>;
151
+ }): DocsCollection<DocSchema, MetaSchema>;
147
152
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
148
153
 
154
+ type BuildEnvironment = 'bundler' | 'runtime';
149
155
  interface LoadedConfig {
150
156
  collectionList: CollectionItem[];
151
157
  getCollection(name: string): CollectionItem | undefined;
152
158
  global: GlobalConfig;
153
- getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
159
+ getMDXOptions(collection?: DocCollectionItem, environment?: BuildEnvironment): ProcessorOptions | Promise<ProcessorOptions>;
154
160
  }
155
161
  type CollectionItem = MetaCollectionItem | DocCollectionItem | DocsCollectionItem;
156
162
  type PrimitiveCollectionItem<T extends DocCollection | MetaCollection> = Omit<T, 'files'> & {
@@ -165,8 +171,8 @@ interface DocsCollectionItem extends DocsCollection {
165
171
  name: string;
166
172
  meta: MetaCollectionItem;
167
173
  docs: DocCollectionItem;
174
+ hasFile: (filePath: string) => boolean;
168
175
  }
169
- declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
170
176
 
171
177
  type Awaitable<T> = T | Promise<T>;
172
178
  interface EmitEntry {
@@ -179,6 +185,12 @@ interface EmitEntry {
179
185
  interface PluginContext extends CoreOptions {
180
186
  core: Core;
181
187
  }
188
+ type CompilationContext<Collection> = PluginContext & TransformOptions<Collection>;
189
+ interface TransformOptions<Collection> {
190
+ collection: Collection;
191
+ filePath: string;
192
+ source: string;
193
+ }
182
194
  interface Plugin {
183
195
  name?: string;
184
196
  /**
@@ -193,8 +205,24 @@ interface Plugin {
193
205
  * Configure Fumadocs dev server
194
206
  */
195
207
  configureServer?: (this: PluginContext, server: ServerContext) => Awaitable<void>;
208
+ meta?: {
209
+ /**
210
+ * Transform metadata
211
+ */
212
+ transform?: (this: CompilationContext<MetaCollectionItem>, data: unknown) => Awaitable<unknown | void>;
213
+ };
214
+ doc?: {
215
+ /**
216
+ * Transform frontmatter
217
+ */
218
+ frontmatter?: (this: CompilationContext<DocCollectionItem>, data: Record<string, unknown>) => Awaitable<Record<string, unknown> | void>;
219
+ /**
220
+ * Transform `vfile` on compilation stage
221
+ */
222
+ vfile?: (this: CompilationContext<DocCollectionItem>, file: VFile) => Awaitable<VFile | void>;
223
+ };
196
224
  }
197
- type PluginOption = Awaitable<Plugin | Plugin[] | false>;
225
+ type PluginOption = Awaitable<Plugin | PluginOption[] | false>;
198
226
  interface ServerContext {
199
227
  /**
200
228
  * the file watcher, by default all content files are watched, along with other files.
@@ -214,10 +242,12 @@ interface EmitOptions {
214
242
  */
215
243
  filterPlugin?: (plugin: Plugin) => boolean;
216
244
  }
217
- declare function findConfigFile(): string;
245
+ declare const _Defaults: {
246
+ configPath: string;
247
+ outDir: string;
248
+ };
218
249
  declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[]): {
219
250
  _options: CoreOptions;
220
- getPluginContext(): PluginContext;
221
251
  /**
222
252
  * Convenient cache store, reset when config changes
223
253
  */
@@ -226,9 +256,17 @@ declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[
226
256
  config: Awaitable<LoadedConfig>;
227
257
  }): Promise</*elided*/ any>;
228
258
  getConfig(): LoadedConfig;
259
+ /**
260
+ * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
261
+ */
262
+ getCompiledConfigPath(): string;
229
263
  initServer(server: ServerContext): Promise<void>;
230
- emitAndWrite({ filterPlugin, }?: EmitOptions): Promise<void>;
264
+ emit({ filterPlugin }?: EmitOptions): Promise<EmitEntry[]>;
265
+ emitAndWrite(emitOptions?: EmitOptions): Promise<void>;
266
+ transformMeta(options: TransformOptions<MetaCollectionItem>, data: unknown): Promise<unknown>;
267
+ transformFrontmatter(options: TransformOptions<DocCollectionItem>, data: Record<string, unknown>): Promise<Record<string, unknown>>;
268
+ transformVFile(options: TransformOptions<DocCollectionItem>, file: VFile): Promise<VFile>;
231
269
  };
232
270
  type Core = ReturnType<typeof createCore>;
233
271
 
234
- export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DefaultMDXOptions as D, type ExtractedReference as E, type GlobalConfig as G, type LoadedConfig as L, type MetaCollection as M, type PostprocessOptions as P, type ServerContext as S, type CollectionSchema as a, type DocCollection as b, type DocsCollection as c, defineCollections as d, defineDocs as e, defineConfig as f, getDefaultMDXOptions as g, frontmatterSchema as h, type Plugin as i, buildConfig as j, type EmitEntry as k, type PluginContext as l, metaSchema as m, type PluginOption as n, type EmitOptions as o, findConfigFile as p, createCore as q, type Core as r };
272
+ export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DocCollection as D, type ExtractedReference as E, type GlobalConfig as G, type MetaCollection as M, type PostprocessOptions as P, type ServerContext as S, type TransformOptions as T, _Defaults as _, type CollectionSchema as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, type DefaultMDXOptions as f, type MDXPresetOptions as g, applyMdxPreset as h, frontmatterSchema as i, type Plugin as j, type EmitEntry as k, type PluginContext as l, metaSchema as m, type CompilationContext as n, type PluginOption as o, type EmitOptions as p, createCore as q, type Core as r };
@@ -1,30 +1,10 @@
1
1
  import { ProcessorOptions } from '@mdx-js/mdx';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
- import * as plugins from 'fumadocs-core/mdx-plugins';
4
3
  import { Pluggable } from 'unified';
4
+ import * as Plugins from 'fumadocs-core/mdx-plugins';
5
5
  import { z } from 'zod';
6
6
  import { FSWatcher } from 'chokidar';
7
-
8
- interface ExtractedReference {
9
- href: string;
10
- }
11
- interface PostprocessOptions {
12
- _format: 'md' | 'mdx';
13
- /**
14
- * Properties to export from `vfile.data`
15
- */
16
- valueToExport?: string[];
17
- /**
18
- * stringify MDAST and export via `_markdown`.
19
- */
20
- includeProcessedMarkdown?: boolean;
21
- /**
22
- * store MDAST and export via `_mdast`.
23
- */
24
- includeMDAST?: boolean | {
25
- removePosition?: boolean;
26
- };
27
- }
7
+ import { VFile } from 'vfile';
28
8
 
29
9
  type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
30
10
  type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
@@ -34,15 +14,22 @@ type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | '
34
14
  * Properties to export from `vfile.data`
35
15
  */
36
16
  valueToExport?: string[];
37
- remarkStructureOptions?: plugins.StructureOptions | false;
38
- remarkHeadingOptions?: plugins.RemarkHeadingOptions;
39
- remarkImageOptions?: plugins.RemarkImageOptions | false;
40
- remarkCodeTabOptions?: plugins.RemarkCodeTabOptions | false;
41
- remarkNpmOptions?: plugins.RemarkNpmOptions | false;
42
- rehypeCodeOptions?: plugins.RehypeCodeOptions | false;
43
- _withoutBundler?: boolean;
17
+ remarkStructureOptions?: Plugins.StructureOptions | false;
18
+ remarkHeadingOptions?: Plugins.RemarkHeadingOptions;
19
+ remarkImageOptions?: Plugins.RemarkImageOptions | false;
20
+ remarkCodeTabOptions?: Plugins.RemarkCodeTabOptions | false;
21
+ remarkNpmOptions?: Plugins.RemarkNpmOptions | false;
22
+ rehypeCodeOptions?: Plugins.RehypeCodeOptions | false;
44
23
  };
45
- declare function getDefaultMDXOptions({ valueToExport, rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, remarkCodeTabOptions, remarkNpmOptions, _withoutBundler, ...mdxOptions }: DefaultMDXOptions): ProcessorOptions;
24
+ type MDXPresetOptions = ({
25
+ preset?: 'fumadocs';
26
+ } & DefaultMDXOptions) | ({
27
+ preset: 'minimal';
28
+ } & ProcessorOptions);
29
+ /**
30
+ * apply MDX processor presets
31
+ */
32
+ declare function applyMdxPreset(options?: MDXPresetOptions): (environment: BuildEnvironment) => Promise<ProcessorOptions>;
46
33
 
47
34
  /**
48
35
  * Zod 4 schema
@@ -66,13 +53,38 @@ declare const frontmatterSchema: z.ZodObject<{
66
53
  _openapi: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
67
54
  }, z.core.$strip>;
68
55
 
56
+ interface ExtractedReference {
57
+ href: string;
58
+ }
59
+ interface PostprocessOptions {
60
+ _format: 'md' | 'mdx';
61
+ /**
62
+ * Properties to export from `vfile.data`
63
+ */
64
+ valueToExport?: string[];
65
+ /**
66
+ * stringify MDAST and export via `_markdown`.
67
+ */
68
+ includeProcessedMarkdown?: boolean;
69
+ /**
70
+ * extract link references, export via `extractedReferences`.
71
+ */
72
+ extractLinkReferences?: boolean;
73
+ /**
74
+ * store MDAST and export via `_mdast`.
75
+ */
76
+ includeMDAST?: boolean | {
77
+ removePosition?: boolean;
78
+ };
79
+ }
80
+
69
81
  type CollectionSchema<Schema extends StandardSchemaV1, Context> = Schema | ((ctx: Context) => Schema);
70
82
  type AnyCollection = DocsCollection | DocCollection | MetaCollection;
71
83
  interface BaseCollection {
72
84
  /**
73
- * Directories to scan
85
+ * Directory to scan
74
86
  */
75
- dir: string | string[];
87
+ dir: string;
76
88
  /**
77
89
  * what files to include/exclude (glob patterns)
78
90
  *
@@ -87,44 +99,37 @@ interface MetaCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> ext
87
99
  source: string;
88
100
  }>;
89
101
  }
90
- interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> extends BaseCollection {
102
+ interface DocCollection<Schema extends StandardSchemaV1 = StandardSchemaV1> extends BaseCollection {
91
103
  type: 'doc';
92
104
  postprocess?: Partial<PostprocessOptions>;
93
- mdxOptions?: ProcessorOptions;
105
+ mdxOptions?: ProcessorOptions | ((environment: BuildEnvironment) => Promise<ProcessorOptions>);
94
106
  /**
95
107
  * Load files with async
96
108
  */
97
- async?: Async;
109
+ async?: boolean;
110
+ /**
111
+ * Compile files on-demand
112
+ */
113
+ dynamic?: boolean;
98
114
  schema?: CollectionSchema<Schema, {
99
115
  path: string;
100
116
  source: string;
101
117
  }>;
102
118
  }
103
- interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1, MetaSchema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = boolean> {
119
+ interface DocsCollection<DocSchema extends StandardSchemaV1 = StandardSchemaV1, MetaSchema extends StandardSchemaV1 = StandardSchemaV1> {
104
120
  type: 'docs';
105
121
  dir: string;
106
- docs: DocCollection<DocSchema, Async>;
122
+ docs: DocCollection<DocSchema>;
107
123
  meta: MetaCollection<MetaSchema>;
108
124
  }
109
- type GlobalConfigMDXOptions = ({
110
- preset?: 'fumadocs';
111
- } & DefaultMDXOptions) | ({
112
- preset: 'minimal';
113
- } & ProcessorOptions);
114
125
  interface GlobalConfig {
115
- collections?: Record<string, AnyCollection>;
116
126
  plugins?: PluginOption[];
117
127
  /**
118
128
  * Configure global MDX options
119
129
  *
120
- * @remarks `GlobalConfigMDXOptions`
121
- */
122
- mdxOptions?: GlobalConfigMDXOptions | (() => Promise<GlobalConfigMDXOptions>);
123
- /**
124
- * Fetch last modified time with specified version control
125
- * @defaultValue 'none'
130
+ * @remarks `MDXPresetOptions`
126
131
  */
127
- lastModifiedTime?: 'git' | 'none';
132
+ mdxOptions?: MDXPresetOptions | (() => Promise<MDXPresetOptions>);
128
133
  /**
129
134
  * specify a directory to access & store cache (disabled during development mode).
130
135
  *
@@ -132,25 +137,26 @@ interface GlobalConfig {
132
137
  */
133
138
  experimentalBuildCache?: string;
134
139
  }
135
- declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1, Async extends boolean = false>(options: DocCollection<Schema, Async>): DocCollection<Schema, Async>;
140
+ declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: DocCollection<Schema>): DocCollection<Schema>;
136
141
  declare function defineCollections<Schema extends StandardSchemaV1 = StandardSchemaV1>(options: MetaCollection<Schema>): MetaCollection<Schema>;
137
- declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema, Async extends boolean = false>(options: {
142
+ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmatterSchema, MetaSchema extends StandardSchemaV1 = typeof metaSchema>(options: {
138
143
  /**
139
144
  * The content directory to scan files
140
145
  *
141
146
  * @defaultValue 'content/docs'
142
147
  */
143
148
  dir?: string;
144
- docs?: Omit<DocCollection<DocSchema, Async>, 'dir' | 'type'>;
149
+ docs?: Omit<DocCollection<DocSchema>, 'dir' | 'type'>;
145
150
  meta?: Omit<MetaCollection<MetaSchema>, 'dir' | 'type'>;
146
- }): DocsCollection<DocSchema, MetaSchema, Async>;
151
+ }): DocsCollection<DocSchema, MetaSchema>;
147
152
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
148
153
 
154
+ type BuildEnvironment = 'bundler' | 'runtime';
149
155
  interface LoadedConfig {
150
156
  collectionList: CollectionItem[];
151
157
  getCollection(name: string): CollectionItem | undefined;
152
158
  global: GlobalConfig;
153
- getDefaultMDXOptions(mode?: 'default' | 'remote'): Promise<ProcessorOptions>;
159
+ getMDXOptions(collection?: DocCollectionItem, environment?: BuildEnvironment): ProcessorOptions | Promise<ProcessorOptions>;
154
160
  }
155
161
  type CollectionItem = MetaCollectionItem | DocCollectionItem | DocsCollectionItem;
156
162
  type PrimitiveCollectionItem<T extends DocCollection | MetaCollection> = Omit<T, 'files'> & {
@@ -165,8 +171,8 @@ interface DocsCollectionItem extends DocsCollection {
165
171
  name: string;
166
172
  meta: MetaCollectionItem;
167
173
  docs: DocCollectionItem;
174
+ hasFile: (filePath: string) => boolean;
168
175
  }
169
- declare function buildConfig(config: Record<string, unknown>): LoadedConfig;
170
176
 
171
177
  type Awaitable<T> = T | Promise<T>;
172
178
  interface EmitEntry {
@@ -179,6 +185,12 @@ interface EmitEntry {
179
185
  interface PluginContext extends CoreOptions {
180
186
  core: Core;
181
187
  }
188
+ type CompilationContext<Collection> = PluginContext & TransformOptions<Collection>;
189
+ interface TransformOptions<Collection> {
190
+ collection: Collection;
191
+ filePath: string;
192
+ source: string;
193
+ }
182
194
  interface Plugin {
183
195
  name?: string;
184
196
  /**
@@ -193,8 +205,24 @@ interface Plugin {
193
205
  * Configure Fumadocs dev server
194
206
  */
195
207
  configureServer?: (this: PluginContext, server: ServerContext) => Awaitable<void>;
208
+ meta?: {
209
+ /**
210
+ * Transform metadata
211
+ */
212
+ transform?: (this: CompilationContext<MetaCollectionItem>, data: unknown) => Awaitable<unknown | void>;
213
+ };
214
+ doc?: {
215
+ /**
216
+ * Transform frontmatter
217
+ */
218
+ frontmatter?: (this: CompilationContext<DocCollectionItem>, data: Record<string, unknown>) => Awaitable<Record<string, unknown> | void>;
219
+ /**
220
+ * Transform `vfile` on compilation stage
221
+ */
222
+ vfile?: (this: CompilationContext<DocCollectionItem>, file: VFile) => Awaitable<VFile | void>;
223
+ };
196
224
  }
197
- type PluginOption = Awaitable<Plugin | Plugin[] | false>;
225
+ type PluginOption = Awaitable<Plugin | PluginOption[] | false>;
198
226
  interface ServerContext {
199
227
  /**
200
228
  * the file watcher, by default all content files are watched, along with other files.
@@ -214,10 +242,12 @@ interface EmitOptions {
214
242
  */
215
243
  filterPlugin?: (plugin: Plugin) => boolean;
216
244
  }
217
- declare function findConfigFile(): string;
245
+ declare const _Defaults: {
246
+ configPath: string;
247
+ outDir: string;
248
+ };
218
249
  declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[]): {
219
250
  _options: CoreOptions;
220
- getPluginContext(): PluginContext;
221
251
  /**
222
252
  * Convenient cache store, reset when config changes
223
253
  */
@@ -226,9 +256,17 @@ declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[
226
256
  config: Awaitable<LoadedConfig>;
227
257
  }): Promise</*elided*/ any>;
228
258
  getConfig(): LoadedConfig;
259
+ /**
260
+ * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
261
+ */
262
+ getCompiledConfigPath(): string;
229
263
  initServer(server: ServerContext): Promise<void>;
230
- emitAndWrite({ filterPlugin, }?: EmitOptions): Promise<void>;
264
+ emit({ filterPlugin }?: EmitOptions): Promise<EmitEntry[]>;
265
+ emitAndWrite(emitOptions?: EmitOptions): Promise<void>;
266
+ transformMeta(options: TransformOptions<MetaCollectionItem>, data: unknown): Promise<unknown>;
267
+ transformFrontmatter(options: TransformOptions<DocCollectionItem>, data: Record<string, unknown>): Promise<Record<string, unknown>>;
268
+ transformVFile(options: TransformOptions<DocCollectionItem>, file: VFile): Promise<VFile>;
231
269
  };
232
270
  type Core = ReturnType<typeof createCore>;
233
271
 
234
- export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DefaultMDXOptions as D, type ExtractedReference as E, type GlobalConfig as G, type LoadedConfig as L, type MetaCollection as M, type PostprocessOptions as P, type ServerContext as S, type CollectionSchema as a, type DocCollection as b, type DocsCollection as c, defineCollections as d, defineDocs as e, defineConfig as f, getDefaultMDXOptions as g, frontmatterSchema as h, type Plugin as i, buildConfig as j, type EmitEntry as k, type PluginContext as l, metaSchema as m, type PluginOption as n, type EmitOptions as o, findConfigFile as p, createCore as q, type Core as r };
272
+ export { type AnyCollection as A, type BaseCollection as B, type CoreOptions as C, type DocCollection as D, type ExtractedReference as E, type GlobalConfig as G, type MetaCollection as M, type PostprocessOptions as P, type ServerContext as S, type TransformOptions as T, _Defaults as _, type CollectionSchema as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, type DefaultMDXOptions as f, type MDXPresetOptions as g, applyMdxPreset as h, frontmatterSchema as i, type Plugin as j, type EmitEntry as k, type PluginContext as l, metaSchema as m, type CompilationContext as n, type PluginOption as o, type EmitOptions as p, createCore as q, type Core as r };
@@ -0,0 +1,8 @@
1
+ import { C as CoreOptions } from './index-D7JdSMpp.cjs';
2
+
3
+ interface WebpackLoaderOptions extends CoreOptions {
4
+ compiledConfigPath: string;
5
+ isDev: boolean;
6
+ }
7
+
8
+ export type { WebpackLoaderOptions as W };