fumadocs-mdx 11.6.11 → 11.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/{chunk-64MMPGML.js → chunk-2CSSQTP6.js} +1 -10
  2. package/dist/{chunk-SXOJYWZ3.js → chunk-2KBRPMAM.js} +1 -1
  3. package/dist/{chunk-6PDS7MUA.js → chunk-C5INPAZJ.js} +4 -4
  4. package/dist/{chunk-DRVUBK5B.js → chunk-GWR7KMRU.js} +13 -1
  5. package/dist/chunk-OWZSTKKX.js +58 -0
  6. package/dist/{chunk-22SBT5SQ.js → chunk-ZOWJF3OH.js} +6 -6
  7. package/dist/config/index.cjs +4 -19
  8. package/dist/config/index.d.cts +3 -7
  9. package/dist/config/index.d.ts +3 -7
  10. package/dist/config/index.js +7 -13
  11. package/dist/{types-DVeuYiq5.d.cts → define-CCrinVBZ.d.cts} +37 -119
  12. package/dist/{types-DVeuYiq5.d.ts → define-CCrinVBZ.d.ts} +37 -119
  13. package/dist/index.d.cts +6 -7
  14. package/dist/index.d.ts +6 -7
  15. package/dist/loader-mdx.cjs +155 -134
  16. package/dist/loader-mdx.js +7 -10
  17. package/dist/mdx-options-UDV5WEFU.js +6 -0
  18. package/dist/next/index.cjs +253 -85
  19. package/dist/next/index.js +49 -63
  20. package/dist/runtime/async.cjs +167 -15
  21. package/dist/runtime/async.d.cts +5 -6
  22. package/dist/runtime/async.d.ts +5 -6
  23. package/dist/runtime/async.js +24 -15
  24. package/dist/runtime/vite.cjs +150 -0
  25. package/dist/runtime/vite.d.cts +71 -0
  26. package/dist/runtime/vite.d.ts +71 -0
  27. package/dist/runtime/vite.js +123 -0
  28. package/dist/{types-HIdjlLo0.d.ts → types-C0bKwtAx.d.ts} +38 -50
  29. package/dist/{types-BcUhOIxN.d.cts → types-CnslxmoO.d.cts} +38 -50
  30. package/dist/vite/index.cjs +385 -134
  31. package/dist/vite/index.d.cts +12 -3
  32. package/dist/vite/index.d.ts +12 -3
  33. package/dist/vite/index.js +165 -20
  34. package/package.json +20 -10
@@ -30,6 +30,134 @@ 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-exports.ts
34
+ function remarkMdxExport({ values }) {
35
+ return (tree, vfile) => {
36
+ for (const name of values) {
37
+ if (!(name in vfile.data)) return;
38
+ tree.children.unshift(getMdastExport(name, vfile.data[name]));
39
+ }
40
+ };
41
+ }
42
+ function getMdastExport(name, value) {
43
+ return {
44
+ type: "mdxjsEsm",
45
+ value: "",
46
+ data: {
47
+ estree: {
48
+ type: "Program",
49
+ sourceType: "module",
50
+ body: [
51
+ {
52
+ type: "ExportNamedDeclaration",
53
+ specifiers: [],
54
+ source: null,
55
+ declaration: {
56
+ type: "VariableDeclaration",
57
+ kind: "let",
58
+ declarations: [
59
+ {
60
+ type: "VariableDeclarator",
61
+ id: {
62
+ type: "Identifier",
63
+ name
64
+ },
65
+ init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
66
+ }
67
+ ]
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ };
74
+ }
75
+ var import_estree_util_value_to_estree;
76
+ var init_remark_exports = __esm({
77
+ "src/mdx-plugins/remark-exports.ts"() {
78
+ "use strict";
79
+ import_estree_util_value_to_estree = require("estree-util-value-to-estree");
80
+ }
81
+ });
82
+
83
+ // src/utils/mdx-options.ts
84
+ var mdx_options_exports = {};
85
+ __export(mdx_options_exports, {
86
+ getDefaultMDXOptions: () => getDefaultMDXOptions
87
+ });
88
+ function pluginOption(def, options = []) {
89
+ const list = def(Array.isArray(options) ? options : []).filter(
90
+ Boolean
91
+ );
92
+ if (typeof options === "function") {
93
+ return options(list);
94
+ }
95
+ return list;
96
+ }
97
+ function getDefaultMDXOptions({
98
+ valueToExport = [],
99
+ rehypeCodeOptions,
100
+ remarkImageOptions,
101
+ remarkHeadingOptions,
102
+ remarkStructureOptions,
103
+ remarkCodeTabOptions,
104
+ remarkNpmOptions,
105
+ ...mdxOptions
106
+ }) {
107
+ const mdxExports = [
108
+ "structuredData",
109
+ "frontmatter",
110
+ "lastModified",
111
+ ...valueToExport
112
+ ];
113
+ const remarkPlugins = pluginOption(
114
+ (v) => [
115
+ plugins.remarkGfm,
116
+ [
117
+ plugins.remarkHeading,
118
+ {
119
+ generateToc: false,
120
+ ...remarkHeadingOptions
121
+ }
122
+ ],
123
+ remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
124
+ "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
125
+ plugins.remarkCodeTab,
126
+ remarkCodeTabOptions
127
+ ],
128
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
129
+ ...v,
130
+ remarkStructureOptions !== false && [
131
+ plugins.remarkStructure,
132
+ remarkStructureOptions
133
+ ],
134
+ [remarkMdxExport, { values: mdxExports }]
135
+ ],
136
+ mdxOptions.remarkPlugins
137
+ );
138
+ const rehypePlugins = pluginOption(
139
+ (v) => [
140
+ rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
141
+ ...v,
142
+ plugins.rehypeToc
143
+ ],
144
+ mdxOptions.rehypePlugins
145
+ );
146
+ return {
147
+ ...mdxOptions,
148
+ remarkPlugins,
149
+ rehypePlugins
150
+ };
151
+ }
152
+ var plugins;
153
+ var init_mdx_options = __esm({
154
+ "src/utils/mdx-options.ts"() {
155
+ "use strict";
156
+ plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
157
+ init_remark_exports();
158
+ }
159
+ });
160
+
33
161
  // src/map/watcher.ts
34
162
  var watcher_exports = {};
35
163
  __export(watcher_exports, {
@@ -101,11 +229,23 @@ function buildConfig(config) {
101
229
  null
102
230
  ];
103
231
  }
232
+ let cachedMdxOptions;
104
233
  return [
105
234
  null,
106
235
  {
107
236
  global: globalConfig,
108
- collections
237
+ collections,
238
+ async getDefaultMDXOptions() {
239
+ if (cachedMdxOptions) return cachedMdxOptions;
240
+ const input = this.global?.mdxOptions;
241
+ async function uncached() {
242
+ const options = typeof input === "function" ? await input() : input;
243
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
244
+ if (options?.preset === "minimal") return options;
245
+ return getDefaultMDXOptions2(options ?? {});
246
+ }
247
+ return cachedMdxOptions = uncached();
248
+ }
109
249
  }
110
250
  ];
111
251
  }
@@ -161,24 +301,14 @@ async function getConfigHash(configPath) {
161
301
  }
162
302
 
163
303
  // src/map/index.ts
164
- var path4 = __toESM(require("path"), 1);
304
+ var path5 = __toESM(require("path"), 1);
165
305
  var fs3 = __toESM(require("fs/promises"), 1);
166
306
 
167
307
  // src/map/generate.ts
168
- var path3 = __toESM(require("path"), 1);
308
+ var path4 = __toESM(require("path"), 1);
169
309
  var fs2 = __toESM(require("fs/promises"), 1);
170
310
  var import_tinyglobby = require("tinyglobby");
171
311
 
172
- // src/utils/get-type-from-path.ts
173
- var import_node_path = require("path");
174
- var docTypes = [".mdx", ".md"];
175
- var metaTypes = [".json", ".yaml"];
176
- function getTypeFromPath(path6) {
177
- const ext = (0, import_node_path.extname)(path6);
178
- if (docTypes.includes(ext)) return "doc";
179
- if (metaTypes.includes(ext)) return "meta";
180
- }
181
-
182
312
  // src/utils/schema.ts
183
313
  var import_zod = require("zod");
184
314
  var import_picocolors = __toESM(require("picocolors"), 1);
@@ -200,16 +330,16 @@ var frontmatterSchema = import_zod.z.object({
200
330
  });
201
331
  var ValidationError = class extends Error {
202
332
  constructor(message, issues) {
203
- super(message);
333
+ super(
334
+ `${message}:
335
+ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
336
+ );
337
+ this.title = message;
204
338
  this.issues = issues;
205
339
  }
206
- toString() {
207
- return `${this.message}:
208
- ${this.issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
209
- }
210
340
  toStringFormatted() {
211
341
  return [
212
- import_picocolors.default.bold(`[MDX] ${this.message}:`),
342
+ import_picocolors.default.bold(`[MDX] ${this.title}:`),
213
343
  ...this.issues.map(
214
344
  (issue) => import_picocolors.default.redBright(
215
345
  `- ${import_picocolors.default.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
@@ -240,16 +370,16 @@ var map = new import_lru_cache.LRUCache({
240
370
  max: 200
241
371
  });
242
372
  var fileCache = {
243
- read(namespace, path6) {
244
- return map.get(`${namespace}.${path6}`);
373
+ read(namespace, path7) {
374
+ return map.get(`${namespace}.${path7}`);
245
375
  },
246
- write(namespace, path6, data) {
247
- map.set(`${namespace}.${path6}`, data);
376
+ write(namespace, path7, data) {
377
+ map.set(`${namespace}.${path7}`, data);
248
378
  },
249
- removeCache(path6) {
379
+ removeCache(path7) {
250
380
  for (const key of map.keys()) {
251
381
  const keyPath = key.slice(key.indexOf(".") + 1);
252
- if (keyPath === path6) map.delete(key);
382
+ if (keyPath === path7) map.delete(key);
253
383
  }
254
384
  }
255
385
  };
@@ -258,7 +388,7 @@ var fileCache = {
258
388
  var import_js_yaml2 = require("js-yaml");
259
389
 
260
390
  // src/utils/git-timestamp.ts
261
- var import_node_path2 = __toESM(require("path"), 1);
391
+ var import_node_path = __toESM(require("path"), 1);
262
392
  var import_tinyexec = require("tinyexec");
263
393
  var cache2 = /* @__PURE__ */ new Map();
264
394
  async function getGitTimestamp(file) {
@@ -267,7 +397,7 @@ async function getGitTimestamp(file) {
267
397
  try {
268
398
  const out = await (0, import_tinyexec.x)(
269
399
  "git",
270
- ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
400
+ ["log", "-1", '--pretty="%ai"', import_node_path.default.relative(process.cwd(), file)],
271
401
  {
272
402
  throwOnError: true
273
403
  }
@@ -296,6 +426,54 @@ function fumaMatter(input) {
296
426
  return output;
297
427
  }
298
428
 
429
+ // src/utils/import-formatter.ts
430
+ var import_node_path2 = __toESM(require("path"), 1);
431
+ function getImportCode(info) {
432
+ const specifier = JSON.stringify(info.specifier);
433
+ if (info.type === "default") return `import ${info.name} from ${specifier}`;
434
+ if (info.type === "namespace")
435
+ return `import * as ${info.name} from ${specifier}`;
436
+ if (info.type === "named") {
437
+ const names = info.names.map(
438
+ (name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
439
+ );
440
+ return `import { ${names.join(", ")} } from ${specifier}`;
441
+ }
442
+ return `import ${specifier}`;
443
+ }
444
+ function toImportPath(file, config) {
445
+ const ext = import_node_path2.default.extname(file);
446
+ const filename = ext === ".ts" ? file.substring(0, file.length - ext.length) : file;
447
+ let importPath;
448
+ if ("relativeTo" in config) {
449
+ importPath = import_node_path2.default.relative(config.relativeTo, filename);
450
+ if (!import_node_path2.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
451
+ importPath = `./${importPath}`;
452
+ }
453
+ } else {
454
+ importPath = import_node_path2.default.resolve(filename);
455
+ }
456
+ return importPath.replaceAll(import_node_path2.default.sep, "/");
457
+ }
458
+
459
+ // src/utils/collections.ts
460
+ function getSupportedFormats(collection) {
461
+ return {
462
+ doc: ["mdx", "md"],
463
+ meta: ["json", "yaml"]
464
+ }[collection.type];
465
+ }
466
+ function getGlobPatterns(collection) {
467
+ if (collection.files) return collection.files;
468
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
469
+ }
470
+ function isFileSupported(filePath, collection) {
471
+ for (const format of getSupportedFormats(collection)) {
472
+ if (filePath.endsWith(`.${format}`)) return true;
473
+ }
474
+ return false;
475
+ }
476
+
299
477
  // src/map/generate.ts
300
478
  async function readFileWithCache(file) {
301
479
  const cached = fileCache.read("read-file", file);
@@ -428,16 +606,17 @@ async function generateJS(configPath, config, importPath, configHash = false) {
428
606
  async function getCollectionFiles(collection) {
429
607
  const files = /* @__PURE__ */ new Map();
430
608
  const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
609
+ const patterns = getGlobPatterns(collection);
431
610
  await Promise.all(
432
611
  dirs.map(async (dir) => {
433
- const result = await (0, import_tinyglobby.glob)(collection.files ?? "**/*", {
434
- cwd: path3.resolve(dir),
612
+ const result = await (0, import_tinyglobby.glob)(patterns, {
613
+ cwd: path4.resolve(dir),
435
614
  absolute: true
436
615
  });
437
616
  for (const item of result) {
438
- if (getTypeFromPath(item) !== collection.type) continue;
617
+ if (!isFileSupported(item, collection)) continue;
439
618
  files.set(item, {
440
- path: path3.relative(dir, item),
619
+ path: path4.relative(dir, item),
441
620
  absolutePath: item
442
621
  });
443
622
  }
@@ -445,51 +624,24 @@ async function getCollectionFiles(collection) {
445
624
  );
446
625
  return Array.from(files.values());
447
626
  }
448
- function getImportCode(info) {
449
- const specifier = JSON.stringify(info.specifier);
450
- if (info.type === "default") return `import ${info.name} from ${specifier}`;
451
- if (info.type === "namespace")
452
- return `import * as ${info.name} from ${specifier}`;
453
- if (info.type === "named") {
454
- const names = info.names.map(
455
- (name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
456
- );
457
- return `import { ${names.join(", ")} } from ${specifier}`;
458
- }
459
- return `import ${specifier}`;
460
- }
461
- function toImportPath(file, config) {
462
- const ext = path3.extname(file);
463
- const filename = ext === ".ts" ? file.substring(0, file.length - ext.length) : file;
464
- let importPath;
465
- if ("relativeTo" in config) {
466
- importPath = path3.relative(config.relativeTo, filename);
467
- if (!path3.isAbsolute(importPath) && !importPath.startsWith(".")) {
468
- importPath = `./${importPath}`;
469
- }
470
- } else {
471
- importPath = path3.resolve(filename);
472
- }
473
- return importPath.replaceAll(path3.sep, "/");
474
- }
475
627
  function parseMetaEntry(file, content) {
476
- const extname3 = path3.extname(file);
628
+ const extname2 = path4.extname(file);
477
629
  try {
478
- if (extname3 === ".json") return JSON.parse(content);
479
- if (extname3 === ".yaml") return (0, import_js_yaml2.load)(content);
630
+ if (extname2 === ".json") return JSON.parse(content);
631
+ if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
480
632
  } catch (e) {
481
633
  throw new Error(`Failed to parse meta file: ${file}.`, {
482
634
  cause: e
483
635
  });
484
636
  }
485
- throw new Error(`Unknown meta file format: ${extname3}, in ${file}.`);
637
+ throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
486
638
  }
487
639
 
488
640
  // src/map/index.ts
489
641
  async function start(dev, configPath, outDir) {
490
642
  let configHash = await getConfigHash(configPath);
491
643
  let config = await loadConfig(configPath, outDir, configHash, true);
492
- const outPath = path4.resolve(outDir, `index.ts`);
644
+ const outPath = path5.resolve(outDir, `index.ts`);
493
645
  async function updateMapFile() {
494
646
  const start2 = performance.now();
495
647
  try {
@@ -520,7 +672,7 @@ async function start(dev, configPath, outDir) {
520
672
  });
521
673
  instance.on("all", (event, file) => {
522
674
  if (typeof file !== "string") return;
523
- const absolutePath = path4.resolve(file);
675
+ const absolutePath = path5.resolve(file);
524
676
  const onUpdate = async () => {
525
677
  const isConfigFile = absolutePath === configPath;
526
678
  if (isConfigFile) {
@@ -540,7 +692,16 @@ async function start(dev, configPath, outDir) {
540
692
  }
541
693
 
542
694
  // src/next/create.ts
695
+ var import_node_fs = require("fs");
543
696
  var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
697
+ var isTurboExperimental;
698
+ try {
699
+ const content = (0, import_node_fs.readFileSync)("./node_modules/next/package.json").toString();
700
+ const version = JSON.parse(content).version;
701
+ isTurboExperimental = version.startsWith("15.0.") || version.startsWith("15.1.") || version.startsWith("15.2.");
702
+ } catch {
703
+ isTurboExperimental = false;
704
+ }
544
705
  function createMDX({
545
706
  configPath = findConfigFile(),
546
707
  outDir = ".source"
@@ -556,24 +717,25 @@ function createMDX({
556
717
  configPath,
557
718
  outDir
558
719
  };
559
- return {
560
- ...nextConfig,
561
- turbopack: {
562
- ...nextConfig?.turbopack,
563
- rules: {
564
- ...nextConfig?.turbopack?.rules,
565
- // @ts-expect-error -- safe
566
- "*.{md,mdx}": {
567
- loaders: [
568
- {
569
- loader: "fumadocs-mdx/loader-mdx",
570
- options: mdxLoaderOptions
571
- }
572
- ],
573
- as: "*.js"
574
- }
720
+ const turbo = {
721
+ ...nextConfig.experimental?.turbo,
722
+ ...nextConfig.turbopack,
723
+ rules: {
724
+ ...nextConfig.experimental?.turbo?.rules,
725
+ ...nextConfig.turbopack?.rules,
726
+ "*.{md,mdx}": {
727
+ loaders: [
728
+ {
729
+ loader: "fumadocs-mdx/loader-mdx",
730
+ options: mdxLoaderOptions
731
+ }
732
+ ],
733
+ as: "*.js"
575
734
  }
576
- },
735
+ }
736
+ };
737
+ const updated = {
738
+ ...nextConfig,
577
739
  pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
578
740
  webpack: (config, options) => {
579
741
  config.resolve ||= {};
@@ -593,18 +755,24 @@ function createMDX({
593
755
  return nextConfig.webpack?.(config, options) ?? config;
594
756
  }
595
757
  };
758
+ if (isTurboExperimental) {
759
+ updated.experimental = { ...updated.experimental, turbo };
760
+ } else {
761
+ updated.turbopack = turbo;
762
+ }
763
+ return updated;
596
764
  };
597
765
  }
598
766
 
599
767
  // src/postinstall.ts
600
- var path5 = __toESM(require("path"), 1);
768
+ var path6 = __toESM(require("path"), 1);
601
769
  var fs4 = __toESM(require("fs/promises"), 1);
602
770
  async function postInstall(configPath = findConfigFile(), outDir = ".source") {
603
- const jsOut = path5.resolve(outDir, "index.ts");
771
+ const jsOut = path6.resolve(outDir, "index.ts");
604
772
  const hash = await getConfigHash(configPath);
605
773
  const config = await loadConfig(configPath, outDir, hash, true);
606
- await fs4.rm(path5.dirname(jsOut), { recursive: true });
607
- await fs4.mkdir(path5.dirname(jsOut), { recursive: true });
774
+ await fs4.rm(path6.dirname(jsOut), { recursive: true });
775
+ await fs4.mkdir(path6.dirname(jsOut), { recursive: true });
608
776
  await fs4.writeFile(
609
777
  jsOut,
610
778
  await generateJS(configPath, config, { relativeTo: outDir }, hash)
@@ -3,12 +3,18 @@ import {
3
3
  getConfigHash,
4
4
  getGitTimestamp,
5
5
  loadConfig
6
- } from "../chunk-SXOJYWZ3.js";
6
+ } from "../chunk-2KBRPMAM.js";
7
+ import {
8
+ getGlobPatterns,
9
+ getImportCode,
10
+ isFileSupported,
11
+ toImportPath
12
+ } from "../chunk-OWZSTKKX.js";
13
+ import "../chunk-GWR7KMRU.js";
7
14
  import {
8
15
  ValidationError,
9
16
  validate
10
- } from "../chunk-22SBT5SQ.js";
11
- import "../chunk-DRVUBK5B.js";
17
+ } from "../chunk-ZOWJF3OH.js";
12
18
  import {
13
19
  fumaMatter
14
20
  } from "../chunk-KVWX6THC.js";
@@ -22,16 +28,6 @@ import * as path from "path";
22
28
  import * as fs from "fs/promises";
23
29
  import { glob } from "tinyglobby";
24
30
 
25
- // src/utils/get-type-from-path.ts
26
- import { extname } from "path";
27
- var docTypes = [".mdx", ".md"];
28
- var metaTypes = [".json", ".yaml"];
29
- function getTypeFromPath(path4) {
30
- const ext = extname(path4);
31
- if (docTypes.includes(ext)) return "doc";
32
- if (metaTypes.includes(ext)) return "meta";
33
- }
34
-
35
31
  // src/map/file-cache.ts
36
32
  import { LRUCache } from "lru-cache";
37
33
  var map = new LRUCache({
@@ -185,14 +181,15 @@ async function generateJS(configPath, config, importPath, configHash = false) {
185
181
  async function getCollectionFiles(collection) {
186
182
  const files = /* @__PURE__ */ new Map();
187
183
  const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
184
+ const patterns = getGlobPatterns(collection);
188
185
  await Promise.all(
189
186
  dirs.map(async (dir) => {
190
- const result = await glob(collection.files ?? "**/*", {
187
+ const result = await glob(patterns, {
191
188
  cwd: path.resolve(dir),
192
189
  absolute: true
193
190
  });
194
191
  for (const item of result) {
195
- if (getTypeFromPath(item) !== collection.type) continue;
192
+ if (!isFileSupported(item, collection)) continue;
196
193
  files.set(item, {
197
194
  path: path.relative(dir, item),
198
195
  absolutePath: item
@@ -202,44 +199,17 @@ async function getCollectionFiles(collection) {
202
199
  );
203
200
  return Array.from(files.values());
204
201
  }
205
- function getImportCode(info) {
206
- const specifier = JSON.stringify(info.specifier);
207
- if (info.type === "default") return `import ${info.name} from ${specifier}`;
208
- if (info.type === "namespace")
209
- return `import * as ${info.name} from ${specifier}`;
210
- if (info.type === "named") {
211
- const names = info.names.map(
212
- (name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
213
- );
214
- return `import { ${names.join(", ")} } from ${specifier}`;
215
- }
216
- return `import ${specifier}`;
217
- }
218
- function toImportPath(file, config) {
219
- const ext = path.extname(file);
220
- const filename = ext === ".ts" ? file.substring(0, file.length - ext.length) : file;
221
- let importPath;
222
- if ("relativeTo" in config) {
223
- importPath = path.relative(config.relativeTo, filename);
224
- if (!path.isAbsolute(importPath) && !importPath.startsWith(".")) {
225
- importPath = `./${importPath}`;
226
- }
227
- } else {
228
- importPath = path.resolve(filename);
229
- }
230
- return importPath.replaceAll(path.sep, "/");
231
- }
232
202
  function parseMetaEntry(file, content) {
233
- const extname3 = path.extname(file);
203
+ const extname2 = path.extname(file);
234
204
  try {
235
- if (extname3 === ".json") return JSON.parse(content);
236
- if (extname3 === ".yaml") return load(content);
205
+ if (extname2 === ".json") return JSON.parse(content);
206
+ if (extname2 === ".yaml") return load(content);
237
207
  } catch (e) {
238
208
  throw new Error(`Failed to parse meta file: ${file}.`, {
239
209
  cause: e
240
210
  });
241
211
  }
242
- throw new Error(`Unknown meta file format: ${extname3}, in ${file}.`);
212
+ throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
243
213
  }
244
214
 
245
215
  // src/map/index.ts
@@ -297,7 +267,16 @@ async function start(dev, configPath, outDir) {
297
267
  }
298
268
 
299
269
  // src/next/create.ts
270
+ import { readFileSync } from "fs";
300
271
  var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
272
+ var isTurboExperimental;
273
+ try {
274
+ const content = readFileSync("./node_modules/next/package.json").toString();
275
+ const version = JSON.parse(content).version;
276
+ isTurboExperimental = version.startsWith("15.0.") || version.startsWith("15.1.") || version.startsWith("15.2.");
277
+ } catch {
278
+ isTurboExperimental = false;
279
+ }
301
280
  function createMDX({
302
281
  configPath = findConfigFile(),
303
282
  outDir = ".source"
@@ -313,24 +292,25 @@ function createMDX({
313
292
  configPath,
314
293
  outDir
315
294
  };
316
- return {
317
- ...nextConfig,
318
- turbopack: {
319
- ...nextConfig?.turbopack,
320
- rules: {
321
- ...nextConfig?.turbopack?.rules,
322
- // @ts-expect-error -- safe
323
- "*.{md,mdx}": {
324
- loaders: [
325
- {
326
- loader: "fumadocs-mdx/loader-mdx",
327
- options: mdxLoaderOptions
328
- }
329
- ],
330
- as: "*.js"
331
- }
295
+ const turbo = {
296
+ ...nextConfig.experimental?.turbo,
297
+ ...nextConfig.turbopack,
298
+ rules: {
299
+ ...nextConfig.experimental?.turbo?.rules,
300
+ ...nextConfig.turbopack?.rules,
301
+ "*.{md,mdx}": {
302
+ loaders: [
303
+ {
304
+ loader: "fumadocs-mdx/loader-mdx",
305
+ options: mdxLoaderOptions
306
+ }
307
+ ],
308
+ as: "*.js"
332
309
  }
333
- },
310
+ }
311
+ };
312
+ const updated = {
313
+ ...nextConfig,
334
314
  pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
335
315
  webpack: (config, options) => {
336
316
  config.resolve ||= {};
@@ -350,6 +330,12 @@ function createMDX({
350
330
  return nextConfig.webpack?.(config, options) ?? config;
351
331
  }
352
332
  };
333
+ if (isTurboExperimental) {
334
+ updated.experimental = { ...updated.experimental, turbo };
335
+ } else {
336
+ updated.turbopack = turbo;
337
+ }
338
+ return updated;
353
339
  };
354
340
  }
355
341