fumadocs-mdx 15.6.5 → 15.6.6

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 (57) hide show
  1. package/dist/{adapter-Clt8sB1g.js → adapter-CG3tA0Gl.js} +3 -3
  2. package/dist/{build-default-vTNu4xsh.js → build-default-P4XKTKKP.js} +39 -34
  3. package/dist/{build-satteri-BIE-M-JZ.js → build-satteri-At6UToAY.js} +13 -2
  4. package/dist/bun/index.d.ts +2 -2
  5. package/dist/bun/index.js +10 -10
  6. package/dist/{code-BWwFhg-7.js → code-ChiBd2gZ.js} +62 -39
  7. package/dist/{codegen-uHLSduG-.js → codegen-xBM-ArrU.js} +12 -5
  8. package/dist/config/index.d.ts +1 -1
  9. package/dist/config/index.js +1 -1
  10. package/dist/{core-r1WHKfaI.js → core-BcbYlzSD.js} +2 -2
  11. package/dist/{core-OVmyAj82.d.ts → core-Cvyga-oq.d.ts} +4 -4
  12. package/dist/{eval-Ch9sPj_e.js → eval-DcO6h2th.js} +6 -6
  13. package/dist/{index-CCVoEC9e.d.ts → index-Cpt5Opfl.d.ts} +1 -1
  14. package/dist/{index-file-DHU9QZX_.js → index-file-BsK9wdM0.js} +13 -8
  15. package/dist/index.d.ts +1 -1
  16. package/dist/{load-from-file-Bt3g8VEm.js → load-from-file-CS38pmAG.js} +3 -3
  17. package/dist/macro/index.d.ts +4 -4
  18. package/dist/{mdx-CwVlI0Qe.js → mdx-D2xc4zzh.js} +12 -7
  19. package/dist/{meta-CsSsB7_T.js → meta-CSo-QNo9.js} +5 -5
  20. package/dist/next/index.d.ts +2 -2
  21. package/dist/next/index.js +5 -5
  22. package/dist/node/_loader.js +8 -8
  23. package/dist/node/index.d.ts +1 -1
  24. package/dist/node/loader.js +4 -4
  25. package/dist/{options-DZSjmVhY.js → options-BeFk1ZUV.js} +1 -1
  26. package/dist/plugins/index-file.d.ts +1 -1
  27. package/dist/plugins/index-file.js +1 -1
  28. package/dist/plugins/json-schema.d.ts +1 -1
  29. package/dist/plugins/last-modified.d.ts +1 -1
  30. package/dist/press.d.ts +1 -1
  31. package/dist/rolldown/index.d.ts +1 -1
  32. package/dist/rolldown/index.js +8 -8
  33. package/dist/runtime/browser.d.ts +4 -4
  34. package/dist/runtime/browser.js +1 -1
  35. package/dist/runtime/dynamic.d.ts +2 -2
  36. package/dist/runtime/dynamic.js +14 -13
  37. package/dist/runtime/macro.d.ts +1 -1
  38. package/dist/runtime/macro.js +1 -1
  39. package/dist/runtime/server.d.ts +3 -3
  40. package/dist/runtime/server.js +1 -1
  41. package/dist/runtime/types.d.ts +1 -1
  42. package/dist/{transform-CAcchC26.js → transform-CaizSlae.js} +67 -80
  43. package/dist/{types-DfxNhkVk.d.ts → types-DgJ0KQFl.d.ts} +1 -1
  44. package/dist/vite/index.d.ts +2 -2
  45. package/dist/vite/index.js +13 -13
  46. package/dist/webpack/macro.d.ts +1 -1
  47. package/dist/webpack/macro.js +2 -2
  48. package/dist/webpack/mdx.d.ts +1 -1
  49. package/dist/webpack/mdx.js +3 -3
  50. package/dist/webpack/meta.d.ts +1 -1
  51. package/dist/webpack/meta.js +3 -3
  52. package/dist/{webpack-BXq21GfV.js → webpack-CvJ-irFx.js} +2 -2
  53. package/package.json +17 -19
  54. package/dist/build-Cd_zdUwB.js +0 -12
  55. package/dist/{build-Dc0aOaCg.js → build-C5OZJocQ.js} +1 -1
  56. package/dist/{dist-C5kTFYyB.js → dist-Bvx4HiiO.js} +1 -1
  57. package/dist/{page-DI7o9MOD.js → page-BobJcTCF.js} +1 -1
@@ -1,6 +1,6 @@
1
- import { r as buildConfig } from "./build-Dc0aOaCg.js";
2
- import { n as ValidationError } from "./core-r1WHKfaI.js";
3
- import { t as loadConfig } from "./load-from-file-Bt3g8VEm.js";
1
+ import { r as buildConfig } from "./build-C5OZJocQ.js";
2
+ import { n as ValidationError } from "./core-BcbYlzSD.js";
3
+ import { t as loadConfig } from "./load-from-file-CS38pmAG.js";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import fs from "node:fs/promises";
6
6
  import path from "node:path";
@@ -1,12 +1,12 @@
1
1
  import { t as applyMdxPreset } from "./preset-CUfyGsn3.js";
2
- import { t as listCode } from "./code-output-CvL35taM.js";
3
- import { r as walkBranches, t as resolveLastModified } from "./last-modified-DZQhqrFZ.js";
4
- import { Parser } from "acorn";
5
- import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
6
2
  import { createProcessor } from "@mdx-js/mdx";
3
+ import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
7
4
  import { VFile } from "vfile";
8
5
  import { valueToEstree } from "estree-util-value-to-estree";
9
6
  import { removePosition } from "unist-util-remove-position";
7
+ import { parse } from "@fumari/oxc-wasm";
8
+ import { t as listCode } from "./code-output-CvL35taM.js";
9
+ import { r as walkBranches, t as resolveLastModified } from "./last-modified-DZQhqrFZ.js";
10
10
  import { remarkLLMs } from "fumadocs-core/mdx-plugins/remark-llms";
11
11
  // src/loaders/mdx/mdast-utils.ts
12
12
  function flattenNode(node) {
@@ -55,10 +55,7 @@ function remarkPostprocess({ includeProcessedMarkdown = false, includeMDAST = fa
55
55
  tree.children.unshift({
56
56
  type: "mdxjsEsm",
57
57
  value: "",
58
- data: { estree: Parser.parse(`export const extractedReferences = ${listCode(items, false)};`, {
59
- ecmaVersion: "latest",
60
- sourceType: "module"
61
- }) }
58
+ data: { estree: parse(`export const extractedReferences = ${listCode(items, false)};`, "js") }
62
59
  });
63
60
  }
64
61
  if (includeProcessedMarkdown) remarkLLMs(typeof includeProcessedMarkdown === "object" ? includeProcessedMarkdown : void 0)(tree, file, () => void 0);
@@ -118,31 +115,7 @@ function getMdastExport(name, value) {
118
115
  }
119
116
  // src/loaders/mdx/build-default.ts
120
117
  async function buildJSMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment, importsOnly = false }) {
121
- const mdxOptions = await getMDXOptions(core.getConfig(), collection, environment);
122
- function getProcessor(format) {
123
- const cache = core.cache;
124
- const key = `build-mdx:${collection?.name ?? "global"}:${format}:${importsOnly}`;
125
- let processor = cache.get(key);
126
- if (!processor) {
127
- const postprocessOptions = {
128
- _format: format,
129
- ...collection?.postprocess
130
- };
131
- processor = createProcessor({
132
- outputFormat: "program",
133
- development: isDevelopment,
134
- ...mdxOptions,
135
- remarkPlugins: [
136
- [remarkInclude, { getProcessor }],
137
- ...mdxOptions.remarkPlugins ?? [],
138
- importsOnly ? remarkImportsOnly : [remarkPostprocess, postprocessOptions]
139
- ],
140
- format
141
- });
142
- cache.set(key, processor);
143
- }
144
- return processor;
145
- }
118
+ const getProcessor = await processorOf(core, collection, environment, isDevelopment, importsOnly);
146
119
  let vfile = new VFile({
147
120
  value: source,
148
121
  path: filePath,
@@ -172,6 +145,38 @@ async function buildJSMDX(core, collection, { filePath, frontmatter, source, _co
172
145
  map: out.map
173
146
  };
174
147
  }
148
+ /** Parse a page into mdast with the processor of its collection. */
149
+ async function parseJSMDX(core, collection, { source, environment, isDevelopment }) {
150
+ return (await processorOf(core, collection, environment, isDevelopment, false))("mdx").parse(source);
151
+ }
152
+ /** the processors of a collection by format, cached */
153
+ async function processorOf(core, collection, environment, isDevelopment, importsOnly) {
154
+ const mdxOptions = await getMDXOptions(core.getConfig(), collection, environment);
155
+ return function getProcessor(format) {
156
+ const cache = core.cache;
157
+ const key = `build-mdx:${collection?.name ?? "global"}:${format}:${importsOnly}`;
158
+ let processor = cache.get(key);
159
+ if (!processor) {
160
+ const postprocessOptions = {
161
+ _format: format,
162
+ ...collection?.postprocess
163
+ };
164
+ processor = createProcessor({
165
+ outputFormat: "program",
166
+ development: isDevelopment,
167
+ ...mdxOptions,
168
+ remarkPlugins: [
169
+ [remarkInclude, { getProcessor }],
170
+ ...mdxOptions.remarkPlugins ?? [],
171
+ importsOnly ? remarkImportsOnly : [remarkPostprocess, postprocessOptions]
172
+ ],
173
+ format
174
+ });
175
+ cache.set(key, processor);
176
+ }
177
+ return processor;
178
+ };
179
+ }
175
180
  /**
176
181
  * Keep only the ESM, after the remark plugins that may add imports, so the other plugins have nothing to process.
177
182
  */
@@ -208,4 +213,4 @@ function getMDXOptions(config, collection, environment = "bundler") {
208
213
  cacheMap.set(key, result);
209
214
  return result;
210
215
  }
211
- export { buildJSMDX };
216
+ export { buildJSMDX, parseJSMDX };
@@ -1,6 +1,6 @@
1
+ import { pathToFileURL } from "node:url";
1
2
  import { n as showConditions, t as resolveLastModified } from "./last-modified-DZQhqrFZ.js";
2
3
  import { t as listCode } from "./code-output-CvL35taM.js";
3
- import { pathToFileURL } from "node:url";
4
4
  // src/loaders/mdx/build-satteri.ts
5
5
  async function buildSatteriMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment }) {
6
6
  const satteriOptions = await getSatteriOptions(core.getConfig(), collection, environment);
@@ -49,6 +49,17 @@ async function buildSatteriMDX(core, collection, { filePath, frontmatter, source
49
49
  }
50
50
  })).code };
51
51
  }
52
+ /** Parse a page into mdast with the Sätteri features of its collection. */
53
+ async function parseSatteriMDX(core, collection, { source, environment }) {
54
+ const [{ features }, { mdxToMdast }] = await Promise.all([getSatteriOptions(core.getConfig(), collection, environment), import(
55
+ /* turbopackOptional: true */
56
+ "satteri"
57
+ )]);
58
+ return mdxToMdast(source, {
59
+ features,
60
+ position: true
61
+ });
62
+ }
52
63
  function postprocessPlugin({ extractLinkReferences = false }, lastModified) {
53
64
  return {
54
65
  name: "remark-postprocess",
@@ -98,4 +109,4 @@ function getSatteriOptions(config, collection, environment = "bundler") {
98
109
  cache.set(key, result);
99
110
  return result;
100
111
  }
101
- export { buildSatteriMDX };
112
+ export { buildSatteriMDX, parseSatteriMDX };
@@ -1,6 +1,6 @@
1
- import { r as CoreOptions } from "../core-OVmyAj82.js";
2
- import { t as MacroPluginOption } from "../options-aTvMSrKg.js";
3
1
  import { BunPlugin } from "bun";
2
+ import { r as CoreOptions } from "../core-Cvyga-oq.js";
3
+ import { t as MacroPluginOption } from "../options-aTvMSrKg.js";
4
4
  export interface MdxPluginOptions extends Pick<CoreOptions, 'configPath' | 'outDir' | 'plugins'> {
5
5
  /**
6
6
  * Configure the macro API (`fumadocs-mdx/macro`), or `false` to disable it.
package/dist/bun/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import { t as createMdxLoader } from "../mdx-CwVlI0Qe.js";
2
- import { r as buildConfig } from "../build-Dc0aOaCg.js";
3
- import { t as createCore } from "../core-r1WHKfaI.js";
4
- import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-Clt8sB1g.js";
5
- import { t as createMetaLoader } from "../meta-CsSsB7_T.js";
6
- import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-3R0gLmlP.js";
7
- import { i as resolveMacroOptions, n as NodeModulesRegex, r as createMacroMatcher } from "../options-DZSjmVhY.js";
1
+ import { t as createMdxLoader } from "../mdx-D2xc4zzh.js";
2
+ import { r as buildConfig } from "../build-C5OZJocQ.js";
3
+ import { pathToFileURL } from "node:url";
8
4
  import fs from "node:fs/promises";
9
5
  import { randomUUID } from "node:crypto";
10
- import { pathToFileURL } from "node:url";
6
+ import { t as createCore } from "../core-BcbYlzSD.js";
7
+ import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-CG3tA0Gl.js";
8
+ import { t as createMetaLoader } from "../meta-CSo-QNo9.js";
9
+ import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-3R0gLmlP.js";
10
+ import { i as resolveMacroOptions, n as NodeModulesRegex, r as createMacroMatcher } from "../options-BeFk1ZUV.js";
11
11
  // src/bun/index.ts
12
12
  const EvalQueryKey = "fd-macro-eval";
13
13
  const pendingEvals = /* @__PURE__ */ new Map();
@@ -41,7 +41,7 @@ function createMdxPlugin(options = {}) {
41
41
  await core.init({ config: buildConfig(configExports, process.cwd()) });
42
42
  if (macroOptions) {
43
43
  const root = process.cwd();
44
- const { MacroCollector } = await import("../eval-Ch9sPj_e.js").then((n) => n.r);
44
+ const { MacroCollector } = await import("../eval-DcO6h2th.js").then((n) => n.r);
45
45
  core.macro = new MacroCollector({
46
46
  root,
47
47
  outDir: core.outDir,
@@ -72,7 +72,7 @@ function createMdxPlugin(options = {}) {
72
72
  contents: await transform(source, file) ?? source,
73
73
  loader
74
74
  };
75
- const { transformMacroModule } = await import("../transform-CAcchC26.js").then((n) => n.i);
75
+ const { transformMacroModule } = await import("../transform-CaizSlae.js").then((n) => n.i);
76
76
  return {
77
77
  contents: (await transformMacroModule({
78
78
  code: source,
@@ -1,37 +1,61 @@
1
- import { statSync } from "node:fs";
1
+ import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.js";
2
2
  import path from "node:path";
3
+ import { statSync } from "node:fs";
3
4
  import { createRequire } from "node:module";
4
5
  import { compileFunction } from "node:vm";
5
6
  import { buildSync } from "esbuild";
6
- import { Parser } from "acorn";
7
- import acornJsx from "acorn-jsx";
8
- import { fromMarkdown } from "mdast-util-from-markdown";
9
- import { mdxFromMarkdown } from "mdast-util-mdx";
10
- import { mdxjsEsm } from "micromark-extension-mdxjs-esm";
7
+ import { parse } from "@fumari/oxc-wasm";
8
+ // src/loaders/mdx/build.ts
9
+ var build_exports = /* @__PURE__ */ __exportAll({ buildMDX: () => buildMDX });
10
+ async function buildMDX(core, collection, options) {
11
+ if (compilerOf(core, collection) === "satteri") {
12
+ const { buildSatteriMDX } = await import("./build-satteri-At6UToAY.js");
13
+ return buildSatteriMDX(core, collection, options);
14
+ }
15
+ const { buildJSMDX } = await import("./build-default-P4XKTKKP.js");
16
+ return buildJSMDX(core, collection, options);
17
+ }
18
+ /** Parse a page into mdast with the parser of its compiler, with the syntax that `buildMDX()` reads. */
19
+ async function parseMDX(core, collection, options) {
20
+ if (compilerOf(core, collection) === "satteri") {
21
+ const { parseSatteriMDX } = await import("./build-satteri-At6UToAY.js");
22
+ return parseSatteriMDX(core, collection, options);
23
+ }
24
+ const { parseJSMDX } = await import("./build-default-P4XKTKKP.js");
25
+ return parseJSMDX(core, collection, options);
26
+ }
27
+ function compilerOf(core, collection) {
28
+ return collection ? collection.compiler : core.getConfig().global.compiler;
29
+ }
11
30
  // ../shared/frontmatter-code.ts
31
+ /** whether an MDX file has frontmatter in code, `export const frontmatter = {...}` */
32
+ function hasFrontmatterCode(source) {
33
+ return /^export const frontmatter\b/m.test(source);
34
+ }
12
35
  /**
13
36
  * The frontmatter in code of an ESM block, `export const frontmatter = ...`, as the module of `frontmatter(props = {})`:
14
- * with the imports it reads and the exports before it in the block. `remove` is what to leave out of the content.
37
+ * with the imports it reads and the exports before it in the block. `remove` is what to leave out of the block.
15
38
  *
16
39
  * @param imports - the imports of the document with their code, they are hoisted
17
40
  */
18
- function frontmatterModule(source, block, imports, range) {
41
+ function frontmatterModule(block, statements, imports) {
19
42
  let body = "";
20
43
  const declarations = [];
21
- for (const statement of block) {
44
+ for (const statement of statements) {
45
+ if (statement.type !== "ExportNamedDeclaration" || !statement.declaration) continue;
22
46
  const { declaration } = statement;
23
- if (statement.type !== "ExportNamedDeclaration" || !declaration) continue;
24
- body += `${source.slice(...range(declaration))}\n`;
47
+ body += `${block.slice(declaration.start, declaration.end)}\n`;
25
48
  declarations.push(declaration);
26
- const [first, second] = declaration.declarations ?? [];
27
- if (first?.id.type !== "Identifier" || first.id.name !== "frontmatter") continue;
49
+ if (declaration.type !== "VariableDeclaration") continue;
50
+ const [first, second] = declaration.declarations;
51
+ if (first.id.type !== "Identifier" || first.id.name !== "frontmatter") continue;
28
52
  const names = /* @__PURE__ */ new Set();
29
53
  collectNames(declarations, names);
30
54
  let code = "";
31
- for (const [item, text] of imports) if (item.specifiers?.some(({ local }) => local.name && names.has(local.name))) code += `${text}\n`;
55
+ for (const [item, text] of imports) if (item.specifiers.some(({ local }) => names.has(local.name))) code += `${text}\n`;
32
56
  return {
33
57
  module: `${code}export const frontmatter = (props = {}) => {\n${body}return frontmatter;\n};`,
34
- remove: second ? [range(first)[0], range(second)[0]] : range(statement)
58
+ remove: second ? [first.start, second.start] : [statement.start, statement.end]
35
59
  };
36
60
  }
37
61
  }
@@ -55,14 +79,6 @@ function metaModule({ default: data, staticParams = data?.staticParams }) {
55
79
  } };
56
80
  }
57
81
  // src/loaders/mdx/code.ts
58
- const esm = mdxjsEsm({
59
- acorn: Parser.extend(acornJsx()),
60
- acornOptions: {
61
- ecmaVersion: "latest",
62
- sourceType: "module"
63
- },
64
- addResult: true
65
- });
66
82
  /** the last run of each module: its code, the modification times of the files it read, its exports */
67
83
  const modules = /* @__PURE__ */ new Map();
68
84
  /**
@@ -113,25 +129,32 @@ function mtime(file) {
113
129
  return statSync(file, { throwIfNoEntry: false })?.mtimeMs ?? -1;
114
130
  }
115
131
  /**
116
- * The frontmatter in the code of a page, `export const frontmatter = {...}`. It runs at build time with the imports it
117
- * reads, the statements before it in its ESM block and the params of a page as `props`, the content no longer has it.
132
+ * The frontmatter in the code of a page, `export const frontmatter = {...}`, from the ESM that the compiler of the page
133
+ * parses. It runs at build time with the imports it reads, the statements before it in its ESM block and the params of a
134
+ * page as `props`, the content no longer has it.
118
135
  */
119
- function frontmatterCode(filePath, content) {
120
- if (!filePath.endsWith(".mdx") || !/^export const frontmatter\b/m.test(content)) return;
121
- const tree = fromMarkdown(content, {
122
- extensions: [esm],
123
- mdastExtensions: [mdxFromMarkdown()]
124
- });
125
- const range = (node) => node.range;
136
+ async function frontmatterCode(core, collection, options) {
137
+ const { filePath, source: content } = options;
138
+ if (!filePath.endsWith(".mdx") || !hasFrontmatterCode(content)) return;
139
+ const tree = await parseMDX(core, collection, options);
140
+ const blocks = [];
126
141
  const imports = [];
127
- for (const node of tree.children) if (node.type === "mdxjsEsm") {
128
- for (const statement of node.data?.estree?.body ?? []) if (statement.type === "ImportDeclaration") imports.push([statement, content.slice(...range(statement))]);
129
- }
130
142
  for (const node of tree.children) {
131
- if (node.type !== "mdxjsEsm" || !node.data?.estree) continue;
132
- const frontmatter = frontmatterModule(content, node.data.estree.body, imports, range);
143
+ if (node.type !== "mdxjsEsm") continue;
144
+ const { value } = node;
145
+ const statements = parse(value, "tsx").body;
146
+ for (const statement of statements) if (statement.type === "ImportDeclaration") imports.push([statement, value.slice(statement.start, statement.end)]);
147
+ blocks.push({
148
+ offset: node.position.start.offset,
149
+ value,
150
+ statements
151
+ });
152
+ }
153
+ for (const { offset, value, statements } of blocks) {
154
+ const frontmatter = frontmatterModule(value, statements, imports);
133
155
  if (!frontmatter) continue;
134
- const [start, end] = frontmatter.remove;
156
+ const start = offset + frontmatter.remove[0];
157
+ const end = offset + frontmatter.remove[1];
135
158
  return {
136
159
  content: content.slice(0, start) + content.slice(start, end).replace(/[^\n]/g, "") + content.slice(end),
137
160
  /** compile it into a function of the params */
@@ -165,4 +188,4 @@ async function resolveFrontmatter({ code, yaml, staticParams, validate, addDepen
165
188
  _frontmatterAt: frontmatterAt
166
189
  };
167
190
  }
168
- export { metaModule as i, resolveFrontmatter as n, runModule as r, frontmatterCode as t };
191
+ export { metaModule as a, hasFrontmatterCode as i, resolveFrontmatter as n, buildMDX as o, runModule as r, build_exports as s, frontmatterCode as t };
@@ -5,7 +5,6 @@ import { glob } from "tinyglobby";
5
5
  * Code generator (one instance per file)
6
6
  */
7
7
  function createCodegen({ target = "default", outDir = "", jsExtension = false, globCache = /* @__PURE__ */ new Map() }) {
8
- let eagerImportId = 0;
9
8
  const banner = ["// @ts-nocheck"];
10
9
  if (target === "vite") banner.push("/// <reference types=\"vite/client\" />");
11
10
  return {
@@ -14,6 +13,8 @@ function createCodegen({ target = "default", outDir = "", jsExtension = false, g
14
13
  outDir
15
14
  },
16
15
  lines: [],
16
+ /** eager imports of each glob, in call order */
17
+ imports: [],
17
18
  addImport(statement) {
18
19
  this.lines.unshift(statement);
19
20
  },
@@ -45,14 +46,16 @@ function createCodegen({ target = "default", outDir = "", jsExtension = false, g
45
46
  files = glob(patterns, { cwd: base }).then((result) => result.sort());
46
47
  globCache.set(cacheKey, files);
47
48
  }
49
+ const imports = [];
50
+ const id = this.imports.push(imports) - 1;
48
51
  const search = stringifyQuery(query);
49
52
  let code = "{";
50
- for (const item of await files) {
53
+ for (const [i, item] of (await files).entries()) {
51
54
  const fullPath = path.join(base, item);
52
55
  const importPath = this.formatImportPath(fullPath) + search;
53
56
  if (eager) {
54
- const name = `__fd_glob_${eagerImportId++}`;
55
- this.lines.unshift(importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`);
57
+ const name = `__fd_glob_${id}_${i}`;
58
+ imports.push(importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`);
56
59
  code += `${JSON.stringify(item)}: ${name}, `;
57
60
  } else {
58
61
  let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
@@ -76,7 +79,11 @@ function createCodegen({ target = "default", outDir = "", jsExtension = false, g
76
79
  return `./${importPath}`;
77
80
  },
78
81
  toString() {
79
- return [...banner, ...this.lines].join("\n");
82
+ return [
83
+ ...banner,
84
+ ...this.imports.flat(),
85
+ ...this.lines
86
+ ].join("\n");
80
87
  }
81
88
  };
82
89
  }
@@ -1,4 +1,4 @@
1
- import { C as DocsCollection, D as defineCollections, E as SatteriPresetOptions, F as DefaultMDXOptions, I as MDXPresetOptions, L as applyMdxPreset, O as defineConfig, P as PostprocessOptions, S as DocCollectionSatteri, T as MetaCollection, _ as BaseCollection, b as DocCollectionBase, g as AnyCollection, k as defineDocs, v as CollectionSchema, w as GlobalConfig, x as DocCollectionMdx, y as DocCollection } from "../core-OVmyAj82.js";
1
+ import { C as DocsCollection, D as defineCollections, E as SatteriPresetOptions, F as DefaultMDXOptions, I as MDXPresetOptions, L as applyMdxPreset, O as defineConfig, P as PostprocessOptions, S as DocCollectionSatteri, T as MetaCollection, _ as BaseCollection, b as DocCollectionBase, g as AnyCollection, k as defineDocs, v as CollectionSchema, w as GlobalConfig, x as DocCollectionMdx, y as DocCollection } from "../core-Cvyga-oq.js";
2
2
  import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
3
3
  /** @deprecated import `pageSchema` from `fumadocs-core/source/schema` instead (since 16.2.3) */
4
4
  export declare const frontmatterSchema: import("zod").ZodObject<{
@@ -1,7 +1,7 @@
1
1
  import { n as defineConfig, r as defineDocs, t as defineCollections } from "../define-C2jwQBlt.js";
2
2
  import { t as applyMdxPreset } from "../preset-CUfyGsn3.js";
3
- import { metaSchema as metaSchema$1, pageSchema } from "fumadocs-core/source/schema";
4
3
  import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
4
+ import { metaSchema as metaSchema$1, pageSchema } from "fumadocs-core/source/schema";
5
5
  // src/config/index.ts
6
6
  /** @deprecated import `pageSchema` from `fumadocs-core/source/schema` instead (since 16.2.3) */
7
7
  const frontmatterSchema = pageSchema;
@@ -1,6 +1,6 @@
1
- import { n as ident } from "./codegen-uHLSduG-.js";
2
- import fs from "node:fs/promises";
3
1
  import path from "node:path";
2
+ import fs from "node:fs/promises";
3
+ import { n as ident } from "./codegen-xBM-ArrU.js";
4
4
  // src/utils/validation.ts
5
5
  var ValidationError = class extends Error {
6
6
  constructor(message, issues) {
@@ -1,17 +1,17 @@
1
- import { FC, ReactNode } from "react";
2
- import { metaSchema, pageSchema } from "fumadocs-core/source/schema";
3
- import { ProcessorOptions } from "@mdx-js/mdx";
4
- import { VFile } from "vfile";
5
1
  import { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import { ProcessorOptions } from "@mdx-js/mdx";
6
3
  import { Pluggable } from "unified";
7
4
  import * as Plugins from "fumadocs-core/mdx-plugins";
8
5
  import { LLMsOptions } from "fumadocs-core/mdx-plugins";
6
+ import { metaSchema, pageSchema } from "fumadocs-core/source/schema";
9
7
  import "mdast";
10
8
  import { SatteriPresetOptions, SatteriPresetOptions as SatteriPresetOptions$1 } from "@fumadocs/satteri/preset";
11
9
  import { StructuredData, StructuredDataContent } from "fumadocs-core/mdx-plugins/remark-structure";
12
10
  import { TOCItemType } from "fumadocs-core/toc";
11
+ import { FC, ReactNode } from "react";
13
12
  import { MDXProps } from "mdx/types";
14
13
  import { FSWatcher } from "chokidar";
14
+ import { VFile } from "vfile";
15
15
  type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
16
16
  type DefaultMDXOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins' | '_ctx'> & {
17
17
  rehypePlugins?: ResolvePlugins;
@@ -1,13 +1,13 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.js";
2
- import { n as transformMacroConfigModule, t as parseMacroId } from "./transform-CAcchC26.js";
3
- import { n as buildCollection } from "./build-Dc0aOaCg.js";
4
- import { r as defineDocs } from "./define-C2jwQBlt.js";
5
- import { r as slash } from "./codegen-uHLSduG-.js";
6
- import { n as NodeModulesRegex } from "./options-DZSjmVhY.js";
7
- import fs from "node:fs/promises";
8
2
  import path from "node:path";
3
+ import fs from "node:fs/promises";
9
4
  import { randomUUID } from "node:crypto";
10
5
  import { pathToFileURL } from "node:url";
6
+ import { n as transformMacroConfigModule, t as parseMacroId } from "./transform-CaizSlae.js";
7
+ import { n as buildCollection } from "./build-C5OZJocQ.js";
8
+ import { r as defineDocs } from "./define-C2jwQBlt.js";
9
+ import { r as slash } from "./codegen-xBM-ArrU.js";
10
+ import { n as NodeModulesRegex } from "./options-BeFk1ZUV.js";
11
11
  // src/macro/eval.ts
12
12
  var eval_exports = /* @__PURE__ */ __exportAll({ MacroCollector: () => MacroCollector });
13
13
  const Resolving = {};
@@ -1,4 +1,4 @@
1
- import "./core-OVmyAj82.js";
1
+ import "./core-Cvyga-oq.js";
2
2
  interface WebpackLoaderOptions {
3
3
  type: 'webpack' | 'turbopack';
4
4
  /** absolute path */
@@ -1,12 +1,12 @@
1
- import { n as ident, r as slash, t as createCodegen } from "./codegen-uHLSduG-.js";
2
- import { n as resolveFrontmatter, t as frontmatterCode } from "./code-BWwFhg-7.js";
3
- import { n as readStaticParams } from "./meta-CsSsB7_T.js";
4
- import { frontmatter } from "fumadocs-core/content/md/frontmatter";
5
- import fs from "node:fs/promises";
6
1
  import path from "node:path";
7
- import { createHash } from "node:crypto";
2
+ import { n as ident, r as slash, t as createCodegen } from "./codegen-xBM-ArrU.js";
8
3
  import { glob } from "tinyglobby";
4
+ import fs from "node:fs/promises";
5
+ import { createHash } from "node:crypto";
6
+ import { n as resolveFrontmatter, t as frontmatterCode } from "./code-ChiBd2gZ.js";
7
+ import { n as readStaticParams } from "./meta-CSo-QNo9.js";
9
8
  import { getStaticParams } from "fumadocs-core/source";
9
+ import { frontmatter } from "fumadocs-core/content/md/frontmatter";
10
10
  // src/utils/fs-cache.ts
11
11
  const map = /* @__PURE__ */ new Map();
12
12
  function createFSCache() {
@@ -171,7 +171,12 @@ async function generateDynamicIndexFile(ctx) {
171
171
  const parsed = frontmatter(content);
172
172
  const yaml = parsed.data;
173
173
  const data = await resolveFrontmatter({
174
- code: frontmatterCode(absolutePath, parsed.content),
174
+ code: await frontmatterCode(core, collection, {
175
+ filePath: absolutePath,
176
+ source: parsed.content,
177
+ environment: "runtime",
178
+ isDevelopment: false
179
+ }),
175
180
  yaml,
176
181
  staticParams: getStaticParams(slash(path.relative(collection.dir, absolutePath)), {
177
182
  staticParams: yaml.staticParams,
@@ -205,7 +210,7 @@ async function generateDynamicIndexFile(ctx) {
205
210
  cwd: collection.dir,
206
211
  absolute: true
207
212
  });
208
- const entries = await Promise.all(files.map((file) => generateCollectionObjectEntry(collection, file)));
213
+ const entries = await Promise.all(files.sort().map((file) => generateCollectionObjectEntry(collection, file)));
209
214
  switch (parent.type) {
210
215
  case "docs": {
211
216
  const metaGlob = await generateMetaCollectionGlob(ctx, parent.meta, true);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { N as ExtractedReference, a as EmitOptions, c as PluginContext, d as TransformOptions, i as EmitEntry, j as CompiledMDXProperties, l as PluginOption, n as Core, o as EmitOutput, r as CoreOptions, s as Plugin, t as CompilationContext, u as ServerContext } from "./core-OVmyAj82.js";
1
+ import { N as ExtractedReference, a as EmitOptions, c as PluginContext, d as TransformOptions, i as EmitEntry, j as CompiledMDXProperties, l as PluginOption, n as Core, o as EmitOutput, r as CoreOptions, s as Plugin, t as CompilationContext, u as ServerContext } from "./core-Cvyga-oq.js";
2
2
  export type { CompilationContext, CompiledMDXProperties, Core, CoreOptions, EmitEntry, EmitOptions, EmitOutput, ExtractedReference, Plugin, PluginContext, PluginOption, ServerContext, TransformOptions };
@@ -1,7 +1,7 @@
1
- import { r as buildConfig } from "./build-Dc0aOaCg.js";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
1
  import { pathToFileURL } from "node:url";
2
+ import path from "node:path";
3
+ import fs from "node:fs/promises";
4
+ import { r as buildConfig } from "./build-C5OZJocQ.js";
5
5
  // src/config/load-from-file.ts
6
6
  async function compileConfig(core) {
7
7
  const { build } = await import("esbuild");
@@ -1,9 +1,9 @@
1
- import { A as SatteriOptionsInput, N as ExtractedReference, P as PostprocessOptions, h as BuildEnvironment, v as CollectionSchema } from "../core-OVmyAj82.js";
2
- import { MacroAsyncDocCollection, MacroAsyncDocsCollection, MacroDocCollection, MacroDocsCollection, MacroMetaCollection } from "../runtime/macro.js";
1
+ import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
2
+ import { ProcessorOptions } from "@mdx-js/mdx";
3
3
  import { MetaData, PageData } from "fumadocs-core/source";
4
4
  import { metaSchema, pageSchema } from "fumadocs-core/source/schema";
5
- import { ProcessorOptions } from "@mdx-js/mdx";
6
- import { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
5
+ import { A as SatteriOptionsInput, N as ExtractedReference, P as PostprocessOptions, h as BuildEnvironment, v as CollectionSchema } from "../core-Cvyga-oq.js";
6
+ import { MacroAsyncDocCollection, MacroAsyncDocsCollection, MacroDocCollection, MacroDocsCollection, MacroMetaCollection } from "../runtime/macro.js";
7
7
  export interface MacroSchemaContext {
8
8
  path: string;
9
9
  source: string;
@@ -1,12 +1,12 @@
1
- import { r as slash } from "./codegen-uHLSduG-.js";
2
- import { n as resolveFrontmatter, t as frontmatterCode } from "./code-BWwFhg-7.js";
3
- import { n as readStaticParams } from "./meta-CsSsB7_T.js";
4
1
  import { frontmatter } from "fumadocs-core/content/md/frontmatter";
5
2
  import { z } from "zod";
6
3
  import fs from "node:fs/promises";
7
4
  import path from "node:path";
8
5
  import { createHash } from "node:crypto";
6
+ import { r as slash } from "./codegen-xBM-ArrU.js";
9
7
  import { getStaticParams, isDynamicPath } from "fumadocs-core/source";
8
+ import { i as hasFrontmatterCode, n as resolveFrontmatter, t as frontmatterCode } from "./code-ChiBd2gZ.js";
9
+ import { n as readStaticParams } from "./meta-CSo-QNo9.js";
10
10
  // src/loaders/mdx/index.ts
11
11
  const querySchema = z.looseObject({
12
12
  only: z.literal(["frontmatter", "all"]).default("all"),
@@ -28,10 +28,8 @@ function createMdxLoader({ getCore }) {
28
28
  const { collection: collectionName, workspace, only, macro_id: macroId } = querySchema.parse(query);
29
29
  if (workspace) core = core.getWorkspaces().get(workspace) ?? core;
30
30
  let after;
31
- const code = frontmatterCode(filePath, matter.content);
32
- if (code) matter.content = code.content;
33
31
  const { experimentalBuildCache = false } = core.getConfig().global;
34
- if (!isDevelopment && !importsOnly && experimentalBuildCache && only === "all" && !code && !isDynamicPath(slash(filePath))) {
32
+ if (!isDevelopment && !importsOnly && experimentalBuildCache && only === "all" && !hasFrontmatterCode(matter.content) && !isDynamicPath(slash(filePath))) {
35
33
  const cacheDir = experimentalBuildCache;
36
34
  const cacheKey = `${(macroId ?? collectionName ?? "global").replace(/[^a-zA-Z0-9_-]/g, "_")}_${generateCacheHash(filePath)}`;
37
35
  const cached = await fs.readFile(path.join(cacheDir, cacheKey), "utf-8").then((content) => cacheEntry.parse(JSON.parse(content))).catch(() => null);
@@ -60,6 +58,13 @@ function createMdxLoader({ getCore }) {
60
58
  case "docs": docCollection = collection.docs;
61
59
  }
62
60
  }
61
+ const code = await frontmatterCode(core, docCollection, {
62
+ filePath,
63
+ source: matter.content,
64
+ environment: "bundler",
65
+ isDevelopment
66
+ });
67
+ if (code) matter.content = code.content;
63
68
  const validate = (data) => docCollection ? core.transformFrontmatter({
64
69
  collection: docCollection,
65
70
  filePath,
@@ -82,7 +87,7 @@ function createMdxLoader({ getCore }) {
82
87
  listed: only === "frontmatter" || !docCollection?.async
83
88
  });
84
89
  if (only === "frontmatter") return { code: `export const frontmatter = ${JSON.stringify(data)}` };
85
- const { buildMDX } = await import("./build-Cd_zdUwB.js").then((n) => n.n);
90
+ const { buildMDX } = await import("./code-ChiBd2gZ.js").then((n) => n.s);
86
91
  const compiled = await buildMDX(core, docCollection, {
87
92
  isDevelopment,
88
93
  source: "\n".repeat(countLines(matter.matter)) + matter.content,
@@ -1,10 +1,10 @@
1
- import { i as metaModule, r as runModule } from "./code-BWwFhg-7.js";
2
- import { r as slash } from "./codegen-uHLSduG-.js";
3
- import { readFileSync } from "node:fs";
1
+ import { parse as parse$1 } from "yaml";
4
2
  import { z } from "zod";
5
- import path from "node:path";
3
+ import { a as metaModule, r as runModule } from "./code-ChiBd2gZ.js";
4
+ import { r as slash } from "./codegen-xBM-ArrU.js";
6
5
  import { getStaticParams } from "fumadocs-core/source";
7
- import { parse as parse$1 } from "yaml";
6
+ import { readFileSync } from "node:fs";
7
+ import path from "node:path";
8
8
  // src/loaders/meta.ts
9
9
  const querySchema = z.looseObject({
10
10
  collection: z.string().optional(),
@@ -1,6 +1,6 @@
1
- import { p as IndexFilePluginOptions, r as CoreOptions } from "../core-OVmyAj82.js";
2
- import { t as MacroPluginOption } from "../options-aTvMSrKg.js";
3
1
  import { NextConfig } from "next";
2
+ import { p as IndexFilePluginOptions, r as CoreOptions } from "../core-Cvyga-oq.js";
3
+ import { t as MacroPluginOption } from "../options-aTvMSrKg.js";
4
4
  export interface CreateMDXOptions extends Pick<CoreOptions, 'configPath' | 'outDir'> {
5
5
  /**
6
6
  * Configure the macro API (`fumadocs-mdx/macro`), or `false` to disable it.