fumadocs-mdx 14.0.0 → 14.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 (67) hide show
  1. package/dist/bin.cjs +270 -201
  2. package/dist/bun/index.cjs +63 -28
  3. package/dist/bun/index.d.cts +7 -1
  4. package/dist/bun/index.d.ts +7 -1
  5. package/dist/bun/index.js +6 -5
  6. package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
  7. package/dist/{chunk-XHJCLBZ4.js → chunk-7UKSZSPY.js} +87 -162
  8. package/dist/{chunk-7L2KNF6B.js → chunk-BEBCWQC7.js} +51 -7
  9. package/dist/{chunk-5UMZCWKV.js → chunk-IQGEFL2B.js} +1 -1
  10. package/dist/{chunk-SRSRFOVI.js → chunk-K6HCOGOX.js} +3 -3
  11. package/dist/{chunk-OXSRIWQW.js → chunk-MTTISKQJ.js} +3 -2
  12. package/dist/chunk-WBIHDYMN.js +126 -0
  13. package/dist/config/index.d.cts +6 -1
  14. package/dist/config/index.d.ts +6 -1
  15. package/dist/{index-D7JdSMpp.d.cts → core-B9ZoS6sA.d.ts} +73 -4
  16. package/dist/{index-D7JdSMpp.d.ts → core-DTuP23zu.d.cts} +73 -4
  17. package/dist/{index-BlVBvy-z.d.ts → index-BD8Woo4m.d.cts} +1 -1
  18. package/dist/{index-P2NNUkHn.d.cts → index-CNOvhtOn.d.ts} +1 -1
  19. package/dist/index.d.cts +56 -3
  20. package/dist/index.d.ts +56 -3
  21. package/dist/{load-from-file-I3ALLIVB.js → load-from-file-5HUQN36V.js} +1 -1
  22. package/dist/next/index.cjs +260 -192
  23. package/dist/next/index.d.cts +7 -2
  24. package/dist/next/index.d.ts +7 -2
  25. package/dist/next/index.js +10 -8
  26. package/dist/node/loader.cjs +72 -37
  27. package/dist/node/loader.js +3 -3
  28. package/dist/plugins/index-file.cjs +69 -45
  29. package/dist/plugins/index-file.d.cts +7 -22
  30. package/dist/plugins/index-file.d.ts +7 -22
  31. package/dist/plugins/index-file.js +2 -2
  32. package/dist/plugins/json-schema.d.cts +7 -1
  33. package/dist/plugins/json-schema.d.ts +7 -1
  34. package/dist/plugins/last-modified.cjs +41 -6
  35. package/dist/plugins/last-modified.d.cts +11 -1
  36. package/dist/plugins/last-modified.d.ts +11 -1
  37. package/dist/plugins/last-modified.js +34 -4
  38. package/dist/runtime/browser.cjs +7 -8
  39. package/dist/runtime/browser.d.cts +22 -19
  40. package/dist/runtime/browser.d.ts +22 -19
  41. package/dist/runtime/browser.js +5 -6
  42. package/dist/runtime/dynamic.cjs +81 -43
  43. package/dist/runtime/dynamic.d.cts +12 -12
  44. package/dist/runtime/dynamic.d.ts +12 -12
  45. package/dist/runtime/dynamic.js +9 -8
  46. package/dist/runtime/server.cjs +9 -6
  47. package/dist/runtime/server.d.cts +10 -157
  48. package/dist/runtime/server.d.ts +10 -157
  49. package/dist/runtime/server.js +3 -3
  50. package/dist/runtime/types.cjs +18 -0
  51. package/dist/runtime/types.d.cts +61 -0
  52. package/dist/runtime/types.d.ts +61 -0
  53. package/dist/runtime/types.js +0 -0
  54. package/dist/vite/index.cjs +257 -190
  55. package/dist/vite/index.d.cts +7 -2
  56. package/dist/vite/index.d.ts +7 -2
  57. package/dist/vite/index.js +7 -6
  58. package/dist/webpack/mdx.cjs +60 -25
  59. package/dist/webpack/mdx.d.cts +8 -2
  60. package/dist/webpack/mdx.d.ts +8 -2
  61. package/dist/webpack/mdx.js +4 -4
  62. package/dist/webpack/meta.cjs +60 -25
  63. package/dist/webpack/meta.d.cts +8 -2
  64. package/dist/webpack/meta.d.ts +8 -2
  65. package/dist/webpack/meta.js +4 -4
  66. package/package.json +2 -2
  67. package/dist/chunk-PKI7ZDA5.js +0 -29
@@ -1,6 +1,6 @@
1
1
  import {
2
- removeFileCache
3
- } from "./chunk-PKI7ZDA5.js";
2
+ ident
3
+ } from "./chunk-WBIHDYMN.js";
4
4
 
5
5
  // src/utils/validation.ts
6
6
  var ValidationError = class extends Error {
@@ -75,7 +75,6 @@ function createCore(options, defaultPlugins = []) {
75
75
  return data;
76
76
  }
77
77
  const core = {
78
- _options: options,
79
78
  /**
80
79
  * Convenient cache store, reset when config changes
81
80
  */
@@ -84,6 +83,7 @@ function createCore(options, defaultPlugins = []) {
84
83
  config = await newConfig;
85
84
  this.cache.clear();
86
85
  plugins = await getPlugins([
86
+ postprocessPlugin(),
87
87
  ...defaultPlugins,
88
88
  ...config.global.plugins ?? []
89
89
  ]);
@@ -91,7 +91,9 @@ function createCore(options, defaultPlugins = []) {
91
91
  const out = await plugin.config?.call(pluginContext, config);
92
92
  if (out) config = out;
93
93
  }
94
- return this;
94
+ },
95
+ getOptions() {
96
+ return options;
95
97
  },
96
98
  getConfig() {
97
99
  return config;
@@ -102,10 +104,13 @@ function createCore(options, defaultPlugins = []) {
102
104
  getCompiledConfigPath() {
103
105
  return path.join(options.outDir, "source.config.mjs");
104
106
  },
107
+ getPlugins() {
108
+ return plugins;
109
+ },
110
+ getPluginContext() {
111
+ return pluginContext;
112
+ },
105
113
  async initServer(server) {
106
- server.watcher?.on("all", async (event, file) => {
107
- if (event === "change") removeFileCache(file);
108
- });
109
114
  for (const plugin of plugins) {
110
115
  await plugin.configureServer?.call(pluginContext, server);
111
116
  }
@@ -172,6 +177,45 @@ function createCore(options, defaultPlugins = []) {
172
177
  };
173
178
  return core;
174
179
  }
180
+ function postprocessPlugin() {
181
+ const LinkReferenceTypes = `{
182
+ /**
183
+ * extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
184
+ */
185
+ extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
186
+ }`;
187
+ return {
188
+ "index-file": {
189
+ generateTypeConfig() {
190
+ const lines = [];
191
+ lines.push("{");
192
+ lines.push(" DocData: {");
193
+ for (const collection of this.core.getConfig().collectionList) {
194
+ let postprocessOptions;
195
+ switch (collection.type) {
196
+ case "doc":
197
+ postprocessOptions = collection.postprocess;
198
+ break;
199
+ case "docs":
200
+ postprocessOptions = collection.docs.postprocess;
201
+ break;
202
+ }
203
+ if (postprocessOptions?.extractLinkReferences) {
204
+ lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
205
+ }
206
+ }
207
+ lines.push(" }");
208
+ lines.push("}");
209
+ return lines.join("\n");
210
+ },
211
+ serverOptions(options) {
212
+ options.doc ??= {};
213
+ options.doc.passthroughs ??= [];
214
+ options.doc.passthroughs.push("extractedReferences");
215
+ }
216
+ }
217
+ };
218
+ }
175
219
 
176
220
  export {
177
221
  ValidationError,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createCore
3
- } from "./chunk-7L2KNF6B.js";
3
+ } from "./chunk-BEBCWQC7.js";
4
4
 
5
5
  // src/webpack/index.ts
6
6
  var core;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-7L2KNF6B.js";
3
+ } from "./chunk-BEBCWQC7.js";
4
4
 
5
5
  // src/loaders/adapter.ts
6
6
  import { fileURLToPath } from "url";
@@ -137,13 +137,13 @@ function createStandaloneConfigLoader({
137
137
  let loaded;
138
138
  async function getConfigHash() {
139
139
  if (mode === "production") return "static";
140
- const stats = await fs2.stat(core._options.configPath).catch(() => {
140
+ const stats = await fs2.stat(core.getOptions().configPath).catch(() => {
141
141
  throw new Error("Cannot find config file");
142
142
  });
143
143
  return stats.mtime.getTime().toString();
144
144
  }
145
145
  async function newConfig() {
146
- const { loadConfig } = await import("./load-from-file-I3ALLIVB.js");
146
+ const { loadConfig } = await import("./load-from-file-5HUQN36V.js");
147
147
  await core.init({
148
148
  config: loadConfig(core, buildConfig)
149
149
  });
@@ -6,10 +6,11 @@ import {
6
6
  import { pathToFileURL } from "url";
7
7
  async function compileConfig(core) {
8
8
  const { build } = await import("esbuild");
9
+ const { configPath, outDir } = core.getOptions();
9
10
  const transformed = await build({
10
- entryPoints: [{ in: core._options.configPath, out: "source.config" }],
11
+ entryPoints: [{ in: configPath, out: "source.config" }],
11
12
  bundle: true,
12
- outdir: core._options.outDir,
13
+ outdir: outDir,
13
14
  target: "node20",
14
15
  write: true,
15
16
  platform: "node",
@@ -0,0 +1,126 @@
1
+ // src/utils/codegen.ts
2
+ import path from "path";
3
+ import { glob } from "tinyglobby";
4
+ function createCodegen({
5
+ target = "default",
6
+ outDir = "",
7
+ jsExtension = false,
8
+ globCache = /* @__PURE__ */ new Map()
9
+ }) {
10
+ let eagerImportId = 0;
11
+ const banner = ["// @ts-nocheck"];
12
+ if (target === "vite") {
13
+ banner.push('/// <reference types="vite/client" />');
14
+ }
15
+ return {
16
+ options: {
17
+ target,
18
+ outDir
19
+ },
20
+ lines: [],
21
+ addImport(statement) {
22
+ this.lines.unshift(statement);
23
+ },
24
+ async pushAsync(insert) {
25
+ for (const line of await Promise.all(insert)) {
26
+ if (line === void 0) continue;
27
+ this.lines.push(line);
28
+ }
29
+ },
30
+ async generateGlobImport(patterns, options) {
31
+ if (target === "vite") {
32
+ return this.generateViteGlobImport(patterns, options);
33
+ }
34
+ return this.generateNodeGlobImport(patterns, options);
35
+ },
36
+ generateViteGlobImport(patterns, { base, ...rest }) {
37
+ patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
38
+ normalizeViteGlobPath
39
+ );
40
+ return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
41
+ {
42
+ base: normalizeViteGlobPath(path.relative(outDir, base)),
43
+ ...rest
44
+ },
45
+ null,
46
+ 2
47
+ )})`;
48
+ },
49
+ async generateNodeGlobImport(patterns, {
50
+ base,
51
+ eager = false,
52
+ query = {},
53
+ import: importName
54
+ }) {
55
+ const cacheKey = JSON.stringify({ patterns, base });
56
+ let files = globCache.get(cacheKey);
57
+ if (!files) {
58
+ files = glob(patterns, {
59
+ cwd: base
60
+ });
61
+ globCache.set(cacheKey, files);
62
+ }
63
+ let code = "{";
64
+ for (const item of await files) {
65
+ const fullPath = path.join(base, item);
66
+ const searchParams = new URLSearchParams();
67
+ for (const [k, v] of Object.entries(query)) {
68
+ searchParams.set(k, v);
69
+ }
70
+ const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
71
+ if (eager) {
72
+ const name = `__fd_glob_${eagerImportId++}`;
73
+ this.lines.unshift(
74
+ importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
75
+ );
76
+ code += `${JSON.stringify(item)}: ${name}, `;
77
+ } else {
78
+ let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
79
+ if (importName) {
80
+ line += `.then(mod => mod.${importName})`;
81
+ }
82
+ code += `${line}, `;
83
+ }
84
+ }
85
+ code += "}";
86
+ return code;
87
+ },
88
+ formatImportPath(file) {
89
+ const ext = path.extname(file);
90
+ let filename;
91
+ if (ext === ".ts" && jsExtension) {
92
+ filename = file.substring(0, file.length - ext.length) + ".js";
93
+ } else if (ext === ".ts") {
94
+ filename = file.substring(0, file.length - ext.length);
95
+ } else {
96
+ filename = file;
97
+ }
98
+ const importPath = slash(path.relative(outDir, filename));
99
+ return importPath.startsWith(".") ? importPath : `./${importPath}`;
100
+ },
101
+ toString() {
102
+ return [...banner, ...this.lines].join("\n");
103
+ }
104
+ };
105
+ }
106
+ function normalizeViteGlobPath(file) {
107
+ file = slash(file);
108
+ if (file.startsWith("./")) return file;
109
+ if (file.startsWith("/")) return `.${file}`;
110
+ return `./${file}`;
111
+ }
112
+ function slash(path2) {
113
+ const isExtendedLengthPath = path2.startsWith("\\\\?\\");
114
+ if (isExtendedLengthPath) {
115
+ return path2;
116
+ }
117
+ return path2.replaceAll("\\", "/");
118
+ }
119
+ function ident(code, tab = 1) {
120
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
121
+ }
122
+
123
+ export {
124
+ createCodegen,
125
+ ident
126
+ };
@@ -1,4 +1,4 @@
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.cjs';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, e as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, f as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, g as applyMdxPreset, d as defineCollections, c as defineConfig, b as defineDocs, h as frontmatterSchema, m as metaSchema } from '../core-DTuP23zu.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -7,6 +7,11 @@ import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
9
  import 'vfile';
10
+ import 'fumadocs-core/source';
11
+ import '../runtime/types.cjs';
12
+ import 'fumadocs-core/mdx-plugins/remark-structure';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdx/types';
10
15
 
11
16
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
12
17
 
@@ -1,4 +1,4 @@
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';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, e as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, f as MDXPresetOptions, M as MetaCollection, P as PostprocessOptions, g as applyMdxPreset, d as defineCollections, c as defineConfig, b as defineDocs, h as frontmatterSchema, m as metaSchema } from '../core-B9ZoS6sA.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -7,6 +7,11 @@ import 'fumadocs-core/mdx-plugins';
7
7
  import 'zod';
8
8
  import 'chokidar';
9
9
  import 'vfile';
10
+ import 'fumadocs-core/source';
11
+ import '../runtime/types.js';
12
+ import 'fumadocs-core/mdx-plugins/remark-structure';
13
+ import 'fumadocs-core/toc';
14
+ import 'mdx/types';
10
15
 
11
16
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
12
17
 
@@ -5,6 +5,8 @@ import * as Plugins from 'fumadocs-core/mdx-plugins';
5
5
  import { z } from 'zod';
6
6
  import { FSWatcher } from 'chokidar';
7
7
  import { VFile } from 'vfile';
8
+ import { PageData, MetaData, Source } from 'fumadocs-core/source';
9
+ import { InternalTypeConfig, DocData, DocMethods, MetaMethods } from './runtime/types.js';
8
10
 
9
11
  type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
10
12
  type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
@@ -174,6 +176,71 @@ interface DocsCollectionItem extends DocsCollection {
174
176
  hasFile: (filePath: string) => boolean;
175
177
  }
176
178
 
179
+ type MetaCollectionEntry<Data> = Data & MetaMethods;
180
+ type DocCollectionEntry<Name extends string = string, Frontmatter = unknown, TC extends InternalTypeConfig = InternalTypeConfig> = DocData & DocMethods & Frontmatter & TC['DocData'][Name];
181
+ type AsyncDocCollectionEntry<Name extends string = string, Frontmatter = unknown, TC extends InternalTypeConfig = InternalTypeConfig> = {
182
+ load: () => Promise<DocData & TC['DocData'][Name]>;
183
+ } & DocMethods & Frontmatter;
184
+ interface DocsCollectionEntry<Name extends string = string, Frontmatter extends PageData = PageData, Meta extends MetaData = MetaData, TC extends InternalTypeConfig = InternalTypeConfig> {
185
+ docs: DocCollectionEntry<Name, Frontmatter, TC>[];
186
+ meta: MetaCollectionEntry<Meta>[];
187
+ toFumadocsSource: () => Source<{
188
+ pageData: DocCollectionEntry<Name, Frontmatter, TC>;
189
+ metaData: MetaCollectionEntry<Meta>;
190
+ }>;
191
+ }
192
+ interface AsyncDocsCollectionEntry<Name extends string = string, Frontmatter extends PageData = PageData, Meta extends MetaData = MetaData, TC extends InternalTypeConfig = InternalTypeConfig> {
193
+ docs: AsyncDocCollectionEntry<Name, Frontmatter, TC>[];
194
+ meta: MetaCollectionEntry<Meta>[];
195
+ toFumadocsSource: () => Source<{
196
+ pageData: AsyncDocCollectionEntry<Name, Frontmatter, TC>;
197
+ metaData: MetaCollectionEntry<Meta>;
198
+ }>;
199
+ }
200
+ type AwaitableGlobEntries<T> = Record<string, T | (() => Promise<T>)>;
201
+ type ServerCreate<Config, TC extends InternalTypeConfig = InternalTypeConfig> = ReturnType<typeof server<Config, TC>>;
202
+ interface ServerOptions {
203
+ doc?: {
204
+ passthroughs?: string[];
205
+ };
206
+ }
207
+ declare function server<Config, TC extends InternalTypeConfig>(options?: ServerOptions): {
208
+ doc<Name extends keyof Config & string>(_name: Name, base: string, glob: AwaitableGlobEntries<unknown>): Promise<Config[Name] extends DocCollection<infer Schema extends StandardSchemaV1<unknown, unknown>> | DocsCollection<infer Schema extends StandardSchemaV1<unknown, unknown>, StandardSchemaV1<unknown, unknown>> ? DocCollectionEntry<Name, StandardSchemaV1.InferOutput<Schema>, TC>[] : never>;
209
+ docLazy<Name extends keyof Config & string>(_name: Name, base: string, head: AwaitableGlobEntries<unknown>, body: Record<string, () => Promise<unknown>>): Promise<Config[Name] extends DocCollection<infer Schema extends StandardSchemaV1<unknown, unknown>> | DocsCollection<infer Schema extends StandardSchemaV1<unknown, unknown>, StandardSchemaV1<unknown, unknown>> ? AsyncDocCollectionEntry<Name, StandardSchemaV1.InferOutput<Schema>, TC>[] : never>;
210
+ meta<Name extends keyof Config & string>(_name: Name, base: string, glob: AwaitableGlobEntries<unknown>): Promise<Config[Name] extends MetaCollection<infer Schema extends StandardSchemaV1<unknown, unknown>> | DocsCollection<StandardSchemaV1<unknown, unknown>, infer Schema extends StandardSchemaV1<unknown, unknown>> ? MetaCollectionEntry<StandardSchemaV1.InferOutput<Schema>>[] : never>;
211
+ docs<Name extends keyof Config & string>(name: Name, base: string, metaGlob: AwaitableGlobEntries<unknown>, docGlob: AwaitableGlobEntries<unknown>): Promise<Config[Name] extends DocsCollection<infer Page extends StandardSchemaV1<unknown, unknown>, infer Meta extends StandardSchemaV1<unknown, unknown>> ? StandardSchemaV1.InferOutput<Page> extends PageData ? StandardSchemaV1.InferOutput<Meta> extends MetaData ? DocsCollectionEntry<Name, StandardSchemaV1.InferOutput<Page>, StandardSchemaV1.InferOutput<Meta>, TC> : never : never : never>;
212
+ docsLazy<Name extends keyof Config & string>(name: Name, base: string, metaGlob: AwaitableGlobEntries<unknown>, docHeadGlob: AwaitableGlobEntries<unknown>, docBodyGlob: Record<string, () => Promise<unknown>>): Promise<Config[Name] extends DocsCollection<infer Page extends StandardSchemaV1<unknown, unknown>, infer Meta extends StandardSchemaV1<unknown, unknown>> ? StandardSchemaV1.InferOutput<Page> extends PageData ? StandardSchemaV1.InferOutput<Meta> extends MetaData ? AsyncDocsCollectionEntry<Name, StandardSchemaV1.InferOutput<Page>, StandardSchemaV1.InferOutput<Meta>, TC> : never : never : never>;
213
+ };
214
+ declare function toFumadocsSource<Page extends DocMethods & PageData, Meta extends MetaMethods & MetaData>(pages: Page[], metas: Meta[]): Source<{
215
+ pageData: Page;
216
+ metaData: Meta;
217
+ }>;
218
+
219
+ interface IndexFilePluginOptions {
220
+ target?: 'default' | 'vite';
221
+ /**
222
+ * add `.js` extensions to imports, needed for ESM without bundler resolution
223
+ */
224
+ addJsExtension?: boolean;
225
+ /**
226
+ * Generate entry point for browser
227
+ * @defaultValue true
228
+ */
229
+ browser?: boolean;
230
+ /**
231
+ * Generate entry point for dynamic compilation
232
+ * @defaultValue true
233
+ */
234
+ dynamic?: boolean;
235
+ }
236
+ interface IndexFilePlugin {
237
+ ['index-file']?: {
238
+ generateTypeConfig?: (this: PluginContext) => string | void;
239
+ serverOptions?: (this: PluginContext, options: ServerOptions) => void;
240
+ };
241
+ }
242
+ declare function indexFile(options?: IndexFilePluginOptions): Plugin;
243
+
177
244
  type Awaitable<T> = T | Promise<T>;
178
245
  interface EmitEntry {
179
246
  /**
@@ -191,7 +258,7 @@ interface TransformOptions<Collection> {
191
258
  filePath: string;
192
259
  source: string;
193
260
  }
194
- interface Plugin {
261
+ interface Plugin extends IndexFilePlugin {
195
262
  name?: string;
196
263
  /**
197
264
  * on config loaded/updated
@@ -247,19 +314,21 @@ declare const _Defaults: {
247
314
  outDir: string;
248
315
  };
249
316
  declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[]): {
250
- _options: CoreOptions;
251
317
  /**
252
318
  * Convenient cache store, reset when config changes
253
319
  */
254
320
  cache: Map<string, unknown>;
255
321
  init({ config: newConfig }: {
256
322
  config: Awaitable<LoadedConfig>;
257
- }): Promise</*elided*/ any>;
323
+ }): Promise<void>;
324
+ getOptions(): CoreOptions;
258
325
  getConfig(): LoadedConfig;
259
326
  /**
260
327
  * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
261
328
  */
262
329
  getCompiledConfigPath(): string;
330
+ getPlugins(): Plugin[];
331
+ getPluginContext(): PluginContext;
263
332
  initServer(server: ServerContext): Promise<void>;
264
333
  emit({ filterPlugin }?: EmitOptions): Promise<EmitEntry[]>;
265
334
  emitAndWrite(emitOptions?: EmitOptions): Promise<void>;
@@ -269,4 +338,4 @@ declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[
269
338
  };
270
339
  type Core = ReturnType<typeof createCore>;
271
340
 
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 };
341
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DocCollection as D, type ExtractedReference as E, toFumadocsSource as F, type GlobalConfig as G, indexFile as H, type IndexFilePluginOptions as I, type IndexFilePlugin as J, type MetaCollection as M, type PostprocessOptions as P, type ServerOptions as S, type TransformOptions as T, _Defaults as _, type DocsCollection as a, defineDocs as b, defineConfig as c, defineCollections as d, type DefaultMDXOptions as e, type MDXPresetOptions as f, applyMdxPreset as g, frontmatterSchema as h, type CoreOptions as i, type Plugin as j, type AsyncDocCollectionEntry as k, type AsyncDocsCollectionEntry as l, metaSchema as m, type EmitEntry as n, type PluginContext as o, type CompilationContext as p, type PluginOption as q, type ServerContext as r, type EmitOptions as s, createCore as t, type Core as u, type MetaCollectionEntry as v, type DocCollectionEntry as w, type DocsCollectionEntry as x, type ServerCreate as y, server as z };
@@ -5,6 +5,8 @@ import * as Plugins from 'fumadocs-core/mdx-plugins';
5
5
  import { z } from 'zod';
6
6
  import { FSWatcher } from 'chokidar';
7
7
  import { VFile } from 'vfile';
8
+ import { PageData, MetaData, Source } from 'fumadocs-core/source';
9
+ import { InternalTypeConfig, DocData, DocMethods, MetaMethods } from './runtime/types.cjs';
8
10
 
9
11
  type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
10
12
  type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
@@ -174,6 +176,71 @@ interface DocsCollectionItem extends DocsCollection {
174
176
  hasFile: (filePath: string) => boolean;
175
177
  }
176
178
 
179
+ type MetaCollectionEntry<Data> = Data & MetaMethods;
180
+ type DocCollectionEntry<Name extends string = string, Frontmatter = unknown, TC extends InternalTypeConfig = InternalTypeConfig> = DocData & DocMethods & Frontmatter & TC['DocData'][Name];
181
+ type AsyncDocCollectionEntry<Name extends string = string, Frontmatter = unknown, TC extends InternalTypeConfig = InternalTypeConfig> = {
182
+ load: () => Promise<DocData & TC['DocData'][Name]>;
183
+ } & DocMethods & Frontmatter;
184
+ interface DocsCollectionEntry<Name extends string = string, Frontmatter extends PageData = PageData, Meta extends MetaData = MetaData, TC extends InternalTypeConfig = InternalTypeConfig> {
185
+ docs: DocCollectionEntry<Name, Frontmatter, TC>[];
186
+ meta: MetaCollectionEntry<Meta>[];
187
+ toFumadocsSource: () => Source<{
188
+ pageData: DocCollectionEntry<Name, Frontmatter, TC>;
189
+ metaData: MetaCollectionEntry<Meta>;
190
+ }>;
191
+ }
192
+ interface AsyncDocsCollectionEntry<Name extends string = string, Frontmatter extends PageData = PageData, Meta extends MetaData = MetaData, TC extends InternalTypeConfig = InternalTypeConfig> {
193
+ docs: AsyncDocCollectionEntry<Name, Frontmatter, TC>[];
194
+ meta: MetaCollectionEntry<Meta>[];
195
+ toFumadocsSource: () => Source<{
196
+ pageData: AsyncDocCollectionEntry<Name, Frontmatter, TC>;
197
+ metaData: MetaCollectionEntry<Meta>;
198
+ }>;
199
+ }
200
+ type AwaitableGlobEntries<T> = Record<string, T | (() => Promise<T>)>;
201
+ type ServerCreate<Config, TC extends InternalTypeConfig = InternalTypeConfig> = ReturnType<typeof server<Config, TC>>;
202
+ interface ServerOptions {
203
+ doc?: {
204
+ passthroughs?: string[];
205
+ };
206
+ }
207
+ declare function server<Config, TC extends InternalTypeConfig>(options?: ServerOptions): {
208
+ doc<Name extends keyof Config & string>(_name: Name, base: string, glob: AwaitableGlobEntries<unknown>): Promise<Config[Name] extends DocCollection<infer Schema extends StandardSchemaV1<unknown, unknown>> | DocsCollection<infer Schema extends StandardSchemaV1<unknown, unknown>, StandardSchemaV1<unknown, unknown>> ? DocCollectionEntry<Name, StandardSchemaV1.InferOutput<Schema>, TC>[] : never>;
209
+ docLazy<Name extends keyof Config & string>(_name: Name, base: string, head: AwaitableGlobEntries<unknown>, body: Record<string, () => Promise<unknown>>): Promise<Config[Name] extends DocCollection<infer Schema extends StandardSchemaV1<unknown, unknown>> | DocsCollection<infer Schema extends StandardSchemaV1<unknown, unknown>, StandardSchemaV1<unknown, unknown>> ? AsyncDocCollectionEntry<Name, StandardSchemaV1.InferOutput<Schema>, TC>[] : never>;
210
+ meta<Name extends keyof Config & string>(_name: Name, base: string, glob: AwaitableGlobEntries<unknown>): Promise<Config[Name] extends MetaCollection<infer Schema extends StandardSchemaV1<unknown, unknown>> | DocsCollection<StandardSchemaV1<unknown, unknown>, infer Schema extends StandardSchemaV1<unknown, unknown>> ? MetaCollectionEntry<StandardSchemaV1.InferOutput<Schema>>[] : never>;
211
+ docs<Name extends keyof Config & string>(name: Name, base: string, metaGlob: AwaitableGlobEntries<unknown>, docGlob: AwaitableGlobEntries<unknown>): Promise<Config[Name] extends DocsCollection<infer Page extends StandardSchemaV1<unknown, unknown>, infer Meta extends StandardSchemaV1<unknown, unknown>> ? StandardSchemaV1.InferOutput<Page> extends PageData ? StandardSchemaV1.InferOutput<Meta> extends MetaData ? DocsCollectionEntry<Name, StandardSchemaV1.InferOutput<Page>, StandardSchemaV1.InferOutput<Meta>, TC> : never : never : never>;
212
+ docsLazy<Name extends keyof Config & string>(name: Name, base: string, metaGlob: AwaitableGlobEntries<unknown>, docHeadGlob: AwaitableGlobEntries<unknown>, docBodyGlob: Record<string, () => Promise<unknown>>): Promise<Config[Name] extends DocsCollection<infer Page extends StandardSchemaV1<unknown, unknown>, infer Meta extends StandardSchemaV1<unknown, unknown>> ? StandardSchemaV1.InferOutput<Page> extends PageData ? StandardSchemaV1.InferOutput<Meta> extends MetaData ? AsyncDocsCollectionEntry<Name, StandardSchemaV1.InferOutput<Page>, StandardSchemaV1.InferOutput<Meta>, TC> : never : never : never>;
213
+ };
214
+ declare function toFumadocsSource<Page extends DocMethods & PageData, Meta extends MetaMethods & MetaData>(pages: Page[], metas: Meta[]): Source<{
215
+ pageData: Page;
216
+ metaData: Meta;
217
+ }>;
218
+
219
+ interface IndexFilePluginOptions {
220
+ target?: 'default' | 'vite';
221
+ /**
222
+ * add `.js` extensions to imports, needed for ESM without bundler resolution
223
+ */
224
+ addJsExtension?: boolean;
225
+ /**
226
+ * Generate entry point for browser
227
+ * @defaultValue true
228
+ */
229
+ browser?: boolean;
230
+ /**
231
+ * Generate entry point for dynamic compilation
232
+ * @defaultValue true
233
+ */
234
+ dynamic?: boolean;
235
+ }
236
+ interface IndexFilePlugin {
237
+ ['index-file']?: {
238
+ generateTypeConfig?: (this: PluginContext) => string | void;
239
+ serverOptions?: (this: PluginContext, options: ServerOptions) => void;
240
+ };
241
+ }
242
+ declare function indexFile(options?: IndexFilePluginOptions): Plugin;
243
+
177
244
  type Awaitable<T> = T | Promise<T>;
178
245
  interface EmitEntry {
179
246
  /**
@@ -191,7 +258,7 @@ interface TransformOptions<Collection> {
191
258
  filePath: string;
192
259
  source: string;
193
260
  }
194
- interface Plugin {
261
+ interface Plugin extends IndexFilePlugin {
195
262
  name?: string;
196
263
  /**
197
264
  * on config loaded/updated
@@ -247,19 +314,21 @@ declare const _Defaults: {
247
314
  outDir: string;
248
315
  };
249
316
  declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[]): {
250
- _options: CoreOptions;
251
317
  /**
252
318
  * Convenient cache store, reset when config changes
253
319
  */
254
320
  cache: Map<string, unknown>;
255
321
  init({ config: newConfig }: {
256
322
  config: Awaitable<LoadedConfig>;
257
- }): Promise</*elided*/ any>;
323
+ }): Promise<void>;
324
+ getOptions(): CoreOptions;
258
325
  getConfig(): LoadedConfig;
259
326
  /**
260
327
  * The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
261
328
  */
262
329
  getCompiledConfigPath(): string;
330
+ getPlugins(): Plugin[];
331
+ getPluginContext(): PluginContext;
263
332
  initServer(server: ServerContext): Promise<void>;
264
333
  emit({ filterPlugin }?: EmitOptions): Promise<EmitEntry[]>;
265
334
  emitAndWrite(emitOptions?: EmitOptions): Promise<void>;
@@ -269,4 +338,4 @@ declare function createCore(options: CoreOptions, defaultPlugins?: PluginOption[
269
338
  };
270
339
  type Core = ReturnType<typeof createCore>;
271
340
 
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 };
341
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DocCollection as D, type ExtractedReference as E, toFumadocsSource as F, type GlobalConfig as G, indexFile as H, type IndexFilePluginOptions as I, type IndexFilePlugin as J, type MetaCollection as M, type PostprocessOptions as P, type ServerOptions as S, type TransformOptions as T, _Defaults as _, type DocsCollection as a, defineDocs as b, defineConfig as c, defineCollections as d, type DefaultMDXOptions as e, type MDXPresetOptions as f, applyMdxPreset as g, frontmatterSchema as h, type CoreOptions as i, type Plugin as j, type AsyncDocCollectionEntry as k, type AsyncDocsCollectionEntry as l, metaSchema as m, type EmitEntry as n, type PluginContext as o, type CompilationContext as p, type PluginOption as q, type ServerContext as r, type EmitOptions as s, createCore as t, type Core as u, type MetaCollectionEntry as v, type DocCollectionEntry as w, type DocsCollectionEntry as x, type ServerCreate as y, server as z };
@@ -1,4 +1,4 @@
1
- import { C as CoreOptions } from './index-D7JdSMpp.js';
1
+ import { i as CoreOptions } from './core-DTuP23zu.cjs';
2
2
 
3
3
  interface WebpackLoaderOptions extends CoreOptions {
4
4
  compiledConfigPath: string;
@@ -1,4 +1,4 @@
1
- import { C as CoreOptions } from './index-D7JdSMpp.cjs';
1
+ import { i as CoreOptions } from './core-B9ZoS6sA.js';
2
2
 
3
3
  interface WebpackLoaderOptions extends CoreOptions {
4
4
  compiledConfigPath: string;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,61 @@
1
- export { n as CompilationContext, r as Core, C as CoreOptions, k as EmitEntry, p as EmitOptions, E as ExtractedReference, j as Plugin, l as PluginContext, o as PluginOption, S as ServerContext, T as TransformOptions, _ as _Defaults, q as createCore } from './index-D7JdSMpp.cjs';
2
- import '@mdx-js/mdx';
1
+ export { p as CompilationContext, u as Core, i as CoreOptions, n as EmitEntry, s as EmitOptions, E as ExtractedReference, j as Plugin, o as PluginContext, q as PluginOption, r as ServerContext, T as TransformOptions, _ as _Defaults, t as createCore } from './core-DTuP23zu.cjs';
2
+ import { createProcessor } from '@mdx-js/mdx';
3
+ import { StructuredData } from 'fumadocs-core/mdx-plugins';
4
+ import { TOCItemType } from 'fumadocs-core/toc';
5
+ import { FC } from 'react';
6
+ import { MDXProps } from 'mdx/types';
3
7
  import '@standard-schema/spec';
4
8
  import 'unified';
5
- import 'fumadocs-core/mdx-plugins';
6
9
  import 'zod';
7
10
  import 'chokidar';
8
11
  import 'vfile';
12
+ import 'fumadocs-core/source';
13
+ import './runtime/types.cjs';
14
+ import 'fumadocs-core/mdx-plugins/remark-structure';
15
+ import 'mdast';
16
+
17
+ type Processor = ReturnType<typeof createProcessor>;
18
+ interface CompilerOptions {
19
+ addDependency: (file: string) => void;
20
+ }
21
+ interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
22
+ frontmatter: Frontmatter;
23
+ structuredData: StructuredData;
24
+ toc: TOCItemType[];
25
+ default: FC<MDXProps>;
26
+ /**
27
+ * Enable from `postprocess` option.
28
+ */
29
+ _markdown?: string;
30
+ /**
31
+ * Enable from `postprocess` option.
32
+ */
33
+ _mdast?: string;
34
+ }
35
+ interface FumadocsDataMap {
36
+ /**
37
+ * [Fumadocs MDX] raw frontmatter, you can modify it
38
+ */
39
+ frontmatter?: Record<string, unknown>;
40
+ /**
41
+ * [Fumadocs MDX] additional ESM exports to write
42
+ */
43
+ 'mdx-export'?: {
44
+ name: string;
45
+ value: unknown;
46
+ }[];
47
+ /**
48
+ * [Fumadocs MDX] The compiler object from loader
49
+ */
50
+ _compiler?: CompilerOptions;
51
+ /**
52
+ * [Fumadocs MDX] get internal processor, do not use this on user land.
53
+ */
54
+ _getProcessor?: (format: 'md' | 'mdx') => Processor;
55
+ }
56
+ declare module 'vfile' {
57
+ interface DataMap extends FumadocsDataMap {
58
+ }
59
+ }
60
+
61
+ export type { CompiledMDXProperties };