@vercel/geistdocs 2.15.2 → 2.15.3-canary.7d55dcf

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 (64) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/internal/mdx-to-markdown.d.ts.map +1 -1
  3. package/dist/internal/mdx-to-markdown.js +9 -0
  4. package/dist/internal/page-actions.d.ts +4 -4
  5. package/dist/internal/page-actions.d.ts.map +1 -1
  6. package/dist/internal/page-actions.js +6 -1
  7. package/dist/internal/source-loader.d.ts +28 -0
  8. package/dist/internal/source-loader.d.ts.map +1 -0
  9. package/dist/internal/source-loader.js +77 -0
  10. package/dist/mdx-basic.d.ts +27 -0
  11. package/dist/mdx-basic.d.ts.map +1 -0
  12. package/dist/mdx-basic.js +61 -0
  13. package/dist/mdx.d.ts +3 -25
  14. package/dist/mdx.d.ts.map +1 -1
  15. package/dist/mdx.js +8 -61
  16. package/dist/navigation.d.ts +11 -0
  17. package/dist/navigation.d.ts.map +1 -0
  18. package/dist/navigation.js +8 -0
  19. package/dist/next.d.ts +9 -1
  20. package/dist/next.d.ts.map +1 -1
  21. package/dist/next.js +25 -2
  22. package/dist/pages/docs-custom.d.ts +111 -0
  23. package/dist/pages/docs-custom.d.ts.map +1 -0
  24. package/dist/pages/docs-custom.js +250 -0
  25. package/dist/pages/docs.d.ts +5 -98
  26. package/dist/pages/docs.d.ts.map +1 -1
  27. package/dist/pages/docs.js +13 -250
  28. package/dist/source-config.d.ts +10 -1
  29. package/dist/source-config.d.ts.map +1 -1
  30. package/dist/source-config.js +20 -10
  31. package/dist/source.d.ts +6 -17
  32. package/dist/source.d.ts.map +1 -1
  33. package/dist/source.js +2 -75
  34. package/docs/agents.md +1 -1
  35. package/docs/llms.txt +9 -1
  36. package/docs/manifest.json +1 -1
  37. package/docs/pages/configuration.md +8 -0
  38. package/native-mdx/LICENSE-mdxjs-rs +22 -0
  39. package/native-mdx/binaries/darwin-arm64.node +0 -0
  40. package/native-mdx/binaries/linux-x64-gnu.node +0 -0
  41. package/native-mdx/data-entry.d.mts +15 -0
  42. package/native-mdx/data-entry.mjs +97 -0
  43. package/native-mdx/data-projection.mjs +205 -0
  44. package/native-mdx/index-emitter.mjs +34 -0
  45. package/native-mdx/loader-data.cjs +36 -0
  46. package/native-mdx/loader-mdx.cjs +9 -0
  47. package/native-mdx/loader-mdx.mjs +262 -0
  48. package/native-mdx/native-binding.cjs +25 -0
  49. package/native-mdx/navigation-entry.d.mts +11 -0
  50. package/native-mdx/navigation-entry.mjs +136 -0
  51. package/native-mdx/navigation-title.mjs +53 -0
  52. package/package.json +36 -8
  53. package/rehype-code-highlights.d.ts +13 -0
  54. package/rehype-code-highlights.js +230 -0
  55. package/source-config.js +24 -10
  56. package/template/app/[lang]/(home)/opengraph-image.tsx +4 -28
  57. package/template/app/[lang]/og/[...slug]/route.tsx +5 -68
  58. package/template/content/docs/configuration.mdx +8 -0
  59. package/template/lib/geistdocs/geist-mono-regular.ttf +0 -0
  60. package/template/lib/geistdocs/og.tsx +95 -0
  61. package/template/package.json +1 -1
  62. package/template/app/[lang]/og/[...slug]/background.png +0 -0
  63. package/template/app/[lang]/og/[...slug]/geist-sans-semibold.ttf +0 -0
  64. /package/template/{app/[lang]/og/[...slug] → lib/geistdocs}/geist-sans-regular.ttf +0 -0
@@ -0,0 +1,97 @@
1
+ import { DATA_QUERY, withoutDataQuery } from "./data-projection.mjs";
2
+ import { extendIndexEmitter } from "./index-emitter.mjs";
3
+
4
+ const MDX_EXTENSION = /\.mdx?$/;
5
+
6
+ /**
7
+ * Opt-in Fumadocs 14 plugin. Extend the existing index-file emitter in place:
8
+ * its own watcher calls core.emitAndWrite filtered to name === "index-file".
9
+ * Registering an independent emitter would miss those development updates.
10
+ */
11
+ export function dataEntryPlugin(typeScriptOrLoader) {
12
+ let parserPromise;
13
+ const getParser = () =>
14
+ (parserPromise ??= Promise.resolve()
15
+ .then(() =>
16
+ typeof typeScriptOrLoader === "function"
17
+ ? typeScriptOrLoader()
18
+ : typeScriptOrLoader
19
+ )
20
+ .then((module) => module.default ?? module));
21
+ return {
22
+ name: "geistdocs-data-entry",
23
+ config() {
24
+ extendIndexEmitter(this, "geistdocs-data-entry", async (entries) => {
25
+ const server = entries.find((entry) => entry.path === "server.ts");
26
+ if (!server || entries.some((entry) => entry.path === "data.ts")) {
27
+ throw new Error(
28
+ "Content entries require server.ts and an unused data.ts output"
29
+ );
30
+ }
31
+ return [
32
+ ...entries,
33
+ {
34
+ path: "data.ts",
35
+ content: createDataEntry(server.content, await getParser()).code,
36
+ },
37
+ ];
38
+ });
39
+ },
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Derive data.ts from Fumadocs' authoritative generated server.ts in the SAME
45
+ * directory. Call from the existing generation lifecycle after each emission.
46
+ * No globbing, watcher, filesystem writes or extra content registry is created.
47
+ * TypeScript is supplied by the build-time host, not a runtime dependency.
48
+ */
49
+ export function createDataEntry(serverCode, ts) {
50
+ const file = ts.createSourceFile(
51
+ "server.ts",
52
+ serverCode,
53
+ ts.ScriptTarget.Latest,
54
+ true,
55
+ ts.ScriptKind.TS
56
+ );
57
+ if (file.parseDiagnostics.length) {
58
+ throw new Error("Cannot parse generated server entry");
59
+ }
60
+ const edits = [];
61
+ for (const statement of file.statements) {
62
+ if (
63
+ !(
64
+ ts.isImportDeclaration(statement) &&
65
+ ts.isStringLiteral(statement.moduleSpecifier)
66
+ )
67
+ ) {
68
+ continue;
69
+ }
70
+ const specifier = statement.moduleSpecifier;
71
+ const separator = specifier.text.indexOf("?");
72
+ const pathname =
73
+ separator < 0 ? specifier.text : specifier.text.slice(0, separator);
74
+ if (!MDX_EXTENSION.test(pathname)) {
75
+ continue;
76
+ }
77
+ const query = new URLSearchParams(
78
+ separator < 0 ? "" : specifier.text.slice(separator + 1)
79
+ );
80
+ // Only collection imports emitted by Fumadocs; preserve metadata JSON and
81
+ // unrelated modules, runtime options, passthroughs and collection order.
82
+ if (!query.has("collection") || query.has("only")) {
83
+ continue;
84
+ }
85
+ const canonicalQuery = withoutDataQuery(specifier.text.slice(separator));
86
+ edits.push({
87
+ start: specifier.getStart(file),
88
+ end: specifier.end,
89
+ value: JSON.stringify(`${pathname}${canonicalQuery}&${DATA_QUERY}=1`),
90
+ });
91
+ }
92
+ let code = serverCode;
93
+ for (const edit of edits.reverse()) {
94
+ code = code.slice(0, edit.start) + edit.value + code.slice(edit.end);
95
+ }
96
+ return { code, imports: edits.length };
97
+ }
@@ -0,0 +1,205 @@
1
+ import { basename } from "node:path";
2
+
3
+ // Deliberately conservative, opt-in projection of an already compiled module.
4
+ // Compilation, frontmatter validation and user plugins run before this helper.
5
+ export const DATA_QUERY = "geistdocs-data";
6
+
7
+ // Preserve spelling/order/encoding of every other parameter so forwarding
8
+ // resolves to the same module identity as the original rendering request.
9
+ export function withoutDataQuery(resourceQuery = "") {
10
+ const parts = (
11
+ resourceQuery.startsWith("?") ? resourceQuery.slice(1) : resourceQuery
12
+ ).split("&");
13
+ const kept = parts.filter(
14
+ (part) => !new URLSearchParams(part).has(DATA_QUERY)
15
+ );
16
+ return kept.some(Boolean) ? `?${kept.join("&")}` : "";
17
+ }
18
+
19
+ const JSX_RUNTIME = /^react\/jsx-(?:dev-)?runtime$/;
20
+
21
+ function createClosedValidator(ast) {
22
+ const runtimeCalls = new Set();
23
+ const runtimeValues = new Set();
24
+ const bindings = new Set();
25
+ for (const node of ast.body) {
26
+ if (node.id) {
27
+ bindings.add(node.id.name);
28
+ }
29
+ const declaration = node.declaration ?? node;
30
+ for (const item of declaration.declarations ?? []) {
31
+ bindings.add(item.id.name);
32
+ }
33
+ if (node.type !== "ImportDeclaration") {
34
+ continue;
35
+ }
36
+ for (const item of node.specifiers) {
37
+ bindings.add(item.local.name);
38
+ if (!JSX_RUNTIME.test(node.source.value)) {
39
+ continue;
40
+ }
41
+ if (["jsx", "jsxs", "jsxDEV"].includes(item.imported?.name)) {
42
+ runtimeCalls.add(item.local.name);
43
+ }
44
+ if (item.imported?.name === "Fragment") {
45
+ runtimeValues.add(item.local.name);
46
+ }
47
+ }
48
+ }
49
+ const closed = (node) => {
50
+ if (!node) {
51
+ return false;
52
+ }
53
+ switch (node.type) {
54
+ case "Literal":
55
+ return !node.regex;
56
+ case "Identifier":
57
+ return (
58
+ runtimeValues.has(node.name) ||
59
+ (node.name === "undefined" && !bindings.has("undefined"))
60
+ );
61
+ case "ArrayExpression":
62
+ return node.elements.every((item) => item === null || closed(item));
63
+ case "ObjectExpression":
64
+ return node.properties.every(
65
+ (item) =>
66
+ item.type === "Property" &&
67
+ item.kind === "init" &&
68
+ !item.method &&
69
+ !item.computed &&
70
+ closed(item.value)
71
+ );
72
+ case "UnaryExpression":
73
+ return (
74
+ ["-", "+", "!", "void"].includes(node.operator) &&
75
+ closed(node.argument)
76
+ );
77
+ case "CallExpression":
78
+ return (
79
+ node.callee.type === "Identifier" &&
80
+ runtimeCalls.has(node.callee.name) &&
81
+ node.arguments.every(closed)
82
+ );
83
+ case "NewExpression":
84
+ return (
85
+ node.callee.name === "Date" &&
86
+ !bindings.has("Date") &&
87
+ node.arguments.length === 1 &&
88
+ node.arguments[0].type === "Literal"
89
+ );
90
+ default:
91
+ return false;
92
+ }
93
+ };
94
+ return closed;
95
+ }
96
+
97
+ export function projectDataModule(code, parse) {
98
+ const fallback = (reason) => ({ code, projected: false, reason });
99
+ let ast;
100
+ try {
101
+ ast = parse(code, { ecmaVersion: "latest", sourceType: "module" });
102
+ } catch {
103
+ return fallback("unrecognized compiled syntax");
104
+ }
105
+ const closed = createClosedValidator(ast);
106
+ const kept = [];
107
+ let hasBody = false;
108
+ let hasFrontmatter = false;
109
+ for (const node of ast.body) {
110
+ switch (node.type) {
111
+ case "ImportDeclaration":
112
+ // Keep all imports, including component imports: their evaluation may
113
+ // have side effects. Let the bundler honor each package's sideEffects.
114
+ kept.push(code.slice(node.start, node.end));
115
+ break;
116
+ case "FunctionDeclaration":
117
+ case "EmptyStatement":
118
+ break;
119
+ case "ExportDefaultDeclaration":
120
+ if (
121
+ node.declaration.type !== "FunctionDeclaration" &&
122
+ !(
123
+ node.declaration.type === "Identifier" &&
124
+ ast.body.some(
125
+ (item) =>
126
+ item.type === "FunctionDeclaration" &&
127
+ item.id.name === node.declaration.name
128
+ )
129
+ )
130
+ ) {
131
+ return fallback("non-function default export");
132
+ }
133
+ hasBody = true;
134
+ break;
135
+ case "ExportNamedDeclaration": {
136
+ const declaration = node.declaration;
137
+ if (declaration?.type !== "VariableDeclaration") {
138
+ return fallback("executable or re-exported metadata");
139
+ }
140
+ if (
141
+ declaration.declarations.some(
142
+ (item) => item.id.type !== "Identifier" || !closed(item.init)
143
+ )
144
+ ) {
145
+ return fallback("metadata depends on executable code");
146
+ }
147
+ hasFrontmatter ||= declaration.declarations.some(
148
+ (item) => item.id.name === "frontmatter"
149
+ );
150
+ kept.push(code.slice(node.start, node.end));
151
+ break;
152
+ }
153
+ default:
154
+ return fallback(`module evaluation requires ${node.type}`);
155
+ }
156
+ }
157
+ if (!(hasBody && hasFrontmatter)) {
158
+ return fallback("missing compiled MDX contract");
159
+ }
160
+ kept.push(
161
+ 'export default function(){throw new Error("Data-only MDX cannot render a page; use the server entry.");}'
162
+ );
163
+ return { code: kept.join("\n"), projected: true, reason: null };
164
+ }
165
+
166
+ // Compose with the existing loader rather than bypassing its compatibility gate.
167
+ // The delegate owns dependencies/config reloads and native-to-JS fallback.
168
+ export function createDataLoader(delegate, parse, onResult = () => undefined) {
169
+ return function dataLoader(source) {
170
+ const query = new URLSearchParams((this.resourceQuery ?? "").slice(1));
171
+ if (!query.has(DATA_QUERY)) {
172
+ return delegate.call(this, source);
173
+ }
174
+ const done = this.async();
175
+ const context = Object.create(this);
176
+ context.resourceQuery = withoutDataQuery(this.resourceQuery);
177
+ context.async = () => (error, code, _map, metadata) => {
178
+ if (error) {
179
+ return done(error);
180
+ }
181
+ let result;
182
+ try {
183
+ result = projectDataModule(code, parse);
184
+ if (!result.projected) {
185
+ // Reuse the canonical module instead of evaluating a second copy of
186
+ // authored MDX effects. This import still runs the full loader chain.
187
+ const request = JSON.stringify(
188
+ `./${basename(this.resourcePath)}${context.resourceQuery}${this.resourceFragment ?? ""}`
189
+ );
190
+ result = {
191
+ ...result,
192
+ forwarded: true,
193
+ code: `export * from ${request};\nexport { default } from ${request};`,
194
+ };
195
+ }
196
+ onResult({ filePath: this.resourcePath, ...result });
197
+ } catch (error) {
198
+ return done(error);
199
+ }
200
+ // Both projection and canonical forwarding invalidate the original map.
201
+ done(null, result.code, undefined, metadata);
202
+ };
203
+ return delegate.call(context, source);
204
+ };
205
+ }
@@ -0,0 +1,34 @@
1
+ const EXTENSIONS = Symbol.for("geistdocs.index-emitter.extensions");
2
+
3
+ /** One wrapper for sibling entries; re-registering on config reload replaces
4
+ * each extension instead of recursively wrapping another plugin's emitter. */
5
+ export function extendIndexEmitter(context, name, extend) {
6
+ const plugins = context.core.getPlugins();
7
+ const indexes = plugins.filter((plugin) => plugin.name === "index-file");
8
+ if (indexes.length === 0 && context.environment === "webpack") {
9
+ return;
10
+ }
11
+ if (indexes.length !== 1 || typeof indexes[0].emit !== "function") {
12
+ throw new Error("Content entries require one Fumadocs index-file emitter");
13
+ }
14
+ const index = indexes[0];
15
+ let state = index.emit[EXTENSIONS];
16
+ if (!state) {
17
+ state = { original: index.emit, extensions: new Map() };
18
+ const emit = async function () {
19
+ let entries = await state.original.call(this);
20
+ const active = new Set(
21
+ context.core.getPlugins().map((plugin) => plugin.name)
22
+ );
23
+ for (const [extensionName, extension] of state.extensions) {
24
+ if (active.has(extensionName)) {
25
+ entries = await extension(entries);
26
+ }
27
+ }
28
+ return entries;
29
+ };
30
+ emit[EXTENSIONS] = state;
31
+ index.emit = emit;
32
+ }
33
+ state.extensions.set(name, extend);
34
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ // Experimental wrapper: point experimentalMdxLoader at this file. Ordinary MDX
4
+ // stays unchanged; only generated data-entry imports carry geistdocs-data=1.
5
+ module.exports = function loader(source) {
6
+ if (
7
+ !new URLSearchParams((this.resourceQuery ?? "").slice(1)).has(
8
+ "geistdocs-data"
9
+ )
10
+ ) {
11
+ // Rendering-only workers should not load the projection parser at all.
12
+ return require("./loader-mdx.cjs").call(this, source);
13
+ }
14
+ const done = this.async();
15
+ import("./data-projection.mjs")
16
+ .then(({ createDataLoader }) => {
17
+ const { parse } = require("next/dist/compiled/acorn");
18
+ const delegate = require("./loader-mdx.cjs");
19
+ const context = Object.create(this);
20
+ context.async = () => done;
21
+ return createDataLoader(
22
+ delegate,
23
+ parse,
24
+ ({ filePath, projected, forwarded = false, reason, code }) => {
25
+ // Optional diagnostics for validation builds, never enable when timing.
26
+ if (process.env.GEISTDOCS_DATA_REPORT) {
27
+ require("node:fs").appendFileSync(
28
+ process.env.GEISTDOCS_DATA_REPORT,
29
+ `${JSON.stringify({ filePath, projected, forwarded, reason, outputBytes: Buffer.byteLength(code) })}\n`
30
+ );
31
+ }
32
+ }
33
+ ).call(context, source);
34
+ })
35
+ .catch(done);
36
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // CommonJS entry for Turbopack/webpack, like fumadocs-mdx's own shim.
3
+ module.exports = function loader(source) {
4
+ const callback = this.async();
5
+ import("./loader-mdx.mjs").then(
6
+ (mod) => mod.run.call(this, source, callback),
7
+ callback
8
+ );
9
+ };
@@ -0,0 +1,262 @@
1
+ // Webpack/Turbopack loader for MDX, backed by the native fumadocs-mdx-rs
2
+ // compiler. Mirrors fumadocs-mdx's `createMdxLoader`: config, collection,
3
+ // frontmatter validation, and doc plugins stay in JS (they're user code);
4
+ // parsing, transforms, highlighting, and codegen run natively. Files that
5
+ // use something the native pipeline doesn't cover go to fumadocs-mdx.
6
+ import { createHash } from "node:crypto";
7
+ import { readFile } from "node:fs/promises";
8
+ import { createRequire } from "node:module";
9
+ import path from "node:path";
10
+ import { pathToFileURL } from "node:url";
11
+
12
+ // fumadocs-mdx 14.0.4 internals (not in its public exports).
13
+ const fumadocsDist = path.dirname(
14
+ new URL(import.meta.resolve("fumadocs-mdx")).pathname
15
+ );
16
+ const internal = (chunk) =>
17
+ import(pathToFileURL(path.join(fumadocsDist, chunk)).href);
18
+ const { fumaMatter } = await internal("chunk-VWJKRQZR.js");
19
+ const { getCore } = await internal("chunk-CGGDM5F3.js");
20
+ const { createStandaloneConfigLoader } = await internal("chunk-NKIL543T.js");
21
+
22
+ const require = createRequire(import.meta.url);
23
+ const native = require(
24
+ process.env.FUMADOCS_MDX_RS_BINARY ?? "./native-binding.cjs"
25
+ );
26
+
27
+ let configLoader;
28
+ let jsLoader;
29
+ let compiledConfigIdentity;
30
+ const compatibility = new WeakMap();
31
+
32
+ // The plugin list the native pipeline implements: Geistdocs' defaults with
33
+ // Highlights (`defineGeistdocsSourceConfig()`), in fumadocs-mdx's order.
34
+ const NATIVE_REMARK = [
35
+ ["remarkGfm"],
36
+ ["remarkSteps"],
37
+ ["remarkHeading", { generateToc: false }],
38
+ ["remarkImage", { useImport: true }],
39
+ ["remarkCodeTab"],
40
+ ["remarkNpm"],
41
+ ["remarkMdxMermaid"],
42
+ ["remarkDetails"],
43
+ ["remarkStructure", { exportAs: "structuredData" }],
44
+ ];
45
+ const NATIVE_REHYPE = [
46
+ ["rehypeCodeHighlights"],
47
+ ["rehypeTaskListLabels"],
48
+ ["rehypeToc"],
49
+ ];
50
+ const NATIVE_OPTION_KEYS = new Set([
51
+ "remarkPlugins",
52
+ "rehypePlugins",
53
+ "outputFormat",
54
+ ]);
55
+
56
+ const samePlugins = (actual, expected) =>
57
+ actual.length === expected.length &&
58
+ actual.every((entry, index) => {
59
+ const [plugin, options] = Array.isArray(entry) ? entry : [entry];
60
+ const [name, expectedOptions] = expected[index];
61
+ if (plugin?.name !== name) {
62
+ return false;
63
+ }
64
+ if (name === "rehypeCodeHighlights") {
65
+ // Geistdocs forces the theme; any other option changes the output.
66
+ return Object.keys(options ?? {}).every(
67
+ (key) => key === "themes" || key === "defaultColor"
68
+ );
69
+ }
70
+ return (
71
+ JSON.stringify(options ?? {}) === JSON.stringify(expectedOptions ?? {})
72
+ );
73
+ });
74
+
75
+ /** Why a collection's MDX options need the JS pipeline, if they do. */
76
+ async function incompatibility(config, collection) {
77
+ // Collection names survive config reloads; compatibility decisions must not.
78
+ if (!compatibility.has(config)) {
79
+ compatibility.set(config, new Map());
80
+ }
81
+ const reasons = compatibility.get(config);
82
+ const key = collection?.name ?? "global";
83
+ if (!reasons.has(key)) {
84
+ const options = await config.getMDXOptions(collection, "bundler");
85
+ let reason = null;
86
+ const extraKeys = Object.keys(options).filter(
87
+ (k) => !NATIVE_OPTION_KEYS.has(k)
88
+ );
89
+ if (extraKeys.length > 0) {
90
+ reason = `MDX options: ${extraKeys.join(", ")}`;
91
+ } else if (!samePlugins(options.remarkPlugins ?? [], NATIVE_REMARK)) {
92
+ reason = "custom remark plugins";
93
+ } else if (!samePlugins(options.rehypePlugins ?? [], NATIVE_REHYPE)) {
94
+ reason = "custom rehype plugins or Shiki";
95
+ }
96
+ reasons.set(key, reason);
97
+ }
98
+ return reasons.get(key);
99
+ }
100
+
101
+ /** The doc collection behind a `doc` or `docs` collection. */
102
+ const docCollectionOf = (collection) => {
103
+ if (collection?.type === "doc") {
104
+ return collection;
105
+ }
106
+ if (collection?.type === "docs") {
107
+ return collection.docs;
108
+ }
109
+ };
110
+
111
+ async function fallback({ source, development, query, compiler, filePath }) {
112
+ jsLoader ??= (await internal("chunk-USWQVJWR.js")).createMdxLoader(
113
+ configLoader
114
+ );
115
+ const out = await jsLoader.load({
116
+ getSource: () => source,
117
+ development,
118
+ query,
119
+ compiler,
120
+ filePath,
121
+ });
122
+ return out.code;
123
+ }
124
+
125
+ const literal = (value) => {
126
+ if (value instanceof Date) {
127
+ return `new Date(${JSON.stringify(value.toISOString())})`;
128
+ }
129
+ if (value === undefined) {
130
+ return "undefined";
131
+ }
132
+ return JSON.stringify(value);
133
+ };
134
+
135
+ async function fillNavigationTitle(matter, config, docCollection, filePath) {
136
+ if (matter.data.title === "") {
137
+ throw new Error(
138
+ "Navigation requires a nonempty frontmatter title; omit it to use heading fallback with a compatible schema"
139
+ );
140
+ }
141
+ if (matter.data.title != null) {
142
+ return;
143
+ }
144
+ if (await incompatibility(config, docCollection)) {
145
+ throw new Error(
146
+ "Navigation requires an explicit frontmatter title when using custom MDX plugins or options"
147
+ );
148
+ }
149
+ const { navigationTitle } = await import("./navigation-title.mjs");
150
+ const title = await navigationTitle(
151
+ matter.content,
152
+ filePath.endsWith(".mdx") ? "mdx" : "md"
153
+ );
154
+ if (title !== undefined) {
155
+ matter.data.title = title;
156
+ }
157
+ }
158
+
159
+ export async function load({
160
+ source,
161
+ filePath,
162
+ query,
163
+ development,
164
+ compiler,
165
+ options,
166
+ }) {
167
+ if (development) {
168
+ // Imported settings can change the bundled config without changing the
169
+ // source config's mtime, which is all Fumadocs checks for reloads.
170
+ const compiled = await readFile(options.absoluteCompiledConfigPath);
171
+ const identity = createHash("sha256").update(compiled).digest("hex");
172
+ if (identity !== compiledConfigIdentity) {
173
+ compiledConfigIdentity = identity;
174
+ configLoader = undefined;
175
+ jsLoader = undefined;
176
+ }
177
+ }
178
+ configLoader ??= createStandaloneConfigLoader({
179
+ core: getCore(options),
180
+ buildConfig: false,
181
+ mode: development ? "dev" : "production",
182
+ });
183
+ const core = configLoader.core;
184
+ const config = await configLoader.getConfig();
185
+ const matter = fumaMatter(source);
186
+ const collection = query.collection
187
+ ? config.getCollection(query.collection)
188
+ : undefined;
189
+ const docCollection = docCollectionOf(collection);
190
+ if (docCollection) {
191
+ matter.data = await core.transformFrontmatter(
192
+ { collection: docCollection, filePath, source },
193
+ matter.data
194
+ );
195
+ }
196
+ if (query.only === "frontmatter") {
197
+ if (query["geistdocs-navigation"] === "1") {
198
+ await fillNavigationTitle(matter, config, docCollection, filePath);
199
+ }
200
+ return `export const frontmatter = ${JSON.stringify(matter.data)}`;
201
+ }
202
+
203
+ if (await incompatibility(config, docCollection)) {
204
+ return fallback({ source, development, query, compiler, filePath });
205
+ }
206
+
207
+ const result = native.compile(
208
+ matter.content,
209
+ JSON.stringify(matter.data ?? {}),
210
+ {
211
+ filePath,
212
+ includeProcessedMarkdown:
213
+ docCollection?.postprocess?.includeProcessedMarkdown === true,
214
+ development,
215
+ }
216
+ );
217
+ if (result.fallback) {
218
+ return fallback({ source, development, query, compiler, filePath });
219
+ }
220
+
221
+ // Doc plugins (e.g. last-modified) contribute extra exports.
222
+ let code = result.code;
223
+ if (docCollection) {
224
+ const file = await core.transformVFile(
225
+ { collection: docCollection, filePath, source },
226
+ { data: {}, path: filePath, value: source }
227
+ );
228
+ for (const { name, value } of file.data["mdx-export"] ?? []) {
229
+ code += `\nexport let ${name} = ${literal(value)};`;
230
+ }
231
+ }
232
+ return code;
233
+ }
234
+
235
+ /** Webpack loader entry. */
236
+ export default function loader(source) {
237
+ return run.call(this, source, this.async());
238
+ }
239
+
240
+ /** Loader body with an explicit callback (used by the CJS shim). */
241
+ export async function run(source, callback) {
242
+ const options = this.getOptions();
243
+ this.cacheable(true);
244
+ this.addDependency(options.absoluteCompiledConfigPath);
245
+ try {
246
+ const query = Object.fromEntries(
247
+ new URLSearchParams(this.resourceQuery.slice(1))
248
+ );
249
+ const code = await load({
250
+ source,
251
+ filePath: this.resourcePath,
252
+ query,
253
+ development: this.mode === "development",
254
+ compiler: this,
255
+ options,
256
+ });
257
+ callback(undefined, code);
258
+ } catch (error) {
259
+ error.message = `${path.relative(this.context, this.resourcePath)}: ${error.message}`;
260
+ callback(error);
261
+ }
262
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const { existsSync } = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const local = path.join(__dirname, "fumadocs-mdx-rs.node");
7
+ const platform = `${process.platform}-${process.arch}${process.platform === "linux" ? "-gnu" : ""}`;
8
+ const bundled = path.join(__dirname, "binaries", `${platform}.node`);
9
+
10
+ if (existsSync(local)) {
11
+ module.exports = require(local);
12
+ } else {
13
+ if (
14
+ !existsSync(bundled) ||
15
+ (process.platform === "linux" &&
16
+ !process.report.getReport().header.glibcVersionRuntime)
17
+ ) {
18
+ throw new Error(
19
+ `This Geistdocs native MDX canary has no binary for ${platform}. ` +
20
+ "Supported: macOS arm64 and Linux x64 (glibc). " +
21
+ "Remove experimentalMdxLoader to use the JS compiler."
22
+ );
23
+ }
24
+ module.exports = require(bundled);
25
+ }
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from "fumadocs-mdx";
2
+ import type * as TypeScript from "typescript";
3
+ type Parser = typeof TypeScript;
4
+ /** Opt-in metadata-only navigation.ts, for synchronous collections and the native canary loader. */
5
+ export declare function navigationEntryPlugin(
6
+ parser: Parser | (() => Parser | Promise<Parser>)
7
+ ): Plugin;
8
+ export declare function createNavigationEntry(
9
+ serverCode: string,
10
+ parser: Parser
11
+ ): { code: string; imports: number };