fumadocs-mdx 11.7.0 → 11.7.3

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildConfig
3
- } from "./chunk-GWR7KMRU.js";
3
+ } from "./chunk-JFNBRKRV.js";
4
4
 
5
5
  // src/utils/config.ts
6
6
  import * as fs from "fs/promises";
@@ -37,12 +37,10 @@ async function loadConfig(configPath, outDir, hash, build = false) {
37
37
  if (build) await compileConfig(configPath, outDir);
38
38
  const url = pathToFileURL(path.resolve(outDir, "source.config.mjs"));
39
39
  const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
40
- const [err, config2] = buildConfig(
40
+ return buildConfig(
41
41
  // every call to `loadConfig` will cause the previous cache to be ignored
42
42
  loaded
43
43
  );
44
- if (err !== null) throw new Error(err);
45
- return config2;
46
44
  });
47
45
  cache = { config, hash };
48
46
  return await config;
@@ -55,32 +53,8 @@ async function getConfigHash(configPath) {
55
53
  throw new Error("Cannot find config file");
56
54
  }
57
55
 
58
- // src/utils/git-timestamp.ts
59
- import path2 from "path";
60
- import { x } from "tinyexec";
61
- var cache2 = /* @__PURE__ */ new Map();
62
- async function getGitTimestamp(file) {
63
- const cached = cache2.get(file);
64
- if (cached) return cached;
65
- try {
66
- const out = await x(
67
- "git",
68
- ["log", "-1", '--pretty="%ai"', path2.relative(process.cwd(), file)],
69
- {
70
- throwOnError: true
71
- }
72
- );
73
- const time = new Date(out.stdout);
74
- cache2.set(file, time);
75
- return time;
76
- } catch {
77
- return;
78
- }
79
- }
80
-
81
56
  export {
82
57
  findConfigFile,
83
58
  loadConfig,
84
- getConfigHash,
85
- getGitTimestamp
59
+ getConfigHash
86
60
  };
@@ -0,0 +1,47 @@
1
+ // src/config/build.ts
2
+ function buildConfig(config) {
3
+ const collections = /* @__PURE__ */ new Map();
4
+ let globalConfig = {};
5
+ for (const [k, v] of Object.entries(config)) {
6
+ if (!v) {
7
+ continue;
8
+ }
9
+ if (typeof v === "object" && "type" in v) {
10
+ if (v.type === "docs") {
11
+ collections.set(k, v);
12
+ continue;
13
+ }
14
+ if (v.type === "doc" || v.type === "meta") {
15
+ collections.set(k, v);
16
+ continue;
17
+ }
18
+ }
19
+ if (k === "default" && v) {
20
+ globalConfig = v;
21
+ continue;
22
+ }
23
+ throw new Error(
24
+ `Unknown export "${k}", you can only export collections from source configuration file.`
25
+ );
26
+ }
27
+ let cachedMdxOptions;
28
+ return {
29
+ global: globalConfig,
30
+ collections,
31
+ async getDefaultMDXOptions() {
32
+ if (cachedMdxOptions) return cachedMdxOptions;
33
+ const input = this.global.mdxOptions;
34
+ async function uncached() {
35
+ const options = typeof input === "function" ? await input() : input;
36
+ const { getDefaultMDXOptions } = await import("./mdx-options-UDV5WEFU.js");
37
+ if (options?.preset === "minimal") return options;
38
+ return getDefaultMDXOptions(options ?? {});
39
+ }
40
+ return cachedMdxOptions = uncached();
41
+ }
42
+ };
43
+ }
44
+
45
+ export {
46
+ buildConfig
47
+ };
@@ -27,8 +27,32 @@ function toImportPath(file, config) {
27
27
  }
28
28
  return importPath.replaceAll(path.sep, "/");
29
29
  }
30
+ function ident(code, tab = 1) {
31
+ return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
32
+ }
33
+
34
+ // src/utils/collections.ts
35
+ function getSupportedFormats(collection) {
36
+ return {
37
+ doc: ["mdx", "md"],
38
+ meta: ["json", "yaml"]
39
+ }[collection.type];
40
+ }
41
+ function getGlobPatterns(collection) {
42
+ if (collection.files) return collection.files;
43
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
44
+ }
45
+ function isFileSupported(filePath, collection) {
46
+ for (const format of getSupportedFormats(collection)) {
47
+ if (filePath.endsWith(`.${format}`)) return true;
48
+ }
49
+ return false;
50
+ }
30
51
 
31
52
  export {
32
53
  getImportCode,
33
- toImportPath
54
+ toImportPath,
55
+ ident,
56
+ getGlobPatterns,
57
+ isFileSupported
34
58
  };
@@ -0,0 +1,26 @@
1
+ // src/utils/git-timestamp.ts
2
+ import path from "path";
3
+ import { x } from "tinyexec";
4
+ var cache = /* @__PURE__ */ new Map();
5
+ async function getGitTimestamp(file) {
6
+ const cached = cache.get(file);
7
+ if (cached) return cached;
8
+ try {
9
+ const out = await x(
10
+ "git",
11
+ ["log", "-1", '--pretty="%ai"', path.relative(process.cwd(), file)],
12
+ {
13
+ throwOnError: true
14
+ }
15
+ );
16
+ const time = new Date(out.stdout);
17
+ cache.set(file, time);
18
+ return time;
19
+ } catch {
20
+ return;
21
+ }
22
+ }
23
+
24
+ export {
25
+ getGitTimestamp
26
+ };
@@ -76,13 +76,11 @@ function defineDocs(options) {
76
76
  docs: defineCollections({
77
77
  type: "doc",
78
78
  dir,
79
- files: ["**/*.{md,mdx}"],
80
79
  schema: frontmatterSchema,
81
80
  ...options?.docs
82
81
  }),
83
82
  meta: defineCollections({
84
83
  type: "meta",
85
- files: ["**/*.{json,yaml}"],
86
84
  dir,
87
85
  schema: metaSchema,
88
86
  ...options?.meta
@@ -1,4 +1,4 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, b as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-CCrinVBZ.cjs';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-E6TRBwBQ.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import 'zod';
@@ -1,4 +1,4 @@
1
- export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, b as DefaultMDXOptions, D as DocCollection, a as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-CCrinVBZ.js';
1
+ export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, f as frontmatterSchema, g as getDefaultMDXOptions, m as metaSchema } from '../define-E6TRBwBQ.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import 'zod';
@@ -26,13 +26,11 @@ function defineDocs(options) {
26
26
  docs: defineCollections({
27
27
  type: "doc",
28
28
  dir,
29
- files: ["**/*.{md,mdx}"],
30
29
  schema: frontmatterSchema,
31
30
  ...options?.docs
32
31
  }),
33
32
  meta: defineCollections({
34
33
  type: "meta",
35
- files: ["**/*.{json,yaml}"],
36
34
  dir,
37
35
  schema: metaSchema,
38
36
  ...options?.meta
@@ -106,4 +106,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
106
106
  }): DocsCollection<DocSchema, MetaSchema, Async>;
107
107
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
108
108
 
109
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DocCollection as D, type GlobalConfig as G, type MetaCollection as M, type DocsCollection as a, type DefaultMDXOptions as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
109
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
@@ -106,4 +106,4 @@ declare function defineDocs<DocSchema extends StandardSchemaV1 = typeof frontmat
106
106
  }): DocsCollection<DocSchema, MetaSchema, Async>;
107
107
  declare function defineConfig(config?: GlobalConfig): GlobalConfig;
108
108
 
109
- export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DocCollection as D, type GlobalConfig as G, type MetaCollection as M, type DocsCollection as a, type DefaultMDXOptions as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
109
+ export { type AnyCollection as A, type BaseCollection as B, type CollectionSchema as C, type DefaultMDXOptions as D, type GlobalConfig as G, type MetaCollection as M, type DocCollection as a, type DocsCollection as b, defineDocs as c, defineCollections as d, defineConfig as e, frontmatterSchema as f, getDefaultMDXOptions as g, metaSchema as m };
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-CnslxmoO.cjs';
2
+ import { R as Runtime, B as BaseCollectionEntry } from './types-Lh_-Uuix.cjs';
3
3
  import '@standard-schema/spec';
4
- import './define-CCrinVBZ.cjs';
4
+ import './define-E6TRBwBQ.cjs';
5
5
  import 'zod';
6
6
  import 'fumadocs-core/mdx-plugins';
7
7
  import '@mdx-js/mdx';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-C0bKwtAx.js';
2
+ import { R as Runtime, B as BaseCollectionEntry } from './types-DiL328cG.js';
3
3
  import '@standard-schema/spec';
4
- import './define-CCrinVBZ.js';
4
+ import './define-E6TRBwBQ.js';
5
5
  import 'zod';
6
6
  import 'fumadocs-core/mdx-plugins';
7
7
  import '@mdx-js/mdx';
@@ -175,7 +175,7 @@ var import_node_url = require("url");
175
175
  // src/config/build.ts
176
176
  function buildConfig(config) {
177
177
  const collections = /* @__PURE__ */ new Map();
178
- let globalConfig;
178
+ let globalConfig = {};
179
179
  for (const [k, v] of Object.entries(config)) {
180
180
  if (!v) {
181
181
  continue;
@@ -190,34 +190,30 @@ function buildConfig(config) {
190
190
  continue;
191
191
  }
192
192
  }
193
- if (k === "default") {
193
+ if (k === "default" && v) {
194
194
  globalConfig = v;
195
195
  continue;
196
196
  }
197
- return [
198
- `Unknown export "${k}", you can only export collections from source configuration file.`,
199
- null
200
- ];
197
+ throw new Error(
198
+ `Unknown export "${k}", you can only export collections from source configuration file.`
199
+ );
201
200
  }
202
201
  let cachedMdxOptions;
203
- return [
204
- null,
205
- {
206
- global: globalConfig,
207
- collections,
208
- async getDefaultMDXOptions() {
209
- if (cachedMdxOptions) return cachedMdxOptions;
210
- const input = this.global?.mdxOptions;
211
- async function uncached() {
212
- const options = typeof input === "function" ? await input() : input;
213
- const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
214
- if (options?.preset === "minimal") return options;
215
- return getDefaultMDXOptions2(options ?? {});
216
- }
217
- return cachedMdxOptions = uncached();
202
+ return {
203
+ global: globalConfig,
204
+ collections,
205
+ async getDefaultMDXOptions() {
206
+ if (cachedMdxOptions) return cachedMdxOptions;
207
+ const input = this.global.mdxOptions;
208
+ async function uncached() {
209
+ const options = typeof input === "function" ? await input() : input;
210
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
211
+ if (options?.preset === "minimal") return options;
212
+ return getDefaultMDXOptions2(options ?? {});
218
213
  }
214
+ return cachedMdxOptions = uncached();
219
215
  }
220
- ];
216
+ };
221
217
  }
222
218
 
223
219
  // src/utils/config.ts
@@ -249,12 +245,10 @@ async function loadConfig(configPath, outDir, hash, build = false) {
249
245
  if (build) await compileConfig(configPath, outDir);
250
246
  const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
251
247
  const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
252
- const [err, config2] = buildConfig(
248
+ return buildConfig(
253
249
  // every call to `loadConfig` will cause the previous cache to be ignored
254
250
  loaded
255
251
  );
256
- if (err !== null) throw new Error(err);
257
- return config2;
258
252
  });
259
253
  cache = { config, hash };
260
254
  return await config;
@@ -1,18 +1,20 @@
1
1
  import {
2
2
  getConfigHash,
3
- getGitTimestamp,
4
3
  loadConfig
5
- } from "./chunk-2KBRPMAM.js";
4
+ } from "./chunk-4CGSOZUZ.js";
6
5
  import {
7
6
  buildMDX,
8
7
  countLines
9
8
  } from "./chunk-C5INPAZJ.js";
10
- import "./chunk-GWR7KMRU.js";
9
+ import {
10
+ getGitTimestamp
11
+ } from "./chunk-VUEZTR2H.js";
11
12
  import {
12
13
  ValidationError,
13
14
  validate
14
15
  } from "./chunk-ZOWJF3OH.js";
15
16
  import "./chunk-AVMO2SRO.js";
17
+ import "./chunk-JFNBRKRV.js";
16
18
  import {
17
19
  fumaMatter
18
20
  } from "./chunk-KVWX6THC.js";
@@ -205,7 +205,7 @@ var import_node_url = require("url");
205
205
  // src/config/build.ts
206
206
  function buildConfig(config) {
207
207
  const collections = /* @__PURE__ */ new Map();
208
- let globalConfig;
208
+ let globalConfig = {};
209
209
  for (const [k, v] of Object.entries(config)) {
210
210
  if (!v) {
211
211
  continue;
@@ -220,34 +220,30 @@ function buildConfig(config) {
220
220
  continue;
221
221
  }
222
222
  }
223
- if (k === "default") {
223
+ if (k === "default" && v) {
224
224
  globalConfig = v;
225
225
  continue;
226
226
  }
227
- return [
228
- `Unknown export "${k}", you can only export collections from source configuration file.`,
229
- null
230
- ];
227
+ throw new Error(
228
+ `Unknown export "${k}", you can only export collections from source configuration file.`
229
+ );
231
230
  }
232
231
  let cachedMdxOptions;
233
- return [
234
- null,
235
- {
236
- global: globalConfig,
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();
232
+ return {
233
+ global: globalConfig,
234
+ collections,
235
+ async getDefaultMDXOptions() {
236
+ if (cachedMdxOptions) return cachedMdxOptions;
237
+ const input = this.global.mdxOptions;
238
+ async function uncached() {
239
+ const options = typeof input === "function" ? await input() : input;
240
+ const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_mdx_options(), mdx_options_exports));
241
+ if (options?.preset === "minimal") return options;
242
+ return getDefaultMDXOptions2(options ?? {});
248
243
  }
244
+ return cachedMdxOptions = uncached();
249
245
  }
250
- ];
246
+ };
251
247
  }
252
248
 
253
249
  // src/utils/config.ts
@@ -282,12 +278,10 @@ async function loadConfig(configPath, outDir, hash, build = false) {
282
278
  if (build) await compileConfig(configPath, outDir);
283
279
  const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
284
280
  const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
285
- const [err, config2] = buildConfig(
281
+ return buildConfig(
286
282
  // every call to `loadConfig` will cause the previous cache to be ignored
287
283
  loaded
288
284
  );
289
- if (err !== null) throw new Error(err);
290
- return config2;
291
285
  });
292
286
  cache = { config, hash };
293
287
  return await config;
@@ -309,16 +303,6 @@ var path4 = __toESM(require("path"), 1);
309
303
  var fs2 = __toESM(require("fs/promises"), 1);
310
304
  var import_tinyglobby = require("tinyglobby");
311
305
 
312
- // src/utils/get-type-from-path.ts
313
- var import_node_path = require("path");
314
- var docTypes = [".mdx", ".md"];
315
- var metaTypes = [".json", ".yaml"];
316
- function getTypeFromPath(path7) {
317
- const ext = (0, import_node_path.extname)(path7);
318
- if (docTypes.includes(ext)) return "doc";
319
- if (metaTypes.includes(ext)) return "meta";
320
- }
321
-
322
306
  // src/utils/schema.ts
323
307
  var import_zod = require("zod");
324
308
  var import_picocolors = __toESM(require("picocolors"), 1);
@@ -398,7 +382,7 @@ var fileCache = {
398
382
  var import_js_yaml2 = require("js-yaml");
399
383
 
400
384
  // src/utils/git-timestamp.ts
401
- var import_node_path2 = __toESM(require("path"), 1);
385
+ var import_node_path = __toESM(require("path"), 1);
402
386
  var import_tinyexec = require("tinyexec");
403
387
  var cache2 = /* @__PURE__ */ new Map();
404
388
  async function getGitTimestamp(file) {
@@ -407,7 +391,7 @@ async function getGitTimestamp(file) {
407
391
  try {
408
392
  const out = await (0, import_tinyexec.x)(
409
393
  "git",
410
- ["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
394
+ ["log", "-1", '--pretty="%ai"', import_node_path.default.relative(process.cwd(), file)],
411
395
  {
412
396
  throwOnError: true
413
397
  }
@@ -437,7 +421,7 @@ function fumaMatter(input) {
437
421
  }
438
422
 
439
423
  // src/utils/import-formatter.ts
440
- var import_node_path3 = __toESM(require("path"), 1);
424
+ var import_node_path2 = __toESM(require("path"), 1);
441
425
  function getImportCode(info) {
442
426
  const specifier = JSON.stringify(info.specifier);
443
427
  if (info.type === "default") return `import ${info.name} from ${specifier}`;
@@ -452,18 +436,36 @@ function getImportCode(info) {
452
436
  return `import ${specifier}`;
453
437
  }
454
438
  function toImportPath(file, config) {
455
- const ext = import_node_path3.default.extname(file);
439
+ const ext = import_node_path2.default.extname(file);
456
440
  const filename = ext === ".ts" ? file.substring(0, file.length - ext.length) : file;
457
441
  let importPath;
458
442
  if ("relativeTo" in config) {
459
- importPath = import_node_path3.default.relative(config.relativeTo, filename);
460
- if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
443
+ importPath = import_node_path2.default.relative(config.relativeTo, filename);
444
+ if (!import_node_path2.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
461
445
  importPath = `./${importPath}`;
462
446
  }
463
447
  } else {
464
- importPath = import_node_path3.default.resolve(filename);
448
+ importPath = import_node_path2.default.resolve(filename);
465
449
  }
466
- return importPath.replaceAll(import_node_path3.default.sep, "/");
450
+ return importPath.replaceAll(import_node_path2.default.sep, "/");
451
+ }
452
+
453
+ // src/utils/collections.ts
454
+ function getSupportedFormats(collection) {
455
+ return {
456
+ doc: ["mdx", "md"],
457
+ meta: ["json", "yaml"]
458
+ }[collection.type];
459
+ }
460
+ function getGlobPatterns(collection) {
461
+ if (collection.files) return collection.files;
462
+ return [`**/*.{${getSupportedFormats(collection).join(",")}}`];
463
+ }
464
+ function isFileSupported(filePath, collection) {
465
+ for (const format of getSupportedFormats(collection)) {
466
+ if (filePath.endsWith(`.${format}`)) return true;
467
+ }
468
+ return false;
467
469
  }
468
470
 
469
471
  // src/map/generate.ts
@@ -535,8 +537,7 @@ async function generateJS(configPath, config, importPath, configHash = false) {
535
537
  specifier: "fumadocs-mdx/runtime/async",
536
538
  names: ["_runtimeAsync", "buildConfig"]
537
539
  }),
538
- "const [err, _sourceConfig] = buildConfig(_source)",
539
- "if (!_sourceConfig) throw new Error(err)"
540
+ "const _sourceConfig = buildConfig(_source)"
540
541
  );
541
542
  asyncInit = true;
542
543
  }
@@ -598,14 +599,15 @@ async function generateJS(configPath, config, importPath, configHash = false) {
598
599
  async function getCollectionFiles(collection) {
599
600
  const files = /* @__PURE__ */ new Map();
600
601
  const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
602
+ const patterns = getGlobPatterns(collection);
601
603
  await Promise.all(
602
604
  dirs.map(async (dir) => {
603
- const result = await (0, import_tinyglobby.glob)(collection.files ?? "**/*", {
605
+ const result = await (0, import_tinyglobby.glob)(patterns, {
604
606
  cwd: path4.resolve(dir),
605
607
  absolute: true
606
608
  });
607
609
  for (const item of result) {
608
- if (getTypeFromPath(item) !== collection.type) continue;
610
+ if (!isFileSupported(item, collection)) continue;
609
611
  files.set(item, {
610
612
  path: path4.relative(dir, item),
611
613
  absolutePath: item
@@ -616,16 +618,16 @@ async function getCollectionFiles(collection) {
616
618
  return Array.from(files.values());
617
619
  }
618
620
  function parseMetaEntry(file, content) {
619
- const extname3 = path4.extname(file);
621
+ const extname2 = path4.extname(file);
620
622
  try {
621
- if (extname3 === ".json") return JSON.parse(content);
622
- if (extname3 === ".yaml") return (0, import_js_yaml2.load)(content);
623
+ if (extname2 === ".json") return JSON.parse(content);
624
+ if (extname2 === ".yaml") return (0, import_js_yaml2.load)(content);
623
625
  } catch (e) {
624
626
  throw new Error(`Failed to parse meta file: ${file}.`, {
625
627
  cause: e
626
628
  });
627
629
  }
628
- throw new Error(`Unknown meta file format: ${extname3}, in ${file}.`);
630
+ throw new Error(`Unknown meta file format: ${extname2}, in ${file}.`);
629
631
  }
630
632
 
631
633
  // src/map/index.ts
@@ -683,7 +685,16 @@ async function start(dev, configPath, outDir) {
683
685
  }
684
686
 
685
687
  // src/next/create.ts
688
+ var import_node_fs = require("fs");
686
689
  var defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
690
+ var isTurboExperimental;
691
+ try {
692
+ const content = (0, import_node_fs.readFileSync)("./node_modules/next/package.json").toString();
693
+ const version = JSON.parse(content).version;
694
+ isTurboExperimental = version.startsWith("15.0.") || version.startsWith("15.1.") || version.startsWith("15.2.");
695
+ } catch {
696
+ isTurboExperimental = false;
697
+ }
687
698
  function createMDX({
688
699
  configPath = findConfigFile(),
689
700
  outDir = ".source"
@@ -699,24 +710,25 @@ function createMDX({
699
710
  configPath,
700
711
  outDir
701
712
  };
702
- return {
703
- ...nextConfig,
704
- turbopack: {
705
- ...nextConfig?.turbopack,
706
- rules: {
707
- ...nextConfig?.turbopack?.rules,
708
- // @ts-expect-error -- safe
709
- "*.{md,mdx}": {
710
- loaders: [
711
- {
712
- loader: "fumadocs-mdx/loader-mdx",
713
- options: mdxLoaderOptions
714
- }
715
- ],
716
- as: "*.js"
717
- }
713
+ const turbo = {
714
+ ...nextConfig.experimental?.turbo,
715
+ ...nextConfig.turbopack,
716
+ rules: {
717
+ ...nextConfig.experimental?.turbo?.rules,
718
+ ...nextConfig.turbopack?.rules,
719
+ "*.{md,mdx}": {
720
+ loaders: [
721
+ {
722
+ loader: "fumadocs-mdx/loader-mdx",
723
+ options: mdxLoaderOptions
724
+ }
725
+ ],
726
+ as: "*.js"
718
727
  }
719
- },
728
+ }
729
+ };
730
+ const updated = {
731
+ ...nextConfig,
720
732
  pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
721
733
  webpack: (config, options) => {
722
734
  config.resolve ||= {};
@@ -736,6 +748,12 @@ function createMDX({
736
748
  return nextConfig.webpack?.(config, options) ?? config;
737
749
  }
738
750
  };
751
+ if (isTurboExperimental) {
752
+ updated.experimental = { ...updated.experimental, turbo };
753
+ } else {
754
+ updated.turbopack = turbo;
755
+ }
756
+ return updated;
739
757
  };
740
758
  }
741
759