fumadocs-mdx 14.0.0 → 14.0.2
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/{build-mdx-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
- package/dist/bun/index.d.ts +7 -1
- package/dist/bun/index.js +9 -8
- package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
- package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
- package/dist/{chunk-XHJCLBZ4.js → chunk-ED3ON275.js} +86 -162
- package/dist/{chunk-7L2KNF6B.js → chunk-GB4W3YCZ.js} +51 -7
- package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
- package/dist/{chunk-OXSRIWQW.js → chunk-LPX7ZO66.js} +4 -3
- package/dist/{chunk-SRSRFOVI.js → chunk-OLL7FM7W.js} +3 -3
- package/dist/{chunk-5UMZCWKV.js → chunk-Q5OSGLJL.js} +1 -1
- package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
- package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
- package/dist/chunk-WBIHDYMN.js +126 -0
- package/dist/config/index.d.ts +6 -1
- package/dist/config/index.js +1 -1
- package/dist/{index-D7JdSMpp.d.cts → core-C3QZSdEx.d.ts} +73 -4
- package/dist/{index-BlVBvy-z.d.ts → index-RVIZxMZG.d.ts} +1 -1
- package/dist/index.d.ts +56 -3
- package/dist/load-from-file-OZ5N7DXU.js +8 -0
- package/dist/next/index.cjs +263 -193
- package/dist/next/index.d.ts +7 -2
- package/dist/next/index.js +12 -10
- package/dist/node/loader.js +4 -4
- package/dist/plugins/index-file.d.ts +7 -22
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.ts +7 -1
- package/dist/plugins/last-modified.d.ts +15 -2
- package/dist/plugins/last-modified.js +43 -6
- package/dist/runtime/browser.d.ts +22 -19
- package/dist/runtime/browser.js +5 -6
- package/dist/runtime/dynamic.d.ts +12 -12
- package/dist/runtime/dynamic.js +12 -11
- package/dist/runtime/server.d.ts +10 -157
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/types.d.ts +61 -0
- package/dist/runtime/types.js +0 -0
- package/dist/vite/index.d.ts +7 -2
- package/dist/vite/index.js +10 -9
- package/dist/webpack/mdx.d.ts +8 -2
- package/dist/webpack/mdx.js +5 -5
- package/dist/webpack/meta.d.ts +8 -2
- package/dist/webpack/meta.js +4 -4
- package/package.json +4 -6
- package/dist/bin.cjs +0 -1889
- package/dist/bin.d.cts +0 -1
- package/dist/bun/index.cjs +0 -1112
- package/dist/bun/index.d.cts +0 -19
- package/dist/chunk-PKI7ZDA5.js +0 -29
- package/dist/config/index.cjs +0 -400
- package/dist/config/index.d.cts +0 -13
- package/dist/index-D7JdSMpp.d.ts +0 -272
- package/dist/index-P2NNUkHn.d.cts +0 -8
- package/dist/index.cjs +0 -18
- package/dist/index.d.cts +0 -8
- package/dist/load-from-file-I3ALLIVB.js +0 -8
- package/dist/next/index.d.cts +0 -28
- package/dist/node/loader.cjs +0 -1165
- package/dist/node/loader.d.cts +0 -5
- package/dist/plugins/index-file.cjs +0 -471
- package/dist/plugins/index-file.d.cts +0 -29
- package/dist/plugins/json-schema.cjs +0 -114
- package/dist/plugins/json-schema.d.cts +0 -25
- package/dist/plugins/last-modified.cjs +0 -75
- package/dist/plugins/last-modified.d.cts +0 -27
- package/dist/runtime/browser.cjs +0 -94
- package/dist/runtime/browser.d.cts +0 -50
- package/dist/runtime/dynamic.cjs +0 -985
- package/dist/runtime/dynamic.d.cts +0 -27
- package/dist/runtime/server.cjs +0 -173
- package/dist/runtime/server.d.cts +0 -161
- package/dist/vite/index.cjs +0 -1620
- package/dist/vite/index.d.cts +0 -39
- package/dist/webpack/mdx.cjs +0 -1089
- package/dist/webpack/mdx.d.cts +0 -14
- package/dist/webpack/meta.cjs +0 -649
- package/dist/webpack/meta.d.cts +0 -14
package/dist/bun/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BunPlugin } from 'bun';
|
|
2
|
-
import { C as CoreOptions } from '../
|
|
2
|
+
import { C as CoreOptions } from '../core-C3QZSdEx.js';
|
|
3
3
|
import '@mdx-js/mdx';
|
|
4
4
|
import '@standard-schema/spec';
|
|
5
5
|
import 'unified';
|
|
@@ -7,6 +7,12 @@ import 'fumadocs-core/mdx-plugins';
|
|
|
7
7
|
import 'zod';
|
|
8
8
|
import 'chokidar';
|
|
9
9
|
import 'vfile';
|
|
10
|
+
import 'fumadocs-core/source';
|
|
11
|
+
import '../runtime/types.js';
|
|
12
|
+
import 'fumadocs-core/mdx-plugins/remark-structure';
|
|
13
|
+
import 'fumadocs-core/toc';
|
|
14
|
+
import 'mdast';
|
|
15
|
+
import 'mdx/types';
|
|
10
16
|
|
|
11
17
|
interface MdxPluginOptions extends Partial<CoreOptions> {
|
|
12
18
|
/**
|
package/dist/bun/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-6RPNS75C.js";
|
|
4
|
+
import "../chunk-S7KOJHHO.js";
|
|
5
5
|
import {
|
|
6
6
|
createMdxLoader
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-USWQVJWR.js";
|
|
8
8
|
import {
|
|
9
9
|
createMetaLoader
|
|
10
10
|
} from "../chunk-TYJDYTKH.js";
|
|
11
11
|
import {
|
|
12
12
|
createIntegratedConfigLoader,
|
|
13
13
|
toBun
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-OLL7FM7W.js";
|
|
15
15
|
import "../chunk-4JSFLXXT.js";
|
|
16
16
|
import {
|
|
17
17
|
_Defaults,
|
|
18
18
|
createCore
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import "../chunk-
|
|
19
|
+
} from "../chunk-GB4W3YCZ.js";
|
|
20
|
+
import "../chunk-WBIHDYMN.js";
|
|
21
21
|
import "../chunk-VWJKRQZR.js";
|
|
22
22
|
|
|
23
23
|
// src/bun/index.ts
|
|
@@ -33,11 +33,12 @@ function createMdxPlugin(options = {}) {
|
|
|
33
33
|
name: "bun-plugin-fumadocs-mdx",
|
|
34
34
|
async setup(build) {
|
|
35
35
|
const importPath = pathToFileURL(configPath).href;
|
|
36
|
-
const core =
|
|
36
|
+
const core = createCore({
|
|
37
37
|
environment,
|
|
38
38
|
outDir,
|
|
39
39
|
configPath
|
|
40
|
-
})
|
|
40
|
+
});
|
|
41
|
+
await core.init({
|
|
41
42
|
config: buildConfig(await import(importPath))
|
|
42
43
|
});
|
|
43
44
|
const configLoader = createIntegratedConfigLoader(core);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/runtime/server.ts
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
function
|
|
3
|
+
function server(options = {}) {
|
|
4
|
+
const { doc: { passthroughs: docPassthroughs = [] } = {} } = options;
|
|
4
5
|
function fileInfo(file, base) {
|
|
5
6
|
if (file.startsWith("./")) {
|
|
6
7
|
file = file.slice(2);
|
|
@@ -11,14 +12,16 @@ function fromConfig() {
|
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
function mapDocData(entry) {
|
|
14
|
-
|
|
15
|
+
const data = {
|
|
15
16
|
body: entry.default,
|
|
16
17
|
toc: entry.toc,
|
|
17
|
-
extractedReferences: entry.extractedReferences,
|
|
18
18
|
structuredData: entry.structuredData,
|
|
19
|
-
lastModified: entry.lastModified,
|
|
20
19
|
_exports: entry
|
|
21
20
|
};
|
|
21
|
+
for (const key of docPassthroughs) {
|
|
22
|
+
data[key] = entry[key];
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
22
25
|
}
|
|
23
26
|
return {
|
|
24
27
|
async doc(_name, base, glob) {
|
|
@@ -133,6 +136,6 @@ function createDocMethods(info, load) {
|
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
export {
|
|
136
|
-
|
|
139
|
+
server,
|
|
137
140
|
toFumadocsSource
|
|
138
141
|
};
|
|
@@ -1,137 +1,41 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
createCodegen,
|
|
3
|
+
ident
|
|
4
|
+
} from "./chunk-WBIHDYMN.js";
|
|
4
5
|
import {
|
|
5
6
|
fumaMatter
|
|
6
7
|
} from "./chunk-VWJKRQZR.js";
|
|
7
8
|
|
|
8
9
|
// src/plugins/index-file.ts
|
|
9
10
|
import path2 from "path";
|
|
11
|
+
import { glob } from "tinyglobby";
|
|
10
12
|
|
|
11
|
-
// src/utils/
|
|
13
|
+
// src/utils/fs-cache.ts
|
|
14
|
+
import { LRUCache } from "lru-cache";
|
|
15
|
+
import fs from "fs/promises";
|
|
12
16
|
import path from "path";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}) {
|
|
20
|
-
let eagerImportId = 0;
|
|
21
|
-
const banner = ["// @ts-nocheck"];
|
|
22
|
-
if (target === "vite") {
|
|
23
|
-
banner.push('/// <reference types="vite/client" />');
|
|
17
|
+
var map = new LRUCache({
|
|
18
|
+
max: 100
|
|
19
|
+
});
|
|
20
|
+
function toFullPath(file) {
|
|
21
|
+
if (path.isAbsolute(file)) {
|
|
22
|
+
return path.relative(process.cwd(), file);
|
|
24
23
|
}
|
|
25
|
-
return
|
|
26
|
-
options: {
|
|
27
|
-
target,
|
|
28
|
-
outDir
|
|
29
|
-
},
|
|
30
|
-
lines: [],
|
|
31
|
-
addImport(statement) {
|
|
32
|
-
this.lines.unshift(statement);
|
|
33
|
-
},
|
|
34
|
-
async pushAsync(insert) {
|
|
35
|
-
for (const line of await Promise.all(insert)) {
|
|
36
|
-
if (line === void 0) continue;
|
|
37
|
-
this.lines.push(line);
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
async generateGlobImport(patterns, options) {
|
|
41
|
-
if (target === "vite") {
|
|
42
|
-
return this.generateViteGlobImport(patterns, options);
|
|
43
|
-
}
|
|
44
|
-
return this.generateNodeGlobImport(patterns, options);
|
|
45
|
-
},
|
|
46
|
-
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
47
|
-
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
48
|
-
normalizeViteGlobPath
|
|
49
|
-
);
|
|
50
|
-
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
51
|
-
{
|
|
52
|
-
base: normalizeViteGlobPath(path.relative(outDir, base)),
|
|
53
|
-
...rest
|
|
54
|
-
},
|
|
55
|
-
null,
|
|
56
|
-
2
|
|
57
|
-
)})`;
|
|
58
|
-
},
|
|
59
|
-
async generateNodeGlobImport(patterns, {
|
|
60
|
-
base,
|
|
61
|
-
eager = false,
|
|
62
|
-
query = {},
|
|
63
|
-
import: importName
|
|
64
|
-
}) {
|
|
65
|
-
const cacheKey = JSON.stringify({ patterns, base });
|
|
66
|
-
let files = globCache.get(cacheKey);
|
|
67
|
-
if (!files) {
|
|
68
|
-
files = glob(patterns, {
|
|
69
|
-
cwd: base
|
|
70
|
-
});
|
|
71
|
-
globCache.set(cacheKey, files);
|
|
72
|
-
}
|
|
73
|
-
let code = "{";
|
|
74
|
-
for (const item of await files) {
|
|
75
|
-
const fullPath = path.join(base, item);
|
|
76
|
-
const searchParams = new URLSearchParams();
|
|
77
|
-
for (const [k, v] of Object.entries(query)) {
|
|
78
|
-
searchParams.set(k, v);
|
|
79
|
-
}
|
|
80
|
-
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
81
|
-
if (eager) {
|
|
82
|
-
const name = `__fd_glob_${eagerImportId++}`;
|
|
83
|
-
this.lines.unshift(
|
|
84
|
-
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
85
|
-
);
|
|
86
|
-
code += `${JSON.stringify(item)}: ${name}, `;
|
|
87
|
-
} else {
|
|
88
|
-
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
89
|
-
if (importName) {
|
|
90
|
-
line += `.then(mod => mod.${importName})`;
|
|
91
|
-
}
|
|
92
|
-
code += `${line}, `;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
code += "}";
|
|
96
|
-
return code;
|
|
97
|
-
},
|
|
98
|
-
formatImportPath(file) {
|
|
99
|
-
const ext = path.extname(file);
|
|
100
|
-
let filename;
|
|
101
|
-
if (ext === ".ts" && jsExtension) {
|
|
102
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
103
|
-
} else if (ext === ".ts") {
|
|
104
|
-
filename = file.substring(0, file.length - ext.length);
|
|
105
|
-
} else {
|
|
106
|
-
filename = file;
|
|
107
|
-
}
|
|
108
|
-
const importPath = slash(path.relative(outDir, filename));
|
|
109
|
-
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
110
|
-
},
|
|
111
|
-
toString() {
|
|
112
|
-
return [...banner, ...this.lines].join("\n");
|
|
113
|
-
}
|
|
114
|
-
};
|
|
24
|
+
return file;
|
|
115
25
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
26
|
+
function readFileWithCache(file) {
|
|
27
|
+
const fullPath = toFullPath(file);
|
|
28
|
+
const cached = map.get(fullPath);
|
|
29
|
+
if (cached) return cached;
|
|
30
|
+
const read = fs.readFile(fullPath).then((s) => s.toString());
|
|
31
|
+
map.set(fullPath, read);
|
|
32
|
+
return read;
|
|
121
33
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
if (isExtendedLengthPath) {
|
|
125
|
-
return path3;
|
|
126
|
-
}
|
|
127
|
-
return path3.replaceAll("\\", "/");
|
|
128
|
-
}
|
|
129
|
-
function ident(code, tab = 1) {
|
|
130
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
34
|
+
function removeFileCache(file) {
|
|
35
|
+
map.delete(toFullPath(file));
|
|
131
36
|
}
|
|
132
37
|
|
|
133
38
|
// src/plugins/index-file.ts
|
|
134
|
-
import { glob as glob2 } from "tinyglobby";
|
|
135
39
|
import { createHash } from "crypto";
|
|
136
40
|
function indexFile(options = {}) {
|
|
137
41
|
const {
|
|
@@ -145,6 +49,24 @@ function indexFile(options = {}) {
|
|
|
145
49
|
function isDynamic(collection) {
|
|
146
50
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
147
51
|
}
|
|
52
|
+
function generateConfigs(core) {
|
|
53
|
+
const serverOptions = {};
|
|
54
|
+
const typeConfigs = [
|
|
55
|
+
'import("fumadocs-mdx/runtime/types").InternalTypeConfig'
|
|
56
|
+
];
|
|
57
|
+
const ctx = core.getPluginContext();
|
|
58
|
+
for (const plugin of core.getPlugins()) {
|
|
59
|
+
const indexFilePlugin = plugin["index-file"];
|
|
60
|
+
if (!indexFilePlugin) continue;
|
|
61
|
+
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
62
|
+
const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
63
|
+
if (config2) typeConfigs.push(config2);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
serverOptions,
|
|
67
|
+
tc: typeConfigs.join(" & ")
|
|
68
|
+
};
|
|
69
|
+
}
|
|
148
70
|
return {
|
|
149
71
|
name: "index-file",
|
|
150
72
|
config(v) {
|
|
@@ -154,6 +76,7 @@ function indexFile(options = {}) {
|
|
|
154
76
|
configureServer(server) {
|
|
155
77
|
if (!server.watcher) return;
|
|
156
78
|
server.watcher.on("all", async (event, file) => {
|
|
79
|
+
removeFileCache(file);
|
|
157
80
|
if (dynamicCollections.length === 0) {
|
|
158
81
|
if (target === "vite") return;
|
|
159
82
|
if (target === "default" && event === "change") return;
|
|
@@ -173,48 +96,47 @@ function indexFile(options = {}) {
|
|
|
173
96
|
},
|
|
174
97
|
async emit() {
|
|
175
98
|
const globCache = /* @__PURE__ */ new Map();
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
99
|
+
const { serverOptions, tc } = generateConfigs(this.core);
|
|
100
|
+
const toEmitEntry = async (path3, content) => {
|
|
101
|
+
const codegen = createCodegen({
|
|
102
|
+
target,
|
|
103
|
+
outDir: this.outDir,
|
|
104
|
+
jsExtension: addJsExtension,
|
|
105
|
+
globCache
|
|
106
|
+
});
|
|
107
|
+
await content({
|
|
108
|
+
core: this.core,
|
|
109
|
+
codegen,
|
|
110
|
+
serverOptions,
|
|
111
|
+
tc
|
|
112
|
+
});
|
|
183
113
|
return {
|
|
184
114
|
path: path3,
|
|
185
|
-
content:
|
|
115
|
+
content: codegen.toString()
|
|
186
116
|
};
|
|
187
|
-
}
|
|
117
|
+
};
|
|
188
118
|
const out = [
|
|
189
|
-
toEmitEntry(
|
|
190
|
-
"server.ts",
|
|
191
|
-
generateServerIndexFile(makeCodeGen(), config, this.configPath)
|
|
192
|
-
)
|
|
119
|
+
toEmitEntry("server.ts", generateServerIndexFile)
|
|
193
120
|
];
|
|
194
121
|
if (dynamic)
|
|
195
|
-
out.push(
|
|
196
|
-
toEmitEntry(
|
|
197
|
-
"dynamic.ts",
|
|
198
|
-
generateDynamicIndexFile(this.core, makeCodeGen())
|
|
199
|
-
)
|
|
200
|
-
);
|
|
122
|
+
out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
|
|
201
123
|
if (browser)
|
|
202
|
-
out.push(
|
|
203
|
-
toEmitEntry(
|
|
204
|
-
"browser.ts",
|
|
205
|
-
generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
|
|
206
|
-
)
|
|
207
|
-
);
|
|
124
|
+
out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
|
|
208
125
|
return await Promise.all(out);
|
|
209
126
|
}
|
|
210
127
|
};
|
|
211
128
|
}
|
|
212
|
-
async function generateServerIndexFile(
|
|
129
|
+
async function generateServerIndexFile({
|
|
130
|
+
core,
|
|
131
|
+
codegen,
|
|
132
|
+
serverOptions,
|
|
133
|
+
tc
|
|
134
|
+
}) {
|
|
213
135
|
codegen.lines.push(
|
|
214
|
-
`import {
|
|
215
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
136
|
+
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
137
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
216
138
|
"",
|
|
217
|
-
`const create =
|
|
139
|
+
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
218
140
|
);
|
|
219
141
|
async function generateCollectionObject(collection) {
|
|
220
142
|
switch (collection.type) {
|
|
@@ -261,22 +183,26 @@ async function generateServerIndexFile(codegen, config, configPath) {
|
|
|
261
183
|
}
|
|
262
184
|
}
|
|
263
185
|
await codegen.pushAsync(
|
|
264
|
-
|
|
186
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
265
187
|
const obj = await generateCollectionObject(collection);
|
|
266
188
|
if (!obj) return;
|
|
267
189
|
return `
|
|
268
190
|
export const ${collection.name} = ${obj};`;
|
|
269
191
|
})
|
|
270
192
|
);
|
|
271
|
-
return codegen.toString();
|
|
272
193
|
}
|
|
273
|
-
async function generateDynamicIndexFile(
|
|
274
|
-
|
|
194
|
+
async function generateDynamicIndexFile({
|
|
195
|
+
core,
|
|
196
|
+
codegen,
|
|
197
|
+
serverOptions,
|
|
198
|
+
tc
|
|
199
|
+
}) {
|
|
200
|
+
const { configPath } = core.getOptions();
|
|
275
201
|
codegen.lines.push(
|
|
276
|
-
`import {
|
|
202
|
+
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
277
203
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
278
204
|
"",
|
|
279
|
-
`const create = await
|
|
205
|
+
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
|
|
280
206
|
);
|
|
281
207
|
async function generateCollectionObjectEntry(collection, file) {
|
|
282
208
|
const fullPath = path2.join(collection.dir, file);
|
|
@@ -312,7 +238,7 @@ async function generateDynamicIndexFile(core, codegen) {
|
|
|
312
238
|
if (parent.type === "doc") collection = parent;
|
|
313
239
|
else if (parent.type === "docs") collection = parent.docs;
|
|
314
240
|
if (!collection || !collection.dynamic) return;
|
|
315
|
-
const files = await
|
|
241
|
+
const files = await glob(collection.patterns, {
|
|
316
242
|
cwd: collection.dir
|
|
317
243
|
});
|
|
318
244
|
const entries = await Promise.all(
|
|
@@ -339,14 +265,13 @@ async function generateDynamicIndexFile(core, codegen) {
|
|
|
339
265
|
export const ${collection.name} = ${obj};`;
|
|
340
266
|
})
|
|
341
267
|
);
|
|
342
|
-
return codegen.toString();
|
|
343
268
|
}
|
|
344
|
-
async function generateBrowserIndexFile(
|
|
269
|
+
async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
345
270
|
codegen.lines.push(
|
|
346
|
-
`import {
|
|
347
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
271
|
+
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
272
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
348
273
|
"",
|
|
349
|
-
`const create =
|
|
274
|
+
`const create = browser<typeof Config, ${tc}>();`
|
|
350
275
|
);
|
|
351
276
|
async function generateCollectionObject(collection) {
|
|
352
277
|
switch (collection.type) {
|
|
@@ -361,14 +286,13 @@ async function generateBrowserIndexFile(codegen, config, configPath) {
|
|
|
361
286
|
}
|
|
362
287
|
codegen.lines.push("const browserCollections = {");
|
|
363
288
|
await codegen.pushAsync(
|
|
364
|
-
|
|
289
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
365
290
|
const obj = await generateCollectionObject(collection);
|
|
366
291
|
if (!obj) return;
|
|
367
292
|
return ident(`${collection.name}: ${obj},`);
|
|
368
293
|
})
|
|
369
294
|
);
|
|
370
295
|
codegen.lines.push("};", "export default browserCollections;");
|
|
371
|
-
return codegen.toString();
|
|
372
296
|
}
|
|
373
297
|
function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
|
|
374
298
|
return codegen.generateGlobImport(collection.patterns, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
ident
|
|
3
|
+
} from "./chunk-WBIHDYMN.js";
|
|
4
4
|
|
|
5
5
|
// src/utils/validation.ts
|
|
6
6
|
var ValidationError = class extends Error {
|
|
@@ -75,7 +75,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
75
75
|
return data;
|
|
76
76
|
}
|
|
77
77
|
const core = {
|
|
78
|
-
_options: options,
|
|
79
78
|
/**
|
|
80
79
|
* Convenient cache store, reset when config changes
|
|
81
80
|
*/
|
|
@@ -84,6 +83,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
84
83
|
config = await newConfig;
|
|
85
84
|
this.cache.clear();
|
|
86
85
|
plugins = await getPlugins([
|
|
86
|
+
postprocessPlugin(),
|
|
87
87
|
...defaultPlugins,
|
|
88
88
|
...config.global.plugins ?? []
|
|
89
89
|
]);
|
|
@@ -91,7 +91,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
91
91
|
const out = await plugin.config?.call(pluginContext, config);
|
|
92
92
|
if (out) config = out;
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
},
|
|
95
|
+
getOptions() {
|
|
96
|
+
return options;
|
|
95
97
|
},
|
|
96
98
|
getConfig() {
|
|
97
99
|
return config;
|
|
@@ -102,10 +104,13 @@ function createCore(options, defaultPlugins = []) {
|
|
|
102
104
|
getCompiledConfigPath() {
|
|
103
105
|
return path.join(options.outDir, "source.config.mjs");
|
|
104
106
|
},
|
|
107
|
+
getPlugins() {
|
|
108
|
+
return plugins;
|
|
109
|
+
},
|
|
110
|
+
getPluginContext() {
|
|
111
|
+
return pluginContext;
|
|
112
|
+
},
|
|
105
113
|
async initServer(server) {
|
|
106
|
-
server.watcher?.on("all", async (event, file) => {
|
|
107
|
-
if (event === "change") removeFileCache(file);
|
|
108
|
-
});
|
|
109
114
|
for (const plugin of plugins) {
|
|
110
115
|
await plugin.configureServer?.call(pluginContext, server);
|
|
111
116
|
}
|
|
@@ -172,6 +177,45 @@ function createCore(options, defaultPlugins = []) {
|
|
|
172
177
|
};
|
|
173
178
|
return core;
|
|
174
179
|
}
|
|
180
|
+
function postprocessPlugin() {
|
|
181
|
+
const LinkReferenceTypes = `{
|
|
182
|
+
/**
|
|
183
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
184
|
+
*/
|
|
185
|
+
extractedReferences: import("fumadocs-mdx").ExtractedReference[];
|
|
186
|
+
}`;
|
|
187
|
+
return {
|
|
188
|
+
"index-file": {
|
|
189
|
+
generateTypeConfig() {
|
|
190
|
+
const lines = [];
|
|
191
|
+
lines.push("{");
|
|
192
|
+
lines.push(" DocData: {");
|
|
193
|
+
for (const collection of this.core.getConfig().collectionList) {
|
|
194
|
+
let postprocessOptions;
|
|
195
|
+
switch (collection.type) {
|
|
196
|
+
case "doc":
|
|
197
|
+
postprocessOptions = collection.postprocess;
|
|
198
|
+
break;
|
|
199
|
+
case "docs":
|
|
200
|
+
postprocessOptions = collection.docs.postprocess;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
if (postprocessOptions?.extractLinkReferences) {
|
|
204
|
+
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
lines.push(" }");
|
|
208
|
+
lines.push("}");
|
|
209
|
+
return lines.join("\n");
|
|
210
|
+
},
|
|
211
|
+
serverOptions(options) {
|
|
212
|
+
options.doc ??= {};
|
|
213
|
+
options.doc.passthroughs ??= [];
|
|
214
|
+
options.doc.passthroughs.push("extractedReferences");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
175
219
|
|
|
176
220
|
export {
|
|
177
221
|
ValidationError,
|
|
@@ -38,6 +38,10 @@ function remarkPostprocess({
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
file.data["mdx-export"] ??= [];
|
|
41
|
+
file.data["mdx-export"].push({
|
|
42
|
+
name: "frontmatter",
|
|
43
|
+
value: frontmatter
|
|
44
|
+
});
|
|
41
45
|
if (extractLinkReferences) {
|
|
42
46
|
const urls = [];
|
|
43
47
|
visit(tree, "link", (node) => {
|
|
@@ -135,12 +139,7 @@ async function buildMDX(core, collection, {
|
|
|
135
139
|
if (!processor) {
|
|
136
140
|
const postprocessOptions = {
|
|
137
141
|
_format: format,
|
|
138
|
-
...collection?.postprocess
|
|
139
|
-
valueToExport: [
|
|
140
|
-
...collection?.postprocess?.valueToExport ?? [],
|
|
141
|
-
"structuredData",
|
|
142
|
-
"frontmatter"
|
|
143
|
-
]
|
|
142
|
+
...collection?.postprocess
|
|
144
143
|
};
|
|
145
144
|
processor = createProcessor({
|
|
146
145
|
outputFormat: "program",
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildConfig
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6RPNS75C.js";
|
|
4
4
|
|
|
5
5
|
// src/config/load-from-file.ts
|
|
6
6
|
import { pathToFileURL } from "url";
|
|
7
7
|
async function compileConfig(core) {
|
|
8
8
|
const { build } = await import("esbuild");
|
|
9
|
+
const { configPath, outDir } = core.getOptions();
|
|
9
10
|
const transformed = await build({
|
|
10
|
-
entryPoints: [{ in:
|
|
11
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
11
12
|
bundle: true,
|
|
12
|
-
outdir:
|
|
13
|
+
outdir: outDir,
|
|
13
14
|
target: "node20",
|
|
14
15
|
write: true,
|
|
15
16
|
platform: "node",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ValidationError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GB4W3YCZ.js";
|
|
4
4
|
|
|
5
5
|
// src/loaders/adapter.ts
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
@@ -137,13 +137,13 @@ function createStandaloneConfigLoader({
|
|
|
137
137
|
let loaded;
|
|
138
138
|
async function getConfigHash() {
|
|
139
139
|
if (mode === "production") return "static";
|
|
140
|
-
const stats = await fs2.stat(core.
|
|
140
|
+
const stats = await fs2.stat(core.getOptions().configPath).catch(() => {
|
|
141
141
|
throw new Error("Cannot find config file");
|
|
142
142
|
});
|
|
143
143
|
return stats.mtime.getTime().toString();
|
|
144
144
|
}
|
|
145
145
|
async function newConfig() {
|
|
146
|
-
const { loadConfig } = await import("./load-from-file-
|
|
146
|
+
const { loadConfig } = await import("./load-from-file-OZ5N7DXU.js");
|
|
147
147
|
await core.init({
|
|
148
148
|
config: loadConfig(core, buildConfig)
|
|
149
149
|
});
|
|
@@ -47,7 +47,10 @@ function applyMdxPreset(options = {}) {
|
|
|
47
47
|
...v,
|
|
48
48
|
remarkStructureOptions !== false && [
|
|
49
49
|
plugins.remarkStructure,
|
|
50
|
-
|
|
50
|
+
{
|
|
51
|
+
exportAs: "structuredData",
|
|
52
|
+
...remarkStructureOptions
|
|
53
|
+
}
|
|
51
54
|
],
|
|
52
55
|
valueToExport.length > 0 && (() => {
|
|
53
56
|
return (_, file) => {
|
|
@@ -73,7 +73,7 @@ function createMdxLoader(configLoader) {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
76
|
-
const { buildMDX } = await import("./build-mdx-
|
|
76
|
+
const { buildMDX } = await import("./build-mdx-W3233QBZ.js");
|
|
77
77
|
const compiled = await buildMDX(configLoader.core, docCollection, {
|
|
78
78
|
isDevelopment,
|
|
79
79
|
source: "\n".repeat(lineOffset) + matter.content,
|