@vercel/geistdocs 2.15.3-canary.633944d → 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.
- package/dist/cli/index.js +1 -1
- package/dist/internal/mdx-to-markdown.d.ts.map +1 -1
- package/dist/internal/mdx-to-markdown.js +9 -0
- package/dist/internal/page-actions.d.ts +4 -4
- package/dist/internal/page-actions.d.ts.map +1 -1
- package/dist/internal/page-actions.js +6 -1
- package/dist/internal/source-loader.d.ts +28 -0
- package/dist/internal/source-loader.d.ts.map +1 -0
- package/dist/internal/source-loader.js +77 -0
- package/dist/mdx-basic.d.ts +27 -0
- package/dist/mdx-basic.d.ts.map +1 -0
- package/dist/mdx-basic.js +61 -0
- package/dist/mdx.d.ts +3 -25
- package/dist/mdx.d.ts.map +1 -1
- package/dist/mdx.js +8 -61
- package/dist/navigation.d.ts +11 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +8 -0
- package/dist/pages/docs-custom.d.ts +111 -0
- package/dist/pages/docs-custom.d.ts.map +1 -0
- package/dist/pages/docs-custom.js +250 -0
- package/dist/pages/docs.d.ts +5 -98
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +13 -250
- package/dist/source.d.ts +6 -17
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +2 -75
- package/docs/agents.md +1 -1
- package/docs/llms.txt +1 -1
- package/docs/manifest.json +1 -1
- package/native-mdx/data-entry.d.mts +15 -0
- package/native-mdx/data-entry.mjs +97 -0
- package/native-mdx/data-projection.mjs +205 -0
- package/native-mdx/index-emitter.mjs +34 -0
- package/native-mdx/loader-data.cjs +36 -0
- package/native-mdx/loader-mdx.mjs +50 -4
- package/native-mdx/navigation-entry.d.mts +11 -0
- package/native-mdx/navigation-entry.mjs +136 -0
- package/native-mdx/navigation-title.mjs +53 -0
- package/package.json +23 -2
- package/template/package.json +1 -1
package/dist/source.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { InferPageType } from "fumadocs-core/source";
|
|
2
2
|
import type { PluggableList } from "unified";
|
|
3
|
-
import { type
|
|
3
|
+
import { type GeistdocsPageSurface } from "./config.js";
|
|
4
4
|
import { type MarkdownComponentElement, type MarkdownComponentSerializer, type MarkdownPropValue } from "./internal/mdx-to-markdown.js";
|
|
5
|
+
import { type CreateNavigationOptions } from "./internal/source-loader.js";
|
|
5
6
|
import { type GeistdocsVersionPaths } from "./internal/version-paths.js";
|
|
7
|
+
export type { FumadocsCollection, GeistdocsSlugsContext, } from "./internal/source-loader.js";
|
|
6
8
|
export type { GeistdocsVersionPaths } from "./internal/version-paths.js";
|
|
7
|
-
type LoaderOptions = Parameters<typeof loader>[0];
|
|
8
|
-
export interface FumadocsCollection {
|
|
9
|
-
toFumadocsSource(): LoaderOptions["source"];
|
|
10
|
-
}
|
|
11
9
|
export interface GeistdocsSourcePageData {
|
|
12
10
|
badge?: string;
|
|
13
11
|
canonical?: string;
|
|
@@ -62,16 +60,7 @@ export interface GeistdocsMarkdownOptions {
|
|
|
62
60
|
remarkPlugins?: PluggableList;
|
|
63
61
|
transform?: (markdown: string, context: GeistdocsMarkdownContext) => Promise<string> | string;
|
|
64
62
|
}
|
|
65
|
-
export interface
|
|
66
|
-
/** Content file path relative to the content directory, including any language suffix, such as `errors/NOT_FOUND.mdx` or `guide.cn.mdx`. */
|
|
67
|
-
path: string;
|
|
68
|
-
/** Default slugs derived from the path, without folder groups or a trailing `index`. */
|
|
69
|
-
slugs: string[];
|
|
70
|
-
}
|
|
71
|
-
export interface CreateSourceOptions {
|
|
72
|
-
baseUrl?: string;
|
|
73
|
-
config: Pick<GeistdocsConfig, "agent" | "basePath" | "defaultLanguage" | "singleLanguage" | "siteUrl" | "translations"> & Partial<Pick<GeistdocsConfig, "title">>;
|
|
74
|
-
docs: FumadocsCollection;
|
|
63
|
+
export interface CreateSourceOptions extends CreateNavigationOptions {
|
|
75
64
|
id?: string;
|
|
76
65
|
label?: string;
|
|
77
66
|
markdown?: GeistdocsMarkdownOptions;
|
|
@@ -80,7 +69,7 @@ export interface CreateSourceOptions {
|
|
|
80
69
|
* slugs apply everywhere page URLs appear: routes, the page tree, Markdown
|
|
81
70
|
* routes, the sitemap, and `llms.txt`. Two pages may not share a URL.
|
|
82
71
|
*/
|
|
83
|
-
slugs?:
|
|
72
|
+
slugs?: CreateNavigationOptions["slugs"];
|
|
84
73
|
}
|
|
85
74
|
export interface GeistdocsSourceDefinition extends Omit<CreateSourceOptions, "config"> {
|
|
86
75
|
id: string;
|
package/dist/source.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EACL,KAAK,oBAAoB,EAG1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EACvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,KAAK,uBAAuB,EAE7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,6BAA6B,CAAC;AAErC,YAAY,EACV,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AA0FzE,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,oBA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AAM,EAYrC,CAAC;AAEF,MAAM,WAAW,gCAAgC;IAC/C,UAAU,CAAC,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,EAAE,KAAK,CAAC,CAAC;CAClE;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,iCAIvC,gCAAgC,KAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAiBvE,CAAC"}
|
package/dist/source.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { defineI18n } from "fumadocs-core/i18n";
|
|
2
|
-
import { loader, } from "fumadocs-core/source";
|
|
3
1
|
import { getPublicPath, withBasePath, } from "./config.js";
|
|
4
2
|
import { createMdxToMarkdown, } from "./internal/mdx-to-markdown.js";
|
|
3
|
+
import { createSourceLoader, } from "./internal/source-loader.js";
|
|
5
4
|
import { stripVersionRoutePrefix, } from "./internal/version-paths.js";
|
|
6
5
|
const MARKDOWN_LINK_PATTERN = /(\]\()(\/(?!\/)[^)\s]*)/g;
|
|
7
6
|
const ROOT_ATTRIBUTE_PATTERN = /(\b(?:href|src)=["'])(\/(?!\/)[^"']*)/g;
|
|
@@ -57,45 +56,6 @@ const prefixMarkdownLinks = (markdown, basePath) => {
|
|
|
57
56
|
...prefixContentLinks(lines.slice(frontmatterEnd + 1), basePath),
|
|
58
57
|
].join("\n");
|
|
59
58
|
};
|
|
60
|
-
const createSlugsPlugin = (transform) => {
|
|
61
|
-
// Each locale's storage inherits fallback pages from the default locale by
|
|
62
|
-
// reference, so transform every page object once.
|
|
63
|
-
const transformed = new WeakSet();
|
|
64
|
-
return {
|
|
65
|
-
name: "geistdocs:slugs",
|
|
66
|
-
// Runs after Fumadocs assigns the default slugs, so `index` pages and
|
|
67
|
-
// folder groups resolve before the transform sees them.
|
|
68
|
-
enforce: "post",
|
|
69
|
-
transformStorage({ storage }) {
|
|
70
|
-
const pathsByUrl = new Map();
|
|
71
|
-
for (const key of storage.getFiles()) {
|
|
72
|
-
const file = storage.read(key);
|
|
73
|
-
if (file?.format !== "page") {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (!transformed.has(file)) {
|
|
77
|
-
// Storage keys drop the locale; `file.path` is the content file path.
|
|
78
|
-
file.slugs = transform({ path: file.path, slugs: [...file.slugs] });
|
|
79
|
-
transformed.add(file);
|
|
80
|
-
}
|
|
81
|
-
const url = file.slugs.join("/");
|
|
82
|
-
const existing = pathsByUrl.get(url);
|
|
83
|
-
if (existing) {
|
|
84
|
-
throw new Error(`Geistdocs slugs: ${existing} and ${file.path} both resolve to "/${url}".`);
|
|
85
|
-
}
|
|
86
|
-
pathsByUrl.set(url, file.path);
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
const getLanguages = (config) => {
|
|
92
|
-
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
93
|
-
const languages = Object.keys(config.translations ?? {});
|
|
94
|
-
return {
|
|
95
|
-
defaultLanguage,
|
|
96
|
-
languages: Array.from(new Set([defaultLanguage, ...languages])),
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
59
|
const YAML_NEEDS_QUOTING = /[:#{}[\]&*!|>'"%@`]/;
|
|
100
60
|
const ALWAYS_QUOTED_FRONTMATTER = new Set(["badge", "navTitle"]);
|
|
101
61
|
const formatFrontmatterValue = (value, forceQuotes = false) => {
|
|
@@ -130,41 +90,8 @@ const formatFrontmatter = (fields) => {
|
|
|
130
90
|
lines.push("---");
|
|
131
91
|
return lines.join("\n");
|
|
132
92
|
};
|
|
133
|
-
const pageTreeTransformer = {
|
|
134
|
-
file(node, filePath) {
|
|
135
|
-
if (!filePath) {
|
|
136
|
-
return node;
|
|
137
|
-
}
|
|
138
|
-
const file = this.storage.read(filePath);
|
|
139
|
-
if (file?.format !== "page") {
|
|
140
|
-
return node;
|
|
141
|
-
}
|
|
142
|
-
const { badge, navTitle } = file.data;
|
|
143
|
-
return {
|
|
144
|
-
...node,
|
|
145
|
-
...(typeof badge === "string" && badge.length > 0 ? { badge } : {}),
|
|
146
|
-
...(typeof navTitle === "string" && navTitle.length > 0
|
|
147
|
-
? { name: navTitle }
|
|
148
|
-
: {}),
|
|
149
|
-
};
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
93
|
export const createSource = ({ docs, config, baseUrl = "/docs", id, label, markdown, slugs, }) => {
|
|
153
|
-
const {
|
|
154
|
-
const i18n = defineI18n({
|
|
155
|
-
defaultLanguage,
|
|
156
|
-
languages,
|
|
157
|
-
hideLocale: "default-locale",
|
|
158
|
-
});
|
|
159
|
-
const source = loader({
|
|
160
|
-
i18n,
|
|
161
|
-
baseUrl,
|
|
162
|
-
pageTree: {
|
|
163
|
-
transformers: [pageTreeTransformer],
|
|
164
|
-
},
|
|
165
|
-
plugins: slugs ? [createSlugsPlugin(slugs)] : undefined,
|
|
166
|
-
source: docs.toFumadocsSource(),
|
|
167
|
-
});
|
|
94
|
+
const source = createSourceLoader({ docs, config, baseUrl, slugs });
|
|
168
95
|
const getPageImage = (page) => {
|
|
169
96
|
const segments = [...page.slugs, "image.png"];
|
|
170
97
|
return {
|
package/docs/agents.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Geistdocs Package Docs
|
|
2
2
|
|
|
3
|
-
These docs are bundled with `@vercel/geistdocs` 2.15.3-canary.
|
|
3
|
+
These docs are bundled with `@vercel/geistdocs` 2.15.3-canary.7d55dcf so agents can understand the installed package without web access.
|
|
4
4
|
They are generated from `apps/template/content/docs` during the package build.
|
|
5
5
|
|
|
6
6
|
## How to use these files
|
package/docs/llms.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Geistdocs Package Documentation
|
|
2
2
|
|
|
3
|
-
These docs are bundled with `@vercel/geistdocs` 2.15.3-canary.
|
|
3
|
+
These docs are bundled with `@vercel/geistdocs` 2.15.3-canary.7d55dcf.
|
|
4
4
|
They describe how to build package-backed Geistdocs sites and how to use the package APIs from generated project adapters.
|
|
5
5
|
|
|
6
6
|
## Documentation Index
|
package/docs/manifest.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
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 };
|
|
@@ -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
|
+
};
|