@vercel/geistdocs 2.15.4-canary.2a54b38 → 2.16.0-canary.abbda54

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 (81) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/config.d.ts +3 -3
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/internal/mdx-to-markdown.d.ts.map +1 -1
  5. package/dist/internal/mdx-to-markdown.js +0 -9
  6. package/dist/internal/navbar/mobile-menu.d.ts +3 -3
  7. package/dist/internal/navbar/mobile-menu.d.ts.map +1 -1
  8. package/dist/internal/navbar/mobile-menu.js +3 -3
  9. package/dist/internal/navbar/navbar-logo.d.ts +5 -3
  10. package/dist/internal/navbar/navbar-logo.d.ts.map +1 -1
  11. package/dist/internal/navbar/navbar-logo.js +71 -14
  12. package/dist/internal/page-actions.d.ts +4 -4
  13. package/dist/internal/page-actions.d.ts.map +1 -1
  14. package/dist/internal/page-actions.js +1 -6
  15. package/dist/mdx.d.ts +25 -3
  16. package/dist/mdx.d.ts.map +1 -1
  17. package/dist/mdx.js +61 -8
  18. package/dist/navbar.js +4 -3
  19. package/dist/next.d.ts +15 -12
  20. package/dist/next.d.ts.map +1 -1
  21. package/dist/next.js +28 -86
  22. package/dist/pages/docs.d.ts +98 -5
  23. package/dist/pages/docs.d.ts.map +1 -1
  24. package/dist/pages/docs.js +250 -13
  25. package/dist/routes/search.d.ts +8 -1
  26. package/dist/routes/search.d.ts.map +1 -1
  27. package/dist/routes/search.js +120 -82
  28. package/dist/source-config.d.ts +3 -10
  29. package/dist/source-config.d.ts.map +1 -1
  30. package/dist/source-config.js +12 -21
  31. package/dist/source.d.ts +17 -6
  32. package/dist/source.d.ts.map +1 -1
  33. package/dist/source.js +75 -2
  34. package/docs/agents.md +1 -1
  35. package/docs/llms.txt +70 -14
  36. package/docs/manifest.json +1 -1
  37. package/docs/pages/configuration.md +69 -13
  38. package/package.json +20 -35
  39. package/rehype-code-highlights.d.ts +1 -1
  40. package/rehype-code-highlights.js +49 -1
  41. package/search-index.d.ts +14 -0
  42. package/search-index.js +447 -0
  43. package/source-config-public.d.ts +15 -0
  44. package/source-config-public.js +47 -0
  45. package/source-config.js +12 -27
  46. package/template/AGENTS.md +4 -0
  47. package/template/app/api/search/route.ts +7 -2
  48. package/template/content/docs/configuration.mdx +69 -13
  49. package/template/lib/geistdocs/search-source.ts +6 -0
  50. package/template/next.config.ts +1 -1
  51. package/template/package.json +4 -7
  52. package/template/source.config.ts +1 -1
  53. package/dist/internal/source-loader.d.ts +0 -28
  54. package/dist/internal/source-loader.d.ts.map +0 -1
  55. package/dist/internal/source-loader.js +0 -77
  56. package/dist/mdx-basic.d.ts +0 -27
  57. package/dist/mdx-basic.d.ts.map +0 -1
  58. package/dist/mdx-basic.js +0 -61
  59. package/dist/navigation.d.ts +0 -11
  60. package/dist/navigation.d.ts.map +0 -1
  61. package/dist/navigation.js +0 -8
  62. package/dist/pages/docs-custom.d.ts +0 -111
  63. package/dist/pages/docs-custom.d.ts.map +0 -1
  64. package/dist/pages/docs-custom.js +0 -250
  65. package/native-mdx/LICENSE-mdxjs-rs +0 -22
  66. package/native-mdx/UPSTREAM.md +0 -16
  67. package/native-mdx/binaries/darwin-arm64.node +0 -0
  68. package/native-mdx/binaries/linux-x64-gnu.node +0 -0
  69. package/native-mdx/data-entry.d.mts +0 -15
  70. package/native-mdx/data-entry.mjs +0 -97
  71. package/native-mdx/data-projection.mjs +0 -205
  72. package/native-mdx/fumadocs-adapter.mjs +0 -36
  73. package/native-mdx/index-emitter.mjs +0 -34
  74. package/native-mdx/loader-data.cjs +0 -36
  75. package/native-mdx/loader-mdx.cjs +0 -9
  76. package/native-mdx/loader-mdx.mjs +0 -419
  77. package/native-mdx/native-binding.cjs +0 -27
  78. package/native-mdx/navigation-entry.d.mts +0 -11
  79. package/native-mdx/navigation-entry.mjs +0 -136
  80. package/native-mdx/navigation-title.mjs +0 -53
  81. package/template/pnpm-workspace.yaml +0 -3
@@ -1,250 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import Link from "fumadocs-core/link";
3
- import { DocsBody as FumadocsDocsBody, DocsPage as FumadocsDocsPage, DocsTitle as FumadocsDocsTitle, } from "fumadocs-ui/layouts/docs/page";
4
- import { notFound } from "next/navigation";
5
- import { cache, } from "react";
6
- import { cn } from "#geistdocs-ui/utils";
7
- import { NativeDocsLink } from "../components/link";
8
- import { getPublicPath, withBasePath } from "../config";
9
- import { getDocsLinkClassName } from "../internal/docs-link-class-name";
10
- import { DocsPageErrorBoundary } from "../internal/docs-page-error-boundary";
11
- import { resolveDocumentTitle } from "../internal/document-title";
12
- import { omitLanguageParam, resolveRouteLanguage } from "../internal/languages";
13
- import { resolveLinkHref, stripBasePathFromHref } from "../internal/link-href";
14
- import { resolvePageMarkdownUrl as resolveInternalPageMarkdownUrl } from "../internal/markdown-url.js";
15
- import { createPageActions as createInternalPageActions, resolveExtraPageActions, } from "../internal/page-actions";
16
- import { GeistdocsPageActions } from "../internal/page-actions-gate";
17
- import { PageBreadcrumb } from "../internal/page-breadcrumb";
18
- import { getPageFooterItems, PageFooter } from "../internal/page-footer";
19
- import { filterPageTree } from "../internal/page-tree-visibility";
20
- import { createRelativeDocsLink } from "../internal/relative-docs-link";
21
- import { GeistdocsTableOfContents } from "../internal/table-of-contents";
22
- import { GeistdocsTableOfContentsActions } from "../internal/toc-actions-client";
23
- import { getPageRobots, } from "../page-visibility";
24
- const renderPrefetchedDocsLink = (siteUrl, basePath, { children, className, href, rel, target, ...props }) => {
25
- const originalHref = String(href ?? "");
26
- const resolved = resolveLinkHref(originalHref, siteUrl);
27
- const linkHref = resolved.href === originalHref
28
- ? resolved.href
29
- : stripBasePathFromHref(resolved.href, basePath);
30
- return (_jsx(Link, { ...props, className: getDocsLinkClassName(className), href: linkHref, prefetch: !resolved.external, rel: resolved.external ? rel : undefined, target: resolved.external ? target : undefined, children: children }));
31
- };
32
- export const resolvePageMarkdownUrl = (options) => resolveInternalPageMarkdownUrl(options);
33
- /**
34
- * The page's visible article parts carry `data-geistdocs-article` (`title`,
35
- * `body`) so tools that read the rendered HTML (docs
36
- * crawlers, parity checks against the Markdown route) can select the
37
- * article without depending on Fumadocs' element ids or on class names.
38
- * The marked elements hold content only: page actions, breadcrumbs, the
39
- * table of contents, and the previous/next footer sit outside them.
40
- */
41
- const DocsTitle = ({ className, ...props }) => (_jsx(FumadocsDocsTitle, { className: cn("mb-4 text-balance", className), "data-geistdocs-article": "title", ...props }));
42
- const DocsBody = ({ className, ...props }) => (_jsx(FumadocsDocsBody, { className: cn("mx-auto w-full", className), "data-geistdocs-article": "body", ...props }));
43
- /** App-provided footer content below the table-of-contents actions. */
44
- const TocFooterSlot = ({ children }) => children ? _jsx("div", { className: "mt-4", children: children }) : null;
45
- const hasTableOfContentsActions = (config, extraActions) => config.pageActions?.scrollTop !== false ||
46
- config.feedback?.enabled !== false ||
47
- extraActions.length > 0;
48
- const serializeParams = (params) => JSON.stringify(Object.entries(params)
49
- .filter(([, value]) => value !== undefined)
50
- .sort(([left], [right]) => left.localeCompare(right)));
51
- export const createDocsPage = ({ canViewPage, config, source, mdx, pageActions = createInternalPageActions({ config }), filterStaticParams, getMarkdownUrl, getPageUrl, getPublicPageUrl, metadata, openGraph, renderTop, resolveLink, tableOfContent, tableOfContentPopover, }) => {
52
- const DocsLink = renderPrefetchedDocsLink.bind(null, config.siteUrl, config.basePath);
53
- const resolvePageUrls = (page, params) => {
54
- const pageUrl = getPageUrl?.({ page, params }) ?? page.url;
55
- const publicPageUrl = getPublicPageUrl?.({ page, params, pageUrl }) ??
56
- getPublicPath(pageUrl, config.basePath);
57
- const markdownUrl = getMarkdownUrl?.({ page, params, pageUrl, publicPageUrl }) ??
58
- resolveInternalPageMarkdownUrl({
59
- basePath: config.basePath,
60
- isRootMountedPage: source.baseUrl === "/" && page.slugs.length === 0,
61
- pageUrl,
62
- publicPageUrl,
63
- });
64
- return { markdownUrl, pageUrl, publicPageUrl };
65
- };
66
- const getAccessState = cache(async (paramsKey) => {
67
- const params = Object.fromEntries(JSON.parse(paramsKey));
68
- const tree = source.source.getPageTree(params.lang);
69
- if (!canViewPage) {
70
- return { tree, visibleUrls: undefined };
71
- }
72
- const access = await Promise.all(source.source.getPages(params.lang).map(async (page) => ({
73
- page,
74
- visible: await canViewPage(page, { params, source }),
75
- })));
76
- const visibleUrls = new Set(access.filter(({ visible }) => visible).map(({ page }) => page.url));
77
- const hiddenUrls = new Set(access.filter(({ visible }) => !visible).map(({ page }) => page.url));
78
- return { tree: filterPageTree(tree, hiddenUrls), visibleUrls };
79
- });
80
- // Single-language apps have no [lang] segment, so params arrive without it.
81
- const resolveParams = async (params) => {
82
- const resolved = await params;
83
- return {
84
- ...resolved,
85
- lang: resolveRouteLanguage(config, resolved.lang),
86
- };
87
- };
88
- const getPage = async (params) => {
89
- const page = source.source.getPage(params.slug, params.lang);
90
- if (!page) {
91
- notFound();
92
- }
93
- if (canViewPage) {
94
- const { visibleUrls } = await getAccessState(serializeParams(params));
95
- if (!visibleUrls?.has(page.url)) {
96
- notFound();
97
- }
98
- }
99
- return page;
100
- };
101
- const getPageTree = async (params) => (await getAccessState(serializeParams(params))).tree;
102
- const PageContent = async ({ params }) => {
103
- const resolvedParams = await resolveParams(params);
104
- const { lang } = resolvedParams;
105
- const page = await getPage(resolvedParams);
106
- const pageTree = await getPageTree(resolvedParams);
107
- const data = page.data;
108
- const MDX = data.body;
109
- const defaultLink = createRelativeDocsLink(source.source, page, DocsLink);
110
- const link = resolveLink
111
- ? resolveLink({
112
- link: defaultLink,
113
- nativeLink: NativeDocsLink,
114
- page,
115
- source,
116
- })
117
- : defaultLink;
118
- const resolvedMdx = typeof mdx === "function" ? mdx({ link, page, source }) : mdx;
119
- const { markdownUrl, pageUrl, publicPageUrl } = resolvePageUrls(page, resolvedParams);
120
- const footerItems = getPageFooterItems(pageTree, page.url);
121
- const pagesByUrl = getPageUrl
122
- ? new Map(source.source.getPages(lang).map((entry) => [entry.url, entry]))
123
- : undefined;
124
- const resolveFooterItem = (item) => {
125
- if (!(item && getPageUrl && pagesByUrl)) {
126
- return item;
127
- }
128
- const itemPage = pagesByUrl.get(item.url);
129
- if (!itemPage) {
130
- return item;
131
- }
132
- return {
133
- ...item,
134
- url: getPageUrl({
135
- page: itemPage,
136
- params: { ...resolvedParams, slug: itemPage.slugs },
137
- }),
138
- };
139
- };
140
- const resolvedFooterItems = {
141
- previous: resolveFooterItem(footerItems.previous),
142
- next: resolveFooterItem(footerItems.next),
143
- };
144
- const markdown = pageActions.getExtraActions || typeof renderTop === "function"
145
- ? await source.getPageMarkdown(page)
146
- : undefined;
147
- const footerActions = resolveExtraPageActions(pageActions, {
148
- markdown: markdown ?? "",
149
- page: {
150
- path: page.path,
151
- url: publicPageUrl,
152
- },
153
- });
154
- const hasTocActions = hasTableOfContentsActions(pageActions.config, footerActions);
155
- const hasTocLinks = Boolean(data.toc?.length);
156
- // Actions stay adjacent to the table of contents; the app-provided
157
- // footer (promos and other custom content) renders below them.
158
- const tocFooter = (_jsxs(_Fragment, { children: [hasTocLinks && hasTocActions ? (_jsx("div", { className: "mt-4 border-gray-alpha-400 border-t pt-4", children: _jsx("nav", { "aria-label": "Page actions", className: "flex min-w-0 flex-col gap-1", children: _jsx(GeistdocsTableOfContentsActions, { config: pageActions.config, extraActions: footerActions }) }) })) : null, _jsx(TocFooterSlot, { children: tableOfContent?.footer })] }));
159
- const tocComponent = tableOfContent?.component ?? (_jsx(GeistdocsTableOfContents, { footer: tocFooter, header: tableOfContent?.header, toc: data.toc ?? [] }));
160
- return (_jsxs(FumadocsDocsPage, { breadcrumb: {
161
- component: _jsx(PageBreadcrumb, { tree: pageTree, url: page.url }),
162
- }, footer: { component: _jsx(PageFooter, { ...resolvedFooterItems }) }, full: data.full, tableOfContent: {
163
- enabled: true,
164
- single: true,
165
- ...tableOfContent,
166
- component: tocComponent,
167
- }, tableOfContentPopover: {
168
- enabled: false,
169
- ...tableOfContentPopover,
170
- }, toc: data.toc, children: [typeof renderTop === "function"
171
- ? renderTop({
172
- data,
173
- markdown: markdown ?? "",
174
- markdownUrl,
175
- page,
176
- pageUrl,
177
- publicPageUrl,
178
- })
179
- : renderTop, _jsxs("div", { className: "mb-8 flex flex-col-reverse gap-4 md:flex-row md:items-end md:justify-between", children: [_jsx(DocsTitle, { className: "mb-0 min-w-0", children: data.title }), _jsx(GeistdocsPageActions, { config: pageActions.config, only: "desktop", page: {
180
- markdownUrl,
181
- path: page.path,
182
- title: data.title,
183
- url: publicPageUrl,
184
- } })] }), _jsx("div", { className: "-mt-6 mb-4 @min-[961px]:hidden", children: _jsx(GeistdocsPageActions, { config: pageActions.config, only: "mobile", page: {
185
- markdownUrl,
186
- path: page.path,
187
- title: data.title,
188
- url: publicPageUrl,
189
- } }) }), _jsx(DocsBody, { children: _jsx(MDX, { components: {
190
- a: link,
191
- ...resolvedMdx,
192
- } }) })] }));
193
- };
194
- const Page = ({ params }) => (_jsx(DocsPageErrorBoundary, { children: _jsx(PageContent, { params: params }) }));
195
- const generateStaticParams = () => {
196
- const params = source.source.generateParams();
197
- const filtered = filterStaticParams
198
- ? params.filter(filterStaticParams)
199
- : params;
200
- return omitLanguageParam(config, filtered);
201
- };
202
- const generateMetadata = async ({ params, }) => {
203
- const resolvedParams = await resolveParams(params);
204
- const page = await getPage(resolvedParams);
205
- const pageTree = await getPageTree(resolvedParams);
206
- const data = page.data;
207
- const { markdownUrl, publicPageUrl } = resolvePageUrls(page, resolvedParams);
208
- const openGraphImages = openGraph?.images === true
209
- ? source.getPageImage(page).url
210
- : openGraph?.images;
211
- let canonicalUrl;
212
- if (data.canonical) {
213
- canonicalUrl = withBasePath(data.canonical, config.basePath);
214
- }
215
- else if (config.siteUrl) {
216
- canonicalUrl = new URL(publicPageUrl, config.siteUrl).toString();
217
- }
218
- const defaultMetadata = {
219
- title: resolveDocumentTitle({
220
- pageTitle: data.title,
221
- pageUrl: page.url,
222
- tree: pageTree,
223
- }),
224
- description: data.description,
225
- keywords: data.keywords,
226
- robots: getPageRobots(page),
227
- ...(openGraphImages ? { openGraph: { images: openGraphImages } } : {}),
228
- alternates: {
229
- canonical: canonicalUrl,
230
- types: {
231
- "text/markdown": markdownUrl,
232
- },
233
- },
234
- };
235
- return metadata
236
- ? await metadata({
237
- metadata: defaultMetadata,
238
- page,
239
- params: resolvedParams,
240
- })
241
- : defaultMetadata;
242
- };
243
- return {
244
- Page,
245
- getPageTree,
246
- generateStaticParams,
247
- generateMetadata,
248
- };
249
- };
250
- export const createPageActions = createInternalPageActions;
@@ -1,22 +0,0 @@
1
- (The MIT License)
2
-
3
- Copyright (c) 2022 Titus Wormer <tituswormer@gmail.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- 'Software'), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,16 +0,0 @@
1
- # Vendored MDX compiler
2
-
3
- Upstream: https://github.com/wooorm/mdxjs-rs
4
-
5
- Source version: `mdxjs` 1.0.4 (MIT).
6
- Published crate revision: `282729e6a0750c19dfd9217bc511971bf3295a29`, recorded in
7
- that crate's `.cargo_vcs_info.json`.
8
-
9
- This directory is an adapted subset, not an unmodified upstream checkout.
10
- Geistdocs adds pipeline hooks and fixes JSX style attributes, URL encoding,
11
- GFM nested links and component-only paragraph handling. Geistdocs-specific
12
- transforms and highlighting live outside this directory.
13
-
14
- Keep `LICENSE-mdxjs-rs` with these sources and with every distributed native
15
- binary, including the private Geistdocs package. Review upstream changes and
16
- rerun output parity tests before updating this fork.
@@ -1,15 +0,0 @@
1
- import type { Plugin } from "fumadocs-mdx";
2
- import type * as TypeScript from "typescript";
3
-
4
- type Parser = typeof TypeScript;
5
-
6
- /** Extend Fumadocs 14's existing emitter with an opt-in data.ts entry. */
7
- export declare function dataEntryPlugin(
8
- parser: Parser | (() => Parser | Promise<Parser>)
9
- ): Plugin;
10
-
11
- /** Derive an entry in the same directory as the generated server.ts. */
12
- export declare function createDataEntry(
13
- serverCode: string,
14
- parser: Parser
15
- ): { code: string; imports: number };
@@ -1,97 +0,0 @@
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
- }
@@ -1,205 +0,0 @@
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
- }
@@ -1,36 +0,0 @@
1
- // The version-specific Fumadocs boundary. Upgrades must update these imports
2
- // together and pass native/JS parity plus configuration-reload tests.
3
- import { createRequire } from "node:module";
4
- import path from "node:path";
5
- import { fileURLToPath, pathToFileURL } from "node:url";
6
-
7
- const require = createRequire(import.meta.url);
8
- const dist = path.dirname(fileURLToPath(import.meta.resolve("fumadocs-mdx")));
9
- const version = require(path.join(dist, "../package.json")).version;
10
- if (version !== "14.0.4") {
11
- throw new Error(
12
- `Geistdocs MDX requires fumadocs-mdx 14.0.4; found ${version}`
13
- );
14
- }
15
- export const internal = (chunk) =>
16
- import(pathToFileURL(path.join(dist, chunk)).href);
17
- export const { fumaMatter } = await internal("chunk-VWJKRQZR.js");
18
- const { createCore } = await internal("chunk-K4KWUM3J.js");
19
- const cores = new Map();
20
- export function getCore(options) {
21
- const key = JSON.stringify([options.configPath, options.outDir]);
22
- if (!cores.has(key)) {
23
- cores.set(
24
- key,
25
- createCore({
26
- environment: "webpack",
27
- configPath: options.configPath,
28
- outDir: options.outDir,
29
- })
30
- );
31
- }
32
- return cores.get(key);
33
- }
34
- export const { createStandaloneConfigLoader } =
35
- await internal("chunk-NKIL543T.js");
36
- export const { buildConfig } = await internal("chunk-6RPNS75C.js");