fumadocs-mdx 12.0.3 → 13.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 (80) hide show
  1. package/dist/bin.cjs +1033 -308
  2. package/dist/bin.js +4 -4
  3. package/dist/build-mdx-BHG-_uxo.d.cts +53 -0
  4. package/dist/build-mdx-CzrQDBRZ.d.ts +53 -0
  5. package/dist/bun/index.cjs +92 -28
  6. package/dist/bun/index.js +6 -7
  7. package/dist/{chunk-QAUWMR5D.js → chunk-3J3WL7WN.js} +23 -5
  8. package/dist/chunk-4MAYA5QX.js +44 -0
  9. package/dist/{chunk-RMDXSZYE.js → chunk-CEA6MYJU.js} +13 -8
  10. package/dist/{chunk-IQAEAI4P.js → chunk-HI62EXSB.js} +63 -2
  11. package/dist/{chunk-46UPKP5R.js → chunk-II3H5ZVZ.js} +5 -5
  12. package/dist/{chunk-LGYVNESJ.js → chunk-JVZFH6ND.js} +6 -22
  13. package/dist/{chunk-LMG6UWCL.js → chunk-K5ZLPEIQ.js} +56 -16
  14. package/dist/{chunk-OMAMTKDE.js → chunk-KILFIBVW.js} +3 -12
  15. package/dist/chunk-NVRDCY6Z.js +30 -0
  16. package/dist/{chunk-VXEBLM4X.js → chunk-XV5Z4BFL.js} +1 -1
  17. package/dist/config/index.cjs +56 -16
  18. package/dist/config/index.d.cts +2 -1
  19. package/dist/config/index.d.ts +2 -1
  20. package/dist/config/index.js +1 -1
  21. package/dist/{define-DJbJduHy.d.ts → define-BCNh3n4O.d.cts} +40 -16
  22. package/dist/{define-DJbJduHy.d.cts → define-bck_EB4t.d.ts} +40 -16
  23. package/dist/index.cjs +0 -109
  24. package/dist/index.d.cts +73 -12
  25. package/dist/index.d.ts +73 -12
  26. package/dist/index.js +0 -11
  27. package/dist/{load-UUXLUBHL.js → load-MNG3CLET.js} +1 -3
  28. package/dist/loader-mdx.cjs +153 -60
  29. package/dist/loader-mdx.d.cts +1 -0
  30. package/dist/loader-mdx.d.ts +1 -0
  31. package/dist/loader-mdx.js +23 -9
  32. package/dist/next/index.cjs +213 -181
  33. package/dist/next/index.d.cts +2 -11
  34. package/dist/next/index.d.ts +2 -11
  35. package/dist/next/index.js +145 -117
  36. package/dist/node/loader.cjs +128 -70
  37. package/dist/node/loader.js +14 -9
  38. package/dist/plugins/index.cjs +78 -0
  39. package/dist/plugins/index.d.cts +7 -0
  40. package/dist/plugins/index.d.ts +7 -0
  41. package/dist/plugins/index.js +6 -0
  42. package/dist/plugins/json-schema.cjs +61 -0
  43. package/dist/plugins/json-schema.d.cts +16 -0
  44. package/dist/plugins/json-schema.d.ts +16 -0
  45. package/dist/plugins/json-schema.js +40 -0
  46. package/dist/remark-postprocess-K233ZVBK.d.cts +22 -0
  47. package/dist/remark-postprocess-K233ZVBK.d.ts +22 -0
  48. package/dist/runtime/next/async.cjs +108 -70
  49. package/dist/runtime/next/async.d.cts +9 -6
  50. package/dist/runtime/next/async.d.ts +9 -6
  51. package/dist/runtime/next/async.js +9 -19
  52. package/dist/runtime/next/index.cjs +25 -14
  53. package/dist/runtime/next/index.d.cts +11 -8
  54. package/dist/runtime/next/index.d.ts +11 -8
  55. package/dist/runtime/next/index.js +2 -2
  56. package/dist/runtime/vite/browser.cjs +7 -3
  57. package/dist/runtime/vite/browser.d.cts +56 -7
  58. package/dist/runtime/vite/browser.d.ts +56 -7
  59. package/dist/runtime/vite/browser.js +2 -1
  60. package/dist/runtime/vite/server.cjs +40 -34
  61. package/dist/runtime/vite/server.d.cts +13 -10
  62. package/dist/runtime/vite/server.d.ts +13 -10
  63. package/dist/runtime/vite/server.js +8 -23
  64. package/dist/{types-TeHjsmja.d.ts → types-1cCFEzWt.d.ts} +3 -10
  65. package/dist/{types-BRx1QsIJ.d.cts → types-D5NhXTJY.d.cts} +3 -10
  66. package/dist/vite/index.cjs +386 -224
  67. package/dist/vite/index.d.cts +23 -10
  68. package/dist/vite/index.d.ts +23 -10
  69. package/dist/vite/index.js +211 -37
  70. package/dist/{watcher-HGOH3APP.js → watcher-WXJDWRZY.js} +1 -1
  71. package/package.json +28 -15
  72. package/dist/browser-BupUnhpC.d.ts +0 -98
  73. package/dist/browser-R0x9IPaQ.d.cts +0 -98
  74. package/dist/chunk-ADR6R7HM.js +0 -29
  75. package/dist/chunk-XMFLD5J6.js +0 -30
  76. package/dist/chunk-ZLCSVXCD.js +0 -10
  77. package/dist/chunk-ZX7TM4AR.js +0 -127
  78. package/dist/postinstall-SCSXM4IM.js +0 -10
  79. package/dist/shared-CfiiRctw.d.ts +0 -70
  80. package/dist/shared-fFqiuWJC.d.cts +0 -70
@@ -1,98 +0,0 @@
1
- import { createProcessor } from '@mdx-js/mdx';
2
- import { StructuredData } from 'fumadocs-core/mdx-plugins';
3
- import { TableOfContents } from 'fumadocs-core/server';
4
- import { FC, ReactNode } from 'react';
5
- import { MDXProps } from 'mdx/types';
6
- import { E as ExtractedReference, a as DocCollection, b as DocsCollection, M as MetaCollection } from './define-DJbJduHy.cjs';
7
- import { StandardSchemaV1 } from '@standard-schema/spec';
8
-
9
- type Processor = ReturnType<typeof createProcessor>;
10
- interface CompilerOptions {
11
- addDependency: (file: string) => void;
12
- }
13
- interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
14
- frontmatter: Frontmatter;
15
- structuredData: StructuredData;
16
- toc: TableOfContents;
17
- default: FC<MDXProps>;
18
- /**
19
- * Only available when `lastModifiedTime` is enabled on MDX loader
20
- */
21
- lastModified?: Date;
22
- extractedReferences?: ExtractedReference[];
23
- _markdown?: string;
24
- }
25
- interface FumadocsDataMap {
26
- /**
27
- * [Fumadocs MDX] raw frontmatter, you can modify it
28
- */
29
- frontmatter?: Record<string, unknown>;
30
- /**
31
- * [Fumadocs MDX] additional ESM exports to write
32
- */
33
- 'mdx-export'?: {
34
- name: string;
35
- value: unknown;
36
- }[];
37
- extractedReferences: ExtractedReference[];
38
- /**
39
- * [Fumadocs MDX] The compiler object from loader
40
- */
41
- _compiler?: CompilerOptions;
42
- _getProcessor?: (format: 'md' | 'mdx') => Processor;
43
- /**
44
- * [Fumadocs MDX] Processed Markdown content before `remark-rehype`.
45
- */
46
- _markdown?: string;
47
- }
48
- declare module 'vfile' {
49
- interface DataMap extends FumadocsDataMap {
50
- }
51
- }
52
-
53
- type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> & Record<string, unknown>;
54
- type DocMap<Frontmatter> = Record<string, (() => Promise<CompiledMDXFile<Frontmatter>>) & {
55
- base: string;
56
- }>;
57
- type MetaMap<Data> = Record<string, (() => Promise<Data>) & {
58
- base: string;
59
- }>;
60
- interface LazyDocMap<Frontmatter> {
61
- base: string;
62
- head: Record<string, () => Promise<Frontmatter>>;
63
- body: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>;
64
- }
65
-
66
- interface BaseCreate<Config> {
67
- doc: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocMap<StandardSchemaV1.InferOutput<Schema>> : never;
68
- docLazy: <Name extends keyof Config>(name: Name, base: string, headGlob: Record<string, () => Promise<unknown>>, bodyGlob: Record<string, () => Promise<unknown>>) => Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? LazyDocMap<StandardSchemaV1.InferOutput<Schema>> : never;
69
- meta: <Name extends keyof Config>(name: Name, base: string, glob: Record<string, () => Promise<unknown>>) => Config[Name] extends MetaCollection<infer Schema> | DocsCollection<StandardSchemaV1, infer Schema> ? MetaMap<StandardSchemaV1.InferOutput<Schema>> : never;
70
- }
71
- declare function fromConfigBase<Config>(): BaseCreate<Config>;
72
-
73
- interface ClientLoaderOptions<Frontmatter, Props> {
74
- /**
75
- * Loader ID (usually your collection name)
76
- *
77
- * The code splitting strategy of frameworks like Tanstack Start may duplicate `createClientLoader()` into different chunks.
78
- *
79
- * We use loader ID to share cache between multiple instances of client loader.
80
- *
81
- * @defaultValue ''
82
- */
83
- id?: string;
84
- component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode;
85
- }
86
- type ClientRenderer<Props> = Record<string, FC<Props>>;
87
- interface ClientLoader<Frontmatter, Props> {
88
- preload: (path: string) => Promise<CompiledMDXFile<Frontmatter>>;
89
- /**
90
- * Get a component that renders content with `React.lazy`
91
- */
92
- getComponent: (path: string) => FC<Props>;
93
- getRenderer: () => ClientRenderer<Props>;
94
- }
95
- declare function createClientLoader<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, options: ClientLoaderOptions<Frontmatter, Props>): ClientLoader<Frontmatter, Props>;
96
- declare function toClientRenderer<Frontmatter, Props = object>(files: Record<string, () => Promise<CompiledMDXFile<Frontmatter>>>, component: (loaded: CompiledMDXFile<Frontmatter>, props: Props) => ReactNode): ClientRenderer<Props>;
97
-
98
- export { type BaseCreate as B, type ClientLoader as C, type DocMap as D, type LazyDocMap as L, type MetaMap as M, type ClientLoaderOptions as a, type CompiledMDXFile as b, createClientLoader as c, fromConfigBase as f, toClientRenderer as t };
@@ -1,29 +0,0 @@
1
- // src/next/map/file-cache.ts
2
- import { LRUCache } from "lru-cache";
3
- import fs from "fs/promises";
4
- import path from "path";
5
- var map = new LRUCache({
6
- max: 100
7
- });
8
- function toFullPath(file) {
9
- if (path.isAbsolute(file)) {
10
- return path.relative(process.cwd(), file);
11
- }
12
- return file;
13
- }
14
- async function readFileWithCache(file) {
15
- const fullPath = toFullPath(file);
16
- const cached = map.get(fullPath);
17
- if (cached) return cached;
18
- const read = fs.readFile(fullPath).then((s) => s.toString());
19
- map.set(fullPath, read);
20
- return read;
21
- }
22
- function removeFileCache(file) {
23
- map.delete(toFullPath(file));
24
- }
25
-
26
- export {
27
- readFileWithCache,
28
- removeFileCache
29
- };
@@ -1,30 +0,0 @@
1
- // src/loaders/config/index.ts
2
- import path from "path";
3
- function findConfigFile() {
4
- return path.resolve("source.config.ts");
5
- }
6
- function resolvedConfig(loaded) {
7
- return {
8
- getConfig() {
9
- return loaded;
10
- }
11
- };
12
- }
13
- function dynamicConfig(configPath, outDir) {
14
- return {
15
- async getConfig(hash) {
16
- const { loadConfig, getConfigHash } = await import("./load-UUXLUBHL.js");
17
- return loadConfig(
18
- configPath,
19
- outDir,
20
- hash ?? await getConfigHash(configPath)
21
- );
22
- }
23
- };
24
- }
25
-
26
- export {
27
- findConfigFile,
28
- resolvedConfig,
29
- dynamicConfig
30
- };
@@ -1,10 +0,0 @@
1
- // src/runtime/shared.ts
2
- function missingProcessedMarkdown() {
3
- throw new Error(
4
- "getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
5
- );
6
- }
7
-
8
- export {
9
- missingProcessedMarkdown
10
- };
@@ -1,127 +0,0 @@
1
- import {
2
- getGlobPatterns,
3
- ident,
4
- toImportPath
5
- } from "./chunk-6Y5JDZHD.js";
6
- import {
7
- loadConfig
8
- } from "./chunk-LGYVNESJ.js";
9
- import {
10
- findConfigFile
11
- } from "./chunk-XMFLD5J6.js";
12
-
13
- // src/vite/postinstall.ts
14
- import fs from "fs/promises";
15
- import path from "path";
16
-
17
- // src/vite/generate-glob.ts
18
- function generateGlob(name, patterns, globOptions) {
19
- const options = {
20
- ...globOptions,
21
- query: {
22
- ...globOptions?.query,
23
- collection: name
24
- }
25
- };
26
- return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
27
- }
28
- function mapGlobPatterns(patterns) {
29
- return patterns.map(enforceRelative);
30
- }
31
- function enforceRelative(file) {
32
- if (file.startsWith("./")) return file;
33
- if (file.startsWith("/")) return `.${file}`;
34
- return `./${file}`;
35
- }
36
- function getGlobBase(collection) {
37
- let dir = collection.dir;
38
- if (Array.isArray(dir)) {
39
- if (dir.length !== 1)
40
- throw new Error(
41
- `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
42
- );
43
- dir = dir[0];
44
- }
45
- return enforceRelative(dir);
46
- }
47
-
48
- // src/vite/generate.ts
49
- function docs(name, collection) {
50
- const obj = [
51
- ident(`doc: ${doc(name, collection.docs)}`),
52
- ident(`meta: ${meta(name, collection.meta)}`)
53
- ].join(",\n");
54
- return `{
55
- ${obj}
56
- }`;
57
- }
58
- function doc(name, collection) {
59
- const patterns = getGlobPatterns(collection);
60
- const base = getGlobBase(collection);
61
- const docGlob = generateGlob(name, patterns, {
62
- base
63
- });
64
- if (collection.async) {
65
- const headBlob = generateGlob(name, patterns, {
66
- query: {
67
- only: "frontmatter"
68
- },
69
- import: "frontmatter",
70
- base
71
- });
72
- return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
73
- }
74
- return `create.doc("${name}", "${base}", ${docGlob})`;
75
- }
76
- function meta(name, collection) {
77
- const patterns = getGlobPatterns(collection);
78
- const base = getGlobBase(collection);
79
- return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
80
- import: "default",
81
- base
82
- })})`;
83
- }
84
- function entry(configPath, config, outDir, jsExtension) {
85
- const lines = [
86
- '/// <reference types="vite/client" />',
87
- `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
88
- `import type * as Config from '${toImportPath(configPath, {
89
- relativeTo: outDir,
90
- jsExtension
91
- })}';`,
92
- "",
93
- `export const create = fromConfig<typeof Config>();`
94
- ];
95
- for (const [name, collection] of config.collections.entries()) {
96
- let body;
97
- if (collection.type === "docs") {
98
- body = docs(name, collection);
99
- } else if (collection.type === "meta") {
100
- body = meta(name, collection);
101
- } else {
102
- body = doc(name, collection);
103
- }
104
- lines.push("");
105
- lines.push(`export const ${name} = ${body};`);
106
- }
107
- return lines.join("\n");
108
- }
109
-
110
- // src/vite/postinstall.ts
111
- async function postInstall(configPath = findConfigFile(), outDir, addJsExtension = false) {
112
- const config = await loadConfig(configPath, "node_modules", void 0, true);
113
- const outFile = "source.generated.ts";
114
- if (outDir) {
115
- await fs.mkdir(outDir, { recursive: true });
116
- }
117
- await fs.writeFile(
118
- outDir ? path.join(outDir, outFile) : outFile,
119
- entry(configPath, config, outDir ?? process.cwd(), addJsExtension)
120
- );
121
- console.log("[MDX] types generated");
122
- }
123
-
124
- export {
125
- entry,
126
- postInstall
127
- };
@@ -1,10 +0,0 @@
1
- import {
2
- postInstall
3
- } from "./chunk-ZX7TM4AR.js";
4
- import "./chunk-6Y5JDZHD.js";
5
- import "./chunk-LGYVNESJ.js";
6
- import "./chunk-U4MQ44TS.js";
7
- import "./chunk-XMFLD5J6.js";
8
- export {
9
- postInstall
10
- };
@@ -1,70 +0,0 @@
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-DJbJduHy.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> = DocData & DocMethods & Frontmatter;
65
- type AsyncDocCollectionEntry<Frontmatter> = DocMethods & {
66
- load: () => Promise<DocData>;
67
- } & Frontmatter;
68
- declare function missingProcessedMarkdown(): never;
69
-
70
- export { type AsyncDocCollectionEntry as A, type DocCollectionEntry as D, type FileInfo as F, type MetaCollectionEntry as M, type DocData as a, type DocMethods as b, missingProcessedMarkdown as m };
@@ -1,70 +0,0 @@
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-DJbJduHy.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> = DocData & DocMethods & Frontmatter;
65
- type AsyncDocCollectionEntry<Frontmatter> = DocMethods & {
66
- load: () => Promise<DocData>;
67
- } & Frontmatter;
68
- declare function missingProcessedMarkdown(): never;
69
-
70
- export { type AsyncDocCollectionEntry as A, type DocCollectionEntry as D, type FileInfo as F, type MetaCollectionEntry as M, type DocData as a, type DocMethods as b, missingProcessedMarkdown as m };