fumadocs-mdx 15.5.1 → 15.5.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.
Files changed (55) hide show
  1. package/dist/adapter-C04Ekc4W.js +277 -0
  2. package/dist/{build-6pmheBOc.js → build-Bnz9TOnv.js} +3 -3
  3. package/dist/build-TiTOkhq4.js +89 -0
  4. package/dist/{build-default-DxRVIZIq.js → build-default-BU_9K-PJ.js} +3 -2
  5. package/dist/{build-satteri-BRRVAMZo.js → build-satteri-D8On1S2_.js} +2 -1
  6. package/dist/bun/index.d.ts +1 -1
  7. package/dist/bun/index.js +8 -8
  8. package/dist/code-BF5OS485.js +86 -0
  9. package/dist/{codegen-D-Cjx_kh.js → codegen-BAuFQ5Ew.js} +1 -1
  10. package/dist/config/index.d.ts +3 -1
  11. package/dist/config/index.js +1 -1
  12. package/dist/{core-B3ysiPKS.js → core-CJjfu3ju.js} +2 -79
  13. package/dist/{core-CdciznjV.d.ts → core-DA_zPpY3.d.ts} +5 -1
  14. package/dist/{eval-BK4eWlcF.js → eval-DAaN7Bq9.js} +5 -8
  15. package/dist/{index-DHkDeoqE.d.ts → index-BghUMTgU.d.ts} +1 -1
  16. package/dist/{index-file-Cd0QDLxu.js → index-file-BKxOSG_x.js} +6 -2
  17. package/dist/index.d.ts +1 -1
  18. package/dist/{load-from-file-BP8EpGZa.js → load-from-file-gZlf7m88.js} +1 -1
  19. package/dist/{loaders-B_gj5Fq1.js → loaders-3R0gLmlP.js} +2 -2
  20. package/dist/macro/index.d.ts +2 -2
  21. package/dist/{mdx-wIFREygW.js → mdx-VmqU5Oaj.js} +58 -7
  22. package/dist/next/index.d.ts +1 -1
  23. package/dist/next/index.js +12 -4
  24. package/dist/node/_loader.js +7 -8
  25. package/dist/node/index.d.ts +1 -1
  26. package/dist/node/loader.js +4 -5
  27. package/dist/plugins/index-file.d.ts +1 -1
  28. package/dist/plugins/index-file.js +1 -1
  29. package/dist/plugins/json-schema.d.ts +1 -1
  30. package/dist/plugins/last-modified.d.ts +1 -1
  31. package/dist/{preset-Vhfrb01t.js → preset-BLDvTSeK.js} +2 -1
  32. package/dist/rolldown/index.d.ts +1 -1
  33. package/dist/rolldown/index.js +8 -8
  34. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  35. package/dist/runtime/browser.d.ts +1 -1
  36. package/dist/runtime/dynamic.d.ts +2 -2
  37. package/dist/runtime/dynamic.js +5 -2
  38. package/dist/runtime/macro.d.ts +5 -3
  39. package/dist/runtime/macro.js +13 -3
  40. package/dist/runtime/server.d.ts +4 -2
  41. package/dist/runtime/server.js +76 -14
  42. package/dist/{transform-CVIZq8Al.js → transform-D7pyKPqb.js} +13 -17
  43. package/dist/vite/index.d.ts +1 -1
  44. package/dist/vite/index.js +8 -8
  45. package/dist/webpack/macro.d.ts +1 -1
  46. package/dist/webpack/macro.js +1 -1
  47. package/dist/webpack/mdx.d.ts +1 -1
  48. package/dist/webpack/mdx.js +3 -3
  49. package/dist/webpack/meta.d.ts +1 -1
  50. package/dist/webpack/meta.js +2 -3
  51. package/dist/{webpack-DyVbvTYa.js → webpack-BoqJZRKf.js} +2 -2
  52. package/package.json +20 -16
  53. package/dist/adapter-C_fAYz8a.js +0 -142
  54. package/dist/meta-B2-_R5y0.js +0 -84
  55. package/dist/rolldown-runtime-D8jQpDG7.js +0 -12
@@ -0,0 +1,277 @@
1
+ import { r as slash } from "./codegen-BAuFQ5Ew.js";
2
+ import { n as runModule } from "./code-BF5OS485.js";
3
+ import { r as buildConfig } from "./build-TiTOkhq4.js";
4
+ import { n as ValidationError } from "./core-CJjfu3ju.js";
5
+ import { t as loadConfig } from "./load-from-file-gZlf7m88.js";
6
+ import { readFileSync } from "node:fs";
7
+ import { z } from "zod";
8
+ import fs from "node:fs/promises";
9
+ import path from "node:path";
10
+ import { getStaticParams } from "fumadocs-core/source";
11
+ import { parse } from "yaml";
12
+ import { fileURLToPath } from "node:url";
13
+ import { parse as parse$1 } from "node:querystring";
14
+ // src/loaders/meta.ts
15
+ const querySchema = z.looseObject({
16
+ collection: z.string().optional(),
17
+ workspace: z.string().optional(),
18
+ macro_id: z.string().optional()
19
+ });
20
+ /**
21
+ * The data of a meta file. A module, like `meta.ts`, has a default export, which can be a function of the params of
22
+ * its folder, and the `staticParams` as a named export or in its data.
23
+ */
24
+ function parse$2(filePath, source, addDependency) {
25
+ if (/\.[jt]s$/.test(filePath)) {
26
+ const { default: data, staticParams = data?.staticParams } = runModule(filePath, source, addDependency);
27
+ if (typeof data === "function") return {
28
+ data: { staticParams },
29
+ dataAt: data
30
+ };
31
+ return { data: {
32
+ ...data,
33
+ staticParams
34
+ } };
35
+ }
36
+ try {
37
+ if (filePath.endsWith(".json")) return { data: JSON.parse(source) };
38
+ if (filePath.endsWith(".yaml")) return { data: parse(source) };
39
+ } catch (e) {
40
+ throw new Error(`invalid data in ${filePath}`, { cause: e });
41
+ }
42
+ throw new Error("Unknown file type " + filePath);
43
+ }
44
+ /** read the `staticParams` of a meta file in `dir`, by its path without the extension, like `[framework]/meta` */
45
+ function readStaticParams(dir, file, addDependency) {
46
+ for (const ext of [
47
+ ".json",
48
+ ".yaml",
49
+ ".ts",
50
+ ".js"
51
+ ]) {
52
+ const metaFile = path.join(dir, file + ext);
53
+ addDependency(metaFile);
54
+ let content;
55
+ try {
56
+ content = readFileSync(metaFile, "utf-8");
57
+ } catch (error) {
58
+ if (error.code === "ENOENT") continue;
59
+ throw error;
60
+ }
61
+ return parse$2(metaFile, content, addDependency).data?.staticParams;
62
+ }
63
+ }
64
+ /**
65
+ * load meta files, fallback to bundler's built-in plugins when ?collection is unspecified.
66
+ */
67
+ function createMetaLoader({ getCore }, resolve = {}) {
68
+ const { json: resolveJson = "js" } = resolve;
69
+ function onMeta(source, { filePath, query, compiler }) {
70
+ const parsed = querySchema.safeParse(query);
71
+ if (!parsed.success) return null;
72
+ const { collection: collectionName, workspace, macro_id: macroId } = parsed.data;
73
+ if (!collectionName && macroId === void 0) return null;
74
+ return async () => {
75
+ let core = await getCore();
76
+ const macro = core.macro;
77
+ if (workspace) core = core.getWorkspaces().get(workspace) ?? core;
78
+ let metaCollection;
79
+ if (macro && macroId !== void 0) {
80
+ const resolved = await macro.resolve(macroId);
81
+ for (const input of resolved.inputs) compiler.addDependency(input);
82
+ const item = resolved.collection;
83
+ if (item.type === "docs") metaCollection = item.meta;
84
+ else if (item.type === "meta") metaCollection = item;
85
+ } else if (collectionName) {
86
+ const collection = core.getCollection(collectionName);
87
+ switch (collection?.type) {
88
+ case "meta":
89
+ metaCollection = collection;
90
+ break;
91
+ case "docs": metaCollection = collection.meta;
92
+ }
93
+ }
94
+ const { data, dataAt } = parse$2(filePath, source, compiler.addDependency);
95
+ if (!metaCollection) return data;
96
+ const options = {
97
+ collection: metaCollection,
98
+ filePath,
99
+ source
100
+ };
101
+ if (!dataAt) return core.transformMeta(options, data);
102
+ const { dir } = metaCollection;
103
+ const out = {
104
+ ...data,
105
+ _dataAt: {}
106
+ };
107
+ const list = getStaticParams(slash(path.relative(dir, filePath)), { readStaticParams: (file) => readStaticParams(dir, file, compiler.addDependency) });
108
+ for (const params of list ?? []) out._dataAt[JSON.stringify(params)] = await core.transformMeta(options, {
109
+ staticParams: data.staticParams,
110
+ ...dataAt(params)
111
+ });
112
+ return out;
113
+ };
114
+ }
115
+ return {
116
+ async load(input) {
117
+ const result = onMeta(await input.getSource(), input);
118
+ if (result === null) return null;
119
+ const data = await result();
120
+ if (input.filePath.endsWith(".json")) return {
121
+ moduleType: resolveJson,
122
+ code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`
123
+ };
124
+ else return {
125
+ moduleType: "js",
126
+ code: `export default ${JSON.stringify(data)}`
127
+ };
128
+ },
129
+ bun: { load(source, input) {
130
+ const result = onMeta(source, input);
131
+ if (result === null) return {
132
+ loader: "object",
133
+ exports: parse$2(input.filePath, source, () => void 0).data
134
+ };
135
+ return result().then((data) => ({
136
+ loader: "object",
137
+ exports: { default: data }
138
+ }));
139
+ } }
140
+ };
141
+ }
142
+ // src/loaders/config.ts
143
+ function createStandaloneConfigLoader({ core, buildConfig: buildConfig$1, mode }) {
144
+ let prev;
145
+ async function getConfigHash() {
146
+ if (mode === "production") return "static";
147
+ const stats = await fs.stat(core.configPath).catch(() => void 0);
148
+ return stats ? stats.mtime.getTime() : "missing";
149
+ }
150
+ async function load(hash) {
151
+ if (hash === "missing") return buildConfig({}, process.cwd());
152
+ return (await loadConfig(core, buildConfig$1)).config;
153
+ }
154
+ return { async getCore() {
155
+ const hash = await getConfigHash();
156
+ if (!prev || hash !== prev.hash) prev = {
157
+ hash,
158
+ init: core.init({ config: load(hash) })
159
+ };
160
+ await prev.init;
161
+ return core;
162
+ } };
163
+ }
164
+ /**
165
+ * create config loader from initialized core
166
+ */
167
+ function createIntegratedConfigLoader(core) {
168
+ return { async getCore() {
169
+ return core;
170
+ } };
171
+ }
172
+ // src/loaders/adapter.ts
173
+ function toNode(test, loader) {
174
+ return async (url, _context, nextLoad) => {
175
+ if (url.startsWith("file:///") && (!test || test.test(url))) {
176
+ const parsedUrl = new URL(url);
177
+ const filePath = fileURLToPath(parsedUrl);
178
+ const result = await loader.load({
179
+ filePath,
180
+ query: Object.fromEntries(parsedUrl.searchParams.entries()),
181
+ async getSource() {
182
+ return await fs.readFile(filePath, "utf-8");
183
+ },
184
+ development: false,
185
+ compiler: { addDependency() {} }
186
+ });
187
+ if (result) return {
188
+ source: result.code,
189
+ format: "module",
190
+ shortCircuit: true
191
+ };
192
+ }
193
+ return nextLoad(url);
194
+ };
195
+ }
196
+ function toVite(loader, getInput) {
197
+ return { async transform(value, id) {
198
+ const [file, query = ""] = id.split("?", 2);
199
+ try {
200
+ const parsedQuery = parse$1(query);
201
+ if ("raw" in parsedQuery) return null;
202
+ const result = await loader.load({
203
+ ...getInput?.(),
204
+ filePath: file,
205
+ query: parsedQuery,
206
+ getSource() {
207
+ return value;
208
+ },
209
+ development: this.environment ? this.environment.mode === "dev" : false,
210
+ compiler: { addDependency: (file) => {
211
+ this.addWatchFile(file);
212
+ } }
213
+ });
214
+ if (result === null) return null;
215
+ return {
216
+ code: result.code,
217
+ map: result.map ?? { mappings: "" },
218
+ moduleType: result.moduleType
219
+ };
220
+ } catch (e) {
221
+ if (e instanceof ValidationError) throw new Error(await e.toStringFormatted(), { cause: e });
222
+ throw e;
223
+ }
224
+ } };
225
+ }
226
+ /**
227
+ * need to handle the `test` regex in Webpack config instead.
228
+ */
229
+ function toWebpack(loader) {
230
+ return async function(source, callback) {
231
+ try {
232
+ const result = await loader.load({
233
+ filePath: this.resourcePath,
234
+ query: parse$1(this.resourceQuery.slice(1)),
235
+ getSource() {
236
+ return source;
237
+ },
238
+ development: this.mode === "development",
239
+ compiler: this
240
+ });
241
+ if (result === null) callback(void 0, source);
242
+ else callback(void 0, result.code, result.map);
243
+ } catch (error) {
244
+ if (error instanceof ValidationError) return callback(new Error(await error.toStringFormatted()));
245
+ if (!(error instanceof Error)) throw error;
246
+ callback(error);
247
+ }
248
+ };
249
+ }
250
+ function toBun(test, loader) {
251
+ function toResult(output) {
252
+ if (!output) return;
253
+ return {
254
+ contents: output.code,
255
+ loader: output.moduleType ?? "js"
256
+ };
257
+ }
258
+ return (build) => {
259
+ build.onLoad({ filter: test ?? /.+/ }, (args) => {
260
+ const [filePath, query = ""] = args.path.split("?", 2);
261
+ const input = {
262
+ async getSource() {
263
+ return Bun.file(filePath).text();
264
+ },
265
+ query: parse$1(query),
266
+ filePath,
267
+ development: false,
268
+ compiler: { addDependency() {} }
269
+ };
270
+ if (loader.bun?.load) return loader.bun.load(readFileSync(filePath, "utf-8"), input);
271
+ const result = loader.load(input);
272
+ if (result instanceof Promise) return result.then(toResult);
273
+ return toResult(result);
274
+ });
275
+ };
276
+ }
277
+ export { createIntegratedConfigLoader as a, readStaticParams as c, toWebpack as i, toNode as n, createStandaloneConfigLoader as o, toVite as r, createMetaLoader as s, toBun as t };
@@ -1,12 +1,12 @@
1
- import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.js";
2
2
  // src/loaders/mdx/build.ts
3
3
  var build_exports = /* @__PURE__ */ __exportAll({ buildMDX: () => buildMDX });
4
4
  async function buildMDX(core, collection, options) {
5
5
  if ((collection ? collection.compiler : core.getConfig().global.compiler) === "satteri") {
6
- const { buildSatteriMDX } = await import("./build-satteri-BRRVAMZo.js");
6
+ const { buildSatteriMDX } = await import("./build-satteri-D8On1S2_.js");
7
7
  return buildSatteriMDX(core, collection, options);
8
8
  }
9
- const { buildJSMDX } = await import("./build-default-DxRVIZIq.js");
9
+ const { buildJSMDX } = await import("./build-default-BU_9K-PJ.js");
10
10
  return buildJSMDX(core, collection, options);
11
11
  }
12
12
  export { build_exports as n, buildMDX as t };
@@ -0,0 +1,89 @@
1
+ import path from "node:path";
2
+ import picomatch from "picomatch";
3
+ // src/config/build.ts
4
+ const SupportedFormats = {
5
+ doc: ["mdx", "md"],
6
+ meta: [
7
+ "json",
8
+ "yaml",
9
+ "js",
10
+ "ts"
11
+ ]
12
+ };
13
+ /** the default `files` of collections, meta files in code are named like `meta.ts` */
14
+ const SupportedPatterns = {
15
+ doc: "**/*.{mdx,md}",
16
+ meta: "**/{*.{json,yaml},meta{,.*}.{js,ts}}"
17
+ };
18
+ function buildCollection(name, collection, cwd) {
19
+ if (collection.type === "docs") return {
20
+ ...collection,
21
+ type: "docs",
22
+ get dir() {
23
+ return this.docs.dir;
24
+ },
25
+ name,
26
+ meta: buildCollection(name, collection.meta, cwd),
27
+ docs: buildCollection(name, collection.docs, cwd),
28
+ hasFile(filePath) {
29
+ return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
30
+ },
31
+ isFileSupported(filePath) {
32
+ return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);
33
+ },
34
+ cwd
35
+ };
36
+ return {
37
+ ...collection,
38
+ ...buildPrimitiveCollection(name, collection, cwd)
39
+ };
40
+ }
41
+ function buildPrimitiveCollection(name, config, cwd) {
42
+ const supportedFormats = SupportedFormats[config.type];
43
+ const patterns = config.files ?? [SupportedPatterns[config.type]];
44
+ let matcher;
45
+ return {
46
+ dir: path.resolve(cwd, config.dir),
47
+ cwd,
48
+ name,
49
+ patterns,
50
+ isFileSupported(filePath) {
51
+ return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
52
+ },
53
+ hasFile(filePath) {
54
+ if (!this.isFileSupported(filePath)) return false;
55
+ const relativePath = path.relative(this.dir, filePath);
56
+ if (relativePath.startsWith(`..${path.sep}`)) return false;
57
+ return (matcher ??= picomatch(patterns))(relativePath);
58
+ }
59
+ };
60
+ }
61
+ function buildConfig(config, cwd) {
62
+ const collections = /* @__PURE__ */ new Map();
63
+ const loaded = {};
64
+ for (const [k, v] of Object.entries(config)) {
65
+ if (!v) continue;
66
+ if (typeof v === "object" && "type" in v) {
67
+ if (v.type === "docs" || v.type === "doc" || v.type === "meta") {
68
+ collections.set(k, buildCollection(k, v, cwd));
69
+ continue;
70
+ }
71
+ }
72
+ if (k === "default" && v) {
73
+ Object.assign(loaded, v);
74
+ continue;
75
+ }
76
+ throw new Error(`Unknown export "${k}", you can only export collections from source configuration file.`);
77
+ }
78
+ return {
79
+ global: loaded,
80
+ collections,
81
+ workspaces: Object.fromEntries(Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
82
+ return [key, {
83
+ dir: value.dir,
84
+ config: buildConfig(value.config, path.resolve(cwd, value.dir))
85
+ }];
86
+ }))
87
+ };
88
+ }
89
+ export { buildCollection as n, buildConfig as r, SupportedPatterns as t };
@@ -1,4 +1,4 @@
1
- import { t as applyMdxPreset } from "./preset-Vhfrb01t.js";
1
+ import { t as applyMdxPreset } from "./preset-BLDvTSeK.js";
2
2
  import { t as resolveLastModified } from "./last-modified-COIEvwZu.js";
3
3
  import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
4
4
  import { createProcessor } from "@mdx-js/mdx";
@@ -110,7 +110,7 @@ function getMdastExport(name, value) {
110
110
  };
111
111
  }
112
112
  // src/loaders/mdx/build-default.ts
113
- async function buildJSMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment, importsOnly = false }) {
113
+ async function buildJSMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment, importsOnly = false, params }) {
114
114
  const mdxOptions = await getMDXOptions(core.getConfig(), collection, environment);
115
115
  function getProcessor(format) {
116
116
  const cache = core.cache;
@@ -150,6 +150,7 @@ async function buildJSMDX(core, collection, { filePath, frontmatter, source, _co
150
150
  filePath,
151
151
  source
152
152
  }, vfile);
153
+ vfile.data.params = params;
153
154
  const lastModified = await resolveLastModified(collection, filePath);
154
155
  if (lastModified) {
155
156
  vfile.data["mdx-export"] ??= [];
@@ -1,7 +1,7 @@
1
1
  import { t as resolveLastModified } from "./last-modified-COIEvwZu.js";
2
2
  import { pathToFileURL } from "node:url";
3
3
  // src/loaders/mdx/build-satteri.ts
4
- async function buildSatteriMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment }) {
4
+ async function buildSatteriMDX(core, collection, { filePath, frontmatter, source, _compiler, environment, isDevelopment, params }) {
5
5
  const satteriOptions = await getSatteriOptions(core.getConfig(), collection, environment);
6
6
  const format = filePath.endsWith(".mdx") ? "mdx" : "md";
7
7
  const postprocess = {
@@ -25,6 +25,7 @@ async function buildSatteriMDX(core, collection, { filePath, frontmatter, source
25
25
  const data = {
26
26
  frontmatter,
27
27
  _compiler,
28
+ params,
28
29
  _cwd: collection?.cwd,
29
30
  _valueToExport: collection?.postprocess?.valueToExport
30
31
  };
@@ -1,4 +1,4 @@
1
- import { r as CoreOptions } from "../core-CdciznjV.js";
1
+ import { r as CoreOptions } from "../core-DA_zPpY3.js";
2
2
  import { n as ResolvedMacroOptions, t as MacroPluginOption } from "../options-BCId5Url.js";
3
3
  import { BunPlugin } from "bun";
4
4
  export interface MdxPluginOptions extends Pick<CoreOptions, 'configPath' | 'outDir' | 'plugins'> {
package/dist/bun/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as createMdxLoader } from "../mdx-wIFREygW.js";
2
- import { i as buildConfig, t as createCore } from "../core-B3ysiPKS.js";
3
- import { r as slash } from "../codegen-D-Cjx_kh.js";
4
- import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-C_fAYz8a.js";
5
- import { t as createMetaLoader } from "../meta-B2-_R5y0.js";
6
- import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-B_gj5Fq1.js";
1
+ import { t as createMdxLoader } from "../mdx-VmqU5Oaj.js";
2
+ import { r as buildConfig } from "../build-TiTOkhq4.js";
3
+ import { t as createCore } from "../core-CJjfu3ju.js";
4
+ import { a as createIntegratedConfigLoader, s as createMetaLoader, t as toBun } from "../adapter-C04Ekc4W.js";
5
+ import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-3R0gLmlP.js";
7
6
  import { r as resolveMacroOptions } from "../options-B2o-zV4A.js";
7
+ import { r as slash } from "../codegen-BAuFQ5Ew.js";
8
8
  import fs from "node:fs/promises";
9
9
  import path from "node:path";
10
10
  import { randomUUID } from "node:crypto";
@@ -44,7 +44,7 @@ function createMdxPlugin(options = {}) {
44
44
  await core.init({ config: buildConfig(configExports, process.cwd()) });
45
45
  if (macroOptions) {
46
46
  const root = process.cwd();
47
- const { MacroCollector } = await import("../eval-BK4eWlcF.js").then((n) => n.r);
47
+ const { MacroCollector } = await import("../eval-DAaN7Bq9.js").then((n) => n.r);
48
48
  const pendingEvals = /* @__PURE__ */ new Map();
49
49
  core.macro = new MacroCollector({
50
50
  root,
@@ -76,7 +76,7 @@ function createMdxPlugin(options = {}) {
76
76
  contents: await transform(source, file) ?? source,
77
77
  loader
78
78
  };
79
- const { transformMacroModule } = await import("../transform-CVIZq8Al.js").then((n) => n.i);
79
+ const { transformMacroModule } = await import("../transform-D7pyKPqb.js").then((n) => n.i);
80
80
  return {
81
81
  contents: (await transformMacroModule({
82
82
  code: source,
@@ -0,0 +1,86 @@
1
+ import path from "node:path";
2
+ import { createRequire } from "node:module";
3
+ import { compileFunction } from "node:vm";
4
+ import { buildSync } from "esbuild";
5
+ import { Parser } from "acorn";
6
+ import acornJsx from "acorn-jsx";
7
+ import { fromMarkdown } from "mdast-util-from-markdown";
8
+ import { mdxFromMarkdown } from "mdast-util-mdx";
9
+ import { mdxjsEsm } from "micromark-extension-mdxjs-esm";
10
+ // src/loaders/mdx/code.ts
11
+ const esm = mdxjsEsm({
12
+ acorn: Parser.extend(acornJsx()),
13
+ acornOptions: {
14
+ ecmaVersion: "latest",
15
+ sourceType: "module"
16
+ },
17
+ addResult: true
18
+ });
19
+ /** run a module in code synchronously, like a meta file in TypeScript */
20
+ function runModule(file, contents, addDependency) {
21
+ const { outputFiles, metafile } = buildSync({
22
+ stdin: {
23
+ contents,
24
+ sourcefile: file,
25
+ resolveDir: path.dirname(file),
26
+ loader: file.endsWith(".mdx") ? "tsx" : "ts"
27
+ },
28
+ bundle: true,
29
+ format: "cjs",
30
+ platform: "node",
31
+ packages: "external",
32
+ write: false,
33
+ metafile: true
34
+ });
35
+ for (const input in metafile.inputs) if (!input.startsWith("<")) addDependency(path.resolve(input));
36
+ const module = { exports: {} };
37
+ compileFunction(outputFiles[0].text, [
38
+ "module",
39
+ "exports",
40
+ "require"
41
+ ], { filename: file })(module, module.exports, createRequire(file));
42
+ return module.exports;
43
+ }
44
+ /**
45
+ * The frontmatter in the code of a page, `export const frontmatter = {...}`. It runs at build time with the imports it
46
+ * reads, the statements before it in its ESM block and the params of a page as `props`, the content no longer has it.
47
+ */
48
+ function frontmatterCode(filePath, content) {
49
+ if (!filePath.endsWith(".mdx") || !/^export const frontmatter\b/m.test(content)) return;
50
+ const tree = fromMarkdown(content, {
51
+ extensions: [esm],
52
+ mdastExtensions: [mdxFromMarkdown()]
53
+ });
54
+ const imports = [];
55
+ for (const node of tree.children) {
56
+ if (node.type !== "mdxjsEsm" || !node.data?.estree) continue;
57
+ let body = "";
58
+ const declarations = [];
59
+ for (const statement of node.data.estree.body) {
60
+ if (statement.type === "ImportDeclaration") imports.push(statement);
61
+ if (statement.type !== "ExportNamedDeclaration" || !statement.declaration?.range) continue;
62
+ const { declaration } = statement;
63
+ body += `${content.slice(...statement.declaration.range)}\n`;
64
+ declarations.push(declaration);
65
+ if (declaration.type !== "VariableDeclaration" || !declaration.declarations.some((item) => item.id.type === "Identifier" && item.id.name === "frontmatter")) continue;
66
+ const names = /* @__PURE__ */ new Set();
67
+ collectNames(declarations, names);
68
+ let code = "";
69
+ for (const item of imports) if (item.range && item.specifiers.some((specifier) => names.has(specifier.local.name))) code += `${content.slice(...item.range)}\n`;
70
+ const [start, end] = statement.range;
71
+ return {
72
+ content: content.slice(0, start) + content.slice(start, end).replace(/[^\n]/g, "") + content.slice(end),
73
+ /** compile it into a function of the params */
74
+ compile(addDependency) {
75
+ return runModule(filePath, `${code}export const frontmatter = (props = {}) => {\n${body}return frontmatter;\n};`, addDependency).frontmatter;
76
+ }
77
+ };
78
+ }
79
+ }
80
+ }
81
+ function collectNames(node, out) {
82
+ if (typeof node !== "object" || node === null) return;
83
+ if ("type" in node && node.type === "Identifier" && "name" in node) out.add(node.name);
84
+ for (const value of Object.values(node)) collectNames(value, out);
85
+ }
86
+ export { runModule as n, frontmatterCode as t };
@@ -86,7 +86,7 @@ function createCodegen({ target = "default", outDir = "", jsExtension = false, g
86
86
  function stringifyQuery(query = {}) {
87
87
  const searchParams = new URLSearchParams();
88
88
  for (const [k, v] of Object.entries(query)) if (v !== void 0) searchParams.set(k, v);
89
- return searchParams.size > 0 ? `?${searchParams}` : "";
89
+ return searchParams.size > 0 ? `?${searchParams.toString().replaceAll(".", "%2E")}` : "";
90
90
  }
91
91
  /**
92
92
  * convert into POSIX & relative file paths, such that Vite can accept it.
@@ -1,7 +1,8 @@
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-CdciznjV.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-DA_zPpY3.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<{
5
+ staticParams: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>>;
5
6
  title: import("zod").ZodString;
6
7
  description: import("zod").ZodOptional<import("zod").ZodString>;
7
8
  icon: import("zod").ZodOptional<import("zod").ZodString>;
@@ -11,6 +12,7 @@ export declare const frontmatterSchema: import("zod").ZodObject<{
11
12
  }, import("zod/v4/core").$strip>;
12
13
  /** @deprecated import from `fumadocs-core/source/schema` instead (since 16.2.3) */
13
14
  export declare const metaSchema: import("zod").ZodObject<{
15
+ staticParams: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>>>;
14
16
  title: import("zod").ZodOptional<import("zod").ZodString>;
15
17
  pages: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
16
18
  pagesIndex: import("zod").ZodOptional<import("zod").ZodString>;
@@ -1,5 +1,5 @@
1
1
  import { n as defineConfig, r as defineDocs, t as defineCollections } from "../define-C2jwQBlt.js";
2
- import { t as applyMdxPreset } from "../preset-Vhfrb01t.js";
2
+ import { t as applyMdxPreset } from "../preset-BLDvTSeK.js";
3
3
  import { metaSchema as metaSchema$1, pageSchema } from "fumadocs-core/source/schema";
4
4
  import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
5
5
  // src/config/index.ts
@@ -1,83 +1,6 @@
1
- import { n as ident } from "./codegen-D-Cjx_kh.js";
1
+ import { n as ident } from "./codegen-BAuFQ5Ew.js";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
- import picomatch from "picomatch";
5
- // src/config/build.ts
6
- const SupportedFormats = {
7
- doc: ["mdx", "md"],
8
- meta: ["json", "yaml"]
9
- };
10
- function buildCollection(name, collection, cwd) {
11
- if (collection.type === "docs") return {
12
- ...collection,
13
- type: "docs",
14
- get dir() {
15
- return this.docs.dir;
16
- },
17
- name,
18
- meta: buildCollection(name, collection.meta, cwd),
19
- docs: buildCollection(name, collection.docs, cwd),
20
- hasFile(filePath) {
21
- return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
22
- },
23
- isFileSupported(filePath) {
24
- return this.docs.isFileSupported(filePath) || this.meta.isFileSupported(filePath);
25
- },
26
- cwd
27
- };
28
- return {
29
- ...collection,
30
- ...buildPrimitiveCollection(name, collection, cwd)
31
- };
32
- }
33
- function buildPrimitiveCollection(name, config, cwd) {
34
- const supportedFormats = SupportedFormats[config.type];
35
- const patterns = config.files ?? [`**/*.{${supportedFormats.join(",")}}`];
36
- let matcher;
37
- return {
38
- dir: path.resolve(cwd, config.dir),
39
- cwd,
40
- name,
41
- patterns,
42
- isFileSupported(filePath) {
43
- return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
44
- },
45
- hasFile(filePath) {
46
- if (!this.isFileSupported(filePath)) return false;
47
- const relativePath = path.relative(this.dir, filePath);
48
- if (relativePath.startsWith(`..${path.sep}`)) return false;
49
- return (matcher ??= picomatch(patterns))(relativePath);
50
- }
51
- };
52
- }
53
- function buildConfig(config, cwd) {
54
- const collections = /* @__PURE__ */ new Map();
55
- const loaded = {};
56
- for (const [k, v] of Object.entries(config)) {
57
- if (!v) continue;
58
- if (typeof v === "object" && "type" in v) {
59
- if (v.type === "docs" || v.type === "doc" || v.type === "meta") {
60
- collections.set(k, buildCollection(k, v, cwd));
61
- continue;
62
- }
63
- }
64
- if (k === "default" && v) {
65
- Object.assign(loaded, v);
66
- continue;
67
- }
68
- throw new Error(`Unknown export "${k}", you can only export collections from source configuration file.`);
69
- }
70
- return {
71
- global: loaded,
72
- collections,
73
- workspaces: Object.fromEntries(Object.entries(loaded.workspaces ?? {}).map(([key, value]) => {
74
- return [key, {
75
- dir: value.dir,
76
- config: buildConfig(value.config, path.resolve(cwd, value.dir))
77
- }];
78
- }))
79
- };
80
- }
81
4
  // src/utils/validation.ts
82
5
  var ValidationError = class extends Error {
83
6
  constructor(message, issues) {
@@ -312,4 +235,4 @@ function postprocessPlugin() {
312
235
  return lines.join("\n");
313
236
  } } };
314
237
  }
315
- export { buildConfig as i, ValidationError as n, buildCollection as r, createCore as t };
238
+ export { ValidationError as n, createCore as t };