fumadocs-mdx 11.10.0 → 11.10.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.
@@ -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";
11
+ } from "../chunk-IQAEAI4P.js";
12
+ import {
13
+ findConfigFile,
14
+ getConfigHash,
15
+ loadConfig
16
+ } from "../chunk-766EAFX6.js";
16
17
  import "../chunk-QVZ7JH4H.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";
@@ -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,
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  toNode
3
- } from "../chunk-NVX3U5YE.js";
3
+ } from "../chunk-CNKI574E.js";
4
4
  import {
5
5
  createMdxLoader,
6
6
  dynamicConfig
7
- } from "../chunk-5XJM5RPV.js";
8
- import {
9
- findConfigFile
10
- } from "../chunk-2HKRTQYP.js";
7
+ } from "../chunk-QJCCVMBJ.js";
11
8
  import "../chunk-QQWCBFFE.js";
12
9
  import "../chunk-SVTXMVLQ.js";
10
+ import "../chunk-IQAEAI4P.js";
11
+ import {
12
+ findConfigFile
13
+ } from "../chunk-766EAFX6.js";
13
14
  import "../chunk-QVZ7JH4H.js";
14
15
  import "../chunk-VWJKRQZR.js";
15
16
 
@@ -0,0 +1,9 @@
1
+ import {
2
+ postInstall
3
+ } from "./chunk-XXSKWWMB.js";
4
+ import "./chunk-6Y5JDZHD.js";
5
+ import "./chunk-766EAFX6.js";
6
+ import "./chunk-QVZ7JH4H.js";
7
+ export {
8
+ postInstall
9
+ };
@@ -197,7 +197,7 @@ var init_mdx_options = __esm({
197
197
  }
198
198
  });
199
199
 
200
- // src/runtime/async.ts
200
+ // src/runtime/next/async.ts
201
201
  var async_exports = {};
202
202
  __export(async_exports, {
203
203
  _runtimeAsync: () => _runtimeAsync,
@@ -205,7 +205,7 @@ __export(async_exports, {
205
205
  });
206
206
  module.exports = __toCommonJS(async_exports);
207
207
 
208
- // src/runtime/index.ts
208
+ // src/runtime/next/index.ts
209
209
  var import_node_fs = __toESM(require("fs"), 1);
210
210
  var cache = /* @__PURE__ */ new Map();
211
211
  var _runtime = {
@@ -463,7 +463,7 @@ async function buildMDX(cacheKey, source, options) {
463
463
  });
464
464
  }
465
465
 
466
- // src/runtime/async.ts
466
+ // src/runtime/next/async.ts
467
467
  var import_client = require("@fumadocs/mdx-remote/client");
468
468
  var import_node_url = require("url");
469
469
 
@@ -517,7 +517,7 @@ function buildConfig(config) {
517
517
  };
518
518
  }
519
519
 
520
- // src/runtime/async.ts
520
+ // src/runtime/next/async.ts
521
521
  async function getOptions(config, collection) {
522
522
  const col = config.collections.get(collection);
523
523
  if (col?.type === "doc" && col.mdxOptions) return col.mdxOptions;
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-DT83Ijs6.cjs';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../../types-DT83Ijs6.cjs';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-BH4bnHQl.cjs';
4
+ import '../../define-BH4bnHQl.cjs';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../build-mdx-DnC1jKvn.cjs';
9
+ import '../../build-mdx-DnC1jKvn.cjs';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-DN9KrG7R.js';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../../types-DN9KrG7R.js';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-BH4bnHQl.js';
4
+ import '../../define-BH4bnHQl.js';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import '../build-mdx-DnC1jKvn.js';
9
+ import '../../build-mdx-DnC1jKvn.js';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  _runtime,
3
3
  createMDXSource
4
- } from "../chunk-NUDEC6C5.js";
4
+ } from "../../chunk-UOOPSLFY.js";
5
5
  import {
6
6
  buildMDX
7
- } from "../chunk-QQWCBFFE.js";
8
- import "../chunk-SVTXMVLQ.js";
7
+ } from "../../chunk-QQWCBFFE.js";
8
+ import "../../chunk-SVTXMVLQ.js";
9
9
  import {
10
10
  buildConfig
11
- } from "../chunk-QVZ7JH4H.js";
12
- import "../chunk-VWJKRQZR.js";
11
+ } from "../../chunk-QVZ7JH4H.js";
12
+ import "../../chunk-VWJKRQZR.js";
13
13
 
14
- // src/runtime/async.ts
14
+ // src/runtime/next/async.ts
15
15
  import { executeMdx } from "@fumadocs/mdx-remote/client";
16
16
  import { pathToFileURL } from "url";
17
17
  async function getOptions(config, collection) {
@@ -27,16 +27,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
30
+ // src/runtime/next/index.ts
31
+ var next_exports = {};
32
+ __export(next_exports, {
33
33
  _runtime: () => _runtime,
34
34
  createMDXSource: () => createMDXSource,
35
35
  resolveFiles: () => resolveFiles
36
36
  });
37
- module.exports = __toCommonJS(index_exports);
38
-
39
- // src/runtime/index.ts
37
+ module.exports = __toCommonJS(next_exports);
40
38
  var import_node_fs = __toESM(require("fs"), 1);
41
39
  var cache = /* @__PURE__ */ new Map();
42
40
  var _runtime = {
@@ -1,12 +1,12 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-DT83Ijs6.cjs';
2
+ import { R as Runtime, B as BaseCollectionEntry } from '../../types-DT83Ijs6.cjs';
3
3
  import '@standard-schema/spec';
4
- import './define-BH4bnHQl.cjs';
4
+ import '../../define-BH4bnHQl.cjs';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import './build-mdx-DnC1jKvn.cjs';
9
+ import '../../build-mdx-DnC1jKvn.cjs';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -1,12 +1,12 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-DN9KrG7R.js';
2
+ import { R as Runtime, B as BaseCollectionEntry } from '../../types-DN9KrG7R.js';
3
3
  import '@standard-schema/spec';
4
- import './define-BH4bnHQl.js';
4
+ import '../../define-BH4bnHQl.js';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import './build-mdx-DnC1jKvn.js';
9
+ import '../../build-mdx-DnC1jKvn.js';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
@@ -2,7 +2,7 @@ import {
2
2
  _runtime,
3
3
  createMDXSource,
4
4
  resolveFiles
5
- } from "./chunk-NUDEC6C5.js";
5
+ } from "../../chunk-UOOPSLFY.js";
6
6
  export {
7
7
  _runtime,
8
8
  createMDXSource,
@@ -200,7 +200,8 @@ var init_mdx_options = __esm({
200
200
  // src/vite/index.ts
201
201
  var vite_exports = {};
202
202
  __export(vite_exports, {
203
- default: () => mdx
203
+ default: () => mdx,
204
+ postInstall: () => postInstall
204
205
  });
205
206
  module.exports = __toCommonJS(vite_exports);
206
207
  var import_vite = require("vite");
@@ -297,8 +298,8 @@ async function validate(schema, data, context, errorMessage) {
297
298
  }
298
299
 
299
300
  // src/vite/index.ts
300
- var fs5 = __toESM(require("fs/promises"), 1);
301
- var path7 = __toESM(require("path"), 1);
301
+ var fs6 = __toESM(require("fs/promises"), 1);
302
+ var path8 = __toESM(require("path"), 1);
302
303
  var import_js_yaml2 = require("js-yaml");
303
304
 
304
305
  // src/utils/import-formatter.ts
@@ -754,6 +755,75 @@ function generateCacheHash(input) {
754
755
  var fs3 = __toESM(require("fs/promises"), 1);
755
756
  var path5 = __toESM(require("path"), 1);
756
757
  var import_node_url = require("url");
758
+ function findConfigFile() {
759
+ return path5.resolve("source.config.ts");
760
+ }
761
+ var cache3 = null;
762
+ async function isZod3() {
763
+ try {
764
+ const content = JSON.parse(
765
+ (await fs3.readFile("node_modules/zod/package.json")).toString()
766
+ );
767
+ const version = content.version;
768
+ return typeof version === "string" && version.startsWith("3.");
769
+ } catch {
770
+ return false;
771
+ }
772
+ }
773
+ function createCompatZodPlugin() {
774
+ return {
775
+ name: "replace-zod-import",
776
+ async setup(build) {
777
+ const usingZod3 = await isZod3();
778
+ if (!usingZod3) return;
779
+ console.warn(
780
+ "[Fumadocs MDX] Noticed Zod v3 in your node_modules, we recommend upgrading to Zod v4 for better compatibility."
781
+ );
782
+ build.onResolve({ filter: /^fumadocs-mdx\/config$/ }, () => {
783
+ return {
784
+ path: "fumadocs-mdx/config/zod-3",
785
+ external: true
786
+ };
787
+ });
788
+ }
789
+ };
790
+ }
791
+ async function compileConfig(configPath, outDir) {
792
+ const { build } = await import("esbuild");
793
+ const transformed = await build({
794
+ entryPoints: [{ in: configPath, out: "source.config" }],
795
+ bundle: true,
796
+ outdir: outDir,
797
+ target: "node20",
798
+ write: true,
799
+ platform: "node",
800
+ format: "esm",
801
+ packages: "external",
802
+ plugins: [createCompatZodPlugin()],
803
+ outExtension: {
804
+ ".js": ".mjs"
805
+ },
806
+ allowOverwrite: true
807
+ });
808
+ if (transformed.errors.length > 0) {
809
+ throw new Error("failed to compile configuration file");
810
+ }
811
+ }
812
+ async function loadConfig(configPath, outDir, hash, build = false) {
813
+ if (cache3 && cache3.hash === hash) {
814
+ return await cache3.config;
815
+ }
816
+ if (build) await compileConfig(configPath, outDir);
817
+ const url = (0, import_node_url.pathToFileURL)(path5.resolve(outDir, "source.config.mjs"));
818
+ const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
819
+ return buildConfig(
820
+ // every call to `loadConfig` will cause the previous cache to be ignored
821
+ loaded
822
+ );
823
+ });
824
+ if (hash) cache3 = { config, hash };
825
+ return await config;
826
+ }
757
827
 
758
828
  // src/loaders/config-loader.ts
759
829
  function resolvedConfig(loaded) {
@@ -789,14 +859,30 @@ function toVite(loader) {
789
859
  };
790
860
  }
791
861
 
862
+ // src/vite/postinstall.ts
863
+ var import_promises3 = __toESM(require("fs/promises"), 1);
864
+ var import_node_path5 = __toESM(require("path"), 1);
865
+ async function postInstall(configPath = findConfigFile(), outDir, addJsExtension = false) {
866
+ const config = await loadConfig(configPath, "node_modules", void 0, true);
867
+ const outFile = "source.generated.ts";
868
+ if (outDir) {
869
+ await import_promises3.default.mkdir(outDir, { recursive: true });
870
+ }
871
+ await import_promises3.default.writeFile(
872
+ outDir ? import_node_path5.default.join(outDir, outFile) : outFile,
873
+ entry(configPath, config, outDir ?? process.cwd(), addJsExtension)
874
+ );
875
+ console.log("[MDX] types generated");
876
+ }
877
+
792
878
  // src/vite/index.ts
793
879
  var FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
794
880
  function mdx(config, options = {}) {
795
881
  const { generateIndexFile = true, configPath = "source.config.ts" } = options;
796
882
  const loaded = buildConfig(config);
797
883
  const mdxLoader = toVite(createMdxLoader(resolvedConfig(loaded)));
798
- async function transformMeta(path8, query, value) {
799
- const isJson = path8.endsWith(".json");
884
+ async function transformMeta(path9, query, value) {
885
+ const isJson = path9.endsWith(".json");
800
886
  const parsed = (0, import_node_querystring2.parse)(query);
801
887
  const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
802
888
  if (!collection) return null;
@@ -819,8 +905,8 @@ function mdx(config, options = {}) {
819
905
  const out = await validate(
820
906
  schema,
821
907
  data,
822
- { path: path8, source: value },
823
- `invalid data in ${path8}`
908
+ { path: path9, source: value },
909
+ `invalid data in ${path9}`
824
910
  );
825
911
  return {
826
912
  code: isJson ? JSON.stringify(out) : `export default ${JSON.stringify(out)}`,
@@ -847,8 +933,8 @@ function mdx(config, options = {}) {
847
933
  console.log("[Fumadocs MDX] Generating index files");
848
934
  const outDir = process.cwd();
849
935
  const outFile = "source.generated.ts";
850
- await fs5.writeFile(
851
- path7.join(outDir, outFile),
936
+ await fs6.writeFile(
937
+ path8.join(outDir, outFile),
852
938
  entry(
853
939
  configPath,
854
940
  loaded,
@@ -859,7 +945,7 @@ function mdx(config, options = {}) {
859
945
  },
860
946
  async transform(value, id) {
861
947
  const [file, query = ""] = id.split("?");
862
- const ext = path7.extname(file);
948
+ const ext = path8.extname(file);
863
949
  try {
864
950
  if ([".yaml", ".json"].includes(ext))
865
951
  return await transformMeta(file, query, value);
@@ -874,3 +960,7 @@ function mdx(config, options = {}) {
874
960
  }
875
961
  };
876
962
  }
963
+ // Annotate the CommonJS export names for ESM import in node:
964
+ 0 && (module.exports = {
965
+ postInstall
966
+ });
@@ -1,5 +1,7 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ declare function postInstall(configPath?: string, outDir?: string, addJsExtension?: boolean): Promise<void>;
4
+
3
5
  interface PluginOptions {
4
6
  /**
5
7
  * Automatically generate index files for accessing files with `import.meta.glob`.
@@ -17,6 +19,7 @@ interface PluginOptions {
17
19
  */
18
20
  configPath?: string;
19
21
  }
22
+
20
23
  declare function mdx(config: Record<string, unknown>, options?: PluginOptions): Plugin;
21
24
 
22
- export { type PluginOptions, mdx as default };
25
+ export { type PluginOptions, mdx as default, postInstall };
@@ -1,5 +1,7 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ declare function postInstall(configPath?: string, outDir?: string, addJsExtension?: boolean): Promise<void>;
4
+
3
5
  interface PluginOptions {
4
6
  /**
5
7
  * Automatically generate index files for accessing files with `import.meta.glob`.
@@ -17,6 +19,7 @@ interface PluginOptions {
17
19
  */
18
20
  configPath?: string;
19
21
  }
22
+
20
23
  declare function mdx(config: Record<string, unknown>, options?: PluginOptions): Plugin;
21
24
 
22
- export { type PluginOptions, mdx as default };
25
+ export { type PluginOptions, mdx as default, postInstall };
@@ -1,19 +1,22 @@
1
1
  import {
2
- entry
3
- } from "../chunk-COQ4VMK2.js";
2
+ entry,
3
+ postInstall
4
+ } from "../chunk-XXSKWWMB.js";
5
+ import "../chunk-6Y5JDZHD.js";
4
6
  import {
5
7
  toVite
6
- } from "../chunk-NVX3U5YE.js";
8
+ } from "../chunk-CNKI574E.js";
7
9
  import {
8
10
  createMdxLoader,
9
11
  resolvedConfig
10
- } from "../chunk-5XJM5RPV.js";
12
+ } from "../chunk-QJCCVMBJ.js";
13
+ import "../chunk-QQWCBFFE.js";
14
+ import "../chunk-SVTXMVLQ.js";
11
15
  import {
12
16
  ValidationError,
13
17
  validate
14
- } from "../chunk-2HKRTQYP.js";
15
- import "../chunk-QQWCBFFE.js";
16
- import "../chunk-SVTXMVLQ.js";
18
+ } from "../chunk-IQAEAI4P.js";
19
+ import "../chunk-766EAFX6.js";
17
20
  import {
18
21
  buildConfig
19
22
  } from "../chunk-QVZ7JH4H.js";
@@ -112,5 +115,6 @@ function mdx(config, options = {}) {
112
115
  };
113
116
  }
114
117
  export {
115
- mdx as default
118
+ mdx as default,
119
+ postInstall
116
120
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.10.0",
3
+ "version": "11.10.1",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -33,9 +33,13 @@
33
33
  "types": "./dist/vite/index.d.ts",
34
34
  "require": "./dist/vite/index.cjs"
35
35
  },
36
+ ".": {
37
+ "import": "./dist/runtime/next/index.js",
38
+ "types": "./dist/runtime/next/index.d.ts"
39
+ },
36
40
  "./runtime/async": {
37
- "import": "./dist/runtime/async.js",
38
- "types": "./dist/runtime/async.d.ts"
41
+ "import": "./dist/runtime/next/async.js",
42
+ "types": "./dist/runtime/next/async.d.ts"
39
43
  },
40
44
  "./runtime/vite": {
41
45
  "browser": "./dist/runtime/vite/browser.js",
@@ -49,20 +53,14 @@
49
53
  "./bun": {
50
54
  "import": "./dist/bun/index.js",
51
55
  "types": "./dist/bun/index.d.ts"
52
- },
53
- ".": {
54
- "import": "./dist/index.js",
55
- "types": "./dist/index.d.ts",
56
- "require": "./dist/index.cjs"
57
56
  }
58
57
  },
59
58
  "main": "./dist/index.js",
60
59
  "types": "./dist/index.d.ts",
61
- "bin": "./bin.js",
60
+ "bin": "./dist/bin.js",
62
61
  "files": [
63
62
  "dist/*",
64
- "loader-mdx.cjs",
65
- "bin.js"
63
+ "loader-mdx.cjs"
66
64
  ],
67
65
  "dependencies": {
68
66
  "@mdx-js/mdx": "^3.1.1",
@@ -97,7 +95,7 @@
97
95
  "webpack": "^5.101.3",
98
96
  "@fumadocs/mdx-remote": "1.4.0",
99
97
  "eslint-config-custom": "0.0.0",
100
- "fumadocs-core": "15.7.12",
98
+ "fumadocs-core": "15.7.13",
101
99
  "tsconfig": "0.0.0"
102
100
  },
103
101
  "peerDependencies": {
package/bin.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { postInstall } from './dist/next/index.js';
4
-
5
- void postInstall(process.argv[2], process.argv[3]);