fumadocs-mdx 15.2.1 → 15.2.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,5 +1,5 @@
1
1
  import { i as buildConfig, n as ValidationError } from "./core-BPlsDtvN.js";
2
- import { t as loadConfig } from "./load-from-file-DNDIyOo3.js";
2
+ import { t as loadConfig } from "./load-from-file-CIW3c2FZ.js";
3
3
  import { readFileSync } from "node:fs";
4
4
  import fs from "node:fs/promises";
5
5
  import { fileURLToPath } from "node:url";
@@ -14,7 +14,7 @@ function createStandaloneConfigLoader({ core, buildConfig: buildConfig$1, mode }
14
14
  }
15
15
  async function load(hash) {
16
16
  if (hash === "missing") return buildConfig({}, process.cwd());
17
- return await loadConfig(core, buildConfig$1);
17
+ return (await loadConfig(core, buildConfig$1)).config;
18
18
  }
19
19
  return { async getCore() {
20
20
  const hash = await getConfigHash();
@@ -6,7 +6,7 @@ async function buildMDX(core, collection, options) {
6
6
  const { buildSatteriMDX } = await import("./build-satteri-k0DGJ1In.js");
7
7
  return buildSatteriMDX(core, collection, options);
8
8
  }
9
- const { buildJSMDX } = await import("./build-default-C77dbnhG.js");
9
+ const { buildJSMDX } = await import("./build-default-LB5TcE_V.js");
10
10
  return buildJSMDX(core, collection, options);
11
11
  }
12
12
  //#endregion
@@ -158,7 +158,8 @@ function getMDXOptions(config, collection, environment = "bundler") {
158
158
  result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
159
159
  } else result = (async () => {
160
160
  const optionsFn = config.global.mdxOptions;
161
- return applyMdxPreset(typeof optionsFn === "function" ? await optionsFn() : optionsFn)(environment);
161
+ const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
162
+ return applyMdxPreset(options)(environment);
162
163
  })();
163
164
  cacheMap.set(key, result);
164
165
  return result;
package/dist/bun/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { t as createMdxLoader } from "../mdx-3XO-apdE.js";
1
+ import { t as createMdxLoader } from "../mdx-B3lIEUoO.js";
2
2
  import { i as buildConfig, t as createCore } from "../core-BPlsDtvN.js";
3
3
  import { r as slash } from "../codegen-ESdi9CDJ.js";
4
- import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-DvWJNDHu.js";
5
- import { t as createMetaLoader } from "../meta-DWvKGgBH.js";
4
+ import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-Bf3BetFi.js";
5
+ import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
6
6
  import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
7
7
  import { r as resolveMacroOptions } from "../options-BNnYUjkM.js";
8
8
  import fs from "node:fs/promises";
@@ -0,0 +1,226 @@
1
+ import fsSync from "node:fs";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { createRequire } from "node:module";
5
+ //#region ../vite/dist/index.js
6
+ let pnp;
7
+ let pnpWorkspaceLocators = [];
8
+ if (process.versions.pnp) try {
9
+ pnp = createRequire(import.meta.url)("pnpapi");
10
+ pnpWorkspaceLocators = pnp.getDependencyTreeRoots();
11
+ } catch {}
12
+ async function crawlFrameworkPkgs(options) {
13
+ const pkgJsonPath = await findClosestPkgJsonPath(options.root);
14
+ if (!pkgJsonPath) return {
15
+ optimizeDeps: {
16
+ include: [],
17
+ exclude: []
18
+ },
19
+ ssr: {
20
+ noExternal: [],
21
+ external: []
22
+ }
23
+ };
24
+ const pkgJson = await readJson(pkgJsonPath).catch((e) => {
25
+ throw new Error(`Unable to read ${pkgJsonPath}`, { cause: e });
26
+ });
27
+ const optimizeDepsIncludeByPkgJsonPath = /* @__PURE__ */ new Map();
28
+ const optimizeDepsSubpathsByPkgJsonPath = /* @__PURE__ */ new Map();
29
+ let optimizeDepsInclude = [];
30
+ let optimizeDepsExclude = [];
31
+ let ssrNoExternal = [];
32
+ let ssrExternal = [];
33
+ await crawl(pkgJsonPath, pkgJson);
34
+ optimizeDepsInclude = [...optimizeDepsIncludeByPkgJsonPath.entries()].flatMap(([depPkgJsonPath, chain]) => (optimizeDepsSubpathsByPkgJsonPath.get(depPkgJsonPath) ?? ["."]).map((subpath) => subpath === "." ? chain : chain + subpath.slice(1)));
35
+ if (options.viteUserConfig) {
36
+ const userOptimizeDepsExclude = options.viteUserConfig.optimizeDeps?.exclude;
37
+ if (userOptimizeDepsExclude) optimizeDepsInclude = optimizeDepsInclude.filter((dep) => !isDepExcluded(dep, userOptimizeDepsExclude));
38
+ const userOptimizeDepsInclude = options.viteUserConfig.optimizeDeps?.include;
39
+ if (userOptimizeDepsInclude) optimizeDepsExclude = optimizeDepsExclude.filter((dep) => !isDepIncluded(dep, userOptimizeDepsInclude));
40
+ const userSsrExternal = options.viteUserConfig.ssr?.external;
41
+ if (userSsrExternal) ssrNoExternal = ssrNoExternal.filter((dep) => !isDepExternaled(dep, userSsrExternal));
42
+ const userSsrNoExternal = options.viteUserConfig.ssr?.noExternal;
43
+ if (userSsrNoExternal) ssrExternal = ssrExternal.filter((dep) => !isDepNoExternaled(dep, userSsrNoExternal));
44
+ }
45
+ optimizeDepsInclude.sort();
46
+ optimizeDepsExclude.sort();
47
+ ssrExternal.sort();
48
+ ssrNoExternal.sort();
49
+ return {
50
+ optimizeDeps: {
51
+ include: optimizeDepsInclude,
52
+ exclude: optimizeDepsExclude
53
+ },
54
+ ssr: {
55
+ noExternal: ssrNoExternal,
56
+ external: ssrExternal
57
+ }
58
+ };
59
+ async function crawl(currentPkgJsonPath, currentPkgJson, parentDepNames = [], parentIsFrameworkPkg = false, hasFrameworkAncestor = false) {
60
+ const crawlDevDependencies = parentDepNames.length === 0 || isPrivateWorkspacePackage(currentPkgJsonPath, currentPkgJson, options.workspaceRoot);
61
+ const deps = [...Object.keys(currentPkgJson.dependencies ?? {}), ...crawlDevDependencies ? Object.keys(currentPkgJson.devDependencies ?? {}) : []].filter((dep) => !parentDepNames.includes(dep));
62
+ await Promise.all(deps.map(async (dep) => {
63
+ const frameworkByName = options.isFrameworkPkgByName?.(dep);
64
+ const semiFrameworkByName = options.isSemiFrameworkPkgByName?.(dep);
65
+ if (frameworkByName === false || semiFrameworkByName === false) return;
66
+ const depPkgJsonPath = await findDepPkgJsonPath(dep, currentPkgJsonPath, !!options.workspaceRoot);
67
+ if (!depPkgJsonPath) return;
68
+ const depPkgJson = await readJson(depPkgJsonPath).catch(() => {});
69
+ if (!depPkgJson) return;
70
+ const isFrameworkPkg = frameworkByName === true || options.isFrameworkPkgByJson?.(depPkgJson) === true;
71
+ const isSemiFrameworkPkg = semiFrameworkByName === true || options.isSemiFrameworkPkgByJson?.(depPkgJson) === true;
72
+ const depChain = parentDepNames.concat(dep);
73
+ if (isFrameworkPkg || isSemiFrameworkPkg) {
74
+ if (isFrameworkPkg) {
75
+ pushUnique(optimizeDepsExclude, dep);
76
+ pushUnique(ssrNoExternal, dep);
77
+ } else pushUnique(ssrNoExternal, dep);
78
+ await crawl(depPkgJsonPath, depPkgJson, depChain, true, true);
79
+ return;
80
+ }
81
+ if (!hasFrameworkAncestor) return;
82
+ if (await pkgNeedsOptimization(depPkgJson, depPkgJsonPath)) addOptimizedDep(depPkgJsonPath, depChain, depPkgJson);
83
+ else await crawl(depPkgJsonPath, depPkgJson, depChain, false, true);
84
+ if (!options.isBuild && parentIsFrameworkPkg) pushUnique(ssrExternal, dep);
85
+ }));
86
+ }
87
+ function addOptimizedDep(depPkgJsonPath, depChain, depPkgJson) {
88
+ const includePath = depChain.join(" > ");
89
+ const current = optimizeDepsIncludeByPkgJsonPath.get(depPkgJsonPath);
90
+ if (!current || compareDepChains(includePath, current) < 0) optimizeDepsIncludeByPkgJsonPath.set(depPkgJsonPath, includePath);
91
+ if (!optimizeDepsSubpathsByPkgJsonPath.has(depPkgJsonPath)) optimizeDepsSubpathsByPkgJsonPath.set(depPkgJsonPath, getExportsSubpaths(depPkgJson.exports));
92
+ }
93
+ }
94
+ async function findClosestPkgJsonPath(dir, predicate) {
95
+ let currentDir = dir.endsWith("package.json") ? path.dirname(dir) : dir;
96
+ while (currentDir) {
97
+ const pkg = path.join(currentDir, "package.json");
98
+ try {
99
+ if ((await fs.stat(pkg)).isFile() && (!predicate || await predicate(pkg))) return pkg;
100
+ } catch {}
101
+ const nextDir = path.dirname(currentDir);
102
+ if (nextDir === currentDir) break;
103
+ currentDir = nextDir;
104
+ }
105
+ }
106
+ async function pkgNeedsOptimization(pkgJson, pkgJsonPath) {
107
+ if (pkgJson.module || pkgJson.type === "module") return false;
108
+ if (pkgJson.exports) return !exportsHasEsmEntry(pkgJson.exports);
109
+ if (pkgJson.main) {
110
+ const entryExt = path.extname(pkgJson.main);
111
+ return !entryExt || entryExt === ".js" || entryExt === ".cjs";
112
+ }
113
+ try {
114
+ await fs.access(path.join(path.dirname(pkgJsonPath), "index.js"));
115
+ return true;
116
+ } catch {
117
+ return false;
118
+ }
119
+ }
120
+ function exportsHasEsmEntry(exportsField) {
121
+ if (typeof exportsField === "string") return exportsField.endsWith(".mjs");
122
+ if (Array.isArray(exportsField)) return exportsField.some(exportsHasEsmEntry);
123
+ if (exportsField && typeof exportsField === "object") return Object.entries(exportsField).some(([key, value]) => key === "import" || key === "module" || exportsHasEsmEntry(value));
124
+ return false;
125
+ }
126
+ function getExportsSubpaths(exportsField) {
127
+ if (!exportsField || typeof exportsField !== "object" || Array.isArray(exportsField)) return ["."];
128
+ const subpathKeys = Object.keys(exportsField).filter((key) => key.startsWith("."));
129
+ if (subpathKeys.length === 0) return ["."];
130
+ const subpaths = subpathKeys.filter((key) => key === "." || /^\.\/[^*.]+$/.test(key));
131
+ return subpaths.length > 0 ? subpaths : ["."];
132
+ }
133
+ async function findDepPkgJsonPath(dep, parent, usePnpWorkspaceLocators) {
134
+ if (pnp) {
135
+ if (usePnpWorkspaceLocators) try {
136
+ const locator = pnpWorkspaceLocators.find((root) => root.name === dep);
137
+ if (locator) {
138
+ const pkgPath = pnp.getPackageInformation(locator).packageLocation;
139
+ return path.resolve(pkgPath, "package.json");
140
+ }
141
+ } catch {}
142
+ try {
143
+ const depRoot = pnp.resolveToUnqualified(dep, parent);
144
+ if (!depRoot) return;
145
+ return path.join(depRoot, "package.json");
146
+ } catch {
147
+ return;
148
+ }
149
+ }
150
+ let root = parent;
151
+ while (root) {
152
+ const pkg = path.join(root, "node_modules", dep, "package.json");
153
+ try {
154
+ await fs.access(pkg);
155
+ return fsSync.realpathSync(pkg);
156
+ } catch {}
157
+ const nextRoot = path.dirname(root);
158
+ if (nextRoot === root) break;
159
+ root = nextRoot;
160
+ }
161
+ }
162
+ async function readJson(pkgJsonPath) {
163
+ return JSON.parse(await fs.readFile(pkgJsonPath, "utf8"));
164
+ }
165
+ function isPrivateWorkspacePackage(pkgJsonPath, pkgJson, workspaceRoot) {
166
+ return !!(workspaceRoot && pkgJson.private && !pkgJsonPath.match(/[/\\]node_modules[/\\]/) && !path.relative(workspaceRoot, pkgJsonPath).startsWith(".."));
167
+ }
168
+ function pushUnique(array, value) {
169
+ if (!array.includes(value)) array.push(value);
170
+ }
171
+ function compareDepChains(left, right) {
172
+ const leftDepth = left.split(" > ").length;
173
+ const rightDepth = right.split(" > ").length;
174
+ if (leftDepth !== rightDepth) return leftDepth - rightDepth;
175
+ return left.localeCompare(right);
176
+ }
177
+ function isDepIncluded(dep, optimizeDepsInclude) {
178
+ return optimizeDepsInclude.some((include) => dep === include);
179
+ }
180
+ function isDepExcluded(dep, optimizeDepsExclude) {
181
+ return optimizeDepsExclude.some((exclude) => dep === exclude || dep.startsWith(`${exclude} > `));
182
+ }
183
+ function isDepNoExternaled(dep, ssrNoExternal) {
184
+ if (typeof ssrNoExternal === "boolean") return ssrNoExternal;
185
+ return (Array.isArray(ssrNoExternal) ? ssrNoExternal : [ssrNoExternal]).some((noExternal) => {
186
+ if (typeof noExternal === "string") return dep === noExternal;
187
+ return noExternal.test(dep);
188
+ });
189
+ }
190
+ function isDepExternaled(dep, ssrExternal) {
191
+ if (typeof ssrExternal === "boolean") return ssrExternal;
192
+ return ssrExternal.some((external) => dep === external);
193
+ }
194
+ /**
195
+ * Vite config for a project using Fumadocs, derived from its installed dependencies.
196
+ *
197
+ * Our packages are served as source rather than pre-bundled, which means Vite also serves their
198
+ * dependencies raw and no longer discovers the CommonJS ones on its own. The crawl walks the
199
+ * project's tree to name them explicitly:
200
+ * https://vite.dev/config/dep-optimization-options#optimizedeps-exclude
201
+ */
202
+ async function getConfig(options) {
203
+ const out = await crawlFrameworkPkgs({
204
+ root: options.root,
205
+ isBuild: options.isBuild,
206
+ isFrameworkPkgByName(pkgName) {
207
+ if (pkgName.startsWith("@fumadocs/") || pkgName.startsWith("fumadocs-")) return true;
208
+ switch (pkgName) {
209
+ case "vite":
210
+ case "waku":
211
+ case "shiki": return false;
212
+ }
213
+ }
214
+ });
215
+ return {
216
+ optimizeDeps: out.optimizeDeps,
217
+ ssr: { noExternal: out.ssr.noExternal },
218
+ resolve: options.isBuild ? { alias: buildAlias } : {}
219
+ };
220
+ }
221
+ const buildAlias = [{
222
+ find: /^use-sync-external-store\/shim$/,
223
+ replacement: "react"
224
+ }];
225
+ //#endregion
226
+ export { getConfig };
@@ -39,10 +39,16 @@ async function loadConfig(core, build = false) {
39
39
  let exists;
40
40
  if (build) exists = await compileConfig(core);
41
41
  exists ??= await fs.access(core.configPath).then(() => true, () => false);
42
- if (!exists) return buildConfig({}, process.cwd());
42
+ if (!exists) return {
43
+ config: buildConfig({}, process.cwd()),
44
+ fromFile: false
45
+ };
43
46
  const url = pathToFileURL(core.getCompiledConfigPath());
44
47
  url.searchParams.set("hash", Date.now().toString());
45
- return buildConfig(await import(url.href), process.cwd());
48
+ return {
49
+ config: buildConfig(await import(url.href), process.cwd()),
50
+ fromFile: true
51
+ };
46
52
  }
47
53
  //#endregion
48
54
  export { loadConfig as t };
@@ -51,9 +51,7 @@ function createMdxLoader({ getCore }) {
51
51
  case "doc":
52
52
  docCollection = collection;
53
53
  break;
54
- case "docs":
55
- docCollection = collection.docs;
56
- break;
54
+ case "docs": docCollection = collection.docs;
57
55
  }
58
56
  }
59
57
  if (docCollection) matter.data = await core.transformFrontmatter({
@@ -65,7 +63,7 @@ function createMdxLoader({ getCore }) {
65
63
  code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
66
64
  map: null
67
65
  };
68
- const { buildMDX } = await import("./build-DINFMoNj.js").then((n) => n.n);
66
+ const { buildMDX } = await import("./build-CsdoQ3rC.js").then((n) => n.n);
69
67
  const compiled = await buildMDX(core, docCollection, {
70
68
  isDevelopment,
71
69
  source: "\n".repeat(countLines(matter.matter)) + matter.content,
@@ -42,9 +42,7 @@ function createMetaLoader({ getCore }, resolve = {}) {
42
42
  case "meta":
43
43
  metaCollection = collection;
44
44
  break;
45
- case "docs":
46
- metaCollection = collection.meta;
47
- break;
45
+ case "docs": metaCollection = collection.meta;
48
46
  }
49
47
  }
50
48
  const data = parse$1(filePath, source);
@@ -11,7 +11,7 @@ interface CreateMDXOptions extends Pick<CoreOptions, 'configPath' | 'outDir'> {
11
11
  macro?: MacroPluginOption;
12
12
  index?: IndexFilePluginOptions | false;
13
13
  }
14
- declare function createMDX(options?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig;
14
+ declare function createMDX(options?: CreateMDXOptions): (nextConfig?: NextConfig) => NextConfig & PromiseLike<NextConfig>;
15
15
  declare function postInstall(options?: CreateMDXOptions): Promise<void>;
16
16
  //#endregion
17
17
  export { CreateMDXOptions, createMDX, postInstall };
@@ -1,5 +1,5 @@
1
1
  import { t as createCore } from "../core-BPlsDtvN.js";
2
- import { t as loadConfig } from "../load-from-file-DNDIyOo3.js";
2
+ import { t as loadConfig } from "../load-from-file-CIW3c2FZ.js";
3
3
  import { i as metaLoaderQueryGlob, n as metaLoaderFileGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
4
4
  import { n as createMacroMatcher, r as resolveMacroOptions } from "../options-BNnYUjkM.js";
5
5
  import { t as indexFile } from "../index-file-pX-fCn8l.js";
@@ -17,9 +17,13 @@ function createMDX(options = {}) {
17
17
  const core = createNextCore(options);
18
18
  const isDev = process.env.NODE_ENV === "development";
19
19
  const macro = resolveMacroOptions(options.macro);
20
+ let pending;
20
21
  if (process.env._FUMADOCS_MDX !== "1") {
21
22
  process.env._FUMADOCS_MDX = "1";
22
- init(isDev, core);
23
+ pending = init(isDev, core);
24
+ pending.catch((err) => {
25
+ console.error("[MDX] failed to generate files:", err);
26
+ });
23
27
  }
24
28
  function onLoaderOptions(type) {
25
29
  return {
@@ -69,7 +73,7 @@ function createMDX(options = {}) {
69
73
  }
70
74
  }
71
75
  };
72
- return {
76
+ const out = {
73
77
  ...nextConfig,
74
78
  turbopack,
75
79
  pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
@@ -108,12 +112,25 @@ function createMDX(options = {}) {
108
112
  return nextConfig.webpack?.(config, options) ?? config;
109
113
  }
110
114
  };
115
+ const ready = pending ?? Promise.resolve();
116
+ return Object.defineProperty(out, "then", {
117
+ enumerable: false,
118
+ configurable: true,
119
+ writable: true,
120
+ value(onFulfilled, onRejected) {
121
+ return ready.then(() => {
122
+ const { ...clean } = out;
123
+ return clean;
124
+ }).then(onFulfilled, onRejected);
125
+ }
126
+ });
111
127
  };
112
128
  }
113
- async function init(dev, core) {
129
+ function init(dev, core) {
114
130
  async function initOrReload() {
115
- await core.init({ config: loadConfig(core, true) });
116
- await core.emit({ write: true });
131
+ const { config, fromFile } = await loadConfig(core, true);
132
+ await core.init({ config });
133
+ if (fromFile) await core.emit({ write: true });
117
134
  }
118
135
  async function devServer() {
119
136
  const { FSWatcher } = await import("chokidar");
@@ -144,13 +161,17 @@ async function init(dev, core) {
144
161
  });
145
162
  await core.initServer({ watcher });
146
163
  }
147
- await initOrReload();
148
- if (dev) await devServer();
164
+ const ready = initOrReload();
165
+ if (dev) ready.then(devServer, () => {}).catch((err) => {
166
+ console.error("[MDX] failed to start dev server:", err);
167
+ });
168
+ return ready;
149
169
  }
150
170
  async function postInstall(options = {}) {
151
171
  const core = createNextCore(options);
152
- await core.init({ config: loadConfig(core, true) });
153
- await core.emit({ write: true });
172
+ const { config, fromFile } = await loadConfig(core, true);
173
+ await core.init({ config });
174
+ if (fromFile) await core.emit({ write: true });
154
175
  }
155
176
  function createNextCore({ outDir, configPath, index = {} }) {
156
177
  return createCore({
@@ -1,8 +1,8 @@
1
- import { t as createMdxLoader } from "../mdx-3XO-apdE.js";
1
+ import { t as createMdxLoader } from "../mdx-B3lIEUoO.js";
2
2
  import { t as createCore } from "../core-BPlsDtvN.js";
3
3
  import { r as slash } from "../codegen-ESdi9CDJ.js";
4
- import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-DvWJNDHu.js";
5
- import { t as createMetaLoader } from "../meta-DWvKGgBH.js";
4
+ import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-Bf3BetFi.js";
5
+ import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
6
6
  import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
7
7
  import { n as createMacroMatcher, r as resolveMacroOptions } from "../options-BNnYUjkM.js";
8
8
  import { n as createNodeEvaluator, t as MacroCollector } from "../eval-z3HV4VJp.js";
@@ -1,11 +1,12 @@
1
- import { t as createMdxLoader } from "../mdx-3XO-apdE.js";
1
+ import { t as createMdxLoader } from "../mdx-B3lIEUoO.js";
2
2
  import { t as createCore } from "../core-BPlsDtvN.js";
3
- import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-DvWJNDHu.js";
4
- import { t as createMetaLoader } from "../meta-DWvKGgBH.js";
3
+ import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-Bf3BetFi.js";
4
+ import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
5
5
  import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
6
6
  //#region src/node/loader.ts
7
+ const core = createCore({ environment: "node" });
7
8
  const configLoader = createStandaloneConfigLoader({
8
- core: createCore({ environment: "node" }),
9
+ core,
9
10
  buildConfig: true,
10
11
  mode: "production"
11
12
  });
@@ -1,8 +1,8 @@
1
- import { t as createMdxLoader } from "../mdx-3XO-apdE.js";
1
+ import { t as createMdxLoader } from "../mdx-B3lIEUoO.js";
2
2
  import { i as buildConfig, t as createCore } from "../core-BPlsDtvN.js";
3
3
  import { r as slash } from "../codegen-ESdi9CDJ.js";
4
- import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-DvWJNDHu.js";
5
- import { t as createMetaLoader } from "../meta-DWvKGgBH.js";
4
+ import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-Bf3BetFi.js";
5
+ import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
6
6
  import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
7
7
  import { r as resolveMacroOptions, t as MacroModuleId } from "../options-BNnYUjkM.js";
8
8
  import { n as createNodeEvaluator, t as MacroCollector } from "../eval-z3HV4VJp.js";
@@ -47,7 +47,8 @@ function createClientLoader(globEntries, options) {
47
47
  return getRenderer(path);
48
48
  },
49
49
  useContent(path, props) {
50
- return /* @__PURE__ */ jsx(getRenderer(path), { ...props });
50
+ const Comp = getRenderer(path);
51
+ return /* @__PURE__ */ jsx(Comp, { ...props });
51
52
  }
52
53
  };
53
54
  }
@@ -1,5 +1,5 @@
1
1
  import { i as buildConfig, t as createCore } from "../core-BPlsDtvN.js";
2
- import { t as buildMDX } from "../build-DINFMoNj.js";
2
+ import { t as buildMDX } from "../build-CsdoQ3rC.js";
3
3
  import { server } from "./server.js";
4
4
  import { frontmatter } from "fumadocs-core/content/md/frontmatter";
5
5
  import fs from "node:fs/promises";
@@ -45,7 +45,8 @@ function asyncEntries(raw) {
45
45
  const load = () => promise ??= track(entry.load());
46
46
  function Body(props) {
47
47
  const loaded = load();
48
- return createElement((loaded.status === "fulfilled" ? loaded.value : use(loaded)).body, props);
48
+ const data = loaded.status === "fulfilled" ? loaded.value : use(loaded);
49
+ return createElement(data.body, props);
49
50
  }
50
51
  return {
51
52
  ...entry,
@@ -1,7 +1,7 @@
1
- import { t as createMdxLoader } from "../mdx-3XO-apdE.js";
1
+ import { t as createMdxLoader } from "../mdx-B3lIEUoO.js";
2
2
  import { i as buildConfig, t as createCore } from "../core-BPlsDtvN.js";
3
- import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-DvWJNDHu.js";
4
- import { t as createMetaLoader } from "../meta-DWvKGgBH.js";
3
+ import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-Bf3BetFi.js";
4
+ import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
5
5
  import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
6
6
  import { r as resolveMacroOptions, t as MacroModuleId } from "../options-BNnYUjkM.js";
7
7
  import { t as indexFile } from "../index-file-pX-fCn8l.js";
@@ -109,11 +109,14 @@ function mdx(forcedConfig, pluginOptions = {}) {
109
109
  }
110
110
  if ("_fumadocs_skipViteConfig" in config && config._fumadocs_skipViteConfig) return;
111
111
  if (!updateViteConfig) return;
112
- const { getConfig } = await import("../dist-Dm0fXCC7.js");
113
- return getConfig({ root: core.root });
112
+ const { getConfig } = await import("../dist-Bniav-AK.js");
113
+ return getConfig({
114
+ root: core.root,
115
+ isBuild: env.command === "build"
116
+ });
114
117
  },
115
118
  async buildStart() {
116
- await managed.core.emit({ write: true });
119
+ if (forcedConfig || managed.watchConfig) await managed.core.emit({ write: true });
117
120
  },
118
121
  async configureServer(server) {
119
122
  const core = managed.core;
@@ -122,7 +125,7 @@ function mdx(forcedConfig, pluginOptions = {}) {
122
125
  const onChange = async (file) => {
123
126
  if (path.resolve(file) !== core.configPath) return;
124
127
  await managed.reload();
125
- await core.emit({ write: true });
128
+ if (managed.watchConfig) await core.emit({ write: true });
126
129
  };
127
130
  server.watcher.on("change", onChange);
128
131
  server.watcher.on("add", onChange);
@@ -168,7 +171,7 @@ async function loadCoreConfig(core, forcedConfig, { globalOptions } = {}) {
168
171
  async function postInstall(pluginOptions = {}) {
169
172
  const managed = createManagedCore(process.cwd(), void 0, pluginOptions);
170
173
  await managed.reload();
171
- await managed.core.emit({ write: true });
174
+ if (managed.watchConfig) await managed.core.emit({ write: true });
172
175
  }
173
176
  function createViteCore(root, { index = true, configPath, outDir }) {
174
177
  if (index === true) index = {};
@@ -1,5 +1,5 @@
1
- import { t as createMdxLoader } from "../mdx-3XO-apdE.js";
2
- import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-DvWJNDHu.js";
1
+ import { t as createMdxLoader } from "../mdx-B3lIEUoO.js";
2
+ import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-Bf3BetFi.js";
3
3
  import { t as getCore } from "../webpack-BSog6pml.js";
4
4
  //#region src/webpack/mdx.ts
5
5
  let instance;
@@ -1,5 +1,5 @@
1
- import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-DvWJNDHu.js";
2
- import { t as createMetaLoader } from "../meta-DWvKGgBH.js";
1
+ import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-Bf3BetFi.js";
2
+ import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
3
3
  import { t as getCore } from "../webpack-BSog6pml.js";
4
4
  //#region src/webpack/meta.ts
5
5
  const instances = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "15.2.1",
3
+ "version": "15.2.3",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "Docs",
@@ -63,14 +63,14 @@
63
63
  "mdast-util-mdx": "^3.0.0",
64
64
  "picocolors": "^1.1.1",
65
65
  "picomatch": "^4.0.5",
66
- "tinyexec": "^1.2.4",
66
+ "tinyexec": "^1.3.0",
67
67
  "tinyglobby": "^0.2.17",
68
68
  "unified": "^11.0.5",
69
69
  "unist-util-remove-position": "^5.0.0",
70
70
  "unist-util-visit": "^5.1.0",
71
71
  "vfile": "^6.0.3",
72
72
  "yaml": "^2.9.0",
73
- "yuku-analyzer": "^0.8.1",
73
+ "yuku-analyzer": "^0.8.3",
74
74
  "zod": "^4.4.3"
75
75
  },
76
76
  "devDependencies": {
@@ -79,22 +79,22 @@
79
79
  "@types/mdx": "^2.0.14",
80
80
  "@types/node": "^26.1.2",
81
81
  "@types/picomatch": "^4.0.3",
82
- "@types/react": "^19.2.17",
82
+ "@types/react": "^19.2.18",
83
83
  "mdast-util-directive": "^3.1.0",
84
- "next": "^16.2.12",
84
+ "next": "^16.3.0",
85
85
  "react": "^19.2.8",
86
86
  "remark": "^15.0.1",
87
87
  "remark-directive": "^4.0.0",
88
88
  "remark-mdx": "^3.1.1",
89
- "rolldown": "^1.2.0",
89
+ "rolldown": "^1.2.2",
90
90
  "satteri": "^0.9.5",
91
91
  "tsdown": "0.22.14",
92
- "vite": "^8.1.5",
92
+ "vite": "^8.2.0",
93
93
  "webpack": "^5.109.2",
94
- "@fumadocs/vite": "0.1.0",
94
+ "@fumadocs/satteri": "0.3.1",
95
+ "fumadocs-core": "16.14.3",
95
96
  "tsconfig": "0.0.0",
96
- "fumadocs-core": "16.14.0",
97
- "@fumadocs/satteri": "0.3.1"
97
+ "@fumadocs/vite": "0.1.0"
98
98
  },
99
99
  "peerDependencies": {
100
100
  "@fumadocs/satteri": "0.x.x",
@@ -1,123 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- //#region ../vite/dist/index.js
4
- async function findClosestPkgJsonPath(dir, predicate) {
5
- let currentDir = dir.endsWith("package.json") ? path.dirname(dir) : dir;
6
- while (currentDir) {
7
- const pkg = path.join(currentDir, "package.json");
8
- try {
9
- if ((await fs.stat(pkg)).isFile() && (!predicate || await predicate(pkg))) return pkg;
10
- } catch {}
11
- const nextDir = path.dirname(currentDir);
12
- if (nextDir === currentDir) break;
13
- currentDir = nextDir;
14
- }
15
- }
16
- async function readJson(pkgJsonPath) {
17
- return JSON.parse(await fs.readFile(pkgJsonPath, "utf8"));
18
- }
19
- var generated_default = {
20
- optimizeDeps: {
21
- "include": [
22
- "@fumadocs/local-md > @fumadocs/local-content > picomatch",
23
- "@fumadocs/local-md > estree-util-to-js > source-map",
24
- "@fumadocs/local-md > hast-util-to-jsx-runtime > mdast-util-mdx-expression > mdast-util-from-markdown > micromark > debug",
25
- "@fumadocs/local-md > hast-util-to-jsx-runtime > style-to-js",
26
- "@fumadocs/local-md > remark > unified > extend",
27
- "@fumadocs/mdx-remote > @mdx-js/mdx > hast-util-to-jsx-runtime > style-to-js",
28
- "@fumadocs/mdx-remote > @mdx-js/mdx > remark-parse > mdast-util-from-markdown > micromark > debug",
29
- "@fumadocs/mdx-remote > @mdx-js/mdx > source-map",
30
- "@fumadocs/mdx-remote > unified > extend",
31
- "@fumadocs/story > ts-morph",
32
- "fumadocs-core > hast-util-to-estree > style-to-js",
33
- "fumadocs-core > mdast-util-mdx > mdast-util-from-markdown > micromark > debug",
34
- "fumadocs-core > tinyglobby > picomatch",
35
- "fumadocs-core > unified > extend",
36
- "fumadocs-mdx > @mdx-js/mdx > hast-util-to-jsx-runtime > style-to-js",
37
- "fumadocs-mdx > @mdx-js/mdx > source-map",
38
- "fumadocs-mdx > esbuild",
39
- "fumadocs-mdx > mdast-util-mdx > mdast-util-from-markdown > micromark > debug",
40
- "fumadocs-mdx > picocolors",
41
- "fumadocs-mdx > picomatch",
42
- "fumadocs-mdx > unified > extend",
43
- "fumadocs-twoslash > mdast-util-from-markdown > micromark > debug",
44
- "fumadocs-typescript > hast-util-to-estree > mdast-util-mdx-expression > mdast-util-from-markdown > micromark > debug",
45
- "fumadocs-typescript > hast-util-to-estree > style-to-js",
46
- "fumadocs-typescript > ts-morph",
47
- "fumadocs-typescript > unified > extend"
48
- ],
49
- "exclude": [
50
- "@fumadocs/basehub",
51
- "@fumadocs/local-content",
52
- "@fumadocs/local-md",
53
- "@fumadocs/mdx-remote",
54
- "@fumadocs/sanity",
55
- "@fumadocs/story",
56
- "@fumadocs/tailwind",
57
- "fumadocs-core",
58
- "fumadocs-mdx",
59
- "fumadocs-twoslash",
60
- "fumadocs-typescript",
61
- "fumadocs-ui"
62
- ]
63
- },
64
- ssr: { "noExternal": [
65
- "@fumadocs/basehub",
66
- "@fumadocs/local-content",
67
- "@fumadocs/local-md",
68
- "@fumadocs/mdx-remote",
69
- "@fumadocs/sanity",
70
- "@fumadocs/story",
71
- "@fumadocs/tailwind",
72
- "fumadocs-core",
73
- "fumadocs-mdx",
74
- "fumadocs-twoslash",
75
- "fumadocs-typescript",
76
- "fumadocs-ui"
77
- ] }
78
- };
79
- /**
80
- * `use-sync-external-store` is a CommonJS package Base UI depends on for React 17, where
81
- * `useSyncExternalStore` wasn't built into React yet.
82
- *
83
- * When it is bundled for SSR, its `require('react')` stays a runtime require, so it ends up with a
84
- * different React instance than the bundled one the renderer installs its hook dispatcher on.
85
- * Calling a hook then reads a null dispatcher and every component using a Base UI store (dialogs,
86
- * navigation menu, scroll area) throws during SSR.
87
- *
88
- * We require React 19, where the shim only forwards to React's own `useSyncExternalStore`.
89
- */
90
- const alias = [{
91
- find: /^use-sync-external-store\/shim$/,
92
- replacement: "react"
93
- }];
94
- async function getConfig(options) {
95
- const pkgJsonPath = await findClosestPkgJsonPath(options.root);
96
- if (!pkgJsonPath) return {
97
- optimizeDeps: {
98
- include: [],
99
- exclude: []
100
- },
101
- ssr: { noExternal: [] },
102
- resolve: { alias }
103
- };
104
- const pkgJson = await readJson(pkgJsonPath).catch((e) => {
105
- throw new Error(`Unable to read ${pkgJsonPath}`, { cause: e });
106
- });
107
- const out = structuredClone(generated_default);
108
- const deps = /* @__PURE__ */ new Set();
109
- if (pkgJson.dependencies) for (const name in pkgJson.dependencies) deps.add(name);
110
- if (pkgJson.devDependencies) for (const name in pkgJson.devDependencies) deps.add(name);
111
- out.optimizeDeps.include = out.optimizeDeps.include.filter((item) => {
112
- const first = item.slice(0, item.indexOf(" > "));
113
- return deps.has(first);
114
- });
115
- out.optimizeDeps.exclude = out.optimizeDeps.exclude.filter((item) => deps.has(item));
116
- out.ssr.noExternal = out.ssr.noExternal.filter((item) => deps.has(item));
117
- return {
118
- ...out,
119
- resolve: { alias }
120
- };
121
- }
122
- //#endregion
123
- export { getConfig };