fumadocs-mdx 12.0.2 → 13.0.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 (80) hide show
  1. package/dist/bin.cjs +1033 -308
  2. package/dist/bin.js +4 -4
  3. package/dist/build-mdx-BHG-_uxo.d.cts +53 -0
  4. package/dist/build-mdx-CzrQDBRZ.d.ts +53 -0
  5. package/dist/bun/index.cjs +92 -28
  6. package/dist/bun/index.js +6 -7
  7. package/dist/{chunk-QAUWMR5D.js → chunk-3J3WL7WN.js} +23 -5
  8. package/dist/chunk-4MAYA5QX.js +44 -0
  9. package/dist/{chunk-RMDXSZYE.js → chunk-CEA6MYJU.js} +13 -8
  10. package/dist/{chunk-IQAEAI4P.js → chunk-HI62EXSB.js} +63 -2
  11. package/dist/{chunk-46UPKP5R.js → chunk-II3H5ZVZ.js} +5 -5
  12. package/dist/{chunk-LGYVNESJ.js → chunk-JVZFH6ND.js} +6 -22
  13. package/dist/{chunk-LMG6UWCL.js → chunk-K5ZLPEIQ.js} +56 -16
  14. package/dist/{chunk-AUOOMFAI.js → chunk-KILFIBVW.js} +4 -13
  15. package/dist/chunk-NVRDCY6Z.js +30 -0
  16. package/dist/{chunk-VXEBLM4X.js → chunk-XV5Z4BFL.js} +1 -1
  17. package/dist/config/index.cjs +56 -16
  18. package/dist/config/index.d.cts +2 -1
  19. package/dist/config/index.d.ts +2 -1
  20. package/dist/config/index.js +1 -1
  21. package/dist/{define-DJbJduHy.d.ts → define-BCNh3n4O.d.cts} +40 -16
  22. package/dist/{define-DJbJduHy.d.cts → define-bck_EB4t.d.ts} +40 -16
  23. package/dist/index.cjs +0 -109
  24. package/dist/index.d.cts +73 -12
  25. package/dist/index.d.ts +73 -12
  26. package/dist/index.js +0 -11
  27. package/dist/{load-UUXLUBHL.js → load-MNG3CLET.js} +1 -3
  28. package/dist/loader-mdx.cjs +153 -60
  29. package/dist/loader-mdx.d.cts +1 -0
  30. package/dist/loader-mdx.d.ts +1 -0
  31. package/dist/loader-mdx.js +23 -9
  32. package/dist/next/index.cjs +213 -181
  33. package/dist/next/index.d.cts +2 -11
  34. package/dist/next/index.d.ts +2 -11
  35. package/dist/next/index.js +145 -117
  36. package/dist/node/loader.cjs +128 -70
  37. package/dist/node/loader.js +14 -9
  38. package/dist/plugins/index.cjs +78 -0
  39. package/dist/plugins/index.d.cts +7 -0
  40. package/dist/plugins/index.d.ts +7 -0
  41. package/dist/plugins/index.js +6 -0
  42. package/dist/plugins/json-schema.cjs +61 -0
  43. package/dist/plugins/json-schema.d.cts +16 -0
  44. package/dist/plugins/json-schema.d.ts +16 -0
  45. package/dist/plugins/json-schema.js +40 -0
  46. package/dist/remark-postprocess-K233ZVBK.d.cts +22 -0
  47. package/dist/remark-postprocess-K233ZVBK.d.ts +22 -0
  48. package/dist/runtime/next/async.cjs +109 -71
  49. package/dist/runtime/next/async.d.cts +9 -6
  50. package/dist/runtime/next/async.d.ts +9 -6
  51. package/dist/runtime/next/async.js +9 -19
  52. package/dist/runtime/next/index.cjs +26 -15
  53. package/dist/runtime/next/index.d.cts +11 -8
  54. package/dist/runtime/next/index.d.ts +11 -8
  55. package/dist/runtime/next/index.js +2 -2
  56. package/dist/runtime/vite/browser.cjs +7 -3
  57. package/dist/runtime/vite/browser.d.cts +56 -7
  58. package/dist/runtime/vite/browser.d.ts +56 -7
  59. package/dist/runtime/vite/browser.js +2 -1
  60. package/dist/runtime/vite/server.cjs +46 -36
  61. package/dist/runtime/vite/server.d.cts +13 -10
  62. package/dist/runtime/vite/server.d.ts +13 -10
  63. package/dist/runtime/vite/server.js +14 -25
  64. package/dist/{types-Ci6BA1tA.d.ts → types-1cCFEzWt.d.ts} +3 -10
  65. package/dist/{types-CbLt05Gc.d.cts → types-D5NhXTJY.d.cts} +3 -10
  66. package/dist/vite/index.cjs +387 -220
  67. package/dist/vite/index.d.cts +29 -10
  68. package/dist/vite/index.d.ts +29 -10
  69. package/dist/vite/index.js +212 -33
  70. package/dist/{watcher-HGOH3APP.js → watcher-WXJDWRZY.js} +1 -1
  71. package/package.json +29 -16
  72. package/dist/browser-BupUnhpC.d.ts +0 -98
  73. package/dist/browser-R0x9IPaQ.d.cts +0 -98
  74. package/dist/chunk-ADR6R7HM.js +0 -29
  75. package/dist/chunk-XMFLD5J6.js +0 -30
  76. package/dist/chunk-ZLCSVXCD.js +0 -10
  77. package/dist/chunk-ZX7TM4AR.js +0 -127
  78. package/dist/postinstall-SCSXM4IM.js +0 -10
  79. package/dist/shared-Cnm1afPW.d.cts +0 -71
  80. package/dist/shared-DpXxElc1.d.ts +0 -71
@@ -193,41 +193,26 @@ async function compileConfig(configPath, outDir) {
193
193
  throw new Error("failed to compile configuration file");
194
194
  }
195
195
  }
196
- async function loadConfig(configPath, outDir, hash, build = false) {
197
- if (cache && cache.hash === hash) {
198
- return await cache.config;
199
- }
196
+ async function loadConfig(configPath, outDir, build = false) {
200
197
  if (build) await compileConfig(configPath, outDir);
201
- const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
202
- const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
203
- return buildConfig(
204
- // every call to `loadConfig` will cause the previous cache to be ignored
205
- loaded
206
- );
207
- });
208
- if (hash) cache = { config, hash };
198
+ const url = (0, import_node_url.pathToFileURL)(path3.resolve(outDir, "source.config.mjs"));
199
+ url.searchParams.set("hash", Date.now().toString());
200
+ const config = import(url.href).then(
201
+ (loaded) => buildConfig(loaded)
202
+ );
209
203
  return await config;
210
204
  }
211
- async function getConfigHash(configPath) {
212
- const stats = await fs.stat(configPath).catch(() => void 0);
213
- if (stats) {
214
- return stats.mtime.getTime().toString();
215
- }
216
- throw new Error("Cannot find config file");
217
- }
218
- var fs, path, import_node_url, cache;
205
+ var path3, import_node_url;
219
206
  var init_load = __esm({
220
207
  "src/loaders/config/load.ts"() {
221
208
  "use strict";
222
- fs = __toESM(require("fs/promises"), 1);
223
- path = __toESM(require("path"), 1);
209
+ path3 = __toESM(require("path"), 1);
224
210
  import_node_url = require("url");
225
211
  init_build();
226
- cache = null;
227
212
  }
228
213
  });
229
214
 
230
- // src/next/map/watcher.ts
215
+ // src/next/watcher.ts
231
216
  var watcher_exports = {};
232
217
  __export(watcher_exports, {
233
218
  watcher: () => watcher
@@ -251,7 +236,7 @@ function watcher(configPath, config, ignored) {
251
236
  }
252
237
  var import_chokidar;
253
238
  var init_watcher = __esm({
254
- "src/next/map/watcher.ts"() {
239
+ "src/next/watcher.ts"() {
255
240
  "use strict";
256
241
  import_chokidar = require("chokidar");
257
242
  }
@@ -261,18 +246,86 @@ var init_watcher = __esm({
261
246
  var next_exports = {};
262
247
  __export(next_exports, {
263
248
  createMDX: () => createMDX,
264
- postInstall: () => postInstall,
265
- start: () => start
249
+ postInstall: () => postInstall
266
250
  });
267
251
  module.exports = __toCommonJS(next_exports);
268
- init_load();
269
- var import_node_path5 = __toESM(require("path"), 1);
252
+
253
+ // src/loaders/config/index.ts
254
+ var import_node_path = __toESM(require("path"), 1);
255
+ var import_promises = __toESM(require("fs/promises"), 1);
256
+ function findConfigFile() {
257
+ return import_node_path.default.resolve("source.config.ts");
258
+ }
259
+
260
+ // src/plugins/index.ts
261
+ var import_node_path2 = __toESM(require("path"), 1);
270
262
  var import_promises2 = __toESM(require("fs/promises"), 1);
263
+ function createPluginHandler(context, defaultPlugins = []) {
264
+ const plugins2 = [];
265
+ async function write(entry) {
266
+ const file = import_node_path2.default.join(context.outDir, entry.path);
267
+ await import_promises2.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
268
+ await import_promises2.default.writeFile(file, entry.content);
269
+ }
270
+ return {
271
+ async init(config) {
272
+ if (config.global.plugins) {
273
+ defaultPlugins.push(...config.global.plugins);
274
+ }
275
+ for await (const option of defaultPlugins) {
276
+ if (!option) continue;
277
+ if (Array.isArray(option)) plugins2.push(...option);
278
+ else plugins2.push(option);
279
+ }
280
+ for (const plugin of plugins2) {
281
+ const out = await plugin.config?.call(context, config);
282
+ if (out) config = out;
283
+ }
284
+ return config;
285
+ },
286
+ async emit() {
287
+ const out = await Promise.all(
288
+ plugins2.map((plugin) => {
289
+ return plugin.emit?.call(context) ?? [];
290
+ })
291
+ );
292
+ return out.flat();
293
+ },
294
+ async emitAndWrite() {
295
+ const entries = await this.emit();
296
+ await Promise.all(entries.map(write));
297
+ }
298
+ };
299
+ }
271
300
 
272
- // src/next/map/generate.ts
273
- var path5 = __toESM(require("path"), 1);
274
- var import_node_crypto = require("crypto");
275
- var import_tinyglobby = require("tinyglobby");
301
+ // src/next/index.ts
302
+ var path8 = __toESM(require("path"), 1);
303
+ init_load();
304
+
305
+ // src/next/file-cache.ts
306
+ var import_lru_cache = require("lru-cache");
307
+ var import_promises3 = __toESM(require("fs/promises"), 1);
308
+ var import_node_path3 = __toESM(require("path"), 1);
309
+ var map = new import_lru_cache.LRUCache({
310
+ max: 100
311
+ });
312
+ function toFullPath(file) {
313
+ if (import_node_path3.default.isAbsolute(file)) {
314
+ return import_node_path3.default.relative(process.cwd(), file);
315
+ }
316
+ return file;
317
+ }
318
+ async function readFileWithCache(file) {
319
+ const fullPath = toFullPath(file);
320
+ const cached = map.get(fullPath);
321
+ if (cached) return cached;
322
+ const read = import_promises3.default.readFile(fullPath).then((s) => s.toString());
323
+ map.set(fullPath, read);
324
+ return read;
325
+ }
326
+ function removeFileCache(file) {
327
+ map.delete(toFullPath(file));
328
+ }
276
329
 
277
330
  // src/utils/validation.ts
278
331
  var import_picocolors = __toESM(require("picocolors"), 1);
@@ -312,51 +365,29 @@ async function validate(schema, data, context, errorMessage) {
312
365
  return data;
313
366
  }
314
367
 
315
- // src/next/map/file-cache.ts
316
- var import_lru_cache = require("lru-cache");
317
- var import_promises = __toESM(require("fs/promises"), 1);
318
- var import_node_path = __toESM(require("path"), 1);
319
- var map = new import_lru_cache.LRUCache({
320
- max: 100
321
- });
322
- function toFullPath(file) {
323
- if (import_node_path.default.isAbsolute(file)) {
324
- return import_node_path.default.relative(process.cwd(), file);
325
- }
326
- return file;
327
- }
328
- async function readFileWithCache(file) {
329
- const fullPath = toFullPath(file);
330
- const cached = map.get(fullPath);
331
- if (cached) return cached;
332
- const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
333
- map.set(fullPath, read);
334
- return read;
335
- }
336
- function removeFileCache(file) {
337
- map.delete(toFullPath(file));
338
- }
339
-
340
- // src/next/map/generate.ts
368
+ // src/plugins/next.ts
369
+ var path7 = __toESM(require("path"), 1);
370
+ var import_node_crypto = require("crypto");
371
+ var import_tinyglobby = require("tinyglobby");
341
372
  var import_js_yaml2 = require("js-yaml");
342
373
 
343
374
  // src/utils/git-timestamp.ts
344
- var import_node_path2 = __toESM(require("path"), 1);
375
+ var import_node_path4 = __toESM(require("path"), 1);
345
376
  var import_tinyexec = require("tinyexec");
346
- var cache2 = /* @__PURE__ */ new Map();
377
+ var cache = /* @__PURE__ */ new Map();
347
378
  async function getGitTimestamp(file) {
348
- const cached = cache2.get(file);
379
+ const cached = cache.get(file);
349
380
  if (cached) return cached;
350
381
  try {
351
382
  const out = await (0, import_tinyexec.x)(
352
383
  "git",
353
- ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
384
+ ["log", "-1", '--pretty="%ai"', import_node_path4.default.relative(process.cwd(), file)],
354
385
  {
355
386
  throwOnError: true
356
387
  }
357
388
  );
358
389
  const time = new Date(out.stdout);
359
- cache2.set(file, time);
390
+ cache.set(file, time);
360
391
  return time;
361
392
  } catch {
362
393
  return;
@@ -380,7 +411,7 @@ function fumaMatter(input) {
380
411
  }
381
412
 
382
413
  // src/utils/import-formatter.ts
383
- var import_node_path3 = __toESM(require("path"), 1);
414
+ var import_node_path5 = __toESM(require("path"), 1);
384
415
  function getImportCode(info) {
385
416
  const specifier = JSON.stringify(info.specifier);
386
417
  if (info.type === "default") return `import ${info.name} from ${specifier}`;
@@ -395,7 +426,7 @@ function getImportCode(info) {
395
426
  return `import ${specifier}`;
396
427
  }
397
428
  function toImportPath(file, config) {
398
- const ext = import_node_path3.default.extname(file);
429
+ const ext = import_node_path5.default.extname(file);
399
430
  let filename;
400
431
  if (ext === ".ts" && config.jsExtension) {
401
432
  filename = file.substring(0, file.length - ext.length) + ".js";
@@ -406,14 +437,14 @@ function toImportPath(file, config) {
406
437
  }
407
438
  let importPath;
408
439
  if ("relativeTo" in config) {
409
- importPath = import_node_path3.default.relative(config.relativeTo, filename);
410
- if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
440
+ importPath = import_node_path5.default.relative(config.relativeTo, filename);
441
+ if (!import_node_path5.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
411
442
  importPath = `./${importPath}`;
412
443
  }
413
444
  } else {
414
- importPath = import_node_path3.default.resolve(filename);
445
+ importPath = import_node_path5.default.resolve(filename);
415
446
  }
416
- return importPath.replaceAll(import_node_path3.default.sep, "/");
447
+ return importPath.replaceAll(import_node_path5.default.sep, "/");
417
448
  }
418
449
 
419
450
  // src/utils/collections.ts
@@ -434,8 +465,26 @@ function isFileSupported(filePath, collection) {
434
465
  return false;
435
466
  }
436
467
 
437
- // src/next/map/generate.ts
438
- async function generateJS(configPath, config, importPath, configHash = false) {
468
+ // src/plugins/next.ts
469
+ function next() {
470
+ let config;
471
+ return {
472
+ config(v) {
473
+ config = v;
474
+ },
475
+ async emit() {
476
+ return [
477
+ {
478
+ path: "index.ts",
479
+ content: await indexFile(this.configPath, config, {
480
+ relativeTo: this.outDir
481
+ })
482
+ }
483
+ ];
484
+ }
485
+ };
486
+ }
487
+ async function indexFile(configPath, config, importPath, configHash = false) {
439
488
  let asyncInit = false;
440
489
  const lines = [
441
490
  getImportCode({
@@ -571,11 +620,11 @@ async function getCollectionFiles(collection) {
571
620
  await Promise.all(
572
621
  dirs.map(async (dir) => {
573
622
  const result = await (0, import_tinyglobby.glob)(patterns, {
574
- cwd: path5.resolve(dir)
623
+ cwd: path7.resolve(dir)
575
624
  });
576
625
  for (const item of result) {
577
626
  if (!isFileSupported(item, collection)) continue;
578
- const fullPath = path5.join(dir, item);
627
+ const fullPath = path7.join(dir, item);
579
628
  files.set(fullPath, {
580
629
  path: item,
581
630
  fullPath
@@ -586,7 +635,7 @@ async function getCollectionFiles(collection) {
586
635
  return Array.from(files.values());
587
636
  }
588
637
  function parseMetaEntry(file, content) {
589
- const extname2 = path5.extname(file);
638
+ const extname2 = path7.extname(file);
590
639
  try {
591
640
  if (extname2 === ".json") return JSON.parse(content);
592
641
  if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
@@ -598,98 +647,23 @@ function parseMetaEntry(file, content) {
598
647
  throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
599
648
  }
600
649
 
601
- // src/loaders/config/index.ts
602
- var import_node_path4 = __toESM(require("path"), 1);
603
- function findConfigFile() {
604
- return import_node_path4.default.resolve("source.config.ts");
605
- }
606
-
607
- // src/next/map/index.ts
608
- var path7 = __toESM(require("path"), 1);
609
- var fs3 = __toESM(require("fs/promises"), 1);
610
- init_load();
611
- async function start(dev, configPath, outDir) {
612
- let configHash = await getConfigHash(configPath);
613
- let config = await loadConfig(configPath, outDir, configHash, true);
614
- const outPath = path7.resolve(outDir, `index.ts`);
615
- async function updateMapFile() {
616
- const start2 = performance.now();
617
- try {
618
- await fs3.writeFile(
619
- outPath,
620
- await generateJS(
621
- configPath,
622
- config,
623
- { relativeTo: outDir },
624
- configHash
625
- )
626
- );
627
- } catch (err) {
628
- if (err instanceof ValidationError) {
629
- console.error(err.toStringFormatted());
630
- } else {
631
- console.error(err);
632
- }
633
- }
634
- console.log(`[MDX] updated map file in ${performance.now() - start2}ms`);
635
- }
636
- await updateMapFile();
637
- if (dev) {
638
- const { watcher: watcher2 } = await Promise.resolve().then(() => (init_watcher(), watcher_exports));
639
- const instance = watcher2(configPath, config, [outPath]);
640
- instance.on("ready", () => {
641
- console.log("[MDX] started dev server");
642
- });
643
- instance.on("all", (event, file) => {
644
- if (typeof file !== "string") return;
645
- const absolutePath = path7.resolve(file);
646
- const onUpdate = async () => {
647
- const isConfigFile = absolutePath === configPath;
648
- if (isConfigFile) {
649
- configHash = await getConfigHash(configPath);
650
- config = await loadConfig(configPath, outDir, configHash, true);
651
- }
652
- if (event === "change") removeFileCache(absolutePath);
653
- await updateMapFile();
654
- };
655
- void onUpdate();
656
- });
657
- process.on("exit", () => {
658
- console.log("[MDX] closing dev server");
659
- void instance.close();
660
- });
661
- }
662
- }
663
-
664
- // src/next/create.ts
665
- var import_node_fs = require("fs");
650
+ // src/next/index.ts
666
651
  var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
667
- var isTurboExperimental;
668
- try {
669
- const content = (0, import_node_fs.readFileSync)("./node_modules/next/package.json").toString();
670
- const version = JSON.parse(content).version;
671
- isTurboExperimental = version.startsWith("15.0.") || version.startsWith("15.1.") || version.startsWith("15.2.");
672
- } catch {
673
- isTurboExperimental = false;
674
- }
675
- function createMDX({
676
- configPath = findConfigFile(),
677
- outDir = ".source"
678
- } = {}) {
652
+ function createMDX(createOptions = {}) {
653
+ const options = applyDefaults(createOptions);
654
+ const isDev = process.env.NODE_ENV === "development";
679
655
  if (process.env._FUMADOCS_MDX !== "1") {
680
656
  process.env._FUMADOCS_MDX = "1";
681
- void start(process.env.NODE_ENV === "development", configPath, outDir);
657
+ void init(isDev, options);
682
658
  }
683
659
  return (nextConfig = {}) => {
684
660
  const mdxLoaderOptions = {
685
- configPath,
686
- outDir
661
+ ...options,
662
+ isDev
687
663
  };
688
- const turbo = {
689
- ...nextConfig.experimental?.turbo,
664
+ const turbopack = {
690
665
  ...nextConfig.turbopack,
691
666
  rules: {
692
- ...nextConfig.experimental?.turbo?.rules,
693
667
  ...nextConfig.turbopack?.rules,
694
668
  "*.{md,mdx}": {
695
669
  loaders: [
@@ -702,17 +676,18 @@ function createMDX({
702
676
  }
703
677
  }
704
678
  };
705
- const updated = {
679
+ return {
706
680
  ...nextConfig,
681
+ turbopack,
707
682
  pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
708
- webpack: (config, options) => {
683
+ webpack: (config, options2) => {
709
684
  config.resolve ||= {};
710
685
  config.module ||= {};
711
686
  config.module.rules ||= [];
712
687
  config.module.rules.push({
713
688
  test: /\.mdx?$/,
714
689
  use: [
715
- options.defaultLoaders.babel,
690
+ options2.defaultLoaders.babel,
716
691
  {
717
692
  loader: "fumadocs-mdx/loader-mdx",
718
693
  options: mdxLoaderOptions
@@ -720,34 +695,91 @@ function createMDX({
720
695
  ]
721
696
  });
722
697
  config.plugins ||= [];
723
- return nextConfig.webpack?.(config, options) ?? config;
698
+ return nextConfig.webpack?.(config, options2) ?? config;
724
699
  }
725
700
  };
726
- if (isTurboExperimental) {
727
- updated.experimental = { ...updated.experimental, turbo };
728
- } else {
729
- updated.turbopack = turbo;
730
- }
731
- return updated;
732
701
  };
733
702
  }
734
-
735
- // src/next/index.ts
703
+ async function init(dev, options) {
704
+ const pluginHandler = createNextPluginHandler(options);
705
+ let config;
706
+ async function updateConfig() {
707
+ config = await pluginHandler.init(
708
+ await loadConfig(options.configPath, options.outDir, true)
709
+ );
710
+ }
711
+ async function emitFiles() {
712
+ const start = performance.now();
713
+ try {
714
+ await pluginHandler.emitAndWrite();
715
+ } catch (err) {
716
+ if (err instanceof ValidationError) {
717
+ console.error(err.toStringFormatted());
718
+ } else {
719
+ console.error(err);
720
+ }
721
+ }
722
+ console.log(`[MDX] updated map file in ${performance.now() - start}ms`);
723
+ }
724
+ async function devServer() {
725
+ const { watcher: watcher2 } = await Promise.resolve().then(() => (init_watcher(), watcher_exports));
726
+ const instance = watcher2(options.configPath, config, [options.outDir]);
727
+ async function onUpdate(event, file) {
728
+ const absolutePath = path8.resolve(file);
729
+ if (event === "change") removeFileCache(absolutePath);
730
+ if (absolutePath === path8.resolve(options.configPath)) {
731
+ await updateConfig();
732
+ console.log("[MDX] restarting dev server");
733
+ await instance.close();
734
+ void devServer();
735
+ }
736
+ await emitFiles();
737
+ }
738
+ instance.on("ready", () => {
739
+ console.log("[MDX] started dev server");
740
+ });
741
+ instance.on("all", (event, file) => {
742
+ void onUpdate(event, file);
743
+ });
744
+ process.on("exit", () => {
745
+ console.log("[MDX] closing dev server");
746
+ void instance.close();
747
+ });
748
+ }
749
+ await updateConfig();
750
+ await emitFiles();
751
+ if (dev) void devServer();
752
+ }
736
753
  async function postInstall(configPath = findConfigFile(), outDir = ".source") {
737
- const config = await loadConfig(configPath, outDir, void 0, true);
738
- const outPath = import_node_path5.default.join(outDir, "index.ts");
739
- await import_promises2.default.rm(outDir, { recursive: true });
740
- await import_promises2.default.mkdir(outDir, { recursive: true });
741
- const hash = await getConfigHash(configPath);
742
- await import_promises2.default.writeFile(
743
- outPath,
744
- await generateJS(configPath, config, { relativeTo: outDir }, hash)
745
- );
754
+ const pluginHandler = createNextPluginHandler({
755
+ outDir,
756
+ configPath
757
+ });
758
+ await pluginHandler.init(await loadConfig(configPath, outDir, true));
759
+ await pluginHandler.emitAndWrite();
746
760
  console.log("[MDX] types generated");
747
761
  }
762
+ function applyDefaults(options) {
763
+ return {
764
+ outDir: options.outDir ?? ".source",
765
+ configPath: options.configPath ?? findConfigFile()
766
+ };
767
+ }
768
+ function createNextPluginHandler({
769
+ outDir,
770
+ configPath
771
+ }) {
772
+ return createPluginHandler(
773
+ {
774
+ environment: "next",
775
+ outDir,
776
+ configPath
777
+ },
778
+ [next()]
779
+ );
780
+ }
748
781
  // Annotate the CommonJS export names for ESM import in node:
749
782
  0 && (module.exports = {
750
783
  createMDX,
751
- postInstall,
752
- start
784
+ postInstall
753
785
  });
@@ -1,12 +1,5 @@
1
1
  import { NextConfig } from 'next';
2
2
 
3
- /**
4
- * Start a MDX server that builds index and manifest files.
5
- *
6
- * In development mode, it starts a file watcher to auto-update output as your input changes.
7
- */
8
- declare function start(dev: boolean, configPath: string, outDir: string): Promise<void>;
9
-
10
3
  interface CreateMDXOptions {
11
4
  /**
12
5
  * Path to source configuration file
@@ -19,9 +12,7 @@ interface CreateMDXOptions {
19
12
  */
20
13
  outDir?: string;
21
14
  }
22
-
23
- declare function createMDX({ configPath, outDir, }?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
24
-
15
+ declare function createMDX(createOptions?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
25
16
  declare function postInstall(configPath?: string, outDir?: string): Promise<void>;
26
17
 
27
- export { type CreateMDXOptions, createMDX, postInstall, start };
18
+ export { type CreateMDXOptions, createMDX, postInstall };
@@ -1,12 +1,5 @@
1
1
  import { NextConfig } from 'next';
2
2
 
3
- /**
4
- * Start a MDX server that builds index and manifest files.
5
- *
6
- * In development mode, it starts a file watcher to auto-update output as your input changes.
7
- */
8
- declare function start(dev: boolean, configPath: string, outDir: string): Promise<void>;
9
-
10
3
  interface CreateMDXOptions {
11
4
  /**
12
5
  * Path to source configuration file
@@ -19,9 +12,7 @@ interface CreateMDXOptions {
19
12
  */
20
13
  outDir?: string;
21
14
  }
22
-
23
- declare function createMDX({ configPath, outDir, }?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
24
-
15
+ declare function createMDX(createOptions?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
25
16
  declare function postInstall(configPath?: string, outDir?: string): Promise<void>;
26
17
 
27
- export { type CreateMDXOptions, createMDX, postInstall, start };
18
+ export { type CreateMDXOptions, createMDX, postInstall };