fumadocs-mdx 13.0.3 → 13.0.5

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 (66) hide show
  1. package/dist/bin.cjs +353 -273
  2. package/dist/bin.js +1 -1
  3. package/dist/{build-mdx-TtQzmq6W.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
  4. package/dist/{build-mdx--WI4tf2-.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
  5. package/dist/bun/index.cjs +177 -57
  6. package/dist/bun/index.d.cts +2 -2
  7. package/dist/bun/index.d.ts +2 -2
  8. package/dist/bun/index.js +26 -34
  9. package/dist/chunk-2HXTGJBI.js +101 -0
  10. package/dist/chunk-4JSFLXXT.js +8 -0
  11. package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
  12. package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
  13. package/dist/chunk-VUEZTR2H.js +26 -0
  14. package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
  15. package/dist/chunk-YAIPHUCZ.js +56 -0
  16. package/dist/chunk-ZNVPB2IR.js +170 -0
  17. package/dist/config/index.d.cts +2 -2
  18. package/dist/config/index.d.ts +2 -2
  19. package/dist/{core-DhfmVKRA.d.cts → core-DB7TdlyC.d.cts} +21 -7
  20. package/dist/{core-DhfmVKRA.d.ts → core-DB7TdlyC.d.ts} +21 -7
  21. package/dist/index-D7s7kCc2.d.cts +7 -0
  22. package/dist/index-D7s7kCc2.d.ts +7 -0
  23. package/dist/index.d.cts +4 -4
  24. package/dist/index.d.ts +4 -4
  25. package/dist/load-from-file-AVYOFOI7.js +7 -0
  26. package/dist/next/index.cjs +145 -139
  27. package/dist/next/index.js +56 -36
  28. package/dist/node/loader.cjs +242 -128
  29. package/dist/node/loader.d.cts +2 -2
  30. package/dist/node/loader.d.ts +2 -2
  31. package/dist/node/loader.js +29 -16
  32. package/dist/plugins/json-schema.cjs +22 -70
  33. package/dist/plugins/json-schema.d.cts +2 -2
  34. package/dist/plugins/json-schema.d.ts +2 -2
  35. package/dist/plugins/json-schema.js +19 -14
  36. package/dist/runtime/next/async.cjs +56 -11
  37. package/dist/runtime/next/async.d.cts +4 -6
  38. package/dist/runtime/next/async.d.ts +4 -6
  39. package/dist/runtime/next/async.js +3 -6
  40. package/dist/runtime/next/index.d.cts +5 -5
  41. package/dist/runtime/next/index.d.ts +5 -5
  42. package/dist/runtime/vite/browser.d.cts +3 -3
  43. package/dist/runtime/vite/browser.d.ts +3 -3
  44. package/dist/runtime/vite/server.d.cts +3 -3
  45. package/dist/runtime/vite/server.d.ts +3 -3
  46. package/dist/{types-zrV4v6mp.d.cts → types-Bnh9n7mj.d.cts} +2 -2
  47. package/dist/{types-CMva20Zp.d.ts → types-ey1AZqrg.d.ts} +2 -2
  48. package/dist/vite/index.cjs +238 -159
  49. package/dist/vite/index.js +113 -118
  50. package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
  51. package/dist/webpack/mdx.d.cts +6 -0
  52. package/dist/webpack/mdx.d.ts +6 -0
  53. package/dist/webpack/{index.js → mdx.js} +12 -14
  54. package/dist/webpack/meta.cjs +528 -0
  55. package/dist/webpack/meta.d.cts +6 -0
  56. package/dist/webpack/meta.d.ts +6 -0
  57. package/dist/webpack/meta.js +42 -0
  58. package/loader-mdx.cjs +1 -1
  59. package/loader-meta.cjs +7 -0
  60. package/package.json +6 -3
  61. package/dist/chunk-U4MQ44TS.js +0 -53
  62. package/dist/chunk-XZY2AWJI.js +0 -81
  63. package/dist/chunk-YVCR6FUH.js +0 -82
  64. package/dist/load-MNG3CLET.js +0 -7
  65. package/dist/webpack/index.d.cts +0 -15
  66. package/dist/webpack/index.d.ts +0 -15
package/dist/bin.cjs CHANGED
@@ -30,19 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
- // src/loaders/config/index.ts
34
- function findConfigFile() {
35
- return import_node_path.default.resolve("source.config.ts");
36
- }
37
- var import_node_path, import_promises;
38
- var init_config = __esm({
39
- "src/loaders/config/index.ts"() {
40
- "use strict";
41
- import_node_path = __toESM(require("path"), 1);
42
- import_promises = __toESM(require("fs/promises"), 1);
43
- }
44
- });
45
-
46
33
  // src/loaders/mdx/preset.ts
47
34
  var preset_exports = {};
48
35
  __export(preset_exports, {
@@ -131,35 +118,78 @@ var init_preset = __esm({
131
118
  });
132
119
 
133
120
  // src/config/build.ts
121
+ function buildCollection(name, config) {
122
+ if (config.type === "docs") {
123
+ return {
124
+ ...config,
125
+ name,
126
+ meta: buildPrimitiveCollection(name, config.meta),
127
+ docs: buildPrimitiveCollection(name, config.docs)
128
+ };
129
+ }
130
+ return buildPrimitiveCollection(name, config);
131
+ }
132
+ function buildPrimitiveCollection(name, { files, ...config }) {
133
+ const supportedFormats = SupportedFormats[config.type];
134
+ const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
135
+ let matchers;
136
+ return {
137
+ ...config,
138
+ name,
139
+ patterns,
140
+ isFileSupported(filePath) {
141
+ return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
142
+ },
143
+ hasFile(filePath) {
144
+ matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
145
+ (dir) => (0, import_picomatch.default)(patterns, {
146
+ cwd: dir
147
+ })
148
+ );
149
+ return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
150
+ }
151
+ };
152
+ }
134
153
  function buildConfig(config) {
135
154
  const collections = /* @__PURE__ */ new Map();
136
- let globalConfig = {};
155
+ const loaded = {};
137
156
  for (const [k, v] of Object.entries(config)) {
138
157
  if (!v) {
139
158
  continue;
140
159
  }
141
160
  if (typeof v === "object" && "type" in v) {
142
161
  if (v.type === "docs") {
143
- collections.set(k, v);
162
+ collections.set(k, buildCollection(k, v));
144
163
  continue;
145
164
  }
146
165
  if (v.type === "doc" || v.type === "meta") {
147
- collections.set(k, v);
166
+ collections.set(
167
+ k,
168
+ buildCollection(k, v)
169
+ );
148
170
  continue;
149
171
  }
150
172
  }
151
173
  if (k === "default" && v) {
152
- globalConfig = v;
174
+ Object.assign(loaded, v);
153
175
  continue;
154
176
  }
155
177
  throw new Error(
156
178
  `Unknown export "${k}", you can only export collections from source configuration file.`
157
179
  );
158
180
  }
181
+ if (loaded.collections) {
182
+ for (const [k, v] of Object.entries(loaded.collections)) {
183
+ collections.set(k, buildCollection(k, v));
184
+ }
185
+ }
159
186
  const mdxOptionsCache = /* @__PURE__ */ new Map();
160
187
  return {
161
- global: globalConfig,
162
- collections,
188
+ global: loaded,
189
+ collectionList: Array.from(collections.values()),
190
+ getCollection(name) {
191
+ return collections.get(name);
192
+ },
163
193
  async getDefaultMDXOptions(mode = "default") {
164
194
  const cached = mdxOptionsCache.get(mode);
165
195
  if (cached) return cached;
@@ -179,15 +209,21 @@ function buildConfig(config) {
179
209
  }
180
210
  };
181
211
  }
212
+ var import_picomatch, SupportedFormats;
182
213
  var init_build = __esm({
183
214
  "src/config/build.ts"() {
184
215
  "use strict";
216
+ import_picomatch = __toESM(require("picomatch"), 1);
217
+ SupportedFormats = {
218
+ doc: ["mdx", "md"],
219
+ meta: ["json", "yaml"]
220
+ };
185
221
  }
186
222
  });
187
223
 
188
- // src/loaders/config/load.ts
189
- var load_exports = {};
190
- __export(load_exports, {
224
+ // src/config/load-from-file.ts
225
+ var load_from_file_exports = {};
226
+ __export(load_from_file_exports, {
191
227
  loadConfig: () => loadConfig
192
228
  });
193
229
  async function compileConfig(configPath, outDir) {
@@ -212,18 +248,18 @@ async function compileConfig(configPath, outDir) {
212
248
  }
213
249
  async function loadConfig(configPath, outDir, build = false) {
214
250
  if (build) await compileConfig(configPath, outDir);
215
- const url = (0, import_node_url.pathToFileURL)(path2.resolve(outDir, "source.config.mjs"));
251
+ const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
216
252
  url.searchParams.set("hash", Date.now().toString());
217
253
  const config = import(url.href).then(
218
254
  (loaded) => buildConfig(loaded)
219
255
  );
220
256
  return await config;
221
257
  }
222
- var path2, import_node_url;
223
- var init_load = __esm({
224
- "src/loaders/config/load.ts"() {
258
+ var path, import_node_url;
259
+ var init_load_from_file = __esm({
260
+ "src/config/load-from-file.ts"() {
225
261
  "use strict";
226
- path2 = __toESM(require("path"), 1);
262
+ path = __toESM(require("path"), 1);
227
263
  import_node_url = require("url");
228
264
  init_build();
229
265
  }
@@ -231,8 +267,8 @@ var init_load = __esm({
231
267
 
232
268
  // src/next/file-cache.ts
233
269
  function toFullPath(file) {
234
- if (import_node_path2.default.isAbsolute(file)) {
235
- return import_node_path2.default.relative(process.cwd(), file);
270
+ if (import_node_path.default.isAbsolute(file)) {
271
+ return import_node_path.default.relative(process.cwd(), file);
236
272
  }
237
273
  return file;
238
274
  }
@@ -240,20 +276,20 @@ async function readFileWithCache(file) {
240
276
  const fullPath = toFullPath(file);
241
277
  const cached = map.get(fullPath);
242
278
  if (cached) return cached;
243
- const read = import_promises2.default.readFile(fullPath).then((s) => s.toString());
279
+ const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
244
280
  map.set(fullPath, read);
245
281
  return read;
246
282
  }
247
283
  function removeFileCache(file) {
248
284
  map.delete(toFullPath(file));
249
285
  }
250
- var import_lru_cache, import_promises2, import_node_path2, map;
286
+ var import_lru_cache, import_promises, import_node_path, map;
251
287
  var init_file_cache = __esm({
252
288
  "src/next/file-cache.ts"() {
253
289
  "use strict";
254
290
  import_lru_cache = require("lru-cache");
255
- import_promises2 = __toESM(require("fs/promises"), 1);
256
- import_node_path2 = __toESM(require("path"), 1);
291
+ import_promises = __toESM(require("fs/promises"), 1);
292
+ import_node_path = __toESM(require("path"), 1);
257
293
  map = new import_lru_cache.LRUCache({
258
294
  max: 100
259
295
  });
@@ -311,7 +347,7 @@ async function getGitTimestamp(file) {
311
347
  try {
312
348
  const out = await (0, import_tinyexec.x)(
313
349
  "git",
314
- ["log", "-1", '--pretty="%ai"', import_node_path3.default.relative(process.cwd(), file)],
350
+ ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
315
351
  {
316
352
  throwOnError: true
317
353
  }
@@ -323,11 +359,11 @@ async function getGitTimestamp(file) {
323
359
  return;
324
360
  }
325
361
  }
326
- var import_node_path3, import_tinyexec, cache;
362
+ var import_node_path2, import_tinyexec, cache;
327
363
  var init_git_timestamp = __esm({
328
364
  "src/utils/git-timestamp.ts"() {
329
365
  "use strict";
330
- import_node_path3 = __toESM(require("path"), 1);
366
+ import_node_path2 = __toESM(require("path"), 1);
331
367
  import_tinyexec = require("tinyexec");
332
368
  cache = /* @__PURE__ */ new Map();
333
369
  }
@@ -370,7 +406,7 @@ function getImportCode(info) {
370
406
  return `import ${specifier}`;
371
407
  }
372
408
  function toImportPath(file, config) {
373
- const ext = import_node_path4.default.extname(file);
409
+ const ext = import_node_path3.default.extname(file);
374
410
  let filename;
375
411
  if (ext === ".ts" && config.jsExtension) {
376
412
  filename = file.substring(0, file.length - ext.length) + ".js";
@@ -381,68 +417,23 @@ function toImportPath(file, config) {
381
417
  }
382
418
  let importPath;
383
419
  if ("relativeTo" in config) {
384
- importPath = import_node_path4.default.relative(config.relativeTo, filename);
385
- if (!import_node_path4.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
420
+ importPath = import_node_path3.default.relative(config.relativeTo, filename);
421
+ if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
386
422
  importPath = `./${importPath}`;
387
423
  }
388
424
  } else {
389
- importPath = import_node_path4.default.resolve(filename);
425
+ importPath = import_node_path3.default.resolve(filename);
390
426
  }
391
- return importPath.replaceAll(import_node_path4.default.sep, "/");
427
+ return importPath.replaceAll(import_node_path3.default.sep, "/");
392
428
  }
393
429
  function ident(code, tab = 1) {
394
430
  return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
395
431
  }
396
- var import_node_path4;
432
+ var import_node_path3;
397
433
  var init_import_formatter = __esm({
398
434
  "src/utils/import-formatter.ts"() {
399
435
  "use strict";
400
- import_node_path4 = __toESM(require("path"), 1);
401
- }
402
- });
403
-
404
- // src/utils/collections.ts
405
- function getGlobPatterns(collection) {
406
- if (collection.files) return collection.files;
407
- return [`**/*.{${SupportedFormats[collection.type].join(",")}}`];
408
- }
409
- function isFileSupported(filePath, collection) {
410
- return SupportedFormats[collection.type].some(
411
- (format) => filePath.endsWith(`.${format}`)
412
- );
413
- }
414
- async function getCollectionFiles(collection) {
415
- const files = /* @__PURE__ */ new Map();
416
- const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
417
- const patterns = getGlobPatterns(collection);
418
- await Promise.all(
419
- dirs.map(async (dir) => {
420
- const result = await (0, import_tinyglobby.glob)(patterns, {
421
- cwd: import_node_path5.default.resolve(dir)
422
- });
423
- for (const item of result) {
424
- if (!isFileSupported(item, collection)) continue;
425
- const fullPath = import_node_path5.default.join(dir, item);
426
- files.set(fullPath, {
427
- path: item,
428
- fullPath
429
- });
430
- }
431
- })
432
- );
433
- return Array.from(files.values());
434
- }
435
- var import_picomatch, import_tinyglobby, import_node_path5, SupportedFormats;
436
- var init_collections = __esm({
437
- "src/utils/collections.ts"() {
438
- "use strict";
439
- import_picomatch = __toESM(require("picomatch"), 1);
440
- import_tinyglobby = require("tinyglobby");
441
- import_node_path5 = __toESM(require("path"), 1);
442
- SupportedFormats = {
443
- doc: ["mdx", "md"],
444
- meta: ["json", "yaml"]
445
- };
436
+ import_node_path3 = __toESM(require("path"), 1);
446
437
  }
447
438
  });
448
439
 
@@ -454,11 +445,9 @@ function next() {
454
445
  name: "next",
455
446
  config(v) {
456
447
  config = v;
457
- shouldEmitOnChange = Array.from(config.collections.values()).some(
458
- (collection) => {
459
- return collection.type === "doc" && collection.async || collection.type === "docs" && collection.docs.async;
460
- }
461
- );
448
+ shouldEmitOnChange = config.collectionList.some((collection) => {
449
+ return collection.type === "doc" && collection.async || collection.type === "docs" || collection.type === "meta";
450
+ });
462
451
  },
463
452
  configureServer(server) {
464
453
  if (!server.watcher) return;
@@ -481,7 +470,7 @@ function next() {
481
470
  }
482
471
  };
483
472
  }
484
- async function indexFile(configPath, config, importPath, configHash = false) {
473
+ async function indexFile(configPath, config, importPath) {
485
474
  let asyncInit = false;
486
475
  const lines = [
487
476
  getImportCode({
@@ -495,14 +484,10 @@ async function indexFile(configPath, config, importPath, configHash = false) {
495
484
  name: "_source"
496
485
  })
497
486
  ];
498
- const entries = Array.from(config.collections.entries());
499
- async function getDocEntries(collectionName, files) {
500
- const items = files.map(async (file, i) => {
501
- const importId = `${collectionName}_${i}`;
502
- const params = [`collection=${collectionName}`];
503
- if (configHash) {
504
- params.push(`hash=${configHash}`);
505
- }
487
+ function getDocEntries(collection, files) {
488
+ return files.map((file, i) => {
489
+ const importId = `d_${collection.name}_${i}`;
490
+ const params = [`collection=${collection.name}`];
506
491
  lines.unshift(
507
492
  getImportCode({
508
493
  type: "namespace",
@@ -512,7 +497,6 @@ async function indexFile(configPath, config, importPath, configHash = false) {
512
497
  );
513
498
  return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
514
499
  });
515
- return Promise.all(items);
516
500
  }
517
501
  async function getMetaEntries(collection, files) {
518
502
  const items = files.map(async (file) => {
@@ -553,7 +537,7 @@ async function indexFile(configPath, config, importPath, configHash = false) {
553
537
  );
554
538
  asyncInit = true;
555
539
  }
556
- const entries2 = files.map(async (file) => {
540
+ const entries = files.map(async (file) => {
557
541
  const content = await readFileWithCache(file.fullPath).catch(() => "");
558
542
  const parsed = fumaMatter(content);
559
543
  let data = parsed.data;
@@ -579,12 +563,13 @@ async function indexFile(configPath, config, importPath, configHash = false) {
579
563
  );
580
564
  return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
581
565
  });
582
- return Promise.all(entries2);
566
+ return Promise.all(entries);
583
567
  }
584
- const declares = entries.map(async ([k, collection]) => {
568
+ const declares = config.collectionList.map(async (collection) => {
569
+ const k = collection.name;
585
570
  if (collection.type === "docs") {
586
- const docs = await getCollectionFiles(collection.docs);
587
- const metas = await getCollectionFiles(collection.meta);
571
+ const docs = await globCollectionFiles(collection.docs);
572
+ const metas = await globCollectionFiles(collection.meta);
588
573
  const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
589
574
  ", "
590
575
  );
@@ -594,14 +579,17 @@ async function indexFile(configPath, config, importPath, configHash = false) {
594
579
  );
595
580
  return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
596
581
  }
597
- const docsEntries = (await getDocEntries(k, docs)).join(", ");
582
+ const docsEntries = getDocEntries(collection.docs, docs).join(", ");
598
583
  return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
599
584
  }
600
- const files = await getCollectionFiles(collection);
601
- if (collection.type === "doc" && collection.async) {
585
+ const files = await globCollectionFiles(collection);
586
+ if (collection.type === "meta") {
587
+ return `export const ${k} = _runtime.meta<typeof _source.${k}>([${(await getMetaEntries(collection, files)).join(", ")}]);`;
588
+ }
589
+ if (collection.async) {
602
590
  return `export const ${k} = _runtimeAsync.doc<typeof _source.${k}>([${(await getAsyncEntries(collection, files)).join(", ")}], "${k}", _sourceConfig)`;
603
591
  }
604
- return `export const ${k} = _runtime.${collection.type}<typeof _source.${k}>([${(await getDocEntries(k, files)).join(", ")}]);`;
592
+ return `export const ${k} = _runtime.doc<typeof _source.${k}>([${getDocEntries(collection, files).join(", ")}]);`;
605
593
  });
606
594
  const resolvedDeclares = await Promise.all(declares);
607
595
  return [
@@ -611,34 +599,57 @@ async function indexFile(configPath, config, importPath, configHash = false) {
611
599
  ].join("\n");
612
600
  }
613
601
  function parseMetaEntry(file, content) {
614
- const extname4 = path7.extname(file);
602
+ const extname3 = path5.extname(file);
615
603
  try {
616
- if (extname4 === ".json") return JSON.parse(content);
617
- if (extname4 === ".yaml") return (0, import_js_yaml2.load)(content);
604
+ if (extname3 === ".json") return JSON.parse(content);
605
+ if (extname3 === ".yaml") return (0, import_js_yaml2.load)(content);
618
606
  } catch (e) {
619
607
  throw new Error(`Failed to parse meta file: ${file}.`, {
620
608
  cause: e
621
609
  });
622
610
  }
623
- throw new Error(`Unknown meta file format: ${extname4}, in ${file}.`);
611
+ throw new Error(`Unknown meta file format: ${extname3}, in ${file}.`);
612
+ }
613
+ async function globCollectionFiles(collection) {
614
+ const { glob } = await import("tinyglobby");
615
+ const files = /* @__PURE__ */ new Map();
616
+ const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
617
+ await Promise.all(
618
+ dirs.map(async (dir) => {
619
+ const result = await glob(collection.patterns, {
620
+ cwd: path5.resolve(dir)
621
+ });
622
+ for (const item of result) {
623
+ if (!collection.isFileSupported(item)) continue;
624
+ const fullPath = path5.join(dir, item);
625
+ files.set(fullPath, {
626
+ path: item,
627
+ fullPath
628
+ });
629
+ }
630
+ })
631
+ );
632
+ return Array.from(files.values());
624
633
  }
625
- var path7, import_node_crypto, import_js_yaml2;
634
+ var path5, import_node_crypto, import_js_yaml2;
626
635
  var init_next = __esm({
627
636
  "src/plugins/next.ts"() {
628
637
  "use strict";
629
- path7 = __toESM(require("path"), 1);
638
+ path5 = __toESM(require("path"), 1);
630
639
  import_node_crypto = require("crypto");
631
640
  init_validation();
632
641
  init_file_cache();
633
- import_js_yaml2 = require("js-yaml");
634
642
  init_git_timestamp();
635
643
  init_fuma_matter();
636
644
  init_import_formatter();
637
- init_collections();
645
+ import_js_yaml2 = require("js-yaml");
638
646
  }
639
647
  });
640
648
 
641
649
  // src/core.ts
650
+ function findConfigFile() {
651
+ return import_node_path4.default.resolve("source.config.ts");
652
+ }
642
653
  function createCore(options, defaultPlugins = []) {
643
654
  let config;
644
655
  let plugins2;
@@ -675,13 +686,6 @@ function createCore(options, defaultPlugins = []) {
675
686
  getConfig() {
676
687
  return config;
677
688
  },
678
- creatConfigLoader() {
679
- return {
680
- getConfig() {
681
- return config;
682
- }
683
- };
684
- },
685
689
  async initServer(server) {
686
690
  for (const plugin of plugins2) {
687
691
  await plugin.configureServer?.call(this.getPluginContext(), server);
@@ -699,21 +703,31 @@ function createCore(options, defaultPlugins = []) {
699
703
  );
700
704
  await Promise.all(
701
705
  out.flat().map(async (entry) => {
702
- const file = import_node_path6.default.join(options.outDir, entry.path);
703
- await import_promises3.default.mkdir(import_node_path6.default.dirname(file), { recursive: true });
704
- await import_promises3.default.writeFile(file, entry.content);
706
+ const file = import_node_path4.default.join(options.outDir, entry.path);
707
+ await import_promises2.default.mkdir(import_node_path4.default.dirname(file), { recursive: true });
708
+ await import_promises2.default.writeFile(file, entry.content);
705
709
  })
706
710
  );
707
711
  console.log(`[MDX] generated files in ${performance.now() - start2}ms`);
708
712
  }
709
713
  };
710
714
  }
711
- var import_node_path6, import_promises3;
715
+ var import_node_path4, import_promises2;
712
716
  var init_core = __esm({
713
717
  "src/core.ts"() {
714
718
  "use strict";
715
- import_node_path6 = __toESM(require("path"), 1);
716
- import_promises3 = __toESM(require("fs/promises"), 1);
719
+ import_node_path4 = __toESM(require("path"), 1);
720
+ import_promises2 = __toESM(require("fs/promises"), 1);
721
+ }
722
+ });
723
+
724
+ // src/loaders/index.ts
725
+ var metaLoaderGlob, mdxLoaderGlob;
726
+ var init_loaders = __esm({
727
+ "src/loaders/index.ts"() {
728
+ "use strict";
729
+ metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
730
+ mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
717
731
  }
718
732
  });
719
733
 
@@ -731,7 +745,7 @@ function createMDX(createOptions = {}) {
731
745
  void init(isDev, options);
732
746
  }
733
747
  return (nextConfig = {}) => {
734
- const mdxLoaderOptions = {
748
+ const loaderOptions = {
735
749
  ...options,
736
750
  isDev
737
751
  };
@@ -743,7 +757,7 @@ function createMDX(createOptions = {}) {
743
757
  loaders: [
744
758
  {
745
759
  loader: "fumadocs-mdx/loader-mdx",
746
- options: mdxLoaderOptions
760
+ options: loaderOptions
747
761
  }
748
762
  ],
749
763
  as: "*.js"
@@ -759,12 +773,12 @@ function createMDX(createOptions = {}) {
759
773
  config.module ||= {};
760
774
  config.module.rules ||= [];
761
775
  config.module.rules.push({
762
- test: /\.mdx?$/,
776
+ test: mdxLoaderGlob,
763
777
  use: [
764
778
  options2.defaultLoaders.babel,
765
779
  {
766
780
  loader: "fumadocs-mdx/loader-mdx",
767
- options: mdxLoaderOptions
781
+ options: loaderOptions
768
782
  }
769
783
  ]
770
784
  });
@@ -790,7 +804,7 @@ async function init(dev, options) {
790
804
  ignored: [options.outDir]
791
805
  });
792
806
  watcher.add(options.configPath);
793
- for (const collection of core.getConfig().collections.values()) {
807
+ for (const collection of core.getConfig().collectionList) {
794
808
  if (collection.type === "docs") {
795
809
  watcher.add(collection.docs.dir);
796
810
  watcher.add(collection.meta.dir);
@@ -802,9 +816,9 @@ async function init(dev, options) {
802
816
  console.log("[MDX] started dev server");
803
817
  });
804
818
  watcher.on("all", async (event, file) => {
805
- const absolutePath = path9.resolve(file);
819
+ const absolutePath = path7.resolve(file);
806
820
  if (event === "change") removeFileCache(absolutePath);
807
- if (absolutePath === path9.resolve(options.configPath)) {
821
+ if (absolutePath === path7.resolve(options.configPath)) {
808
822
  watcher.removeAllListeners();
809
823
  await watcher.close();
810
824
  await initOrReload();
@@ -866,17 +880,17 @@ function createNextCore({
866
880
  }
867
881
  };
868
882
  }
869
- var path9, defaultPageExtensions;
883
+ var path7, defaultPageExtensions;
870
884
  var init_next2 = __esm({
871
885
  "src/next/index.ts"() {
872
886
  "use strict";
873
- init_config();
874
- path9 = __toESM(require("path"), 1);
875
- init_load();
887
+ path7 = __toESM(require("path"), 1);
888
+ init_load_from_file();
876
889
  init_file_cache();
877
890
  init_validation();
878
891
  init_next();
879
892
  init_core();
893
+ init_loaders();
880
894
  defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
881
895
  }
882
896
  });
@@ -999,7 +1013,7 @@ function remarkInclude() {
999
1013
  const embedContent = async (file, heading, params, data) => {
1000
1014
  let content;
1001
1015
  try {
1002
- content = (await fs4.readFile(file)).toString();
1016
+ content = (await fs3.readFile(file)).toString();
1003
1017
  } catch (e) {
1004
1018
  throw new Error(
1005
1019
  `failed to read file ${file}
@@ -1007,7 +1021,7 @@ ${e instanceof Error ? e.message : String(e)}`,
1007
1021
  { cause: e }
1008
1022
  );
1009
1023
  }
1010
- const ext = path10.extname(file);
1024
+ const ext = path8.extname(file);
1011
1025
  data._compiler?.addDependency(file);
1012
1026
  if (params.lang || ext !== ".md" && ext !== ".mdx") {
1013
1027
  const lang = params.lang ?? ext.slice(1);
@@ -1040,7 +1054,7 @@ ${e instanceof Error ? e.message : String(e)}`,
1040
1054
  } else {
1041
1055
  mdast = await baseProcessor.run(mdast);
1042
1056
  }
1043
- await update(mdast, path10.dirname(file), data);
1057
+ await update(mdast, path8.dirname(file), data);
1044
1058
  return mdast;
1045
1059
  };
1046
1060
  async function update(tree, directory, data) {
@@ -1052,7 +1066,7 @@ ${e instanceof Error ? e.message : String(e)}`,
1052
1066
  if (specifier.length === 0) return "skip";
1053
1067
  const attributes = parseElementAttributes(node);
1054
1068
  const { file: relativePath, section } = parseSpecifier(specifier);
1055
- const file = path10.resolve(
1069
+ const file = path8.resolve(
1056
1070
  "cwd" in attributes ? process.cwd() : directory,
1057
1071
  relativePath
1058
1072
  );
@@ -1069,17 +1083,17 @@ ${e instanceof Error ? e.message : String(e)}`,
1069
1083
  await Promise.all(queue);
1070
1084
  }
1071
1085
  return async (tree, file) => {
1072
- await update(tree, path10.dirname(file.path), file.data);
1086
+ await update(tree, path8.dirname(file.path), file.data);
1073
1087
  };
1074
1088
  }
1075
- var import_unified, import_unist_util_visit2, path10, fs4, import_mdx_plugins, ElementLikeTypes;
1089
+ var import_unified, import_unist_util_visit2, path8, fs3, import_mdx_plugins, ElementLikeTypes;
1076
1090
  var init_remark_include = __esm({
1077
1091
  "src/loaders/mdx/remark-include.ts"() {
1078
1092
  "use strict";
1079
1093
  import_unified = require("unified");
1080
1094
  import_unist_util_visit2 = require("unist-util-visit");
1081
- path10 = __toESM(require("path"), 1);
1082
- fs4 = __toESM(require("fs/promises"), 1);
1095
+ path8 = __toESM(require("path"), 1);
1096
+ fs3 = __toESM(require("fs/promises"), 1);
1083
1097
  init_fuma_matter();
1084
1098
  import_mdx_plugins = require("fumadocs-core/mdx-plugins");
1085
1099
  init_remark_unravel();
@@ -1274,12 +1288,12 @@ function createMdxLoader(configLoader) {
1274
1288
  if (!isDevelopment && config.global.experimentalBuildCache) {
1275
1289
  const cacheDir = config.global.experimentalBuildCache;
1276
1290
  const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
1277
- const cached = await import_promises4.default.readFile(import_node_path7.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
1291
+ const cached = await import_promises3.default.readFile(import_node_path5.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
1278
1292
  if (cached && cached.hash === generateCacheHash(value)) return cached;
1279
1293
  after = async () => {
1280
- await import_promises4.default.mkdir(cacheDir, { recursive: true });
1281
- await import_promises4.default.writeFile(
1282
- import_node_path7.default.join(cacheDir, cacheKey),
1294
+ await import_promises3.default.mkdir(cacheDir, { recursive: true });
1295
+ await import_promises3.default.writeFile(
1296
+ import_node_path5.default.join(cacheDir, cacheKey),
1283
1297
  JSON.stringify({
1284
1298
  ...out,
1285
1299
  hash: generateCacheHash(value)
@@ -1287,7 +1301,7 @@ function createMdxLoader(configLoader) {
1287
1301
  );
1288
1302
  };
1289
1303
  }
1290
- const collection = parsed.collection ? config.collections.get(parsed.collection) : void 0;
1304
+ const collection = parsed.collection ? config.getCollection(parsed.collection) : void 0;
1291
1305
  let docCollection;
1292
1306
  switch (collection?.type) {
1293
1307
  case "doc":
@@ -1357,7 +1371,7 @@ function countLines(s) {
1357
1371
  }
1358
1372
  return num;
1359
1373
  }
1360
- var import_zod, import_promises4, import_node_path7, import_node_crypto2, querySchema, cacheEntry, hashes;
1374
+ var import_zod, import_promises3, import_node_path5, import_node_crypto2, querySchema, cacheEntry, hashes;
1361
1375
  var init_mdx = __esm({
1362
1376
  "src/loaders/mdx/index.ts"() {
1363
1377
  "use strict";
@@ -1366,8 +1380,8 @@ var init_mdx = __esm({
1366
1380
  init_git_timestamp();
1367
1381
  init_build_mdx();
1368
1382
  import_zod = require("zod");
1369
- import_promises4 = __toESM(require("fs/promises"), 1);
1370
- import_node_path7 = __toESM(require("path"), 1);
1383
+ import_promises3 = __toESM(require("fs/promises"), 1);
1384
+ import_node_path5 = __toESM(require("path"), 1);
1371
1385
  import_node_crypto2 = require("crypto");
1372
1386
  querySchema = import_zod.z.object({
1373
1387
  only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
@@ -1396,32 +1410,33 @@ function toVite(loader) {
1396
1410
  }
1397
1411
  }
1398
1412
  });
1413
+ if (result === null) return null;
1399
1414
  return {
1400
1415
  code: result.code,
1401
1416
  map: result.map
1402
1417
  };
1403
1418
  };
1404
1419
  }
1405
- var import_node_url2, import_promises5, import_node_querystring, import_node_path8;
1420
+ var import_node_url2, import_promises4, import_node_querystring, import_node_path6;
1406
1421
  var init_adapter = __esm({
1407
1422
  "src/loaders/adapter.ts"() {
1408
1423
  "use strict";
1409
1424
  import_node_url2 = require("url");
1410
- import_promises5 = __toESM(require("fs/promises"), 1);
1425
+ import_promises4 = __toESM(require("fs/promises"), 1);
1411
1426
  import_node_querystring = require("querystring");
1412
1427
  init_validation();
1413
- import_node_path8 = __toESM(require("path"), 1);
1428
+ import_node_path6 = __toESM(require("path"), 1);
1414
1429
  }
1415
1430
  });
1416
1431
 
1417
1432
  // src/utils/glob-import.ts
1418
1433
  function generateGlobImport(patterns, options) {
1419
1434
  let code = "{";
1420
- const result = (0, import_tinyglobby2.globSync)(patterns, {
1435
+ const result = (0, import_tinyglobby.globSync)(patterns, {
1421
1436
  cwd: options.base
1422
1437
  });
1423
1438
  for (const item of result) {
1424
- const fullPath = import_node_path9.default.join(options.base, item);
1439
+ const fullPath = import_node_path7.default.join(options.base, item);
1425
1440
  const url = (0, import_node_url3.pathToFileURL)(fullPath);
1426
1441
  for (const [k, v] of Object.entries(options.query ?? {})) {
1427
1442
  url.searchParams.set(k, v);
@@ -1435,12 +1450,12 @@ function generateGlobImport(patterns, options) {
1435
1450
  code += "}";
1436
1451
  return code;
1437
1452
  }
1438
- var import_tinyglobby2, import_node_path9, import_node_url3;
1453
+ var import_tinyglobby, import_node_path7, import_node_url3;
1439
1454
  var init_glob_import = __esm({
1440
1455
  "src/utils/glob-import.ts"() {
1441
1456
  "use strict";
1442
- import_tinyglobby2 = require("tinyglobby");
1443
- import_node_path9 = __toESM(require("path"), 1);
1457
+ import_tinyglobby = require("tinyglobby");
1458
+ import_node_path7 = __toESM(require("path"), 1);
1444
1459
  import_node_url3 = require("url");
1445
1460
  }
1446
1461
  });
@@ -1450,16 +1465,35 @@ function vite({
1450
1465
  index
1451
1466
  }) {
1452
1467
  let config;
1468
+ let indexOptions;
1469
+ if (index === false) indexOptions = false;
1470
+ else indexOptions = applyDefaults2(index === true ? {} : index);
1453
1471
  return {
1472
+ name: "vite",
1454
1473
  config(v) {
1455
1474
  config = v;
1456
1475
  },
1476
+ configureServer(server) {
1477
+ if (!server.watcher || indexOptions === false || indexOptions.runtime === false)
1478
+ return;
1479
+ server.watcher.on("all", (event, file) => {
1480
+ if (event === "change") return;
1481
+ const isUpdated = config.collectionList.some((collection) => {
1482
+ if (collection.type === "docs")
1483
+ return collection.docs.hasFile(file) || collection.meta.hasFile(file);
1484
+ return collection.hasFile(file);
1485
+ });
1486
+ if (isUpdated) {
1487
+ this.core.emitAndWrite({
1488
+ filterPlugin: (plugin) => plugin.name === "vite"
1489
+ });
1490
+ }
1491
+ });
1492
+ },
1457
1493
  emit() {
1458
1494
  const out = [];
1459
- if (index === false) return out;
1460
- const indexOptions = typeof index === "object" ? index : {};
1461
- const { browser = false } = indexOptions;
1462
- if (browser) {
1495
+ if (indexOptions === false) return out;
1496
+ if (indexOptions.browser) {
1463
1497
  out.push({
1464
1498
  path: "browser.ts",
1465
1499
  content: indexFile2(this, config, indexOptions, "browser")
@@ -1471,15 +1505,21 @@ function vite({
1471
1505
  this,
1472
1506
  config,
1473
1507
  indexOptions,
1474
- browser ? "server" : "all"
1508
+ indexOptions.browser ? "server" : "all"
1475
1509
  )
1476
1510
  });
1477
1511
  return out;
1478
1512
  }
1479
1513
  };
1480
1514
  }
1481
- function indexFile2({ configPath, outDir }, config, options, environment) {
1482
- const { addJsExtension = false, runtime } = options;
1515
+ function applyDefaults2(options) {
1516
+ return {
1517
+ addJsExtension: options.addJsExtension ?? false,
1518
+ browser: options.browser ?? false,
1519
+ runtime: options.runtime ?? false
1520
+ };
1521
+ }
1522
+ function indexFile2({ configPath, outDir }, config, { addJsExtension, runtime }, environment) {
1483
1523
  const runtimePath = {
1484
1524
  all: "fumadocs-mdx/runtime/vite",
1485
1525
  server: "fumadocs-mdx/runtime/vite.server",
@@ -1495,74 +1535,68 @@ function indexFile2({ configPath, outDir }, config, options, environment) {
1495
1535
  "",
1496
1536
  `export const create = fromConfig<typeof Config>();`
1497
1537
  ];
1498
- function docs(name, collection) {
1499
- const obj = [
1500
- ident(`doc: ${doc(name, collection.docs)}`),
1501
- ident(`meta: ${meta(name, collection.meta)}`)
1502
- ].join(",\n");
1503
- return `{
1538
+ function generateCollectionGlob(collection) {
1539
+ if (collection.type === "docs") {
1540
+ const obj = [
1541
+ ident(`doc: ${generateCollectionGlob(collection.docs)}`),
1542
+ ident(`meta: ${generateCollectionGlob(collection.meta)}`)
1543
+ ].join(",\n");
1544
+ return `{
1504
1545
  ${obj}
1505
1546
  }`;
1506
- }
1507
- function doc(name, collection) {
1508
- const patterns = getGlobPatterns(collection);
1547
+ }
1509
1548
  const dir = getCollectionDir(collection);
1510
- const docGlob = generateGlob(patterns, {
1511
- query: {
1512
- collection: name
1513
- },
1514
- base: dir
1515
- });
1516
- if (collection.async) {
1517
- const headBlob = generateGlob(patterns, {
1549
+ if (collection.type === "doc") {
1550
+ const docGlob = generateGlob(collection.patterns, {
1518
1551
  query: {
1519
- only: "frontmatter",
1520
- collection: name
1552
+ collection: collection.name
1521
1553
  },
1522
- import: "frontmatter",
1523
1554
  base: dir
1524
1555
  });
1525
- return `create.docLazy("${name}", "${dir}", ${headBlob}, ${docGlob})`;
1556
+ if (collection.async) {
1557
+ const headBlob = generateGlob(collection.patterns, {
1558
+ query: {
1559
+ only: "frontmatter",
1560
+ collection: collection.name
1561
+ },
1562
+ import: "frontmatter",
1563
+ base: dir
1564
+ });
1565
+ return `create.docLazy("${collection.name}", "${dir}", ${headBlob}, ${docGlob})`;
1566
+ }
1567
+ return `create.doc("${collection.name}", "${dir}", ${docGlob})`;
1526
1568
  }
1527
- return `create.doc("${name}", "${dir}", ${docGlob})`;
1528
- }
1529
- function meta(name, collection) {
1530
- const patterns = getGlobPatterns(collection);
1531
- const dir = getCollectionDir(collection);
1532
- return `create.meta("${name}", "${dir}", ${generateGlob(patterns, {
1533
- import: "default",
1534
- base: dir,
1535
- query: {
1536
- collection: name
1569
+ return `create.meta("${collection.name}", "${dir}", ${generateGlob(
1570
+ collection.patterns,
1571
+ {
1572
+ import: "default",
1573
+ base: dir,
1574
+ query: {
1575
+ collection: collection.name
1576
+ }
1537
1577
  }
1538
- })})`;
1578
+ )})`;
1539
1579
  }
1540
- function generateGlob(patterns, options2) {
1580
+ function generateGlob(patterns, options) {
1541
1581
  patterns = patterns.map(normalizeGlobPath);
1542
1582
  if (runtime === "node" || runtime === "bun") {
1543
- return generateGlobImport(patterns, options2);
1583
+ return generateGlobImport(patterns, options);
1544
1584
  } else {
1545
1585
  return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
1546
1586
  {
1547
- ...options2,
1548
- base: normalizeGlobPath(import_node_path10.default.relative(outDir, options2.base))
1587
+ ...options,
1588
+ base: normalizeGlobPath(import_node_path8.default.relative(outDir, options.base))
1549
1589
  },
1550
1590
  null,
1551
1591
  2
1552
1592
  )})`;
1553
1593
  }
1554
1594
  }
1555
- for (const [name, collection] of config.collections.entries()) {
1556
- let body;
1557
- if (collection.type === "docs") {
1558
- body = docs(name, collection);
1559
- } else if (collection.type === "meta") {
1560
- body = meta(name, collection);
1561
- } else {
1562
- body = doc(name, collection);
1563
- }
1595
+ for (const collection of config.collectionList) {
1564
1596
  lines.push("");
1565
- lines.push(`export const ${name} = ${body};`);
1597
+ lines.push(
1598
+ `export const ${collection.name} = ${generateCollectionGlob(collection)};`
1599
+ );
1566
1600
  }
1567
1601
  return lines.join("\n");
1568
1602
  }
@@ -1572,8 +1606,7 @@ function normalizeGlobPath(file) {
1572
1606
  if (file.startsWith("/")) return `.${file}`;
1573
1607
  return `./${file}`;
1574
1608
  }
1575
- function getCollectionDir(collection) {
1576
- const dir = collection.dir;
1609
+ function getCollectionDir({ dir }) {
1577
1610
  if (Array.isArray(dir)) {
1578
1611
  if (dir.length !== 1)
1579
1612
  throw new Error(
@@ -1583,43 +1616,55 @@ function getCollectionDir(collection) {
1583
1616
  }
1584
1617
  return dir;
1585
1618
  }
1586
- function slash(path16) {
1587
- const isExtendedLengthPath = path16.startsWith("\\\\?\\");
1619
+ function slash(path13) {
1620
+ const isExtendedLengthPath = path13.startsWith("\\\\?\\");
1588
1621
  if (isExtendedLengthPath) {
1589
- return path16;
1622
+ return path13;
1590
1623
  }
1591
- return path16.replaceAll("\\", "/");
1624
+ return path13.replaceAll("\\", "/");
1592
1625
  }
1593
- var import_node_path10;
1626
+ var import_node_path8;
1594
1627
  var init_vite = __esm({
1595
1628
  "src/plugins/vite.ts"() {
1596
1629
  "use strict";
1597
1630
  init_import_formatter();
1598
- init_collections();
1599
1631
  init_glob_import();
1600
- import_node_path10 = __toESM(require("path"), 1);
1632
+ import_node_path8 = __toESM(require("path"), 1);
1601
1633
  }
1602
1634
  });
1603
1635
 
1604
- // src/vite/index.ts
1605
- var vite_exports = {};
1606
- __export(vite_exports, {
1607
- default: () => mdx,
1608
- postInstall: () => postInstall2
1636
+ // src/loaders/config.ts
1637
+ function createIntegratedConfigLoader(core) {
1638
+ return {
1639
+ getConfig() {
1640
+ return core.getConfig();
1641
+ }
1642
+ };
1643
+ }
1644
+ var import_promises5;
1645
+ var init_config = __esm({
1646
+ "src/loaders/config.ts"() {
1647
+ "use strict";
1648
+ import_promises5 = __toESM(require("fs/promises"), 1);
1649
+ }
1609
1650
  });
1610
- async function mdx(config, pluginOptions = {}) {
1611
- const options = applyDefaults2(pluginOptions);
1612
- const core = await createViteCore(options).init({
1613
- config: buildConfig(config)
1614
- });
1615
- const mdxLoader = toVite(createMdxLoader(core.creatConfigLoader()));
1616
- async function transformMeta(path16, query, value) {
1617
- const isJson = path16.endsWith(".json");
1618
- const parsed = (0, import_node_querystring2.parse)(query);
1619
- const collection = parsed.collection ? core.getConfig().collections.get(parsed.collection) : void 0;
1651
+
1652
+ // src/loaders/meta.ts
1653
+ function createMetaLoader(configLoader, resolve5 = {}) {
1654
+ const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve5;
1655
+ return async ({ filePath, query, source }) => {
1656
+ const isJson = filePath.endsWith(".json");
1657
+ const parsed = querySchema2.parse(query);
1658
+ const collection = parsed.collection ? (await configLoader.getConfig()).getCollection(parsed.collection) : void 0;
1620
1659
  if (!collection) return null;
1660
+ let data;
1661
+ try {
1662
+ data = isJson ? JSON.parse(source) : (0, import_js_yaml3.load)(source);
1663
+ } catch (e) {
1664
+ throw new Error(`invalid data in ${filePath}`, { cause: e });
1665
+ }
1621
1666
  let schema;
1622
- switch (collection.type) {
1667
+ switch (collection?.type) {
1623
1668
  case "meta":
1624
1669
  schema = collection.schema;
1625
1670
  break;
@@ -1627,24 +1672,58 @@ async function mdx(config, pluginOptions = {}) {
1627
1672
  schema = collection.meta.schema;
1628
1673
  break;
1629
1674
  }
1630
- if (!schema) return null;
1631
- let data;
1632
- try {
1633
- data = isJson ? JSON.parse(value) : (0, import_js_yaml3.load)(value);
1634
- } catch {
1635
- return null;
1675
+ if (schema) {
1676
+ data = await validate(
1677
+ schema,
1678
+ data,
1679
+ { path: filePath, source },
1680
+ `invalid data in ${filePath}`
1681
+ );
1682
+ }
1683
+ let code;
1684
+ if (isJson) {
1685
+ code = resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`;
1686
+ } else {
1687
+ code = resolveYaml === "yaml" ? (0, import_js_yaml3.dump)(data) : `export default ${JSON.stringify(data)}`;
1636
1688
  }
1637
- const out = await validate(
1638
- schema,
1639
- data,
1640
- { path: path16, source: value },
1641
- `invalid data in ${path16}`
1642
- );
1643
1689
  return {
1644
- code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
1690
+ code,
1645
1691
  map: null
1646
1692
  };
1693
+ };
1694
+ }
1695
+ var import_js_yaml3, import_zod2, querySchema2;
1696
+ var init_meta = __esm({
1697
+ "src/loaders/meta.ts"() {
1698
+ "use strict";
1699
+ import_js_yaml3 = require("js-yaml");
1700
+ init_validation();
1701
+ import_zod2 = require("zod");
1702
+ querySchema2 = import_zod2.z.object({
1703
+ collection: import_zod2.z.string().optional()
1704
+ }).loose();
1647
1705
  }
1706
+ });
1707
+
1708
+ // src/vite/index.ts
1709
+ var vite_exports = {};
1710
+ __export(vite_exports, {
1711
+ default: () => mdx,
1712
+ postInstall: () => postInstall2
1713
+ });
1714
+ async function mdx(config, pluginOptions = {}) {
1715
+ const options = applyDefaults3(pluginOptions);
1716
+ const core = await createViteCore(options).init({
1717
+ config: buildConfig(config)
1718
+ });
1719
+ const configLoader = createIntegratedConfigLoader(core);
1720
+ const mdxLoader = toVite(createMdxLoader(configLoader));
1721
+ const metaLoader = toVite(
1722
+ createMetaLoader(configLoader, {
1723
+ // vite has built-in plugin for JSON files
1724
+ json: "json"
1725
+ })
1726
+ );
1648
1727
  return {
1649
1728
  name: "fumadocs-mdx",
1650
1729
  // needed, otherwise other plugins will be executed before our `transform`.
@@ -1670,13 +1749,15 @@ async function mdx(config, pluginOptions = {}) {
1670
1749
  });
1671
1750
  },
1672
1751
  async transform(value, id) {
1673
- const [file, query = ""] = id.split("?");
1674
- const ext = path15.extname(file);
1675
1752
  try {
1676
- if ([".yaml", ".json"].includes(ext))
1677
- return await transformMeta(file, query, value);
1678
- if ([".md", ".mdx"].includes(ext))
1753
+ if (metaLoaderGlob.test(id)) {
1754
+ const [file, query = ""] = id.split("?", 2);
1755
+ return await metaLoader.call(this, file, query, value);
1756
+ }
1757
+ if (mdxLoaderGlob.test(id)) {
1758
+ const [file, query = ""] = id.split("?", 2);
1679
1759
  return await mdxLoader.call(this, file, query, value);
1760
+ }
1680
1761
  } catch (e) {
1681
1762
  if (e instanceof ValidationError) {
1682
1763
  throw new Error(e.toStringFormatted());
@@ -1687,8 +1768,8 @@ async function mdx(config, pluginOptions = {}) {
1687
1768
  };
1688
1769
  }
1689
1770
  async function postInstall2(configPath = findConfigFile(), pluginOptions = {}) {
1690
- const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load(), load_exports));
1691
- const options = applyDefaults2(pluginOptions);
1771
+ const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load_from_file(), load_from_file_exports));
1772
+ const options = applyDefaults3(pluginOptions);
1692
1773
  const core = await createViteCore(options).init({
1693
1774
  config: loadConfig2(configPath, options.outDir, true)
1694
1775
  });
@@ -1712,7 +1793,7 @@ function createViteCore({
1712
1793
  ]
1713
1794
  );
1714
1795
  }
1715
- function applyDefaults2(options) {
1796
+ function applyDefaults3(options) {
1716
1797
  return {
1717
1798
  updateViteConfig: options.updateViteConfig ?? true,
1718
1799
  generateIndexFile: options.generateIndexFile ?? true,
@@ -1720,21 +1801,20 @@ function applyDefaults2(options) {
1720
1801
  outDir: options.outDir ?? ".source"
1721
1802
  };
1722
1803
  }
1723
- var import_vite, import_node_querystring2, path15, import_js_yaml3, FumadocsDeps;
1804
+ var import_vite, FumadocsDeps;
1724
1805
  var init_vite2 = __esm({
1725
1806
  "src/vite/index.ts"() {
1726
1807
  "use strict";
1727
1808
  import_vite = require("vite");
1728
1809
  init_build();
1729
- import_node_querystring2 = require("querystring");
1730
1810
  init_validation();
1731
- path15 = __toESM(require("path"), 1);
1732
- import_js_yaml3 = require("js-yaml");
1733
1811
  init_mdx();
1734
- init_config();
1735
1812
  init_adapter();
1736
1813
  init_vite();
1737
1814
  init_core();
1815
+ init_config();
1816
+ init_meta();
1817
+ init_loaders();
1738
1818
  FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
1739
1819
  }
1740
1820
  });
@@ -1743,7 +1823,7 @@ var init_vite2 = __esm({
1743
1823
  var import_node_fs = require("fs");
1744
1824
  async function start() {
1745
1825
  const [configPath] = process.argv.slice(2);
1746
- const isNext = (0, import_node_fs.existsSync)("next.config.js") || (0, import_node_fs.existsSync)("next.config.mjs") || (0, import_node_fs.existsSync)("next.config.ts");
1826
+ const isNext = (0, import_node_fs.existsSync)("next.config.js") || (0, import_node_fs.existsSync)("next.config.mjs") || (0, import_node_fs.existsSync)("next.config.mts") || (0, import_node_fs.existsSync)("next.config.ts");
1747
1827
  if (isNext) {
1748
1828
  const { postInstall: postInstall3 } = await Promise.resolve().then(() => (init_next2(), next_exports));
1749
1829
  await postInstall3(configPath);