fumadocs-mdx 11.10.0 → 12.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 (71) hide show
  1. package/dist/bin.cjs +953 -0
  2. package/dist/bin.d.cts +1 -0
  3. package/dist/bin.d.ts +1 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/{browser-B2G8uAF2.d.cts → browser-D5lvL8vv.d.ts} +51 -4
  6. package/dist/{browser-DrH7tKRi.d.ts → browser-DjWADqp8.d.cts} +51 -4
  7. package/dist/bun/index.cjs +129 -109
  8. package/dist/bun/index.js +9 -6
  9. package/dist/chunk-3M4SHY6K.js +80 -0
  10. package/dist/chunk-6Y5JDZHD.js +65 -0
  11. package/dist/{chunk-NUDEC6C5.js → chunk-AUOOMFAI.js} +28 -22
  12. package/dist/chunk-IQAEAI4P.js +66 -0
  13. package/dist/{chunk-5XJM5RPV.js → chunk-KGUBBRL6.js} +13 -13
  14. package/dist/{chunk-SVTXMVLQ.js → chunk-KTDVTBMH.js} +1 -1
  15. package/dist/chunk-POXTQZ4D.js +60 -0
  16. package/dist/chunk-SWNOXPYJ.js +142 -0
  17. package/dist/{chunk-COQ4VMK2.js → chunk-TLD6JMT6.js} +28 -61
  18. package/dist/{chunk-NVX3U5YE.js → chunk-VXEBLM4X.js} +2 -2
  19. package/dist/{chunk-QVZ7JH4H.js → chunk-YC25YEBF.js} +1 -1
  20. package/dist/chunk-ZLCSVXCD.js +10 -0
  21. package/dist/config/index.cjs +18 -97
  22. package/dist/config/index.d.cts +1 -1
  23. package/dist/config/index.d.ts +1 -1
  24. package/dist/config/index.js +48 -9
  25. package/dist/{define-BH4bnHQl.d.cts → define--6HQ1ehX.d.cts} +18 -3
  26. package/dist/{define-BH4bnHQl.d.ts → define--6HQ1ehX.d.ts} +18 -3
  27. package/dist/loader-mdx.cjs +127 -139
  28. package/dist/loader-mdx.js +7 -6
  29. package/dist/next/index.cjs +44 -269
  30. package/dist/next/index.js +30 -46
  31. package/dist/node/loader.cjs +131 -143
  32. package/dist/node/loader.js +7 -6
  33. package/dist/postinstall-U7VROOY7.js +9 -0
  34. package/dist/{mdx-options-T73E4LQB.js → preset-WFEORCAB.js} +1 -1
  35. package/dist/runtime/{async.cjs → next/async.cjs} +202 -154
  36. package/dist/runtime/{async.d.cts → next/async.d.cts} +3 -3
  37. package/dist/runtime/{async.d.ts → next/async.d.ts} +3 -3
  38. package/dist/runtime/next/async.js +92 -0
  39. package/dist/{index.cjs → runtime/next/index.cjs} +35 -26
  40. package/dist/runtime/next/index.d.cts +30 -0
  41. package/dist/runtime/next/index.d.ts +30 -0
  42. package/dist/{index.js → runtime/next/index.js} +2 -1
  43. package/dist/runtime/vite/browser.d.cts +2 -3
  44. package/dist/runtime/vite/browser.d.ts +2 -3
  45. package/dist/runtime/vite/server.cjs +67 -21
  46. package/dist/runtime/vite/server.d.cts +14 -28
  47. package/dist/runtime/vite/server.d.ts +14 -28
  48. package/dist/runtime/vite/server.js +61 -21
  49. package/dist/shared-0QIuV0XZ.d.ts +70 -0
  50. package/dist/shared-CqgMnt9h.d.cts +70 -0
  51. package/dist/{types-DN9KrG7R.d.ts → types-DLIAvrgC.d.ts} +6 -32
  52. package/dist/{types-DT83Ijs6.d.cts → types-Dl8HLbm5.d.cts} +6 -32
  53. package/dist/vite/index.cjs +201 -123
  54. package/dist/vite/index.d.cts +4 -1
  55. package/dist/vite/index.d.ts +4 -1
  56. package/dist/vite/index.js +13 -9
  57. package/package.json +11 -17
  58. package/bin.js +0 -5
  59. package/dist/build-mdx-DnC1jKvn.d.cts +0 -46
  60. package/dist/build-mdx-DnC1jKvn.d.ts +0 -46
  61. package/dist/chunk-2HKRTQYP.js +0 -154
  62. package/dist/chunk-GBMFGEC7.js +0 -57
  63. package/dist/chunk-QQWCBFFE.js +0 -40
  64. package/dist/chunk-SMSNZ6N5.js +0 -155
  65. package/dist/config/zod-3.cjs +0 -422
  66. package/dist/config/zod-3.d.cts +0 -53
  67. package/dist/config/zod-3.d.ts +0 -53
  68. package/dist/config/zod-3.js +0 -40
  69. package/dist/index.d.cts +0 -26
  70. package/dist/index.d.ts +0 -26
  71. package/dist/runtime/async.js +0 -72
@@ -30,86 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // src/mdx-plugins/remark-postprocess.ts
34
- function remarkPostprocess({
35
- injectExports
36
- }) {
37
- return (tree, file) => {
38
- let title;
39
- const urls = [];
40
- (0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
41
- if (node.type === "heading" && node.depth === 1) {
42
- title = flattenNode(node);
43
- }
44
- if (node.type !== "link") return;
45
- urls.push({
46
- href: node.url
47
- });
48
- return "skip";
49
- });
50
- if (title) {
51
- file.data.frontmatter ??= {};
52
- if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
53
- }
54
- file.data.extractedReferences = urls;
55
- for (const name of injectExports) {
56
- if (!(name in file.data)) continue;
57
- tree.children.unshift(getMdastExport(name, file.data[name]));
58
- }
59
- };
60
- }
61
- function flattenNode(node) {
62
- if ("children" in node)
63
- return node.children.map((child) => flattenNode(child)).join("");
64
- if ("value" in node) return node.value;
65
- return "";
66
- }
67
- function getMdastExport(name, value) {
68
- return {
69
- type: "mdxjsEsm",
70
- value: "",
71
- data: {
72
- estree: {
73
- type: "Program",
74
- sourceType: "module",
75
- body: [
76
- {
77
- type: "ExportNamedDeclaration",
78
- attributes: [],
79
- specifiers: [],
80
- source: null,
81
- declaration: {
82
- type: "VariableDeclaration",
83
- kind: "let",
84
- declarations: [
85
- {
86
- type: "VariableDeclarator",
87
- id: {
88
- type: "Identifier",
89
- name
90
- },
91
- init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
92
- }
93
- ]
94
- }
95
- }
96
- ]
97
- }
98
- }
99
- };
100
- }
101
- var import_unist_util_visit, import_estree_util_value_to_estree;
102
- var init_remark_postprocess = __esm({
103
- "src/mdx-plugins/remark-postprocess.ts"() {
104
- "use strict";
105
- import_unist_util_visit = require("unist-util-visit");
106
- import_estree_util_value_to_estree = require("estree-util-value-to-estree");
107
- }
108
- });
109
-
110
- // src/utils/mdx-options.ts
111
- var mdx_options_exports = {};
112
- __export(mdx_options_exports, {
33
+ // src/mdx/preset.ts
34
+ var preset_exports = {};
35
+ __export(preset_exports, {
113
36
  getDefaultMDXOptions: () => getDefaultMDXOptions
114
37
  });
115
38
  function pluginOption(def, options = []) {
@@ -132,13 +55,6 @@ function getDefaultMDXOptions({
132
55
  _withoutBundler = false,
133
56
  ...mdxOptions
134
57
  }) {
135
- const mdxExports = [
136
- "structuredData",
137
- "extractedReferences",
138
- "frontmatter",
139
- "lastModified",
140
- ...valueToExport
141
- ];
142
58
  const remarkPlugins = pluginOption(
143
59
  (v) => [
144
60
  plugins.remarkGfm,
@@ -166,10 +82,15 @@ function getDefaultMDXOptions({
166
82
  plugins.remarkStructure,
167
83
  remarkStructureOptions
168
84
  ],
169
- [
170
- remarkPostprocess,
171
- { injectExports: mdxExports }
172
- ]
85
+ () => {
86
+ return (_, file) => {
87
+ file.data["mdx-export"] ??= [];
88
+ for (const name of valueToExport) {
89
+ if (name in file.data)
90
+ file.data["mdx-export"].push({ name, value: file.data[name] });
91
+ }
92
+ };
93
+ }
173
94
  ],
174
95
  mdxOptions.remarkPlugins
175
96
  );
@@ -189,11 +110,10 @@ function getDefaultMDXOptions({
189
110
  };
190
111
  }
191
112
  var plugins;
192
- var init_mdx_options = __esm({
193
- "src/utils/mdx-options.ts"() {
113
+ var init_preset = __esm({
114
+ "src/mdx/preset.ts"() {
194
115
  "use strict";
195
116
  plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
196
- init_remark_postprocess();
197
117
  }
198
118
  });
199
119
 
@@ -277,7 +197,7 @@ function buildConfig(config) {
277
197
  const input = this.global.mdxOptions;
278
198
  async function uncached() {
279
199
  const options = typeof input === "function" ? await input() : input;
280
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
200
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
281
201
  if (options?.preset === "minimal") return options;
282
202
  return getDefaultMDXOptions2({
283
203
  ...options,
@@ -296,35 +216,6 @@ function findConfigFile() {
296
216
  return path.resolve("source.config.ts");
297
217
  }
298
218
  var cache = null;
299
- async function isZod3() {
300
- try {
301
- const content = JSON.parse(
302
- (await fs.readFile("node_modules/zod/package.json")).toString()
303
- );
304
- const version = content.version;
305
- return typeof version === "string" && version.startsWith("3.");
306
- } catch {
307
- return false;
308
- }
309
- }
310
- function createCompatZodPlugin() {
311
- return {
312
- name: "replace-zod-import",
313
- async setup(build) {
314
- const usingZod3 = await isZod3();
315
- if (!usingZod3) return;
316
- console.warn(
317
- "[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
318
- );
319
- build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
320
- return {
321
- path: "fumadocs-mdx/config/zod-3",
322
- external: true
323
- };
324
- });
325
- }
326
- };
327
- }
328
219
  async function compileConfig(configPath, outDir) {
329
220
  const { build } = await import("esbuild");
330
221
  const transformed = await build({
@@ -336,7 +227,6 @@ async function compileConfig(configPath, outDir) {
336
227
  platform: "node",
337
228
  format: "esm",
338
229
  packages: "external",
339
- plugins: [createCompatZodPlugin()],
340
230
  outExtension: {
341
231
  ".js": ".mjs"
342
232
  },
@@ -369,9 +259,9 @@ async function getConfigHash(configPath) {
369
259
  throw new Error("Cannot find config file");
370
260
  }
371
261
 
372
- // src/map/index.ts
373
- var path5 = __toESM(require("path"), 1);
374
- var fs3 = __toESM(require("fs/promises"), 1);
262
+ // src/next/index.ts
263
+ var import_node_path3 = __toESM(require("path"), 1);
264
+ var import_promises = __toESM(require("fs/promises"), 1);
375
265
 
376
266
  // src/map/generate.ts
377
267
  var path4 = __toESM(require("path"), 1);
@@ -514,9 +404,6 @@ function toImportPath(file, config) {
514
404
  }
515
405
  return importPath.replaceAll(import_node_path2.default.sep, "/");
516
406
  }
517
- function ident(code, tab = 1) {
518
- return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
519
- }
520
407
 
521
408
  // src/utils/collections.ts
522
409
  function getSupportedFormats(collection) {
@@ -568,7 +455,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
568
455
  getImportCode({
569
456
  type: "namespace",
570
457
  name: importId,
571
- specifier: `${toImportPath(file.absolutePath, importPath)}?${params.join("&")}`
458
+ specifier: `${toImportPath(file.fullPath, importPath)}?${params.join("&")}`
572
459
  })
573
460
  );
574
461
  return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
@@ -577,17 +464,17 @@ async function generateJS(configPath, config, importPath, configHash = false) {
577
464
  }
578
465
  async function getMetaEntries(collection, files) {
579
466
  const items = files.map(async (file) => {
580
- const source = await readFileWithCache(file.absolutePath).catch(() => "");
581
- let data = source.length === 0 ? {} : parseMetaEntry(file.absolutePath, source);
467
+ const source = await readFileWithCache(file.fullPath).catch(() => "");
468
+ let data = source.length === 0 ? {} : parseMetaEntry(file.fullPath, source);
582
469
  if (collection?.schema) {
583
470
  data = await validate(
584
471
  collection.schema,
585
472
  data,
586
473
  {
587
474
  source,
588
- path: file.absolutePath
475
+ path: file.fullPath
589
476
  },
590
- `invalid data in ${file.absolutePath}`
477
+ `invalid data in ${file.fullPath}`
591
478
  );
592
479
  }
593
480
  return JSON.stringify({
@@ -611,20 +498,20 @@ async function generateJS(configPath, config, importPath, configHash = false) {
611
498
  }
612
499
  const entries2 = files.map(async (file) => {
613
500
  const parsed = fumaMatter(
614
- await readFileWithCache(file.absolutePath).catch(() => "")
501
+ await readFileWithCache(file.fullPath).catch(() => "")
615
502
  );
616
503
  let data = parsed.data;
617
504
  if (collection.schema) {
618
505
  data = await validate(
619
506
  collection.schema,
620
507
  parsed.data,
621
- { path: file.absolutePath, source: parsed.content },
622
- `invalid frontmatter in ${file.absolutePath}`
508
+ { path: file.fullPath, source: parsed.content },
509
+ `invalid frontmatter in ${file.fullPath}`
623
510
  );
624
511
  }
625
512
  let lastModified;
626
513
  if (config.global?.lastModifiedTime === "git") {
627
- lastModified = await getGitTimestamp(file.absolutePath);
514
+ lastModified = await getGitTimestamp(file.fullPath);
628
515
  }
629
516
  return JSON.stringify({
630
517
  info: file,
@@ -637,18 +524,18 @@ async function generateJS(configPath, config, importPath, configHash = false) {
637
524
  }
638
525
  const declares = entries.map(async ([k, collection]) => {
639
526
  if (collection.type === "docs") {
640
- const docs2 = await getCollectionFiles(collection.docs);
527
+ const docs = await getCollectionFiles(collection.docs);
641
528
  const metas = await getCollectionFiles(collection.meta);
642
529
  const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
643
530
  ", "
644
531
  );
645
532
  if (collection.docs.async) {
646
- const docsEntries2 = (await getAsyncEntries(collection.docs, docs2)).join(
533
+ const docsEntries2 = (await getAsyncEntries(collection.docs, docs)).join(
647
534
  ", "
648
535
  );
649
536
  return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
650
537
  }
651
- const docsEntries = (await getDocEntries(k, docs2)).join(", ");
538
+ const docsEntries = (await getDocEntries(k, docs)).join(", ");
652
539
  return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
653
540
  }
654
541
  const files = await getCollectionFiles(collection);
@@ -671,14 +558,14 @@ async function getCollectionFiles(collection) {
671
558
  await Promise.all(
672
559
  dirs.map(async (dir) => {
673
560
  const result = await (0, import_tinyglobby.glob)(patterns, {
674
- cwd: path4.resolve(dir),
675
- absolute: true
561
+ cwd: path4.resolve(dir)
676
562
  });
677
563
  for (const item of result) {
678
564
  if (!isFileSupported(item, collection)) continue;
679
- files.set(item, {
680
- path: path4.relative(dir, item),
681
- absolutePath: item
565
+ const fullPath = path4.join(dir, item);
566
+ files.set(fullPath, {
567
+ path: item,
568
+ fullPath
682
569
  });
683
570
  }
684
571
  })
@@ -699,6 +586,8 @@ function parseMetaEntry(file, content) {
699
586
  }
700
587
 
701
588
  // src/map/index.ts
589
+ var path5 = __toESM(require("path"), 1);
590
+ var fs3 = __toESM(require("fs/promises"), 1);
702
591
  async function start(dev, configPath, outDir) {
703
592
  let configHash = await getConfigHash(configPath);
704
593
  let config = await loadConfig(configPath, outDir, configHash, true);
@@ -823,132 +712,18 @@ function createMDX({
823
712
  };
824
713
  }
825
714
 
826
- // src/postinstall.ts
827
- var path6 = __toESM(require("path"), 1);
828
- var fs4 = __toESM(require("fs/promises"), 1);
829
- var import_node_fs2 = require("fs");
830
-
831
- // src/vite/generate-glob.ts
832
- function generateGlob(name, patterns, globOptions) {
833
- const options = {
834
- ...globOptions,
835
- query: {
836
- ...globOptions?.query,
837
- collection: name
838
- }
839
- };
840
- return `import.meta.glob(${JSON.stringify(mapGlobPatterns(patterns))}, ${JSON.stringify(options, null, 2)})`;
841
- }
842
- function mapGlobPatterns(patterns) {
843
- return patterns.map(enforceRelative);
844
- }
845
- function enforceRelative(file) {
846
- if (file.startsWith("./")) return file;
847
- if (file.startsWith("/")) return `.${file}`;
848
- return `./${file}`;
849
- }
850
- function getGlobBase(collection) {
851
- let dir = collection.dir;
852
- if (Array.isArray(dir)) {
853
- if (dir.length !== 1)
854
- throw new Error(
855
- `[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
856
- );
857
- dir = dir[0];
858
- }
859
- return enforceRelative(dir);
860
- }
861
-
862
- // src/vite/generate.ts
863
- function docs(name, collection) {
864
- const obj = [
865
- ident(`doc: ${doc(name, collection.docs)}`),
866
- ident(`meta: ${meta(name, collection.meta)}`)
867
- ].join(",\n");
868
- return `{
869
- ${obj}
870
- }`;
871
- }
872
- function doc(name, collection) {
873
- const patterns = getGlobPatterns(collection);
874
- const base = getGlobBase(collection);
875
- const docGlob = generateGlob(name, patterns, {
876
- base
877
- });
878
- if (collection.async) {
879
- const headBlob = generateGlob(name, patterns, {
880
- query: {
881
- only: "frontmatter"
882
- },
883
- import: "frontmatter",
884
- base
885
- });
886
- return `create.docLazy("${name}", "${base}", ${headBlob}, ${docGlob})`;
887
- }
888
- return `create.doc("${name}", "${base}", ${docGlob})`;
889
- }
890
- function meta(name, collection) {
891
- const patterns = getGlobPatterns(collection);
892
- const base = getGlobBase(collection);
893
- return `create.meta("${name}", "${base}", ${generateGlob(name, patterns, {
894
- import: "default",
895
- base
896
- })})`;
897
- }
898
- function entry(configPath, config, outDir, jsExtension) {
899
- const lines = [
900
- '/// <reference types="vite/client" />',
901
- `import { fromConfig } from 'fumadocs-mdx/runtime/vite';`,
902
- `import type * as Config from '${toImportPath(configPath, {
903
- relativeTo: outDir,
904
- jsExtension
905
- })}';`,
906
- "",
907
- `export const create = fromConfig<typeof Config>();`
908
- ];
909
- for (const [name, collection] of config.collections.entries()) {
910
- let body;
911
- if (collection.type === "docs") {
912
- body = docs(name, collection);
913
- } else if (collection.type === "meta") {
914
- body = meta(name, collection);
915
- } else {
916
- body = doc(name, collection);
917
- }
918
- lines.push("");
919
- lines.push(`export const ${name} = ${body};`);
920
- }
921
- return lines.join("\n");
922
- }
923
-
924
- // src/postinstall.ts
925
- async function postInstall(configPath = findConfigFile(), outDir) {
926
- const isNext = (0, import_node_fs2.existsSync)("next.config.js") || (0, import_node_fs2.existsSync)("next.config.mjs") || (0, import_node_fs2.existsSync)("next.config.ts");
927
- if (isNext) {
928
- await onNext(configPath, outDir ?? ".source");
929
- } else {
930
- await onVite(configPath, outDir ?? process.cwd());
931
- }
932
- console.log("[MDX] types generated");
933
- }
934
- async function onNext(configPath, outDir) {
715
+ // src/next/index.ts
716
+ async function postInstall(configPath = findConfigFile(), outDir = ".source") {
935
717
  const config = await loadConfig(configPath, outDir, void 0, true);
936
- const outPath = path6.join(outDir, "index.ts");
937
- await fs4.rm(outDir, { recursive: true });
938
- await fs4.mkdir(outDir, { recursive: true });
718
+ const outPath = import_node_path3.default.join(outDir, "index.ts");
719
+ await import_promises.default.rm(outDir, { recursive: true });
720
+ await import_promises.default.mkdir(outDir, { recursive: true });
939
721
  const hash = await getConfigHash(configPath);
940
- await fs4.writeFile(
722
+ await import_promises.default.writeFile(
941
723
  outPath,
942
724
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
943
725
  );
944
- }
945
- async function onVite(configPath, outDir, addJsExtension) {
946
- const config = await loadConfig(configPath, "node_modules", void 0, true);
947
- const outFile = "source.generated.ts";
948
- await fs4.writeFile(
949
- path6.join(outDir, outFile),
950
- entry(configPath, config, outDir, addJsExtension)
951
- );
726
+ console.log("[MDX] types generated");
952
727
  }
953
728
  // Annotate the CommonJS export names for ESM import in node:
954
729
  0 && (module.exports = {
@@ -1,26 +1,27 @@
1
1
  import {
2
- entry,
3
2
  getGlobPatterns,
4
3
  getImportCode,
5
4
  isFileSupported,
6
5
  toImportPath
7
- } from "../chunk-COQ4VMK2.js";
6
+ } from "../chunk-6Y5JDZHD.js";
8
7
  import {
9
8
  ValidationError,
10
- findConfigFile,
11
- getConfigHash,
12
9
  getGitTimestamp,
13
- loadConfig,
14
10
  validate
15
- } from "../chunk-2HKRTQYP.js";
16
- import "../chunk-QVZ7JH4H.js";
11
+ } from "../chunk-IQAEAI4P.js";
12
+ import {
13
+ findConfigFile,
14
+ getConfigHash,
15
+ loadConfig
16
+ } from "../chunk-POXTQZ4D.js";
17
+ import "../chunk-YC25YEBF.js";
17
18
  import {
18
19
  fumaMatter
19
20
  } from "../chunk-VWJKRQZR.js";
20
21
 
21
- // src/map/index.ts
22
- import * as path2 from "path";
23
- import * as fs2 from "fs/promises";
22
+ // src/next/index.ts
23
+ import path3 from "path";
24
+ import fs3 from "fs/promises";
24
25
 
25
26
  // src/map/generate.ts
26
27
  import * as path from "path";
@@ -80,7 +81,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
80
81
  getImportCode({
81
82
  type: "namespace",
82
83
  name: importId,
83
- specifier: `${toImportPath(file.absolutePath, importPath)}?${params.join("&")}`
84
+ specifier: `${toImportPath(file.fullPath, importPath)}?${params.join("&")}`
84
85
  })
85
86
  );
86
87
  return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
@@ -89,17 +90,17 @@ async function generateJS(configPath, config, importPath, configHash = false) {
89
90
  }
90
91
  async function getMetaEntries(collection, files) {
91
92
  const items = files.map(async (file) => {
92
- const source = await readFileWithCache(file.absolutePath).catch(() => "");
93
- let data = source.length === 0 ? {} : parseMetaEntry(file.absolutePath, source);
93
+ const source = await readFileWithCache(file.fullPath).catch(() => "");
94
+ let data = source.length === 0 ? {} : parseMetaEntry(file.fullPath, source);
94
95
  if (collection?.schema) {
95
96
  data = await validate(
96
97
  collection.schema,
97
98
  data,
98
99
  {
99
100
  source,
100
- path: file.absolutePath
101
+ path: file.fullPath
101
102
  },
102
- `invalid data in ${file.absolutePath}`
103
+ `invalid data in ${file.fullPath}`
103
104
  );
104
105
  }
105
106
  return JSON.stringify({
@@ -123,20 +124,20 @@ async function generateJS(configPath, config, importPath, configHash = false) {
123
124
  }
124
125
  const entries2 = files.map(async (file) => {
125
126
  const parsed = fumaMatter(
126
- await readFileWithCache(file.absolutePath).catch(() => "")
127
+ await readFileWithCache(file.fullPath).catch(() => "")
127
128
  );
128
129
  let data = parsed.data;
129
130
  if (collection.schema) {
130
131
  data = await validate(
131
132
  collection.schema,
132
133
  parsed.data,
133
- { path: file.absolutePath, source: parsed.content },
134
- `invalid frontmatter in ${file.absolutePath}`
134
+ { path: file.fullPath, source: parsed.content },
135
+ `invalid frontmatter in ${file.fullPath}`
135
136
  );
136
137
  }
137
138
  let lastModified;
138
139
  if (config.global?.lastModifiedTime === "git") {
139
- lastModified = await getGitTimestamp(file.absolutePath);
140
+ lastModified = await getGitTimestamp(file.fullPath);
140
141
  }
141
142
  return JSON.stringify({
142
143
  info: file,
@@ -183,14 +184,14 @@ async function getCollectionFiles(collection) {
183
184
  await Promise.all(
184
185
  dirs.map(async (dir) => {
185
186
  const result = await glob(patterns, {
186
- cwd: path.resolve(dir),
187
- absolute: true
187
+ cwd: path.resolve(dir)
188
188
  });
189
189
  for (const item of result) {
190
190
  if (!isFileSupported(item, collection)) continue;
191
- files.set(item, {
192
- path: path.relative(dir, item),
193
- absolutePath: item
191
+ const fullPath = path.join(dir, item);
192
+ files.set(fullPath, {
193
+ path: item,
194
+ fullPath
194
195
  });
195
196
  }
196
197
  })
@@ -211,6 +212,8 @@ function parseMetaEntry(file, content) {
211
212
  }
212
213
 
213
214
  // src/map/index.ts
215
+ import * as path2 from "path";
216
+ import * as fs2 from "fs/promises";
214
217
  async function start(dev, configPath, outDir) {
215
218
  let configHash = await getConfigHash(configPath);
216
219
  let config = await loadConfig(configPath, outDir, configHash, true);
@@ -335,20 +338,8 @@ function createMDX({
335
338
  };
336
339
  }
337
340
 
338
- // src/postinstall.ts
339
- import * as path3 from "path";
340
- import * as fs3 from "fs/promises";
341
- import { existsSync } from "fs";
342
- async function postInstall(configPath = findConfigFile(), outDir) {
343
- const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.ts");
344
- if (isNext) {
345
- await onNext(configPath, outDir ?? ".source");
346
- } else {
347
- await onVite(configPath, outDir ?? process.cwd());
348
- }
349
- console.log("[MDX] types generated");
350
- }
351
- async function onNext(configPath, outDir) {
341
+ // src/next/index.ts
342
+ async function postInstall(configPath = findConfigFile(), outDir = ".source") {
352
343
  const config = await loadConfig(configPath, outDir, void 0, true);
353
344
  const outPath = path3.join(outDir, "index.ts");
354
345
  await fs3.rm(outDir, { recursive: true });
@@ -358,14 +349,7 @@ async function onNext(configPath, outDir) {
358
349
  outPath,
359
350
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
360
351
  );
361
- }
362
- async function onVite(configPath, outDir, addJsExtension) {
363
- const config = await loadConfig(configPath, "node_modules", void 0, true);
364
- const outFile = "source.generated.ts";
365
- await fs3.writeFile(
366
- path3.join(outDir, outFile),
367
- entry(configPath, config, outDir, addJsExtension)
368
- );
352
+ console.log("[MDX] types generated");
369
353
  }
370
354
  export {
371
355
  createMDX,