fumadocs-mdx 11.6.8 → 11.6.9

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.
@@ -1,60 +1,13 @@
1
- import { ProcessorOptions } from '@mdx-js/mdx';
2
1
  import { MDXProps } from 'mdx/types';
3
2
  import * as plugins from 'fumadocs-core/mdx-plugins';
4
3
  import { StructuredData } from 'fumadocs-core/mdx-plugins';
5
4
  import { TableOfContents } from 'fumadocs-core/server';
5
+ import { ProcessorOptions } from '@mdx-js/mdx';
6
6
  import { Pluggable } from 'unified';
7
7
  import { FC } from 'react';
8
8
  import { z } from 'zod';
9
9
  import { StandardSchemaV1 } from '@standard-schema/spec';
10
-
11
- type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
12
- type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
13
- rehypePlugins?: ResolvePlugins;
14
- remarkPlugins?: ResolvePlugins;
15
- /**
16
- * Properties to export from `vfile.data`
17
- */
18
- valueToExport?: string[];
19
- remarkStructureOptions?: plugins.StructureOptions | false;
20
- remarkHeadingOptions?: plugins.RemarkHeadingOptions;
21
- remarkImageOptions?: plugins.RemarkImageOptions | false;
22
- remarkCodeTabOptions?: plugins.RemarkCodeTabOptions | false;
23
- rehypeCodeOptions?: plugins.RehypeCodeOptions | false;
24
- };
25
- declare function getDefaultMDXOptions({ valueToExport, rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, remarkCodeTabOptions, ...mdxOptions }: DefaultMDXOptions): ProcessorOptions;
26
-
27
- interface GlobalConfig {
28
- /**
29
- * Configure global MDX options
30
- */
31
- mdxOptions?: DefaultMDXOptions | (() => DefaultMDXOptions | Promise<DefaultMDXOptions>);
32
- /**
33
- * Fetch last modified time with specified version control
34
- * @defaultValue 'none'
35
- */
36
- lastModifiedTime?: 'git' | 'none';
37
- }
38
- interface FileInfo {
39
- path: string;
40
- absolutePath: string;
41
- }
42
- interface MarkdownProps {
43
- body: FC<MDXProps>;
44
- structuredData: StructuredData;
45
- toc: TableOfContents;
46
- _exports: Record<string, unknown>;
47
- /**
48
- * Only available when `lastModifiedTime` is enabled on MDX loader
49
- */
50
- lastModified?: Date;
51
- }
52
- interface BaseCollectionEntry {
53
- /**
54
- * Raw file path of collection entry, including absolute path (not normalized).
55
- */
56
- _file: FileInfo;
57
- }
10
+ import { MDXOptions as MDXOptions$1 } from '@fumadocs/mdx-remote';
58
11
 
59
12
  interface MDXOptions extends ProcessorOptions {
60
13
  /**
@@ -94,17 +47,17 @@ declare const metaSchema: z.ZodObject<{
94
47
  }, "strip", z.ZodTypeAny, {
95
48
  root?: boolean | undefined;
96
49
  title?: string | undefined;
97
- icon?: string | undefined;
98
50
  pages?: string[] | undefined;
99
51
  description?: string | undefined;
100
52
  defaultOpen?: boolean | undefined;
53
+ icon?: string | undefined;
101
54
  }, {
102
55
  root?: boolean | undefined;
103
56
  title?: string | undefined;
104
- icon?: string | undefined;
105
57
  pages?: string[] | undefined;
106
58
  description?: string | undefined;
107
59
  defaultOpen?: boolean | undefined;
60
+ icon?: string | undefined;
108
61
  }>;
109
62
  declare const frontmatterSchema: z.ZodObject<{
110
63
  title: z.ZodString;
@@ -114,14 +67,14 @@ declare const frontmatterSchema: z.ZodObject<{
114
67
  _openapi: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
115
68
  }, "strip", z.ZodTypeAny, {
116
69
  title: string;
117
- icon?: string | undefined;
118
70
  description?: string | undefined;
71
+ icon?: string | undefined;
119
72
  full?: boolean | undefined;
120
73
  _openapi?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
121
74
  }, {
122
75
  title: string;
123
- icon?: string | undefined;
124
76
  description?: string | undefined;
77
+ icon?: string | undefined;
125
78
  full?: boolean | undefined;
126
79
  _openapi?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
127
80
  }>;
@@ -201,4 +154,63 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
201
154
  };
202
155
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
203
156
 
204
- export { type BaseCollectionEntry as B, type CollectionSchema as C, type DocCollection as D, type FileInfo as F, type GlobalConfig as G, type MarkdownProps as M, type BaseCollection as a, type MetaCollection as b, type DocsCollection as c, defineCollections as d, defineDocs as e, frontmatterSchema as f, defineConfig as g, type DefaultMDXOptions as h, getDefaultMDXOptions as i, metaSchema as m };
157
+ interface LoadedConfig {
158
+ collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
159
+ global?: GlobalConfig;
160
+ _mdx_loader?: {
161
+ cachedOptions?: ProcessorOptions;
162
+ };
163
+ _mdx_async?: {
164
+ cachedMdxOptions?: MDXOptions$1;
165
+ };
166
+ }
167
+
168
+ type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
169
+ type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
170
+ rehypePlugins?: ResolvePlugins;
171
+ remarkPlugins?: ResolvePlugins;
172
+ /**
173
+ * Properties to export from `vfile.data`
174
+ */
175
+ valueToExport?: string[];
176
+ remarkStructureOptions?: plugins.StructureOptions | false;
177
+ remarkHeadingOptions?: plugins.RemarkHeadingOptions;
178
+ remarkImageOptions?: plugins.RemarkImageOptions | false;
179
+ remarkCodeTabOptions?: plugins.RemarkCodeTabOptions | false;
180
+ rehypeCodeOptions?: plugins.RehypeCodeOptions | false;
181
+ };
182
+ declare function loadDefaultOptions(config: LoadedConfig): Promise<ProcessorOptions>;
183
+
184
+ interface GlobalConfig {
185
+ /**
186
+ * Configure global MDX options
187
+ */
188
+ mdxOptions?: DefaultMDXOptions | (() => DefaultMDXOptions | Promise<DefaultMDXOptions>);
189
+ /**
190
+ * Fetch last modified time with specified version control
191
+ * @defaultValue 'none'
192
+ */
193
+ lastModifiedTime?: 'git' | 'none';
194
+ }
195
+ interface FileInfo {
196
+ path: string;
197
+ absolutePath: string;
198
+ }
199
+ interface MarkdownProps {
200
+ body: FC<MDXProps>;
201
+ structuredData: StructuredData;
202
+ toc: TableOfContents;
203
+ _exports: Record<string, unknown>;
204
+ /**
205
+ * Only available when `lastModifiedTime` is enabled on MDX loader
206
+ */
207
+ lastModified?: Date;
208
+ }
209
+ interface BaseCollectionEntry {
210
+ /**
211
+ * Raw file path of collection entry, including absolute path (not normalized).
212
+ */
213
+ _file: FileInfo;
214
+ }
215
+
216
+ export { type BaseCollectionEntry as B, type CollectionSchema as C, type DefaultMDXOptions as D, type FileInfo as F, type GlobalConfig as G, type LoadedConfig as L, type MarkdownProps as M, type BaseCollection as a, type MetaCollection as b, type DocCollection as c, type DocsCollection as d, defineCollections as e, frontmatterSchema as f, defineDocs as g, defineConfig as h, loadDefaultOptions as l, metaSchema as m };
@@ -1,19 +1,6 @@
1
- import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-uoePrCQ_.js';
1
+ import { F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry, L as LoadedConfig } from './types-CDl6YYjj.js';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
4
- import { ProcessorOptions } from '@mdx-js/mdx';
5
- import { MDXOptions } from '@fumadocs/mdx-remote';
6
-
7
- interface LoadedConfig {
8
- collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
9
- global?: GlobalConfig;
10
- _mdx_loader?: {
11
- cachedOptions?: ProcessorOptions;
12
- };
13
- _mdx_async?: {
14
- cachedMdxOptions?: MDXOptions;
15
- };
16
- }
17
4
 
18
5
  interface RuntimeFile {
19
6
  info: FileInfo;
@@ -104,4 +91,4 @@ interface RuntimeAsync {
104
91
  } : never;
105
92
  }
106
93
 
107
- export type { LoadedConfig as L, Runtime as R, RuntimeAsync as a };
94
+ export type { Runtime as R, RuntimeAsync as a };
@@ -1,19 +1,6 @@
1
- import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-uoePrCQ_.cjs';
1
+ import { F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry, L as LoadedConfig } from './types-CDl6YYjj.cjs';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
4
- import { ProcessorOptions } from '@mdx-js/mdx';
5
- import { MDXOptions } from '@fumadocs/mdx-remote';
6
-
7
- interface LoadedConfig {
8
- collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
9
- global?: GlobalConfig;
10
- _mdx_loader?: {
11
- cachedOptions?: ProcessorOptions;
12
- };
13
- _mdx_async?: {
14
- cachedMdxOptions?: MDXOptions;
15
- };
16
- }
17
4
 
18
5
  interface RuntimeFile {
19
6
  info: FileInfo;
@@ -104,4 +91,4 @@ interface RuntimeAsync {
104
91
  } : never;
105
92
  }
106
93
 
107
- export type { LoadedConfig as L, Runtime as R, RuntimeAsync as a };
94
+ export type { Runtime as R, RuntimeAsync as a };
@@ -0,0 +1,383 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/vite/index.ts
31
+ var vite_exports = {};
32
+ __export(vite_exports, {
33
+ default: () => unstable_mdx
34
+ });
35
+ module.exports = __toCommonJS(vite_exports);
36
+
37
+ // src/config/build.ts
38
+ function buildConfig(config) {
39
+ const collections = /* @__PURE__ */ new Map();
40
+ let globalConfig;
41
+ for (const [k, v] of Object.entries(config)) {
42
+ if (!v) {
43
+ continue;
44
+ }
45
+ if (typeof v === "object" && "type" in v) {
46
+ if (v.type === "docs") {
47
+ collections.set(k, v);
48
+ continue;
49
+ }
50
+ if (v.type === "doc" || v.type === "meta") {
51
+ collections.set(k, v);
52
+ continue;
53
+ }
54
+ }
55
+ if (k === "default") {
56
+ globalConfig = v;
57
+ continue;
58
+ }
59
+ return [
60
+ `Unknown export "${k}", you can only export collections from source configuration file.`,
61
+ null
62
+ ];
63
+ }
64
+ return [
65
+ null,
66
+ {
67
+ global: globalConfig,
68
+ collections
69
+ }
70
+ ];
71
+ }
72
+
73
+ // src/utils/build-mdx.ts
74
+ var import_mdx = require("@mdx-js/mdx");
75
+
76
+ // src/mdx-plugins/remark-include.ts
77
+ var import_unist_util_visit = require("unist-util-visit");
78
+ var path = __toESM(require("path"), 1);
79
+ var fs = __toESM(require("fs/promises"), 1);
80
+
81
+ // src/utils/fuma-matter.ts
82
+ var import_js_yaml = require("js-yaml");
83
+ var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
84
+ function fumaMatter(input) {
85
+ const output = { matter: "", data: {}, content: input };
86
+ const match = regex.exec(input);
87
+ if (!match) {
88
+ return output;
89
+ }
90
+ output.matter = match[1];
91
+ output.content = input.slice(match[0].length);
92
+ const loaded = (0, import_js_yaml.load)(output.matter);
93
+ output.data = loaded ?? {};
94
+ return output;
95
+ }
96
+
97
+ // src/mdx-plugins/remark-include.ts
98
+ function flattenNode(node) {
99
+ if ("children" in node)
100
+ return node.children.map((child) => flattenNode(child)).join("");
101
+ if ("value" in node) return node.value;
102
+ return "";
103
+ }
104
+ function remarkInclude() {
105
+ const TagName = "include";
106
+ async function update(tree, file, processor, compiler) {
107
+ const queue = [];
108
+ (0, import_unist_util_visit.visit)(
109
+ tree,
110
+ ["mdxJsxFlowElement", "mdxJsxTextElement"],
111
+ (node, _, parent) => {
112
+ let specifier;
113
+ const params = {};
114
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
115
+ const value = flattenNode(node);
116
+ if (value.length > 0) {
117
+ for (const attr of node.attributes) {
118
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
119
+ params[attr.name] = attr.value;
120
+ }
121
+ }
122
+ specifier = value;
123
+ }
124
+ }
125
+ if (!specifier) return;
126
+ const targetPath = path.resolve(
127
+ "cwd" in params ? process.cwd() : path.dirname(file),
128
+ specifier
129
+ );
130
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
131
+ queue.push(
132
+ fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
133
+ compiler?.addDependency(targetPath);
134
+ if (asCode) {
135
+ const lang = params.lang ?? path.extname(specifier).slice(1);
136
+ Object.assign(node, {
137
+ type: "code",
138
+ lang,
139
+ meta: params.meta,
140
+ value: content.toString(),
141
+ data: {}
142
+ });
143
+ return;
144
+ }
145
+ const parsed = processor.parse(fumaMatter(content).content);
146
+ await update(parsed, targetPath, processor, compiler);
147
+ Object.assign(
148
+ parent && parent.type === "paragraph" ? parent : node,
149
+ parsed
150
+ );
151
+ }).catch((e) => {
152
+ throw new Error(
153
+ `failed to read file ${targetPath}
154
+ ${e instanceof Error ? e.message : String(e)}`
155
+ );
156
+ })
157
+ );
158
+ return "skip";
159
+ }
160
+ );
161
+ await Promise.all(queue);
162
+ }
163
+ return async (tree, file) => {
164
+ await update(tree, file.path, this, file.data._compiler);
165
+ };
166
+ }
167
+
168
+ // src/utils/build-mdx.ts
169
+ var cache = /* @__PURE__ */ new Map();
170
+ async function buildMDX(cacheKey, source, options) {
171
+ const { filePath, frontmatter, data, ...rest } = options;
172
+ let format = options.format;
173
+ if (!format && filePath) {
174
+ format = filePath.endsWith(".mdx") ? "mdx" : "md";
175
+ }
176
+ format ??= "mdx";
177
+ const key = `${cacheKey}:${format}`;
178
+ let cached = cache.get(key);
179
+ if (!cached) {
180
+ cached = (0, import_mdx.createProcessor)({
181
+ outputFormat: "program",
182
+ ...rest,
183
+ remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
184
+ format
185
+ });
186
+ cache.set(key, cached);
187
+ }
188
+ return cached.process({
189
+ value: source,
190
+ path: filePath,
191
+ data: {
192
+ ...data,
193
+ frontmatter,
194
+ _compiler: options._compiler
195
+ }
196
+ });
197
+ }
198
+
199
+ // src/vite/index.ts
200
+ var import_node_querystring = require("querystring");
201
+
202
+ // src/utils/count-lines.ts
203
+ function countLines(s) {
204
+ let num = 0;
205
+ for (const c of s) {
206
+ if (c === "\n") num++;
207
+ }
208
+ return num;
209
+ }
210
+
211
+ // src/utils/mdx-options.ts
212
+ var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
213
+
214
+ // src/mdx-plugins/remark-exports.ts
215
+ var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
216
+ function remarkMdxExport({ values }) {
217
+ return (tree, vfile) => {
218
+ for (const name of values) {
219
+ if (!(name in vfile.data)) return;
220
+ tree.children.unshift(getMdastExport(name, vfile.data[name]));
221
+ }
222
+ };
223
+ }
224
+ function getMdastExport(name, value) {
225
+ return {
226
+ type: "mdxjsEsm",
227
+ value: "",
228
+ data: {
229
+ estree: {
230
+ type: "Program",
231
+ sourceType: "module",
232
+ body: [
233
+ {
234
+ type: "ExportNamedDeclaration",
235
+ specifiers: [],
236
+ source: null,
237
+ declaration: {
238
+ type: "VariableDeclaration",
239
+ kind: "let",
240
+ declarations: [
241
+ {
242
+ type: "VariableDeclarator",
243
+ id: {
244
+ type: "Identifier",
245
+ name
246
+ },
247
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
248
+ }
249
+ ]
250
+ }
251
+ }
252
+ ]
253
+ }
254
+ }
255
+ };
256
+ }
257
+
258
+ // src/utils/mdx-options.ts
259
+ function pluginOption(def, options = []) {
260
+ const list = def(Array.isArray(options) ? options : []).filter(
261
+ Boolean
262
+ );
263
+ if (typeof options === "function") {
264
+ return options(list);
265
+ }
266
+ return list;
267
+ }
268
+ function getDefaultMDXOptions({
269
+ valueToExport = [],
270
+ rehypeCodeOptions,
271
+ remarkImageOptions,
272
+ remarkHeadingOptions,
273
+ remarkStructureOptions,
274
+ remarkCodeTabOptions,
275
+ ...mdxOptions
276
+ }) {
277
+ const mdxExports = [
278
+ "structuredData",
279
+ "frontmatter",
280
+ "lastModified",
281
+ ...valueToExport
282
+ ];
283
+ const remarkPlugins = pluginOption(
284
+ (v) => [
285
+ plugins.remarkGfm,
286
+ [
287
+ plugins.remarkHeading,
288
+ {
289
+ generateToc: false,
290
+ ...remarkHeadingOptions
291
+ }
292
+ ],
293
+ remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
294
+ // Fumadocs 14 compatibility
295
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
296
+ plugins.remarkCodeTab,
297
+ remarkCodeTabOptions
298
+ ],
299
+ ...v,
300
+ remarkStructureOptions !== false && [
301
+ plugins.remarkStructure,
302
+ remarkStructureOptions
303
+ ],
304
+ [remarkMdxExport, { values: mdxExports }]
305
+ ],
306
+ mdxOptions.remarkPlugins
307
+ );
308
+ const rehypePlugins = pluginOption(
309
+ (v) => [
310
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
311
+ ...v,
312
+ plugins.rehypeToc
313
+ ],
314
+ mdxOptions.rehypePlugins
315
+ );
316
+ return {
317
+ ...mdxOptions,
318
+ remarkPlugins,
319
+ rehypePlugins
320
+ };
321
+ }
322
+ async function loadDefaultOptions(config) {
323
+ const input = config.global?.mdxOptions;
324
+ config._mdx_loader ??= {};
325
+ const mdxLoader = config._mdx_loader;
326
+ if (!mdxLoader.cachedOptions) {
327
+ mdxLoader.cachedOptions = typeof input === "function" ? getDefaultMDXOptions(await input()) : getDefaultMDXOptions(input ?? {});
328
+ }
329
+ return mdxLoader.cachedOptions;
330
+ }
331
+
332
+ // src/vite/index.ts
333
+ var fileRegex = /\.(md|mdx)$/;
334
+ function unstable_mdx(config, _options = {}) {
335
+ const [err, loaded] = buildConfig(config);
336
+ if (err || !loaded) {
337
+ throw new Error(err);
338
+ }
339
+ return {
340
+ name: "fumadocs-mdx",
341
+ // TODO: need a way to generate .source folder that works for non-RSC based frameworks, currently, we need to dynamic import MDX files using `import.meta.glob`.
342
+ // at the moment, RR and Tanstack Start has no stable support for RSC yet.
343
+ async transform(value, id) {
344
+ const [path2, query = ""] = id.split("?");
345
+ if (!fileRegex.test(path2)) return;
346
+ const matter = fumaMatter(value);
347
+ const isDevelopment = this.environment.mode === "dev";
348
+ const { collection: collectionId, raw } = (0, import_node_querystring.parse)(query);
349
+ const collection = collectionId ? loaded.collections.get(collectionId) : void 0;
350
+ const lineOffset = "\n".repeat(
351
+ isDevelopment ? countLines(matter.matter) : 0
352
+ );
353
+ let mdxOptions;
354
+ switch (collection?.type) {
355
+ case "doc":
356
+ mdxOptions = collection.mdxOptions;
357
+ break;
358
+ case "docs":
359
+ mdxOptions = collection.docs.mdxOptions;
360
+ break;
361
+ }
362
+ mdxOptions ??= await loadDefaultOptions(loaded);
363
+ const file = await buildMDX(
364
+ collectionId ?? "global",
365
+ lineOffset + matter.content,
366
+ {
367
+ development: isDevelopment,
368
+ ...mdxOptions,
369
+ filePath: path2,
370
+ frontmatter: matter.data,
371
+ _compiler: {
372
+ addDependency: (file2) => {
373
+ this.addWatchFile(file2);
374
+ }
375
+ }
376
+ }
377
+ );
378
+ return {
379
+ code: typeof raw === "string" ? `export default ${JSON.stringify(file.value)}` : String(file.value)
380
+ };
381
+ }
382
+ };
383
+ }
@@ -0,0 +1,8 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface CreateMDXOptions {
4
+ configPath?: string;
5
+ }
6
+ declare function unstable_mdx(config: Record<string, unknown>, _options?: CreateMDXOptions): Plugin;
7
+
8
+ export { type CreateMDXOptions, unstable_mdx as default };
@@ -0,0 +1,8 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface CreateMDXOptions {
4
+ configPath?: string;
5
+ }
6
+ declare function unstable_mdx(config: Record<string, unknown>, _options?: CreateMDXOptions): Plugin;
7
+
8
+ export { type CreateMDXOptions, unstable_mdx as default };
@@ -0,0 +1,71 @@
1
+ import {
2
+ buildMDX,
3
+ countLines
4
+ } from "../chunk-6PDS7MUA.js";
5
+ import {
6
+ loadDefaultOptions
7
+ } from "../chunk-YRT4TZBA.js";
8
+ import "../chunk-AVMO2SRO.js";
9
+ import {
10
+ buildConfig
11
+ } from "../chunk-DRVUBK5B.js";
12
+ import {
13
+ fumaMatter
14
+ } from "../chunk-KVWX6THC.js";
15
+
16
+ // src/vite/index.ts
17
+ import { parse } from "querystring";
18
+ var fileRegex = /\.(md|mdx)$/;
19
+ function unstable_mdx(config, _options = {}) {
20
+ const [err, loaded] = buildConfig(config);
21
+ if (err || !loaded) {
22
+ throw new Error(err);
23
+ }
24
+ return {
25
+ name: "fumadocs-mdx",
26
+ // TODO: need a way to generate .source folder that works for non-RSC based frameworks, currently, we need to dynamic import MDX files using `import.meta.glob`.
27
+ // at the moment, RR and Tanstack Start has no stable support for RSC yet.
28
+ async transform(value, id) {
29
+ const [path, query = ""] = id.split("?");
30
+ if (!fileRegex.test(path)) return;
31
+ const matter = fumaMatter(value);
32
+ const isDevelopment = this.environment.mode === "dev";
33
+ const { collection: collectionId, raw } = parse(query);
34
+ const collection = collectionId ? loaded.collections.get(collectionId) : void 0;
35
+ const lineOffset = "\n".repeat(
36
+ isDevelopment ? countLines(matter.matter) : 0
37
+ );
38
+ let mdxOptions;
39
+ switch (collection?.type) {
40
+ case "doc":
41
+ mdxOptions = collection.mdxOptions;
42
+ break;
43
+ case "docs":
44
+ mdxOptions = collection.docs.mdxOptions;
45
+ break;
46
+ }
47
+ mdxOptions ??= await loadDefaultOptions(loaded);
48
+ const file = await buildMDX(
49
+ collectionId ?? "global",
50
+ lineOffset + matter.content,
51
+ {
52
+ development: isDevelopment,
53
+ ...mdxOptions,
54
+ filePath: path,
55
+ frontmatter: matter.data,
56
+ _compiler: {
57
+ addDependency: (file2) => {
58
+ this.addWatchFile(file2);
59
+ }
60
+ }
61
+ }
62
+ );
63
+ return {
64
+ code: typeof raw === "string" ? `export default ${JSON.stringify(file.value)}` : String(file.value)
65
+ };
66
+ }
67
+ };
68
+ }
69
+ export {
70
+ unstable_mdx as default
71
+ };