fumadocs-mdx 11.6.10 → 11.7.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 (36) 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-JPPCALFT.js +34 -0
  6. package/dist/{chunk-OTM6WYMS.js → chunk-ZOWJF3OH.js} +7 -7
  7. package/dist/config/index.cjs +6 -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 +8 -12
  11. package/dist/define-CCrinVBZ.d.cts +109 -0
  12. package/dist/define-CCrinVBZ.d.ts +109 -0
  13. package/dist/index.d.cts +6 -7
  14. package/dist/index.d.ts +6 -7
  15. package/dist/loader-mdx.cjs +156 -135
  16. package/dist/loader-mdx.js +7 -10
  17. package/dist/mdx-options-UDV5WEFU.js +6 -0
  18. package/dist/next/index.cjs +197 -54
  19. package/dist/next/index.js +7 -30
  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 +26 -17
  24. package/dist/runtime/vite.cjs +116 -0
  25. package/dist/runtime/vite.d.cts +47 -0
  26. package/dist/runtime/vite.d.ts +47 -0
  27. package/dist/runtime/vite.js +90 -0
  28. package/dist/{types-Dk7DhSKZ.d.ts → types-C0bKwtAx.d.ts} +38 -50
  29. package/dist/{types-ZwLebhOl.d.cts → types-CnslxmoO.d.cts} +38 -50
  30. package/dist/vite/index.cjs +384 -137
  31. package/dist/vite/index.d.cts +12 -3
  32. package/dist/vite/index.d.ts +12 -3
  33. package/dist/vite/index.js +177 -21
  34. package/package.json +20 -10
  35. package/dist/types-DvTNxAvo.d.cts +0 -217
  36. package/dist/types-DvTNxAvo.d.ts +0 -217
@@ -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,269 @@ 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
- };
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);
404
+ return result.value;
265
405
  }
266
- return list;
406
+ return data;
267
407
  }
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
- );
317
- return {
318
- ...mdxOptions,
319
- remarkPlugins,
320
- rehypePlugins
321
- };
322
- }
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 ?? {});
408
+
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);
329
425
  }
330
- return mdxLoader.cachedOptions;
426
+ return importPath.replaceAll(import_node_path.default.sep, "/");
331
427
  }
332
428
 
333
429
  // src/vite/index.ts
430
+ var import_promises = __toESM(require("fs/promises"), 1);
431
+ var import_node_path2 = __toESM(require("path"), 1);
432
+ var import_js_yaml2 = require("js-yaml");
334
433
  var fileRegex = /\.(md|mdx)$/;
335
- function unstable_mdx(config, _options = {}) {
434
+ var onlySchema = import_zod2.z.literal(["frontmatter", "all"]);
435
+ function mdx(config, options = {}) {
436
+ const { generateIndexFile = true, configPath = "source.config.ts" } = options;
336
437
  const [err, loaded] = buildConfig(config);
337
438
  if (err || !loaded) {
338
439
  throw new Error(err);
339
440
  }
340
441
  return {
341
442
  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.
443
+ // needed, otherwise other plugins will be executed before our `transform`.
444
+ enforce: "pre",
445
+ async buildStart() {
446
+ if (!generateIndexFile) return;
447
+ console.log("[Fumadocs MDX] Generating index files");
448
+ const outdir = process.cwd();
449
+ const outFile = "source.generated.ts";
450
+ const lines = [
451
+ `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
452
+ `import type * as Config from '${toImportPath(configPath, {
453
+ relativeTo: outdir
454
+ })}';`,
455
+ "",
456
+ `export const create = fromConfig<typeof Config>();`
457
+ ];
458
+ function filesToGlob(files) {
459
+ return files.map((file) => {
460
+ if (file.startsWith("./")) return file;
461
+ if (file.startsWith("/")) return `.${file}`;
462
+ return `./${file}`;
463
+ });
464
+ }
465
+ function docs(name, dir, collection) {
466
+ const docFiles = collection.docs.files ? filesToGlob(collection.docs.files) : ["./**/*.{mdx,md}"];
467
+ const metaFiles = collection.meta.files ? filesToGlob(collection.meta.files) : ["./**/*.{yaml,json}"];
468
+ return `export const ${name} = create.docs('${name}', {
469
+ doc: import.meta.glob(${JSON.stringify(docFiles)}, {
470
+ query: {
471
+ collection: '${name}',
472
+ },
473
+ base: '${dir}',
474
+ }),
475
+ meta: import.meta.glob(${JSON.stringify(metaFiles)}, {
476
+ query: {
477
+ collection: '${name}',
478
+ },
479
+ base: '${dir}',
480
+ import: 'default',
481
+ }),
482
+ });`;
483
+ }
484
+ function doc(name, dir, collection) {
485
+ const files = collection.files ? filesToGlob(collection.files) : ["./**/*.{mdx,md}"];
486
+ return `export const ${name} = create.doc(
487
+ '${name}',
488
+ import.meta.glob(${JSON.stringify(files)}, {
489
+ query: {
490
+ collection: '${name}',
491
+ },
492
+ base: '${dir}',
493
+ }),
494
+ );`;
495
+ }
496
+ function meta(name, dir, collection) {
497
+ const files = collection.files ? filesToGlob(collection.files) : ["./**/*.{yaml,json}"];
498
+ return `export const ${name} = create.meta(
499
+ '${name}',
500
+ import.meta.glob(${JSON.stringify(files)}, {
501
+ query: {
502
+ collection: '${name}',
503
+ },
504
+ base: '${dir}',
505
+ import: 'default',
506
+ }),
507
+ );`;
508
+ }
509
+ for (const [name, collection] of loaded.collections.entries()) {
510
+ let dir = collection.dir;
511
+ if (Array.isArray(dir) && dir.length === 1) {
512
+ dir = dir[0];
513
+ } else if (Array.isArray(dir)) {
514
+ throw new Error(
515
+ `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
516
+ );
517
+ }
518
+ if (!dir.startsWith("./") && !dir.startsWith("/")) {
519
+ dir = "/" + dir;
520
+ }
521
+ lines.push("");
522
+ if (collection.type === "docs") {
523
+ lines.push(docs(name, dir, collection));
524
+ } else if (collection.type === "meta") {
525
+ lines.push(meta(name, dir, collection));
526
+ } else {
527
+ lines.push(doc(name, dir, collection));
528
+ }
529
+ }
530
+ await import_promises.default.writeFile(import_node_path2.default.join(outdir, outFile), lines.join("\n"));
531
+ },
344
532
  async transform(value, id) {
345
- const [path2, query = ""] = id.split("?");
346
- if (!fileRegex.test(path2)) return;
533
+ const [path4, query = ""] = id.split("?");
534
+ const isJson = path4.endsWith(".json");
535
+ const isYaml = path4.endsWith(".yaml");
536
+ if (isJson || isYaml) {
537
+ const parsed2 = (0, import_node_querystring.parse)(query);
538
+ const collection2 = parsed2.collection ? loaded.collections.get(parsed2.collection) : void 0;
539
+ if (!collection2) return null;
540
+ let schema2;
541
+ switch (collection2.type) {
542
+ case "meta":
543
+ schema2 = collection2.schema;
544
+ break;
545
+ case "docs":
546
+ schema2 = collection2.meta.schema;
547
+ break;
548
+ }
549
+ if (!schema2) return null;
550
+ let data;
551
+ try {
552
+ data = isJson ? JSON.parse(value) : (0, import_js_yaml2.load)(value);
553
+ } catch {
554
+ return null;
555
+ }
556
+ const out = await validate(
557
+ schema2,
558
+ data,
559
+ { path: path4, source: value },
560
+ `invalid data in ${path4}`
561
+ );
562
+ return {
563
+ code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
564
+ map: null
565
+ };
566
+ }
567
+ if (!fileRegex.test(path4)) return;
347
568
  const matter = fumaMatter(value);
348
569
  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
- );
570
+ const parsed = (0, import_node_querystring.parse)(query);
571
+ const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
572
+ const only = parsed.only ? onlySchema.parse(parsed.only) : "all";
573
+ let schema;
354
574
  let mdxOptions;
355
575
  switch (collection?.type) {
356
576
  case "doc":
357
577
  mdxOptions = collection.mdxOptions;
578
+ schema = collection.schema;
358
579
  break;
359
580
  case "docs":
360
581
  mdxOptions = collection.docs.mdxOptions;
582
+ schema = collection.docs.schema;
361
583
  break;
362
584
  }
363
- mdxOptions ??= await loadDefaultOptions(loaded);
585
+ if (schema) {
586
+ try {
587
+ matter.data = await validate(
588
+ schema,
589
+ matter.data,
590
+ {
591
+ source: value,
592
+ path: path4
593
+ },
594
+ `invalid frontmatter in ${path4}`
595
+ );
596
+ } catch (e) {
597
+ if (e instanceof ValidationError) {
598
+ throw new Error(e.toStringFormatted());
599
+ }
600
+ throw e;
601
+ }
602
+ }
603
+ if (only === "frontmatter") {
604
+ return {
605
+ code: `export const frontmatter = ${JSON.stringify(matter.data)}`
606
+ };
607
+ }
608
+ mdxOptions ??= await loaded.getDefaultMDXOptions();
609
+ const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
364
610
  const file = await buildMDX(
365
- collectionId ?? "global",
366
- lineOffset + matter.content,
611
+ parsed.collection ?? "global",
612
+ "\n".repeat(lineOffset) + matter.content,
367
613
  {
368
614
  development: isDevelopment,
369
615
  ...mdxOptions,
370
- filePath: path2,
616
+ filePath: path4,
371
617
  frontmatter: matter.data,
372
618
  _compiler: {
373
619
  addDependency: (file2) => {
@@ -377,7 +623,8 @@ function unstable_mdx(config, _options = {}) {
377
623
  }
378
624
  );
379
625
  return {
380
- code: typeof raw === "string" ? `export default ${JSON.stringify(file.value)}` : String(file.value)
626
+ code: String(file.value),
627
+ map: file.map
381
628
  };
382
629
  }
383
630
  };
@@ -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 };