fumadocs-mdx 11.6.0 → 13.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 (93) hide show
  1. package/dist/bin.cjs +1728 -0
  2. package/dist/bin.d.cts +1 -0
  3. package/dist/bin.d.ts +1 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/build-mdx-CCNr86q6.d.ts +53 -0
  6. package/dist/build-mdx-D-r3_eQL.d.cts +53 -0
  7. package/dist/bun/index.cjs +857 -0
  8. package/dist/bun/index.d.cts +13 -0
  9. package/dist/bun/index.d.ts +13 -0
  10. package/dist/bun/index.js +62 -0
  11. package/dist/chunk-3J3WL7WN.js +160 -0
  12. package/dist/chunk-CXA4JO4Z.js +45 -0
  13. package/dist/chunk-EELYB2XC.js +207 -0
  14. package/dist/chunk-FSZMKRVH.js +80 -0
  15. package/dist/chunk-II3H5ZVZ.js +77 -0
  16. package/dist/chunk-JVZFH6ND.js +40 -0
  17. package/dist/chunk-K5ZLPEIQ.js +207 -0
  18. package/dist/{chunk-VFALQK6O.js → chunk-KILFIBVW.js} +21 -12
  19. package/dist/chunk-NVRDCY6Z.js +30 -0
  20. package/dist/chunk-U4MQ44TS.js +53 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-XQ5O7IPO.js +128 -0
  23. package/dist/chunk-XZY2AWJI.js +81 -0
  24. package/dist/chunk-YVCR6FUH.js +82 -0
  25. package/dist/config/index.cjs +232 -128
  26. package/dist/config/index.d.cts +4 -6
  27. package/dist/config/index.d.ts +4 -6
  28. package/dist/config/index.js +26 -19
  29. package/dist/core-B6j6Fxse.d.cts +218 -0
  30. package/dist/core-B6j6Fxse.d.ts +218 -0
  31. package/dist/index.cjs +0 -76
  32. package/dist/index.d.cts +73 -20
  33. package/dist/index.d.ts +73 -20
  34. package/dist/index.js +0 -10
  35. package/dist/load-MNG3CLET.js +7 -0
  36. package/dist/next/index.cjs +567 -314
  37. package/dist/next/index.d.cts +9 -12
  38. package/dist/next/index.d.ts +9 -12
  39. package/dist/next/index.js +238 -211
  40. package/dist/node/loader.cjs +922 -0
  41. package/dist/node/loader.d.cts +5 -0
  42. package/dist/node/loader.d.ts +5 -0
  43. package/dist/node/loader.js +33 -0
  44. package/dist/plugins/json-schema.cjs +162 -0
  45. package/dist/plugins/json-schema.d.cts +24 -0
  46. package/dist/plugins/json-schema.d.ts +24 -0
  47. package/dist/plugins/json-schema.js +78 -0
  48. package/dist/{mdx-options-CAU273O3.js → preset-ZMP6U62C.js} +1 -1
  49. package/dist/runtime/next/async.cjs +715 -0
  50. package/dist/runtime/next/async.d.cts +21 -0
  51. package/dist/runtime/next/async.d.ts +21 -0
  52. package/dist/runtime/next/async.js +89 -0
  53. package/dist/runtime/next/index.cjs +136 -0
  54. package/dist/runtime/next/index.d.cts +33 -0
  55. package/dist/runtime/next/index.d.ts +33 -0
  56. package/dist/runtime/next/index.js +11 -0
  57. package/dist/runtime/vite/browser.cjs +107 -0
  58. package/dist/runtime/vite/browser.d.cts +59 -0
  59. package/dist/runtime/vite/browser.d.ts +59 -0
  60. package/dist/runtime/vite/browser.js +11 -0
  61. package/dist/runtime/vite/server.cjs +243 -0
  62. package/dist/runtime/vite/server.d.cts +30 -0
  63. package/dist/runtime/vite/server.d.ts +30 -0
  64. package/dist/runtime/vite/server.js +111 -0
  65. package/dist/types-AGzTfBmf.d.ts +45 -0
  66. package/dist/types-DKGMoay5.d.cts +45 -0
  67. package/dist/vite/index.cjs +1185 -0
  68. package/dist/vite/index.d.cts +45 -0
  69. package/dist/vite/index.d.ts +45 -0
  70. package/dist/vite/index.js +297 -0
  71. package/dist/webpack/index.cjs +957 -0
  72. package/dist/{loader-mdx.d.cts → webpack/index.d.cts} +3 -6
  73. package/dist/{loader-mdx.d.ts → webpack/index.d.ts} +3 -6
  74. package/dist/webpack/index.js +44 -0
  75. package/loader-mdx.cjs +1 -1
  76. package/package.json +86 -29
  77. package/bin.js +0 -5
  78. package/dist/chunk-2ZOW45YZ.js +0 -63
  79. package/dist/chunk-DRVUBK5B.js +0 -39
  80. package/dist/chunk-HFLDWPJA.js +0 -62
  81. package/dist/chunk-IOENRFUX.js +0 -112
  82. package/dist/chunk-MK7EXW7O.js +0 -75
  83. package/dist/define-BaW0PQDJ.d.cts +0 -201
  84. package/dist/define-BaW0PQDJ.d.ts +0 -201
  85. package/dist/loader-mdx.cjs +0 -527
  86. package/dist/loader-mdx.js +0 -162
  87. package/dist/runtime/async.cjs +0 -269
  88. package/dist/runtime/async.d.cts +0 -18
  89. package/dist/runtime/async.d.ts +0 -18
  90. package/dist/runtime/async.js +0 -73
  91. package/dist/types-BNrQHCj5.d.cts +0 -100
  92. package/dist/types-DEduCvIT.d.ts +0 -100
  93. package/dist/watcher-IAZDSTU7.js +0 -24
@@ -0,0 +1,45 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface IndexFileOptions {
4
+ /**
5
+ * Runtime compat fallbacks for Vite specific APIs
6
+ *
7
+ * - `bun`: use Bun-specific APIs.
8
+ * - `node`: use Node.js APIs.
9
+ * - `false` (default): no fallback.
10
+ */
11
+ runtime?: 'bun' | 'node' | false;
12
+ /**
13
+ * add `.js` extensions to imports, needed for ESM without bundler resolution
14
+ */
15
+ addJsExtension?: boolean;
16
+ }
17
+
18
+ interface PluginOptions {
19
+ /**
20
+ * Automatically generate index files for accessing files with `import.meta.glob`.
21
+ *
22
+ * @defaultValue true
23
+ */
24
+ generateIndexFile?: boolean | IndexFileOptions;
25
+ /**
26
+ * @defaultValue source.config.ts
27
+ */
28
+ configPath?: string;
29
+ /**
30
+ * Update Vite config to fix module resolution of Fumadocs
31
+ *
32
+ * @defaultValue true
33
+ */
34
+ updateViteConfig?: boolean;
35
+ /**
36
+ * Output directory of generated files
37
+ *
38
+ * @defaultValue '.source'
39
+ */
40
+ outDir?: string;
41
+ }
42
+ declare function mdx(config: Record<string, unknown>, pluginOptions?: PluginOptions): Promise<Plugin>;
43
+ declare function postInstall(configPath?: string, pluginOptions?: PluginOptions): Promise<void>;
44
+
45
+ export { type PluginOptions, mdx as default, postInstall };
@@ -0,0 +1,45 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface IndexFileOptions {
4
+ /**
5
+ * Runtime compat fallbacks for Vite specific APIs
6
+ *
7
+ * - `bun`: use Bun-specific APIs.
8
+ * - `node`: use Node.js APIs.
9
+ * - `false` (default): no fallback.
10
+ */
11
+ runtime?: 'bun' | 'node' | false;
12
+ /**
13
+ * add `.js` extensions to imports, needed for ESM without bundler resolution
14
+ */
15
+ addJsExtension?: boolean;
16
+ }
17
+
18
+ interface PluginOptions {
19
+ /**
20
+ * Automatically generate index files for accessing files with `import.meta.glob`.
21
+ *
22
+ * @defaultValue true
23
+ */
24
+ generateIndexFile?: boolean | IndexFileOptions;
25
+ /**
26
+ * @defaultValue source.config.ts
27
+ */
28
+ configPath?: string;
29
+ /**
30
+ * Update Vite config to fix module resolution of Fumadocs
31
+ *
32
+ * @defaultValue true
33
+ */
34
+ updateViteConfig?: boolean;
35
+ /**
36
+ * Output directory of generated files
37
+ *
38
+ * @defaultValue '.source'
39
+ */
40
+ outDir?: string;
41
+ }
42
+ declare function mdx(config: Record<string, unknown>, pluginOptions?: PluginOptions): Promise<Plugin>;
43
+ declare function postInstall(configPath?: string, pluginOptions?: PluginOptions): Promise<void>;
44
+
45
+ export { type PluginOptions, mdx as default, postInstall };
@@ -0,0 +1,297 @@
1
+ import {
2
+ ident,
3
+ toImportPath
4
+ } from "../chunk-CXA4JO4Z.js";
5
+ import {
6
+ buildConfig
7
+ } from "../chunk-U4MQ44TS.js";
8
+ import {
9
+ toVite
10
+ } from "../chunk-YVCR6FUH.js";
11
+ import {
12
+ createMdxLoader
13
+ } from "../chunk-XQ5O7IPO.js";
14
+ import "../chunk-3J3WL7WN.js";
15
+ import "../chunk-K5ZLPEIQ.js";
16
+ import {
17
+ ValidationError,
18
+ createCore,
19
+ findConfigFile,
20
+ validate
21
+ } from "../chunk-EELYB2XC.js";
22
+ import "../chunk-VWJKRQZR.js";
23
+ import {
24
+ getGlobPatterns
25
+ } from "../chunk-XZY2AWJI.js";
26
+
27
+ // src/vite/index.ts
28
+ import {
29
+ mergeConfig
30
+ } from "vite";
31
+ import { parse } from "querystring";
32
+ import * as path3 from "path";
33
+ import { load } from "js-yaml";
34
+
35
+ // src/utils/glob-import.ts
36
+ import { globSync } from "tinyglobby";
37
+ import path from "path";
38
+ import { pathToFileURL } from "url";
39
+ function generateGlobImport(patterns, options) {
40
+ let code = "{";
41
+ const result = globSync(patterns, {
42
+ cwd: options.base
43
+ });
44
+ for (const item of result) {
45
+ const fullPath = path.join(options.base, item);
46
+ const url = pathToFileURL(fullPath);
47
+ for (const [k, v] of Object.entries(options.query ?? {})) {
48
+ url.searchParams.set(k, v);
49
+ }
50
+ let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(url.href)})`;
51
+ if (options.import) {
52
+ line += `.then(mod => mod[${JSON.stringify(options.import)}])`;
53
+ }
54
+ code += `${line}, `;
55
+ }
56
+ code += "}";
57
+ return code;
58
+ }
59
+
60
+ // src/plugins/vite.ts
61
+ import path2 from "path";
62
+ function vite(options) {
63
+ let config;
64
+ return {
65
+ config(v) {
66
+ config = v;
67
+ },
68
+ emit() {
69
+ return [
70
+ {
71
+ path: "index.ts",
72
+ content: indexFile(this.configPath, this.outDir, config, options)
73
+ }
74
+ ];
75
+ }
76
+ };
77
+ }
78
+ function indexFile(configPath, outDir, config, options) {
79
+ const { addJsExtension = false, runtime } = options;
80
+ const lines = [
81
+ '/// <reference types="vite/client" />',
82
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
83
+ `import type * as Config from '${toImportPath(configPath, {
84
+ relativeTo: outDir,
85
+ jsExtension: addJsExtension
86
+ })}';`,
87
+ "",
88
+ `export const create = fromConfig<typeof Config>();`
89
+ ];
90
+ function docs(name, collection) {
91
+ const obj = [
92
+ ident(`doc: ${doc(name, collection.docs)}`),
93
+ ident(`meta: ${meta(name, collection.meta)}`)
94
+ ].join(",\n");
95
+ return `{
96
+ ${obj}
97
+ }`;
98
+ }
99
+ function doc(name, collection) {
100
+ const patterns = getGlobPatterns(collection);
101
+ const base = getGlobBase(collection);
102
+ const docGlob = generateGlob(patterns, {
103
+ query: {
104
+ collection: name
105
+ },
106
+ base
107
+ });
108
+ if (collection.async) {
109
+ const headBlob = generateGlob(patterns, {
110
+ query: {
111
+ only: "frontmatter",
112
+ collection: name
113
+ },
114
+ import: "frontmatter",
115
+ base
116
+ });
117
+ return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
118
+ }
119
+ return `create.doc("${name}", "${base}", ${docGlob})`;
120
+ }
121
+ function meta(name, collection) {
122
+ const patterns = getGlobPatterns(collection);
123
+ const base = getGlobBase(collection);
124
+ return `create.meta("${name}", "${base}", ${generateGlob(patterns, {
125
+ import: "default",
126
+ base,
127
+ query: {
128
+ collection: name
129
+ }
130
+ })})`;
131
+ }
132
+ function generateGlob(patterns, options2) {
133
+ patterns = mapGlobPatterns(patterns);
134
+ if (runtime === "node" || runtime === "bun") {
135
+ return generateGlobImport(patterns, options2);
136
+ } else {
137
+ return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
138
+ {
139
+ ...options2,
140
+ base: path2.relative(outDir, options2.base)
141
+ },
142
+ null,
143
+ 2
144
+ )})`;
145
+ }
146
+ }
147
+ for (const [name, collection] of config.collections.entries()) {
148
+ let body;
149
+ if (collection.type === "docs") {
150
+ body = docs(name, collection);
151
+ } else if (collection.type === "meta") {
152
+ body = meta(name, collection);
153
+ } else {
154
+ body = doc(name, collection);
155
+ }
156
+ lines.push("");
157
+ lines.push(`export const ${name} = ${body};`);
158
+ }
159
+ return lines.join("\n");
160
+ }
161
+ function mapGlobPatterns(patterns) {
162
+ return patterns.map(enforceRelative);
163
+ }
164
+ function enforceRelative(file) {
165
+ if (file.startsWith("./")) return file;
166
+ if (file.startsWith("/")) return `.${file}`;
167
+ return `./${file}`;
168
+ }
169
+ function getGlobBase(collection) {
170
+ let dir = collection.dir;
171
+ if (Array.isArray(dir)) {
172
+ if (dir.length !== 1)
173
+ throw new Error(
174
+ `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
175
+ );
176
+ dir = dir[0];
177
+ }
178
+ return enforceRelative(dir);
179
+ }
180
+
181
+ // src/vite/index.ts
182
+ var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
183
+ async function mdx(config, pluginOptions = {}) {
184
+ const options = applyDefaults(pluginOptions);
185
+ const core = await createViteCore(options).init({
186
+ config: buildConfig(config)
187
+ });
188
+ const mdxLoader = toVite(createMdxLoader(core.creatConfigLoader()));
189
+ async function transformMeta(path4, query, value) {
190
+ const isJson = path4.endsWith(".json");
191
+ const parsed = parse(query);
192
+ const collection = parsed.collection ? core.getConfig().collections.get(parsed.collection) : void 0;
193
+ if (!collection) return null;
194
+ let schema;
195
+ switch (collection.type) {
196
+ case "meta":
197
+ schema = collection.schema;
198
+ break;
199
+ case "docs":
200
+ schema = collection.meta.schema;
201
+ break;
202
+ }
203
+ if (!schema) return null;
204
+ let data;
205
+ try {
206
+ data = isJson ? JSON.parse(value) : load(value);
207
+ } catch {
208
+ return null;
209
+ }
210
+ const out = await validate(
211
+ schema,
212
+ data,
213
+ { path: path4, source: value },
214
+ `invalid data in ${path4}`
215
+ );
216
+ return {
217
+ code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
218
+ map: null
219
+ };
220
+ }
221
+ return {
222
+ name: "fumadocs-mdx",
223
+ // needed, otherwise other plugins will be executed before our `transform`.
224
+ enforce: "pre",
225
+ config(config2) {
226
+ if (!options.updateViteConfig) return config2;
227
+ return mergeConfig(config2, {
228
+ optimizeDeps: {
229
+ exclude: FumadocsDeps
230
+ },
231
+ resolve: {
232
+ noExternal: FumadocsDeps,
233
+ dedupe: FumadocsDeps
234
+ }
235
+ });
236
+ },
237
+ async buildStart() {
238
+ await core.emitAndWrite();
239
+ },
240
+ async configureServer(server) {
241
+ await core.initServer({
242
+ watcher: server.watcher
243
+ });
244
+ },
245
+ async transform(value, id) {
246
+ const [file, query = ""] = id.split("?");
247
+ const ext = path3.extname(file);
248
+ try {
249
+ if ([".yaml", ".json"].includes(ext))
250
+ return await transformMeta(file, query, value);
251
+ if ([".md", ".mdx"].includes(ext))
252
+ return await mdxLoader.call(this, file, query, value);
253
+ } catch (e) {
254
+ if (e instanceof ValidationError) {
255
+ throw new Error(e.toStringFormatted());
256
+ }
257
+ throw e;
258
+ }
259
+ }
260
+ };
261
+ }
262
+ async function postInstall(configPath = findConfigFile(), pluginOptions = {}) {
263
+ const { loadConfig } = await import("../load-MNG3CLET.js");
264
+ const options = applyDefaults(pluginOptions);
265
+ const core = await createViteCore(options).init({
266
+ config: loadConfig(configPath, options.outDir, true)
267
+ });
268
+ await core.emitAndWrite();
269
+ }
270
+ function createViteCore({
271
+ configPath,
272
+ outDir,
273
+ generateIndexFile
274
+ }) {
275
+ return createCore(
276
+ {
277
+ environment: "vite",
278
+ configPath,
279
+ outDir
280
+ },
281
+ [
282
+ generateIndexFile !== false && vite(typeof generateIndexFile === "object" ? generateIndexFile : {})
283
+ ]
284
+ );
285
+ }
286
+ function applyDefaults(options) {
287
+ return {
288
+ updateViteConfig: options.updateViteConfig ?? true,
289
+ generateIndexFile: options.generateIndexFile ?? true,
290
+ configPath: options.configPath ?? "source.config.ts",
291
+ outDir: options.outDir ?? ".source"
292
+ };
293
+ }
294
+ export {
295
+ mdx as default,
296
+ postInstall
297
+ };