fumadocs-mdx 11.6.11 → 11.7.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 (34) hide show
  1. package/dist/{chunk-64MMPGML.js → chunk-2CSSQTP6.js} +1 -10
  2. package/dist/{chunk-SXOJYWZ3.js → chunk-2KBRPMAM.js} +1 -1
  3. package/dist/{chunk-6PDS7MUA.js → chunk-C5INPAZJ.js} +4 -4
  4. package/dist/{chunk-DRVUBK5B.js → chunk-GWR7KMRU.js} +13 -1
  5. package/dist/chunk-OWZSTKKX.js +58 -0
  6. package/dist/{chunk-22SBT5SQ.js → chunk-ZOWJF3OH.js} +6 -6
  7. package/dist/config/index.cjs +4 -19
  8. package/dist/config/index.d.cts +3 -7
  9. package/dist/config/index.d.ts +3 -7
  10. package/dist/config/index.js +7 -13
  11. package/dist/{types-DVeuYiq5.d.cts → define-CCrinVBZ.d.cts} +37 -119
  12. package/dist/{types-DVeuYiq5.d.ts → define-CCrinVBZ.d.ts} +37 -119
  13. package/dist/index.d.cts +6 -7
  14. package/dist/index.d.ts +6 -7
  15. package/dist/loader-mdx.cjs +155 -134
  16. package/dist/loader-mdx.js +7 -10
  17. package/dist/mdx-options-UDV5WEFU.js +6 -0
  18. package/dist/next/index.cjs +253 -85
  19. package/dist/next/index.js +49 -63
  20. package/dist/runtime/async.cjs +167 -15
  21. package/dist/runtime/async.d.cts +5 -6
  22. package/dist/runtime/async.d.ts +5 -6
  23. package/dist/runtime/async.js +24 -15
  24. package/dist/runtime/vite.cjs +150 -0
  25. package/dist/runtime/vite.d.cts +71 -0
  26. package/dist/runtime/vite.d.ts +71 -0
  27. package/dist/runtime/vite.js +123 -0
  28. package/dist/{types-HIdjlLo0.d.ts → types-C0bKwtAx.d.ts} +38 -50
  29. package/dist/{types-BcUhOIxN.d.cts → types-CnslxmoO.d.cts} +38 -50
  30. package/dist/vite/index.cjs +385 -134
  31. package/dist/vite/index.d.cts +12 -3
  32. package/dist/vite/index.d.ts +12 -3
  33. package/dist/vite/index.js +165 -20
  34. package/package.json +20 -10
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,10 +30,138 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
33
+ // src/mdx-plugins/remark-exports.ts
34
+ function remarkMdxExport({ values }) {
35
+ return (tree, vfile) => {
36
+ for (const name of values) {
37
+ if (!(name in vfile.data)) return;
38
+ tree.children.unshift(getMdastExport(name, vfile.data[name]));
39
+ }
40
+ };
41
+ }
42
+ function getMdastExport(name, value) {
43
+ return {
44
+ type: "mdxjsEsm",
45
+ value: "",
46
+ data: {
47
+ estree: {
48
+ type: "Program",
49
+ sourceType: "module",
50
+ body: [
51
+ {
52
+ type: "ExportNamedDeclaration",
53
+ specifiers: [],
54
+ source: null,
55
+ declaration: {
56
+ type: "VariableDeclaration",
57
+ kind: "let",
58
+ declarations: [
59
+ {
60
+ type: "VariableDeclarator",
61
+ id: {
62
+ type: "Identifier",
63
+ name
64
+ },
65
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ };
74
+ }
75
+ var import_estree_util_value_to_estree;
76
+ var init_remark_exports = __esm({
77
+ "src/mdx-plugins/remark-exports.ts"() {
78
+ "use strict";
79
+ import_estree_util_value_to_estree = require("estree-util-value-to-estree");
80
+ }
81
+ });
82
+
83
+ // src/utils/mdx-options.ts
84
+ var mdx_options_exports = {};
85
+ __export(mdx_options_exports, {
86
+ getDefaultMDXOptions: () => getDefaultMDXOptions
87
+ });
88
+ function pluginOption(def, options = []) {
89
+ const list = def(Array.isArray(options) ? options : []).filter(
90
+ Boolean
91
+ );
92
+ if (typeof options === "function") {
93
+ return options(list);
94
+ }
95
+ return list;
96
+ }
97
+ function getDefaultMDXOptions({
98
+ valueToExport = [],
99
+ rehypeCodeOptions,
100
+ remarkImageOptions,
101
+ remarkHeadingOptions,
102
+ remarkStructureOptions,
103
+ remarkCodeTabOptions,
104
+ remarkNpmOptions,
105
+ ...mdxOptions
106
+ }) {
107
+ const mdxExports = [
108
+ "structuredData",
109
+ "frontmatter",
110
+ "lastModified",
111
+ ...valueToExport
112
+ ];
113
+ const remarkPlugins = pluginOption(
114
+ (v) => [
115
+ plugins.remarkGfm,
116
+ [
117
+ plugins.remarkHeading,
118
+ {
119
+ generateToc: false,
120
+ ...remarkHeadingOptions
121
+ }
122
+ ],
123
+ remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
124
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
125
+ plugins.remarkCodeTab,
126
+ remarkCodeTabOptions
127
+ ],
128
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
129
+ ...v,
130
+ remarkStructureOptions !== false && [
131
+ plugins.remarkStructure,
132
+ remarkStructureOptions
133
+ ],
134
+ [remarkMdxExport, { values: mdxExports }]
135
+ ],
136
+ mdxOptions.remarkPlugins
137
+ );
138
+ const rehypePlugins = pluginOption(
139
+ (v) => [
140
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
141
+ ...v,
142
+ plugins.rehypeToc
143
+ ],
144
+ mdxOptions.rehypePlugins
145
+ );
146
+ return {
147
+ ...mdxOptions,
148
+ remarkPlugins,
149
+ rehypePlugins
150
+ };
151
+ }
152
+ var plugins;
153
+ var init_mdx_options = __esm({
154
+ "src/utils/mdx-options.ts"() {
155
+ "use strict";
156
+ plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
157
+ init_remark_exports();
158
+ }
159
+ });
160
+
30
161
  // src/vite/index.ts
31
162
  var vite_exports = {};
32
163
  __export(vite_exports, {
33
- default: () => unstable_mdx
164
+ default: () => mdx
34
165
  });
35
166
  module.exports = __toCommonJS(vite_exports);
36
167
 
@@ -61,11 +192,23 @@ function buildConfig(config) {
61
192
  null
62
193
  ];
63
194
  }
195
+ let cachedMdxOptions;
64
196
  return [
65
197
  null,
66
198
  {
67
199
  global: globalConfig,
68
- collections
200
+ collections,
201
+ async getDefaultMDXOptions() {
202
+ if (cachedMdxOptions) return cachedMdxOptions;
203
+ const input = this.global?.mdxOptions;
204
+ async function uncached() {
205
+ const options = typeof input === "function" ? await input() : input;
206
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
207
+ if (options?.preset === "minimal") return options;
208
+ return getDefaultMDXOptions2(options ?? {});
209
+ }
210
+ return cachedMdxOptions = uncached();
211
+ }
69
212
  }
70
213
  ];
71
214
  }
@@ -168,10 +311,10 @@ ${e instanceof Error ? e.message : String(e)}`
168
311
  // src/utils/build-mdx.ts
169
312
  var cache = /* @__PURE__ */ new Map();
170
313
  async function buildMDX(cacheKey, source, options) {
171
- const { filePath, frontmatter, data, ...rest } = options;
314
+ const { filePath, frontmatter, data, _compiler, ...rest } = options;
172
315
  let format = options.format;
173
- if (!format && filePath) {
174
- format = filePath.endsWith(".mdx") ? "mdx" : "md";
316
+ if (filePath) {
317
+ format ??= filePath.endsWith(".mdx") ? "mdx" : "md";
175
318
  }
176
319
  format ??= "mdx";
177
320
  const key = `${cacheKey}:${format}`;
@@ -191,7 +334,7 @@ async function buildMDX(cacheKey, source, options) {
191
334
  data: {
192
335
  ...data,
193
336
  frontmatter,
194
- _compiler: options._compiler
337
+ _compiler
195
338
  }
196
339
  });
197
340
  }
@@ -208,166 +351,239 @@ function countLines(s) {
208
351
  return num;
209
352
  }
210
353
 
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
- }
354
+ // src/utils/schema.ts
355
+ var import_zod = require("zod");
356
+ var import_picocolors = __toESM(require("picocolors"), 1);
357
+ var metaSchema = import_zod.z.object({
358
+ title: import_zod.z.string().optional(),
359
+ pages: import_zod.z.array(import_zod.z.string()).optional(),
360
+ description: import_zod.z.string().optional(),
361
+ root: import_zod.z.boolean().optional(),
362
+ defaultOpen: import_zod.z.boolean().optional(),
363
+ icon: import_zod.z.string().optional()
364
+ });
365
+ var frontmatterSchema = import_zod.z.object({
366
+ title: import_zod.z.string(),
367
+ description: import_zod.z.string().optional(),
368
+ icon: import_zod.z.string().optional(),
369
+ full: import_zod.z.boolean().optional(),
370
+ // Fumadocs OpenAPI generated
371
+ _openapi: import_zod.z.looseObject({}).optional()
372
+ });
373
+ var ValidationError = class extends Error {
374
+ constructor(message, issues) {
375
+ super(
376
+ `${message}:
377
+ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
378
+ );
379
+ this.title = message;
380
+ this.issues = issues;
381
+ }
382
+ toStringFormatted() {
383
+ return [
384
+ import_picocolors.default.bold(`[MDX] ${this.title}:`),
385
+ ...this.issues.map(
386
+ (issue) => import_picocolors.default.redBright(
387
+ `- ${import_picocolors.default.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
388
+ )
389
+ )
390
+ ].join("\n");
391
+ }
392
+ };
393
+ async function validate(schema, data, context, errorMessage) {
394
+ if (typeof schema === "function" && !("~standard" in schema)) {
395
+ schema = schema(context);
396
+ }
397
+ if ("~standard" in schema) {
398
+ const result = await schema["~standard"].validate(
399
+ data
400
+ );
401
+ if (result.issues) {
402
+ throw new ValidationError(errorMessage, result.issues);
254
403
  }
255
- };
404
+ return result.value;
405
+ }
406
+ return data;
256
407
  }
257
408
 
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);
409
+ // src/vite/index.ts
410
+ var import_zod2 = require("zod");
411
+
412
+ // src/utils/import-formatter.ts
413
+ var import_node_path = __toESM(require("path"), 1);
414
+ function toImportPath(file, config) {
415
+ const ext = import_node_path.default.extname(file);
416
+ const filename = ext === ".ts" ? file.substring(0, file.length - ext.length) : file;
417
+ let importPath;
418
+ if ("relativeTo" in config) {
419
+ importPath = import_node_path.default.relative(config.relativeTo, filename);
420
+ if (!import_node_path.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
421
+ importPath = `./${importPath}`;
422
+ }
423
+ } else {
424
+ importPath = import_node_path.default.resolve(filename);
265
425
  }
266
- return list;
426
+ return importPath.replaceAll(import_node_path.default.sep, "/");
267
427
  }
268
- function getDefaultMDXOptions({
269
- valueToExport = [],
270
- rehypeCodeOptions,
271
- remarkImageOptions,
272
- remarkHeadingOptions,
273
- remarkStructureOptions,
274
- remarkCodeTabOptions,
275
- remarkNpmOptions,
276
- ...mdxOptions
277
- }) {
278
- const mdxExports = [
279
- "structuredData",
280
- "frontmatter",
281
- "lastModified",
282
- ...valueToExport
283
- ];
284
- const remarkPlugins = pluginOption(
285
- (v) => [
286
- plugins.remarkGfm,
287
- [
288
- plugins.remarkHeading,
289
- {
290
- generateToc: false,
291
- ...remarkHeadingOptions
292
- }
293
- ],
294
- remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
295
- "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
296
- plugins.remarkCodeTab,
297
- remarkCodeTabOptions
298
- ],
299
- "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
300
- ...v,
301
- remarkStructureOptions !== false && [
302
- plugins.remarkStructure,
303
- remarkStructureOptions
304
- ],
305
- [remarkMdxExport, { values: mdxExports }]
306
- ],
307
- mdxOptions.remarkPlugins
308
- );
309
- const rehypePlugins = pluginOption(
310
- (v) => [
311
- rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
312
- ...v,
313
- plugins.rehypeToc
314
- ],
315
- mdxOptions.rehypePlugins
316
- );
428
+ function ident(code, tab = 1) {
429
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
430
+ }
431
+
432
+ // src/vite/index.ts
433
+ var import_promises = __toESM(require("fs/promises"), 1);
434
+ var import_node_path2 = __toESM(require("path"), 1);
435
+ var import_js_yaml2 = require("js-yaml");
436
+
437
+ // src/utils/collections.ts
438
+ function getSupportedFormats(collection) {
317
439
  return {
318
- ...mdxOptions,
319
- remarkPlugins,
320
- rehypePlugins
321
- };
440
+ doc: ["mdx", "md"],
441
+ meta: ["json", "yaml"]
442
+ }[collection.type];
322
443
  }
323
- async function loadDefaultOptions(config) {
324
- const input = config.global?.mdxOptions;
325
- config._mdx_loader ??= {};
326
- const mdxLoader = config._mdx_loader;
327
- if (!mdxLoader.cachedOptions) {
328
- mdxLoader.cachedOptions = typeof input === "function" ? getDefaultMDXOptions(await input()) : getDefaultMDXOptions(input ?? {});
329
- }
330
- return mdxLoader.cachedOptions;
444
+ function getGlobPatterns(collection) {
445
+ if (collection.files) return collection.files;
446
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
331
447
  }
332
448
 
333
449
  // src/vite/index.ts
334
450
  var fileRegex = /\.(md|mdx)$/;
335
- function unstable_mdx(config, _options = {}) {
451
+ var onlySchema = import_zod2.z.literal(["frontmatter", "all"]);
452
+ function mdx(config, options = {}) {
453
+ const { generateIndexFile = true, configPath = "source.config.ts" } = options;
336
454
  const [err, loaded] = buildConfig(config);
337
455
  if (err || !loaded) {
338
456
  throw new Error(err);
339
457
  }
340
458
  return {
341
459
  name: "fumadocs-mdx",
342
- // 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`.
343
- // at the moment, RR and Tanstack Start has no stable support for RSC yet.
460
+ // needed, otherwise other plugins will be executed before our `transform`.
461
+ enforce: "pre",
462
+ async buildStart() {
463
+ if (!generateIndexFile) return;
464
+ console.log("[Fumadocs MDX] Generating index files");
465
+ const outdir = process.cwd();
466
+ const outFile = "source.generated.ts";
467
+ const lines = [
468
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
469
+ `import type * as Config from '${toImportPath(configPath, {
470
+ relativeTo: outdir
471
+ })}';`,
472
+ "",
473
+ `export const create = fromConfig<typeof Config>();`
474
+ ];
475
+ function docs(name, collection) {
476
+ const args = [
477
+ ident(`doc: ${generateGlob(name, collection.docs)}`),
478
+ ident(`meta: ${generateGlob(name, collection.meta)}`)
479
+ ].join(",\n");
480
+ return `export const ${name} = create.docs("${name}", {
481
+ ${args}
482
+ });`;
483
+ }
484
+ function doc(name, collection) {
485
+ return `export const ${name} = create.doc("${name}", ${generateGlob(name, collection)});`;
486
+ }
487
+ function meta(name, collection) {
488
+ return `export const ${name} = create.meta("${name}", ${generateGlob(name, collection)});`;
489
+ }
490
+ for (const [name, collection] of loaded.collections.entries()) {
491
+ lines.push("");
492
+ if (collection.type === "docs") {
493
+ lines.push(docs(name, collection));
494
+ } else if (collection.type === "meta") {
495
+ lines.push(meta(name, collection));
496
+ } else {
497
+ lines.push(doc(name, collection));
498
+ }
499
+ }
500
+ await import_promises.default.writeFile(import_node_path2.default.join(outdir, outFile), lines.join("\n"));
501
+ },
344
502
  async transform(value, id) {
345
- const [path2, query = ""] = id.split("?");
346
- if (!fileRegex.test(path2)) return;
503
+ const [path4, query = ""] = id.split("?");
504
+ const isJson = path4.endsWith(".json");
505
+ const isYaml = path4.endsWith(".yaml");
506
+ if (isJson || isYaml) {
507
+ const parsed2 = (0, import_node_querystring.parse)(query);
508
+ const collection2 = parsed2.collection ? loaded.collections.get(parsed2.collection) : void 0;
509
+ if (!collection2) return null;
510
+ let schema2;
511
+ switch (collection2.type) {
512
+ case "meta":
513
+ schema2 = collection2.schema;
514
+ break;
515
+ case "docs":
516
+ schema2 = collection2.meta.schema;
517
+ break;
518
+ }
519
+ if (!schema2) return null;
520
+ let data;
521
+ try {
522
+ data = isJson ? JSON.parse(value) : (0, import_js_yaml2.load)(value);
523
+ } catch {
524
+ return null;
525
+ }
526
+ const out = await validate(
527
+ schema2,
528
+ data,
529
+ { path: path4, source: value },
530
+ `invalid data in ${path4}`
531
+ );
532
+ return {
533
+ code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
534
+ map: null
535
+ };
536
+ }
537
+ if (!fileRegex.test(path4)) return;
347
538
  const matter = fumaMatter(value);
348
539
  const isDevelopment = this.environment.mode === "dev";
349
- const { collection: collectionId, raw } = (0, import_node_querystring.parse)(query);
350
- const collection = collectionId ? loaded.collections.get(collectionId) : void 0;
351
- const lineOffset = "\n".repeat(
352
- isDevelopment ? countLines(matter.matter) : 0
353
- );
540
+ const parsed = (0, import_node_querystring.parse)(query);
541
+ const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
542
+ const only = parsed.only ? onlySchema.parse(parsed.only) : "all";
543
+ let schema;
354
544
  let mdxOptions;
355
545
  switch (collection?.type) {
356
546
  case "doc":
357
547
  mdxOptions = collection.mdxOptions;
548
+ schema = collection.schema;
358
549
  break;
359
550
  case "docs":
360
551
  mdxOptions = collection.docs.mdxOptions;
552
+ schema = collection.docs.schema;
361
553
  break;
362
554
  }
363
- mdxOptions ??= await loadDefaultOptions(loaded);
555
+ if (schema) {
556
+ try {
557
+ matter.data = await validate(
558
+ schema,
559
+ matter.data,
560
+ {
561
+ source: value,
562
+ path: path4
563
+ },
564
+ `invalid frontmatter in ${path4}`
565
+ );
566
+ } catch (e) {
567
+ if (e instanceof ValidationError) {
568
+ throw new Error(e.toStringFormatted());
569
+ }
570
+ throw e;
571
+ }
572
+ }
573
+ if (only === "frontmatter") {
574
+ return {
575
+ code: `export const frontmatter = ${JSON.stringify(matter.data)}`
576
+ };
577
+ }
578
+ mdxOptions ??= await loaded.getDefaultMDXOptions();
579
+ const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
364
580
  const file = await buildMDX(
365
- collectionId ?? "global",
366
- lineOffset + matter.content,
581
+ parsed.collection ?? "global",
582
+ "\n".repeat(lineOffset) + matter.content,
367
583
  {
368
584
  development: isDevelopment,
369
585
  ...mdxOptions,
370
- filePath: path2,
586
+ filePath: path4,
371
587
  frontmatter: matter.data,
372
588
  _compiler: {
373
589
  addDependency: (file2) => {
@@ -377,8 +593,43 @@ function unstable_mdx(config, _options = {}) {
377
593
  }
378
594
  );
379
595
  return {
380
- code: typeof raw === "string" ? `export default ${JSON.stringify(file.value)}` : String(file.value)
596
+ code: String(file.value),
597
+ map: file.map
381
598
  };
382
599
  }
383
600
  };
384
601
  }
602
+ function generateGlob(name, collection) {
603
+ const patterns = mapGlobPatterns(getGlobPatterns(collection));
604
+ const options = {
605
+ query: {
606
+ collection: name
607
+ },
608
+ base: getGlobBase(collection)
609
+ };
610
+ if (collection.type === "meta") {
611
+ options.import = "default";
612
+ }
613
+ return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(options, null, 2)})`;
614
+ }
615
+ function mapGlobPatterns(patterns) {
616
+ return patterns.map((file) => {
617
+ if (file.startsWith("./")) return file;
618
+ if (file.startsWith("/")) return `.${file}`;
619
+ return `./${file}`;
620
+ });
621
+ }
622
+ function getGlobBase(collection) {
623
+ let dir = collection.dir;
624
+ if (Array.isArray(dir)) {
625
+ if (dir.length !== 1)
626
+ throw new Error(
627
+ `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
628
+ );
629
+ dir = dir[0];
630
+ }
631
+ if (!dir.startsWith("./") && !dir.startsWith("/")) {
632
+ return "/" + dir;
633
+ }
634
+ return dir;
635
+ }
@@ -1,8 +1,17 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
- interface CreateMDXOptions {
3
+ interface PluginOptions {
4
+ /**
5
+ * Automatically generate index files for accessing files with `import.meta.glob`.
6
+ *
7
+ * @defaultValue true
8
+ */
9
+ generateIndexFile?: boolean;
10
+ /**
11
+ * @defaultValue source.config.ts
12
+ */
4
13
  configPath?: string;
5
14
  }
6
- declare function unstable_mdx(config: Record<string, unknown>, _options?: CreateMDXOptions): Plugin;
15
+ declare function mdx(config: Record<string, unknown>, options?: PluginOptions): Plugin;
7
16
 
8
- export { type CreateMDXOptions, unstable_mdx as default };
17
+ export { type PluginOptions, mdx as default };
@@ -1,8 +1,17 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
- interface CreateMDXOptions {
3
+ interface PluginOptions {
4
+ /**
5
+ * Automatically generate index files for accessing files with `import.meta.glob`.
6
+ *
7
+ * @defaultValue true
8
+ */
9
+ generateIndexFile?: boolean;
10
+ /**
11
+ * @defaultValue source.config.ts
12
+ */
4
13
  configPath?: string;
5
14
  }
6
- declare function unstable_mdx(config: Record<string, unknown>, _options?: CreateMDXOptions): Plugin;
15
+ declare function mdx(config: Record<string, unknown>, options?: PluginOptions): Plugin;
7
16
 
8
- export { type CreateMDXOptions, unstable_mdx as default };
17
+ export { type PluginOptions, mdx as default };