fumadocs-mdx 13.0.7 → 14.0.0
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/bin.cjs +927 -904
- package/dist/bin.js +3 -3
- package/dist/build-mdx-6UAK5FF5.js +8 -0
- package/dist/bun/index.cjs +592 -481
- package/dist/bun/index.d.cts +3 -2
- package/dist/bun/index.d.ts +3 -2
- package/dist/bun/index.js +12 -12
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/chunk-5UMZCWKV.js +17 -0
- package/dist/chunk-5YXP7JLN.js +138 -0
- package/dist/{chunk-2E2JCOSO.js → chunk-6NISOLQ6.js} +16 -44
- package/dist/chunk-7L2KNF6B.js +180 -0
- package/dist/chunk-E5DJTSIM.js +86 -0
- package/dist/{chunk-K5ZLPEIQ.js → chunk-FBLMK4RS.js} +9 -6
- package/dist/{chunk-QXHN25N3.js → chunk-OXSRIWQW.js} +7 -8
- package/dist/chunk-PKI7ZDA5.js +29 -0
- package/dist/{chunk-3J3WL7WN.js → chunk-SLY7WXTX.js} +71 -58
- package/dist/{chunk-ETIN2W7C.js → chunk-SRSRFOVI.js} +22 -19
- package/dist/chunk-TYJDYTKH.js +85 -0
- package/dist/chunk-XHJCLBZ4.js +406 -0
- package/dist/{chunk-2HXTGJBI.js → chunk-ZY6UZ7NH.js} +22 -19
- package/dist/config/index.cjs +79 -71
- package/dist/config/index.d.cts +2 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +5 -5
- package/dist/index-BlVBvy-z.d.ts +8 -0
- package/dist/{core-HkAVGq_a.d.cts → index-D7JdSMpp.d.cts} +99 -61
- package/dist/{core-HkAVGq_a.d.ts → index-D7JdSMpp.d.ts} +99 -61
- package/dist/index-P2NNUkHn.d.cts +8 -0
- package/dist/index.d.cts +3 -74
- package/dist/index.d.ts +3 -74
- package/dist/load-from-file-I3ALLIVB.js +8 -0
- package/dist/next/index.cjs +698 -476
- package/dist/next/index.d.cts +11 -1
- package/dist/next/index.d.ts +11 -1
- package/dist/next/index.js +78 -281
- package/dist/node/loader.cjs +705 -603
- package/dist/node/loader.js +10 -11
- package/dist/plugins/index-file.cjs +471 -0
- package/dist/plugins/index-file.d.cts +29 -0
- package/dist/plugins/index-file.d.ts +29 -0
- package/dist/plugins/index-file.js +8 -0
- package/dist/plugins/json-schema.d.cts +3 -2
- package/dist/plugins/json-schema.d.ts +3 -2
- package/dist/plugins/last-modified.cjs +75 -0
- package/dist/plugins/last-modified.d.cts +27 -0
- package/dist/plugins/last-modified.d.ts +27 -0
- package/dist/plugins/last-modified.js +44 -0
- package/dist/runtime/{vite/browser.cjs → browser.cjs} +40 -53
- package/dist/runtime/browser.d.cts +50 -0
- package/dist/runtime/browser.d.ts +50 -0
- package/dist/runtime/browser.js +68 -0
- package/dist/runtime/dynamic.cjs +985 -0
- package/dist/runtime/dynamic.d.cts +27 -0
- package/dist/runtime/dynamic.d.ts +27 -0
- package/dist/runtime/dynamic.js +78 -0
- package/dist/runtime/server.cjs +173 -0
- package/dist/runtime/server.d.cts +161 -0
- package/dist/runtime/server.d.ts +161 -0
- package/dist/runtime/server.js +8 -0
- package/dist/vite/index.cjs +935 -639
- package/dist/vite/index.d.cts +12 -22
- package/dist/vite/index.d.ts +12 -22
- package/dist/vite/index.js +30 -221
- package/dist/webpack/mdx.cjs +614 -515
- package/dist/webpack/mdx.d.cts +9 -1
- package/dist/webpack/mdx.d.ts +9 -1
- package/dist/webpack/mdx.js +12 -17
- package/dist/webpack/meta.cjs +328 -234
- package/dist/webpack/meta.d.cts +9 -1
- package/dist/webpack/meta.d.ts +9 -1
- package/dist/webpack/meta.js +13 -15
- package/package.json +15 -32
- package/dist/build-mdx-BnJhW5O1.d.cts +0 -53
- package/dist/build-mdx-DNzfRRlY.d.ts +0 -53
- package/dist/chunk-2AQRQXSO.js +0 -119
- package/dist/chunk-4757L6ST.js +0 -77
- package/dist/chunk-CXA4JO4Z.js +0 -45
- package/dist/chunk-FSZMKRVH.js +0 -80
- package/dist/chunk-II3H5ZVZ.js +0 -77
- package/dist/chunk-KILFIBVW.js +0 -75
- package/dist/chunk-NVRDCY6Z.js +0 -30
- package/dist/chunk-VUEZTR2H.js +0 -26
- package/dist/index-D7s7kCc2.d.cts +0 -7
- package/dist/index-D7s7kCc2.d.ts +0 -7
- package/dist/load-from-file-AVYOFOI7.js +0 -7
- package/dist/preset-ZMP6U62C.js +0 -6
- package/dist/runtime/next/async.cjs +0 -760
- package/dist/runtime/next/async.d.cts +0 -19
- package/dist/runtime/next/async.d.ts +0 -19
- package/dist/runtime/next/async.js +0 -86
- package/dist/runtime/next/index.cjs +0 -136
- package/dist/runtime/next/index.d.cts +0 -33
- package/dist/runtime/next/index.d.ts +0 -33
- package/dist/runtime/next/index.js +0 -11
- package/dist/runtime/vite/browser.d.cts +0 -59
- package/dist/runtime/vite/browser.d.ts +0 -59
- package/dist/runtime/vite/browser.js +0 -11
- package/dist/runtime/vite/server.cjs +0 -243
- package/dist/runtime/vite/server.d.cts +0 -30
- package/dist/runtime/vite/server.d.ts +0 -30
- package/dist/runtime/vite/server.js +0 -111
- package/dist/types-By6wKOnT.d.cts +0 -45
- package/dist/types-DgD5Omj2.d.ts +0 -45
package/dist/bin.cjs
CHANGED
|
@@ -30,11 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
-
// src/
|
|
34
|
-
var preset_exports = {};
|
|
35
|
-
__export(preset_exports, {
|
|
36
|
-
getDefaultMDXOptions: () => getDefaultMDXOptions
|
|
37
|
-
});
|
|
33
|
+
// src/config/preset.ts
|
|
38
34
|
function pluginOption(def, options = []) {
|
|
39
35
|
const list = def(Array.isArray(options) ? options : []).filter(
|
|
40
36
|
Boolean
|
|
@@ -44,76 +40,81 @@ function pluginOption(def, options = []) {
|
|
|
44
40
|
}
|
|
45
41
|
return list;
|
|
46
42
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
43
|
+
function applyMdxPreset(options = {}) {
|
|
44
|
+
return async (environment = "bundler") => {
|
|
45
|
+
if (options.preset === "minimal") return options;
|
|
46
|
+
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
47
|
+
const {
|
|
48
|
+
valueToExport = [],
|
|
49
|
+
rehypeCodeOptions,
|
|
50
|
+
remarkImageOptions,
|
|
51
|
+
remarkHeadingOptions,
|
|
52
|
+
remarkStructureOptions,
|
|
53
|
+
remarkCodeTabOptions,
|
|
54
|
+
remarkNpmOptions,
|
|
55
|
+
...mdxOptions
|
|
56
|
+
} = options;
|
|
57
|
+
const remarkPlugins = pluginOption(
|
|
58
|
+
(v) => [
|
|
59
|
+
plugins.remarkGfm,
|
|
60
|
+
[
|
|
61
|
+
plugins.remarkHeading,
|
|
62
|
+
{
|
|
63
|
+
generateToc: false,
|
|
64
|
+
...remarkHeadingOptions
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
remarkImageOptions !== false && [
|
|
68
|
+
plugins.remarkImage,
|
|
69
|
+
{
|
|
70
|
+
...remarkImageOptions,
|
|
71
|
+
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
75
|
+
plugins.remarkCodeTab,
|
|
76
|
+
remarkCodeTabOptions
|
|
77
|
+
],
|
|
78
|
+
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
79
|
+
...v,
|
|
80
|
+
remarkStructureOptions !== false && [
|
|
81
|
+
plugins.remarkStructure,
|
|
82
|
+
remarkStructureOptions
|
|
83
|
+
],
|
|
84
|
+
valueToExport.length > 0 && (() => {
|
|
85
|
+
return (_, file) => {
|
|
86
|
+
file.data["mdx-export"] ??= [];
|
|
87
|
+
for (const name of valueToExport) {
|
|
88
|
+
if (!(name in file.data)) continue;
|
|
89
|
+
file.data["mdx-export"].push({
|
|
90
|
+
name,
|
|
91
|
+
value: file.data[name]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
})
|
|
78
96
|
],
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
97
|
+
mdxOptions.remarkPlugins
|
|
98
|
+
);
|
|
99
|
+
const rehypePlugins = pluginOption(
|
|
100
|
+
(v) => [
|
|
101
|
+
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
102
|
+
...v,
|
|
103
|
+
plugins.rehypeToc
|
|
84
104
|
],
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
],
|
|
95
|
-
mdxOptions.remarkPlugins
|
|
96
|
-
);
|
|
97
|
-
const rehypePlugins = pluginOption(
|
|
98
|
-
(v) => [
|
|
99
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
100
|
-
...v,
|
|
101
|
-
plugins.rehypeToc
|
|
102
|
-
],
|
|
103
|
-
mdxOptions.rehypePlugins
|
|
104
|
-
);
|
|
105
|
-
return {
|
|
106
|
-
...mdxOptions,
|
|
107
|
-
outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
|
|
108
|
-
remarkPlugins,
|
|
109
|
-
rehypePlugins
|
|
105
|
+
mdxOptions.rehypePlugins
|
|
106
|
+
);
|
|
107
|
+
return {
|
|
108
|
+
...mdxOptions,
|
|
109
|
+
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
110
|
+
remarkPlugins,
|
|
111
|
+
rehypePlugins
|
|
112
|
+
};
|
|
110
113
|
};
|
|
111
114
|
}
|
|
112
|
-
var plugins;
|
|
113
115
|
var init_preset = __esm({
|
|
114
|
-
"src/
|
|
116
|
+
"src/config/preset.ts"() {
|
|
115
117
|
"use strict";
|
|
116
|
-
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
117
118
|
}
|
|
118
119
|
});
|
|
119
120
|
|
|
@@ -124,7 +125,10 @@ function buildCollection(name, config) {
|
|
|
124
125
|
...config,
|
|
125
126
|
name,
|
|
126
127
|
meta: buildPrimitiveCollection(name, config.meta),
|
|
127
|
-
docs: buildPrimitiveCollection(name, config.docs)
|
|
128
|
+
docs: buildPrimitiveCollection(name, config.docs),
|
|
129
|
+
hasFile(filePath) {
|
|
130
|
+
return this.docs.hasFile(filePath) || this.meta.hasFile(filePath);
|
|
131
|
+
}
|
|
128
132
|
};
|
|
129
133
|
}
|
|
130
134
|
return buildPrimitiveCollection(name, config);
|
|
@@ -178,11 +182,6 @@ function buildConfig(config) {
|
|
|
178
182
|
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
179
183
|
);
|
|
180
184
|
}
|
|
181
|
-
if (loaded.collections) {
|
|
182
|
-
for (const [k, v] of Object.entries(loaded.collections)) {
|
|
183
|
-
collections.set(k, buildCollection(k, v));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
185
|
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
187
186
|
return {
|
|
188
187
|
global: loaded,
|
|
@@ -190,21 +189,22 @@ function buildConfig(config) {
|
|
|
190
189
|
getCollection(name) {
|
|
191
190
|
return collections.get(name);
|
|
192
191
|
},
|
|
193
|
-
|
|
194
|
-
const
|
|
192
|
+
getMDXOptions(collection, environment = "bundler") {
|
|
193
|
+
const key = collection ? `${environment}:${collection.name}` : environment;
|
|
194
|
+
const cached = mdxOptionsCache.get(key);
|
|
195
195
|
if (cached) return cached;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
196
|
+
let result;
|
|
197
|
+
if (collection?.mdxOptions) {
|
|
198
|
+
const optionsFn = collection.mdxOptions;
|
|
199
|
+
result = typeof optionsFn === "function" ? optionsFn(environment) : optionsFn;
|
|
200
|
+
} else {
|
|
201
|
+
result = (async () => {
|
|
202
|
+
const optionsFn = this.global.mdxOptions;
|
|
203
|
+
const options = typeof optionsFn === "function" ? await optionsFn() : optionsFn;
|
|
204
|
+
return applyMdxPreset(options)(environment);
|
|
205
|
+
})();
|
|
205
206
|
}
|
|
206
|
-
|
|
207
|
-
mdxOptionsCache.set(mode, result);
|
|
207
|
+
mdxOptionsCache.set(key, result);
|
|
208
208
|
return result;
|
|
209
209
|
}
|
|
210
210
|
};
|
|
@@ -214,6 +214,7 @@ var init_build = __esm({
|
|
|
214
214
|
"src/config/build.ts"() {
|
|
215
215
|
"use strict";
|
|
216
216
|
import_picomatch = __toESM(require("picomatch"), 1);
|
|
217
|
+
init_preset();
|
|
217
218
|
SupportedFormats = {
|
|
218
219
|
doc: ["mdx", "md"],
|
|
219
220
|
meta: ["json", "yaml"]
|
|
@@ -226,12 +227,12 @@ var load_from_file_exports = {};
|
|
|
226
227
|
__export(load_from_file_exports, {
|
|
227
228
|
loadConfig: () => loadConfig
|
|
228
229
|
});
|
|
229
|
-
async function compileConfig(
|
|
230
|
+
async function compileConfig(core) {
|
|
230
231
|
const { build } = await import("esbuild");
|
|
231
232
|
const transformed = await build({
|
|
232
|
-
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
233
|
+
entryPoints: [{ in: core._options.configPath, out: "source.config" }],
|
|
233
234
|
bundle: true,
|
|
234
|
-
outdir: outDir,
|
|
235
|
+
outdir: core._options.outDir,
|
|
235
236
|
target: "node20",
|
|
236
237
|
write: true,
|
|
237
238
|
platform: "node",
|
|
@@ -246,56 +247,24 @@ async function compileConfig(configPath, outDir) {
|
|
|
246
247
|
throw new Error("failed to compile configuration file");
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
|
-
async function loadConfig(
|
|
250
|
-
if (build) await compileConfig(
|
|
251
|
-
const url = (0, import_node_url.pathToFileURL)(
|
|
250
|
+
async function loadConfig(core, build = false) {
|
|
251
|
+
if (build) await compileConfig(core);
|
|
252
|
+
const url = (0, import_node_url.pathToFileURL)(core.getCompiledConfigPath());
|
|
252
253
|
url.searchParams.set("hash", Date.now().toString());
|
|
253
254
|
const config = import(url.href).then(
|
|
254
255
|
(loaded) => buildConfig(loaded)
|
|
255
256
|
);
|
|
256
257
|
return await config;
|
|
257
258
|
}
|
|
258
|
-
var
|
|
259
|
+
var import_node_url;
|
|
259
260
|
var init_load_from_file = __esm({
|
|
260
261
|
"src/config/load-from-file.ts"() {
|
|
261
262
|
"use strict";
|
|
262
|
-
path = __toESM(require("path"), 1);
|
|
263
263
|
import_node_url = require("url");
|
|
264
264
|
init_build();
|
|
265
265
|
}
|
|
266
266
|
});
|
|
267
267
|
|
|
268
|
-
// src/next/file-cache.ts
|
|
269
|
-
function toFullPath(file) {
|
|
270
|
-
if (import_node_path.default.isAbsolute(file)) {
|
|
271
|
-
return import_node_path.default.relative(process.cwd(), file);
|
|
272
|
-
}
|
|
273
|
-
return file;
|
|
274
|
-
}
|
|
275
|
-
async function readFileWithCache(file) {
|
|
276
|
-
const fullPath = toFullPath(file);
|
|
277
|
-
const cached = map.get(fullPath);
|
|
278
|
-
if (cached) return cached;
|
|
279
|
-
const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
|
|
280
|
-
map.set(fullPath, read);
|
|
281
|
-
return read;
|
|
282
|
-
}
|
|
283
|
-
function removeFileCache(file) {
|
|
284
|
-
map.delete(toFullPath(file));
|
|
285
|
-
}
|
|
286
|
-
var import_lru_cache, import_promises, import_node_path, map;
|
|
287
|
-
var init_file_cache = __esm({
|
|
288
|
-
"src/next/file-cache.ts"() {
|
|
289
|
-
"use strict";
|
|
290
|
-
import_lru_cache = require("lru-cache");
|
|
291
|
-
import_promises = __toESM(require("fs/promises"), 1);
|
|
292
|
-
import_node_path = __toESM(require("path"), 1);
|
|
293
|
-
map = new import_lru_cache.LRUCache({
|
|
294
|
-
max: 100
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
268
|
// src/utils/validation.ts
|
|
300
269
|
async function validate(schema, data, context, errorMessage) {
|
|
301
270
|
if (typeof schema === "function" && !("~standard" in schema)) {
|
|
@@ -312,11 +281,10 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
312
281
|
}
|
|
313
282
|
return data;
|
|
314
283
|
}
|
|
315
|
-
var
|
|
284
|
+
var ValidationError;
|
|
316
285
|
var init_validation = __esm({
|
|
317
286
|
"src/utils/validation.ts"() {
|
|
318
287
|
"use strict";
|
|
319
|
-
import_picocolors = __toESM(require("picocolors"), 1);
|
|
320
288
|
ValidationError = class extends Error {
|
|
321
289
|
constructor(message, issues) {
|
|
322
290
|
super(
|
|
@@ -326,12 +294,13 @@ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
|
326
294
|
this.title = message;
|
|
327
295
|
this.issues = issues;
|
|
328
296
|
}
|
|
329
|
-
toStringFormatted() {
|
|
297
|
+
async toStringFormatted() {
|
|
298
|
+
const picocolors = await import("picocolors");
|
|
330
299
|
return [
|
|
331
|
-
|
|
300
|
+
picocolors.bold(`[MDX] ${this.title}:`),
|
|
332
301
|
...this.issues.map(
|
|
333
|
-
(issue) =>
|
|
334
|
-
`- ${
|
|
302
|
+
(issue) => picocolors.redBright(
|
|
303
|
+
`- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
|
|
335
304
|
)
|
|
336
305
|
)
|
|
337
306
|
].join("\n");
|
|
@@ -340,32 +309,313 @@ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
|
340
309
|
}
|
|
341
310
|
});
|
|
342
311
|
|
|
343
|
-
// src/utils/
|
|
344
|
-
|
|
345
|
-
|
|
312
|
+
// src/utils/codegen/cache.ts
|
|
313
|
+
function toFullPath(file) {
|
|
314
|
+
if (import_node_path.default.isAbsolute(file)) {
|
|
315
|
+
return import_node_path.default.relative(process.cwd(), file);
|
|
316
|
+
}
|
|
317
|
+
return file;
|
|
318
|
+
}
|
|
319
|
+
async function readFileWithCache(file) {
|
|
320
|
+
const fullPath = toFullPath(file);
|
|
321
|
+
const cached = map.get(fullPath);
|
|
346
322
|
if (cached) return cached;
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
323
|
+
const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
|
|
324
|
+
map.set(fullPath, read);
|
|
325
|
+
return read;
|
|
326
|
+
}
|
|
327
|
+
function removeFileCache(file) {
|
|
328
|
+
map.delete(toFullPath(file));
|
|
329
|
+
}
|
|
330
|
+
var import_lru_cache, import_promises, import_node_path, map;
|
|
331
|
+
var init_cache = __esm({
|
|
332
|
+
"src/utils/codegen/cache.ts"() {
|
|
333
|
+
"use strict";
|
|
334
|
+
import_lru_cache = require("lru-cache");
|
|
335
|
+
import_promises = __toESM(require("fs/promises"), 1);
|
|
336
|
+
import_node_path = __toESM(require("path"), 1);
|
|
337
|
+
map = new import_lru_cache.LRUCache({
|
|
338
|
+
max: 100
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// src/core.ts
|
|
344
|
+
async function getPlugins(pluginOptions) {
|
|
345
|
+
const plugins = [];
|
|
346
|
+
for await (const option of pluginOptions) {
|
|
347
|
+
if (!option) continue;
|
|
348
|
+
if (Array.isArray(option)) plugins.push(...await getPlugins(option));
|
|
349
|
+
else plugins.push(option);
|
|
350
|
+
}
|
|
351
|
+
return plugins;
|
|
352
|
+
}
|
|
353
|
+
function createCore(options, defaultPlugins = []) {
|
|
354
|
+
let config;
|
|
355
|
+
let plugins;
|
|
356
|
+
async function transformMetadata({
|
|
357
|
+
collection,
|
|
358
|
+
filePath,
|
|
359
|
+
source
|
|
360
|
+
}, data) {
|
|
361
|
+
if (collection.schema) {
|
|
362
|
+
data = await validate(
|
|
363
|
+
collection.schema,
|
|
364
|
+
data,
|
|
365
|
+
{ path: filePath, source },
|
|
366
|
+
collection.type === "doc" ? `invalid frontmatter in ${filePath}` : `invalid data in ${filePath}`
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
return data;
|
|
360
370
|
}
|
|
371
|
+
const core = {
|
|
372
|
+
_options: options,
|
|
373
|
+
/**
|
|
374
|
+
* Convenient cache store, reset when config changes
|
|
375
|
+
*/
|
|
376
|
+
cache: /* @__PURE__ */ new Map(),
|
|
377
|
+
async init({ config: newConfig }) {
|
|
378
|
+
config = await newConfig;
|
|
379
|
+
this.cache.clear();
|
|
380
|
+
plugins = await getPlugins([
|
|
381
|
+
...defaultPlugins,
|
|
382
|
+
...config.global.plugins ?? []
|
|
383
|
+
]);
|
|
384
|
+
for (const plugin of plugins) {
|
|
385
|
+
const out = await plugin.config?.call(pluginContext, config);
|
|
386
|
+
if (out) config = out;
|
|
387
|
+
}
|
|
388
|
+
return this;
|
|
389
|
+
},
|
|
390
|
+
getConfig() {
|
|
391
|
+
return config;
|
|
392
|
+
},
|
|
393
|
+
/**
|
|
394
|
+
* The file path of compiled config file, the file may not exist (e.g. on Vite, or still compiling)
|
|
395
|
+
*/
|
|
396
|
+
getCompiledConfigPath() {
|
|
397
|
+
return import_node_path2.default.join(options.outDir, "source.config.mjs");
|
|
398
|
+
},
|
|
399
|
+
async initServer(server) {
|
|
400
|
+
server.watcher?.on("all", async (event, file) => {
|
|
401
|
+
if (event === "change") removeFileCache(file);
|
|
402
|
+
});
|
|
403
|
+
for (const plugin of plugins) {
|
|
404
|
+
await plugin.configureServer?.call(pluginContext, server);
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
async emit({ filterPlugin = () => true } = {}) {
|
|
408
|
+
return (await Promise.all(
|
|
409
|
+
plugins.map((plugin) => {
|
|
410
|
+
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
411
|
+
return plugin.emit.call(pluginContext);
|
|
412
|
+
})
|
|
413
|
+
)).flat();
|
|
414
|
+
},
|
|
415
|
+
async emitAndWrite(emitOptions) {
|
|
416
|
+
const start2 = performance.now();
|
|
417
|
+
const out = await this.emit(emitOptions);
|
|
418
|
+
await Promise.all(
|
|
419
|
+
out.map(async (entry) => {
|
|
420
|
+
const file = import_node_path2.default.join(options.outDir, entry.path);
|
|
421
|
+
await import_promises2.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
|
|
422
|
+
await import_promises2.default.writeFile(file, entry.content);
|
|
423
|
+
})
|
|
424
|
+
);
|
|
425
|
+
console.log(`[MDX] generated files in ${performance.now() - start2}ms`);
|
|
426
|
+
},
|
|
427
|
+
async transformMeta(options2, data) {
|
|
428
|
+
const ctx = {
|
|
429
|
+
...pluginContext,
|
|
430
|
+
...options2
|
|
431
|
+
};
|
|
432
|
+
data = await transformMetadata(options2, data);
|
|
433
|
+
for (const plugin of plugins) {
|
|
434
|
+
if (plugin.meta?.transform)
|
|
435
|
+
data = await plugin.meta.transform.call(ctx, data) ?? data;
|
|
436
|
+
}
|
|
437
|
+
return data;
|
|
438
|
+
},
|
|
439
|
+
async transformFrontmatter(options2, data) {
|
|
440
|
+
const ctx = {
|
|
441
|
+
...pluginContext,
|
|
442
|
+
...options2
|
|
443
|
+
};
|
|
444
|
+
data = await transformMetadata(options2, data);
|
|
445
|
+
for (const plugin of plugins) {
|
|
446
|
+
if (plugin.doc?.frontmatter)
|
|
447
|
+
data = await plugin.doc.frontmatter.call(ctx, data) ?? data;
|
|
448
|
+
}
|
|
449
|
+
return data;
|
|
450
|
+
},
|
|
451
|
+
async transformVFile(options2, file) {
|
|
452
|
+
const ctx = {
|
|
453
|
+
...pluginContext,
|
|
454
|
+
...options2
|
|
455
|
+
};
|
|
456
|
+
for (const plugin of plugins) {
|
|
457
|
+
if (plugin.doc?.vfile)
|
|
458
|
+
file = await plugin.doc.vfile.call(ctx, file) ?? file;
|
|
459
|
+
}
|
|
460
|
+
return file;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const pluginContext = {
|
|
464
|
+
core,
|
|
465
|
+
...options
|
|
466
|
+
};
|
|
467
|
+
return core;
|
|
361
468
|
}
|
|
362
|
-
var import_node_path2,
|
|
363
|
-
var
|
|
364
|
-
"src/
|
|
469
|
+
var import_node_path2, import_promises2, _Defaults;
|
|
470
|
+
var init_core = __esm({
|
|
471
|
+
"src/core.ts"() {
|
|
365
472
|
"use strict";
|
|
366
473
|
import_node_path2 = __toESM(require("path"), 1);
|
|
367
|
-
|
|
368
|
-
|
|
474
|
+
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
475
|
+
init_cache();
|
|
476
|
+
init_validation();
|
|
477
|
+
_Defaults = {
|
|
478
|
+
configPath: "source.config.ts",
|
|
479
|
+
outDir: ".source"
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
// src/loaders/index.ts
|
|
485
|
+
var metaLoaderGlob, mdxLoaderGlob;
|
|
486
|
+
var init_loaders = __esm({
|
|
487
|
+
"src/loaders/index.ts"() {
|
|
488
|
+
"use strict";
|
|
489
|
+
metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
490
|
+
mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// src/utils/codegen/index.ts
|
|
495
|
+
function createCodegen({
|
|
496
|
+
target = "default",
|
|
497
|
+
outDir = "",
|
|
498
|
+
jsExtension = false,
|
|
499
|
+
globCache = /* @__PURE__ */ new Map()
|
|
500
|
+
}) {
|
|
501
|
+
let eagerImportId = 0;
|
|
502
|
+
const banner = ["// @ts-nocheck"];
|
|
503
|
+
if (target === "vite") {
|
|
504
|
+
banner.push('/// <reference types="vite/client" />');
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
options: {
|
|
508
|
+
target,
|
|
509
|
+
outDir
|
|
510
|
+
},
|
|
511
|
+
lines: [],
|
|
512
|
+
addImport(statement) {
|
|
513
|
+
this.lines.unshift(statement);
|
|
514
|
+
},
|
|
515
|
+
async pushAsync(insert) {
|
|
516
|
+
for (const line of await Promise.all(insert)) {
|
|
517
|
+
if (line === void 0) continue;
|
|
518
|
+
this.lines.push(line);
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
async generateGlobImport(patterns, options) {
|
|
522
|
+
if (target === "vite") {
|
|
523
|
+
return this.generateViteGlobImport(patterns, options);
|
|
524
|
+
}
|
|
525
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
526
|
+
},
|
|
527
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
528
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
529
|
+
normalizeViteGlobPath
|
|
530
|
+
);
|
|
531
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
532
|
+
{
|
|
533
|
+
base: normalizeViteGlobPath(import_node_path3.default.relative(outDir, base)),
|
|
534
|
+
...rest
|
|
535
|
+
},
|
|
536
|
+
null,
|
|
537
|
+
2
|
|
538
|
+
)})`;
|
|
539
|
+
},
|
|
540
|
+
async generateNodeGlobImport(patterns, {
|
|
541
|
+
base,
|
|
542
|
+
eager = false,
|
|
543
|
+
query = {},
|
|
544
|
+
import: importName
|
|
545
|
+
}) {
|
|
546
|
+
const cacheKey = JSON.stringify({ patterns, base });
|
|
547
|
+
let files = globCache.get(cacheKey);
|
|
548
|
+
if (!files) {
|
|
549
|
+
files = (0, import_tinyglobby.glob)(patterns, {
|
|
550
|
+
cwd: base
|
|
551
|
+
});
|
|
552
|
+
globCache.set(cacheKey, files);
|
|
553
|
+
}
|
|
554
|
+
let code = "{";
|
|
555
|
+
for (const item of await files) {
|
|
556
|
+
const fullPath = import_node_path3.default.join(base, item);
|
|
557
|
+
const searchParams = new URLSearchParams();
|
|
558
|
+
for (const [k, v] of Object.entries(query)) {
|
|
559
|
+
searchParams.set(k, v);
|
|
560
|
+
}
|
|
561
|
+
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
562
|
+
if (eager) {
|
|
563
|
+
const name = `__fd_glob_${eagerImportId++}`;
|
|
564
|
+
this.lines.unshift(
|
|
565
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
566
|
+
);
|
|
567
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
568
|
+
} else {
|
|
569
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
570
|
+
if (importName) {
|
|
571
|
+
line += `.then(mod => mod.${importName})`;
|
|
572
|
+
}
|
|
573
|
+
code += `${line}, `;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
code += "}";
|
|
577
|
+
return code;
|
|
578
|
+
},
|
|
579
|
+
formatImportPath(file) {
|
|
580
|
+
const ext = import_node_path3.default.extname(file);
|
|
581
|
+
let filename;
|
|
582
|
+
if (ext === ".ts" && jsExtension) {
|
|
583
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
584
|
+
} else if (ext === ".ts") {
|
|
585
|
+
filename = file.substring(0, file.length - ext.length);
|
|
586
|
+
} else {
|
|
587
|
+
filename = file;
|
|
588
|
+
}
|
|
589
|
+
const importPath = slash(import_node_path3.default.relative(outDir, filename));
|
|
590
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
591
|
+
},
|
|
592
|
+
toString() {
|
|
593
|
+
return [...banner, ...this.lines].join("\n");
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function normalizeViteGlobPath(file) {
|
|
598
|
+
file = slash(file);
|
|
599
|
+
if (file.startsWith("./")) return file;
|
|
600
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
601
|
+
return `./${file}`;
|
|
602
|
+
}
|
|
603
|
+
function slash(path9) {
|
|
604
|
+
const isExtendedLengthPath = path9.startsWith("\\\\?\\");
|
|
605
|
+
if (isExtendedLengthPath) {
|
|
606
|
+
return path9;
|
|
607
|
+
}
|
|
608
|
+
return path9.replaceAll("\\", "/");
|
|
609
|
+
}
|
|
610
|
+
function ident(code, tab = 1) {
|
|
611
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
612
|
+
}
|
|
613
|
+
var import_node_path3, import_tinyglobby;
|
|
614
|
+
var init_codegen = __esm({
|
|
615
|
+
"src/utils/codegen/index.ts"() {
|
|
616
|
+
"use strict";
|
|
617
|
+
import_node_path3 = __toESM(require("path"), 1);
|
|
618
|
+
import_tinyglobby = require("tinyglobby");
|
|
369
619
|
}
|
|
370
620
|
});
|
|
371
621
|
|
|
@@ -391,343 +641,284 @@ var init_fuma_matter = __esm({
|
|
|
391
641
|
}
|
|
392
642
|
});
|
|
393
643
|
|
|
394
|
-
// src/
|
|
395
|
-
function
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
(name) => Array.isArray(name) ? `${name[0]} as ${name[1]}` : name
|
|
403
|
-
);
|
|
404
|
-
return `import { ${names.join(", ")} } from ${specifier}`;
|
|
405
|
-
}
|
|
406
|
-
return `import ${specifier}`;
|
|
407
|
-
}
|
|
408
|
-
function toImportPath(file, config) {
|
|
409
|
-
const ext = import_node_path3.default.extname(file);
|
|
410
|
-
let filename;
|
|
411
|
-
if (ext === ".ts" && config.jsExtension) {
|
|
412
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
413
|
-
} else if (ext === ".ts") {
|
|
414
|
-
filename = file.substring(0, file.length - ext.length);
|
|
415
|
-
} else {
|
|
416
|
-
filename = file;
|
|
417
|
-
}
|
|
418
|
-
let importPath;
|
|
419
|
-
if ("relativeTo" in config) {
|
|
420
|
-
importPath = import_node_path3.default.relative(config.relativeTo, filename);
|
|
421
|
-
if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
422
|
-
importPath = `./${importPath}`;
|
|
423
|
-
}
|
|
424
|
-
} else {
|
|
425
|
-
importPath = import_node_path3.default.resolve(filename);
|
|
426
|
-
}
|
|
427
|
-
return importPath.replaceAll(import_node_path3.default.sep, "/");
|
|
428
|
-
}
|
|
429
|
-
function ident(code, tab = 1) {
|
|
430
|
-
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
431
|
-
}
|
|
432
|
-
var import_node_path3;
|
|
433
|
-
var init_import_formatter = __esm({
|
|
434
|
-
"src/utils/import-formatter.ts"() {
|
|
435
|
-
"use strict";
|
|
436
|
-
import_node_path3 = __toESM(require("path"), 1);
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
// src/plugins/next.ts
|
|
441
|
-
function next() {
|
|
644
|
+
// src/plugins/index-file.ts
|
|
645
|
+
function indexFile(options = {}) {
|
|
646
|
+
const {
|
|
647
|
+
target = "default",
|
|
648
|
+
addJsExtension,
|
|
649
|
+
browser = true,
|
|
650
|
+
dynamic = true
|
|
651
|
+
} = options;
|
|
442
652
|
let config;
|
|
443
|
-
let
|
|
653
|
+
let dynamicCollections;
|
|
654
|
+
function isDynamic(collection) {
|
|
655
|
+
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
656
|
+
}
|
|
444
657
|
return {
|
|
445
|
-
name: "
|
|
658
|
+
name: "index-file",
|
|
446
659
|
config(v) {
|
|
447
660
|
config = v;
|
|
448
|
-
|
|
449
|
-
return collection.type === "doc" && collection.async || collection.type === "docs" || collection.type === "meta";
|
|
450
|
-
});
|
|
661
|
+
dynamicCollections = config.collectionList.filter(isDynamic);
|
|
451
662
|
},
|
|
452
663
|
configureServer(server) {
|
|
453
664
|
if (!server.watcher) return;
|
|
454
|
-
server.watcher.on("all", async (event) => {
|
|
455
|
-
if (
|
|
665
|
+
server.watcher.on("all", async (event, file) => {
|
|
666
|
+
if (dynamicCollections.length === 0) {
|
|
667
|
+
if (target === "vite") return;
|
|
668
|
+
if (target === "default" && event === "change") return;
|
|
669
|
+
}
|
|
670
|
+
const updatedCollection = config.collectionList.find(
|
|
671
|
+
(collection) => collection.hasFile(file)
|
|
672
|
+
);
|
|
673
|
+
if (!updatedCollection) return;
|
|
674
|
+
if (!isDynamic(updatedCollection)) {
|
|
675
|
+
if (target === "vite") return;
|
|
676
|
+
if (target === "default" && event === "change") return;
|
|
677
|
+
}
|
|
456
678
|
await this.core.emitAndWrite({
|
|
457
|
-
filterPlugin: (plugin) => plugin.name === "
|
|
679
|
+
filterPlugin: (plugin) => plugin.name === "index-file"
|
|
458
680
|
});
|
|
459
681
|
});
|
|
460
682
|
},
|
|
461
683
|
async emit() {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
];
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
async function indexFile(configPath, config, importPath) {
|
|
474
|
-
let asyncInit = false;
|
|
475
|
-
const lines = [
|
|
476
|
-
getImportCode({
|
|
477
|
-
type: "named",
|
|
478
|
-
names: ["_runtime"],
|
|
479
|
-
specifier: "fumadocs-mdx/runtime/next"
|
|
480
|
-
}),
|
|
481
|
-
getImportCode({
|
|
482
|
-
type: "namespace",
|
|
483
|
-
specifier: toImportPath(configPath, importPath),
|
|
484
|
-
name: "_source"
|
|
485
|
-
})
|
|
486
|
-
];
|
|
487
|
-
function getDocEntries(collection, files) {
|
|
488
|
-
return files.map((file, i) => {
|
|
489
|
-
const importId = `d_${collection.name}_${i}`;
|
|
490
|
-
const params = [`collection=${collection.name}`];
|
|
491
|
-
lines.unshift(
|
|
492
|
-
getImportCode({
|
|
493
|
-
type: "namespace",
|
|
494
|
-
name: importId,
|
|
495
|
-
specifier: `${toImportPath(file.fullPath, importPath)}?${params.join("&")}`
|
|
496
|
-
})
|
|
497
|
-
);
|
|
498
|
-
return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
async function getMetaEntries(collection, files) {
|
|
502
|
-
const items = files.map(async (file) => {
|
|
503
|
-
const source = await readFileWithCache(file.fullPath).catch(() => "");
|
|
504
|
-
let data = source.length === 0 ? {} : parseMetaEntry(file.fullPath, source);
|
|
505
|
-
if (collection?.schema) {
|
|
506
|
-
data = await validate(
|
|
507
|
-
collection.schema,
|
|
508
|
-
data,
|
|
509
|
-
{
|
|
510
|
-
source,
|
|
511
|
-
path: file.fullPath
|
|
512
|
-
},
|
|
513
|
-
`invalid data in ${file.fullPath}`
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
return JSON.stringify({
|
|
517
|
-
info: file,
|
|
518
|
-
data
|
|
684
|
+
const globCache = /* @__PURE__ */ new Map();
|
|
685
|
+
const makeCodeGen = () => createCodegen({
|
|
686
|
+
target,
|
|
687
|
+
outDir: this.outDir,
|
|
688
|
+
jsExtension: addJsExtension,
|
|
689
|
+
globCache
|
|
519
690
|
});
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
lines.unshift(
|
|
526
|
-
getImportCode({
|
|
527
|
-
type: "named",
|
|
528
|
-
specifier: "fumadocs-mdx/runtime/async",
|
|
529
|
-
names: ["_runtimeAsync", "buildConfig"]
|
|
530
|
-
}),
|
|
531
|
-
"const _sourceConfig = buildConfig(_source)",
|
|
532
|
-
getImportCode({
|
|
533
|
-
type: "default",
|
|
534
|
-
name: "path",
|
|
535
|
-
specifier: "node:path"
|
|
536
|
-
})
|
|
537
|
-
);
|
|
538
|
-
asyncInit = true;
|
|
539
|
-
}
|
|
540
|
-
const entries = files.map(async (file) => {
|
|
541
|
-
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
542
|
-
const parsed = fumaMatter(content);
|
|
543
|
-
let data = parsed.data;
|
|
544
|
-
if (collection.schema) {
|
|
545
|
-
data = await validate(
|
|
546
|
-
collection.schema,
|
|
547
|
-
parsed.data,
|
|
548
|
-
{ path: file.fullPath, source: parsed.content },
|
|
549
|
-
`invalid frontmatter in ${file.fullPath}`
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
let lastModified;
|
|
553
|
-
if (config.global?.lastModifiedTime === "git") {
|
|
554
|
-
lastModified = await getGitTimestamp(file.fullPath);
|
|
555
|
-
}
|
|
556
|
-
const hash = (0, import_node_crypto.createHash)("md5").update(content).digest("hex");
|
|
557
|
-
const infoStr = [];
|
|
558
|
-
for (const [k, v] of Object.entries({ ...file, hash })) {
|
|
559
|
-
infoStr.push(`${k}: ${JSON.stringify(v)}`);
|
|
691
|
+
async function toEmitEntry(path9, content) {
|
|
692
|
+
return {
|
|
693
|
+
path: path9,
|
|
694
|
+
content: await content
|
|
695
|
+
};
|
|
560
696
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
|
|
574
|
-
", "
|
|
575
|
-
);
|
|
576
|
-
if (collection.docs.async) {
|
|
577
|
-
const docsEntries2 = (await getAsyncEntries(collection.docs, docs)).join(
|
|
578
|
-
", "
|
|
697
|
+
const out = [
|
|
698
|
+
toEmitEntry(
|
|
699
|
+
"server.ts",
|
|
700
|
+
generateServerIndexFile(makeCodeGen(), config, this.configPath)
|
|
701
|
+
)
|
|
702
|
+
];
|
|
703
|
+
if (dynamic)
|
|
704
|
+
out.push(
|
|
705
|
+
toEmitEntry(
|
|
706
|
+
"dynamic.ts",
|
|
707
|
+
generateDynamicIndexFile(this.core, makeCodeGen())
|
|
708
|
+
)
|
|
579
709
|
);
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
return
|
|
588
|
-
}
|
|
589
|
-
if (collection.async) {
|
|
590
|
-
return `export const ${k} = _runtimeAsync.doc<typeof _source.${k}>([${(await getAsyncEntries(collection, files)).join(", ")}], "${k}", _sourceConfig)`;
|
|
710
|
+
if (browser)
|
|
711
|
+
out.push(
|
|
712
|
+
toEmitEntry(
|
|
713
|
+
"browser.ts",
|
|
714
|
+
generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
|
|
715
|
+
)
|
|
716
|
+
);
|
|
717
|
+
return await Promise.all(out);
|
|
591
718
|
}
|
|
592
|
-
|
|
593
|
-
});
|
|
594
|
-
const resolvedDeclares = await Promise.all(declares);
|
|
595
|
-
return [
|
|
596
|
-
`// @ts-nocheck -- skip type checking`,
|
|
597
|
-
...lines,
|
|
598
|
-
...resolvedDeclares
|
|
599
|
-
].join("\n");
|
|
600
|
-
}
|
|
601
|
-
function parseMetaEntry(file, content) {
|
|
602
|
-
const extname3 = path5.extname(file);
|
|
603
|
-
try {
|
|
604
|
-
if (extname3 === ".json") return JSON.parse(content);
|
|
605
|
-
if (extname3 === ".yaml") return (0, import_js_yaml2.load)(content);
|
|
606
|
-
} catch (e) {
|
|
607
|
-
throw new Error(`Failed to parse meta file: ${file}.`, {
|
|
608
|
-
cause: e
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
throw new Error(`Unknown meta file format: ${extname3}, in ${file}.`);
|
|
719
|
+
};
|
|
612
720
|
}
|
|
613
|
-
async function
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const result = await glob(collection.patterns, {
|
|
620
|
-
cwd: path5.resolve(dir)
|
|
621
|
-
});
|
|
622
|
-
for (const item of result) {
|
|
623
|
-
if (!collection.isFileSupported(item)) continue;
|
|
624
|
-
const fullPath = path5.join(dir, item);
|
|
625
|
-
files.set(fullPath, {
|
|
626
|
-
path: item,
|
|
627
|
-
fullPath
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
})
|
|
721
|
+
async function generateServerIndexFile(codegen, config, configPath) {
|
|
722
|
+
codegen.lines.push(
|
|
723
|
+
`import { fromConfig } from 'fumadocs-mdx/runtime/server';`,
|
|
724
|
+
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
725
|
+
"",
|
|
726
|
+
`const create = fromConfig<typeof Config>();`
|
|
631
727
|
);
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
728
|
+
async function generateCollectionObject(collection) {
|
|
729
|
+
switch (collection.type) {
|
|
730
|
+
case "docs": {
|
|
731
|
+
if (collection.docs.dynamic) return;
|
|
732
|
+
if (collection.docs.async) {
|
|
733
|
+
const [metaGlob2, headGlob, bodyGlob] = await Promise.all([
|
|
734
|
+
generateMetaCollectionGlob(codegen, collection.meta, true),
|
|
735
|
+
generateDocCollectionFrontmatterGlob(
|
|
736
|
+
codegen,
|
|
737
|
+
collection.docs,
|
|
738
|
+
true
|
|
739
|
+
),
|
|
740
|
+
generateDocCollectionGlob(codegen, collection.docs)
|
|
741
|
+
]);
|
|
742
|
+
return `await create.docsLazy("${collection.name}", "${collection.dir}", ${metaGlob2}, ${headGlob}, ${bodyGlob})`;
|
|
743
|
+
}
|
|
744
|
+
const [metaGlob, docGlob] = await Promise.all([
|
|
745
|
+
generateMetaCollectionGlob(codegen, collection.meta, true),
|
|
746
|
+
generateDocCollectionGlob(codegen, collection.docs, true)
|
|
747
|
+
]);
|
|
748
|
+
return `await create.docs("${collection.name}", "${collection.dir}", ${metaGlob}, ${docGlob})`;
|
|
749
|
+
}
|
|
750
|
+
case "doc":
|
|
751
|
+
if (collection.dynamic) return;
|
|
752
|
+
if (collection.async) {
|
|
753
|
+
const [headGlob, bodyGlob] = await Promise.all([
|
|
754
|
+
generateDocCollectionFrontmatterGlob(codegen, collection, true),
|
|
755
|
+
generateDocCollectionGlob(codegen, collection)
|
|
756
|
+
]);
|
|
757
|
+
return `await create.docLazy("${collection.name}", "${collection.dir}", ${headGlob}, ${bodyGlob})`;
|
|
758
|
+
}
|
|
759
|
+
return `await create.doc("${collection.name}", "${collection.dir}", ${await generateDocCollectionGlob(
|
|
760
|
+
codegen,
|
|
761
|
+
collection,
|
|
762
|
+
true
|
|
763
|
+
)})`;
|
|
764
|
+
case "meta":
|
|
765
|
+
return `await create.meta("${collection.name}", "${collection.dir}", ${await generateMetaCollectionGlob(
|
|
766
|
+
codegen,
|
|
767
|
+
collection,
|
|
768
|
+
true
|
|
769
|
+
)})`;
|
|
770
|
+
}
|
|
646
771
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
772
|
+
await codegen.pushAsync(
|
|
773
|
+
config.collectionList.map(async (collection) => {
|
|
774
|
+
const obj = await generateCollectionObject(collection);
|
|
775
|
+
if (!obj) return;
|
|
776
|
+
return `
|
|
777
|
+
export const ${collection.name} = ${obj};`;
|
|
778
|
+
})
|
|
779
|
+
);
|
|
780
|
+
return codegen.toString();
|
|
781
|
+
}
|
|
782
|
+
async function generateDynamicIndexFile(core, codegen) {
|
|
783
|
+
const { configPath } = core._options;
|
|
784
|
+
codegen.lines.push(
|
|
785
|
+
`import { fromConfigDynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
786
|
+
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
787
|
+
"",
|
|
788
|
+
`const create = await fromConfigDynamic(Config);`
|
|
789
|
+
);
|
|
790
|
+
async function generateCollectionObjectEntry(collection, file) {
|
|
791
|
+
const fullPath = import_path.default.join(collection.dir, file);
|
|
792
|
+
const content = await readFileWithCache(fullPath).catch(() => "");
|
|
793
|
+
const parsed = fumaMatter(content);
|
|
794
|
+
const data = await core.transformFrontmatter(
|
|
795
|
+
{
|
|
796
|
+
collection,
|
|
797
|
+
filePath: fullPath,
|
|
798
|
+
source: content
|
|
799
|
+
},
|
|
800
|
+
parsed.data
|
|
801
|
+
);
|
|
802
|
+
const hash = (0, import_crypto.createHash)("md5").update(content).digest("hex");
|
|
803
|
+
const infoStr = [
|
|
804
|
+
// make sure it's included in vercel/nft
|
|
805
|
+
`absolutePath: path.resolve(${JSON.stringify(fullPath)})`
|
|
806
|
+
];
|
|
807
|
+
for (const [k, v] of Object.entries({
|
|
808
|
+
info: {
|
|
809
|
+
fullPath,
|
|
810
|
+
path: file
|
|
811
|
+
},
|
|
812
|
+
data,
|
|
813
|
+
hash
|
|
814
|
+
})) {
|
|
815
|
+
infoStr.push(`${k}: ${JSON.stringify(v)}`);
|
|
816
|
+
}
|
|
817
|
+
return `{ ${infoStr.join(", ")} }`;
|
|
818
|
+
}
|
|
819
|
+
async function generateCollectionObject(parent) {
|
|
820
|
+
let collection;
|
|
821
|
+
if (parent.type === "doc") collection = parent;
|
|
822
|
+
else if (parent.type === "docs") collection = parent.docs;
|
|
823
|
+
if (!collection || !collection.dynamic) return;
|
|
824
|
+
const files = await (0, import_tinyglobby2.glob)(collection.patterns, {
|
|
825
|
+
cwd: collection.dir
|
|
826
|
+
});
|
|
827
|
+
const entries = await Promise.all(
|
|
828
|
+
files.map((file) => generateCollectionObjectEntry(collection, file))
|
|
829
|
+
);
|
|
830
|
+
switch (parent.type) {
|
|
831
|
+
case "docs": {
|
|
832
|
+
const metaGlob = await generateMetaCollectionGlob(
|
|
833
|
+
codegen,
|
|
834
|
+
parent.meta,
|
|
835
|
+
true
|
|
836
|
+
);
|
|
837
|
+
return `await create.docs("${parent.name}", "${parent.dir}", ${metaGlob}, ${entries.join(", ")})`;
|
|
679
838
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
839
|
+
case "doc":
|
|
840
|
+
return `await create.doc("${collection.name}", "${collection.dir}", ${entries.join(", ")})`;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
await codegen.pushAsync(
|
|
844
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
845
|
+
const obj = await generateCollectionObject(collection);
|
|
846
|
+
if (!obj) return;
|
|
847
|
+
return `
|
|
848
|
+
export const ${collection.name} = ${obj};`;
|
|
849
|
+
})
|
|
850
|
+
);
|
|
851
|
+
return codegen.toString();
|
|
852
|
+
}
|
|
853
|
+
async function generateBrowserIndexFile(codegen, config, configPath) {
|
|
854
|
+
codegen.lines.push(
|
|
855
|
+
`import { fromConfig } from 'fumadocs-mdx/runtime/browser';`,
|
|
856
|
+
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
857
|
+
"",
|
|
858
|
+
`const create = fromConfig<typeof Config>();`
|
|
859
|
+
);
|
|
860
|
+
async function generateCollectionObject(collection) {
|
|
861
|
+
switch (collection.type) {
|
|
862
|
+
case "docs": {
|
|
863
|
+
if (collection.docs.dynamic) return;
|
|
864
|
+
return generateCollectionObject(collection.docs);
|
|
683
865
|
}
|
|
684
|
-
|
|
866
|
+
case "doc":
|
|
867
|
+
if (collection.dynamic) return;
|
|
868
|
+
return `create.doc("${collection.name}", ${await generateDocCollectionGlob(codegen, collection)})`;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
codegen.lines.push("const browserCollections = {");
|
|
872
|
+
await codegen.pushAsync(
|
|
873
|
+
config.collectionList.map(async (collection) => {
|
|
874
|
+
const obj = await generateCollectionObject(collection);
|
|
875
|
+
if (!obj) return;
|
|
876
|
+
return ident(`${collection.name}: ${obj},`);
|
|
877
|
+
})
|
|
878
|
+
);
|
|
879
|
+
codegen.lines.push("};", "export default browserCollections;");
|
|
880
|
+
return codegen.toString();
|
|
881
|
+
}
|
|
882
|
+
function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
|
|
883
|
+
return codegen.generateGlobImport(collection.patterns, {
|
|
884
|
+
query: {
|
|
885
|
+
collection: collection.name,
|
|
886
|
+
only: "frontmatter"
|
|
685
887
|
},
|
|
686
|
-
|
|
687
|
-
|
|
888
|
+
import: "frontmatter",
|
|
889
|
+
base: collection.dir,
|
|
890
|
+
eager
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
function generateDocCollectionGlob(codegen, collection, eager = false) {
|
|
894
|
+
return codegen.generateGlobImport(collection.patterns, {
|
|
895
|
+
query: {
|
|
896
|
+
collection: collection.name
|
|
688
897
|
},
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
898
|
+
base: collection.dir,
|
|
899
|
+
eager
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
function generateMetaCollectionGlob(codegen, collection, eager = false) {
|
|
903
|
+
return codegen.generateGlobImport(collection.patterns, {
|
|
904
|
+
query: {
|
|
905
|
+
collection: collection.name
|
|
693
906
|
},
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
const out = await Promise.all(
|
|
699
|
-
plugins2.map((plugin) => {
|
|
700
|
-
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
701
|
-
return plugin.emit.call(this.getPluginContext());
|
|
702
|
-
})
|
|
703
|
-
);
|
|
704
|
-
await Promise.all(
|
|
705
|
-
out.flat().map(async (entry) => {
|
|
706
|
-
const file = import_node_path4.default.join(options.outDir, entry.path);
|
|
707
|
-
await import_promises2.default.mkdir(import_node_path4.default.dirname(file), { recursive: true });
|
|
708
|
-
await import_promises2.default.writeFile(file, entry.content);
|
|
709
|
-
})
|
|
710
|
-
);
|
|
711
|
-
console.log(`[MDX] generated files in ${performance.now() - start2}ms`);
|
|
712
|
-
}
|
|
713
|
-
};
|
|
907
|
+
import: "default",
|
|
908
|
+
base: collection.dir,
|
|
909
|
+
eager
|
|
910
|
+
});
|
|
714
911
|
}
|
|
715
|
-
var
|
|
716
|
-
var
|
|
717
|
-
"src/
|
|
718
|
-
"use strict";
|
|
719
|
-
import_node_path4 = __toESM(require("path"), 1);
|
|
720
|
-
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
// src/loaders/index.ts
|
|
725
|
-
var metaLoaderGlob, mdxLoaderGlob;
|
|
726
|
-
var init_loaders = __esm({
|
|
727
|
-
"src/loaders/index.ts"() {
|
|
912
|
+
var import_path, import_tinyglobby2, import_crypto;
|
|
913
|
+
var init_index_file = __esm({
|
|
914
|
+
"src/plugins/index-file.ts"() {
|
|
728
915
|
"use strict";
|
|
729
|
-
|
|
730
|
-
|
|
916
|
+
import_path = __toESM(require("path"), 1);
|
|
917
|
+
init_codegen();
|
|
918
|
+
import_tinyglobby2 = require("tinyglobby");
|
|
919
|
+
init_cache();
|
|
920
|
+
import_crypto = require("crypto");
|
|
921
|
+
init_fuma_matter();
|
|
731
922
|
}
|
|
732
923
|
});
|
|
733
924
|
|
|
@@ -738,15 +929,16 @@ __export(next_exports, {
|
|
|
738
929
|
postInstall: () => postInstall
|
|
739
930
|
});
|
|
740
931
|
function createMDX(createOptions = {}) {
|
|
741
|
-
const
|
|
932
|
+
const core = createNextCore(applyDefaults(createOptions));
|
|
742
933
|
const isDev = process.env.NODE_ENV === "development";
|
|
743
934
|
if (process.env._FUMADOCS_MDX !== "1") {
|
|
744
935
|
process.env._FUMADOCS_MDX = "1";
|
|
745
|
-
void init(isDev,
|
|
936
|
+
void init(isDev, core);
|
|
746
937
|
}
|
|
747
938
|
return (nextConfig = {}) => {
|
|
748
939
|
const loaderOptions = {
|
|
749
|
-
...
|
|
940
|
+
...core._options,
|
|
941
|
+
compiledConfigPath: core.getCompiledConfigPath(),
|
|
750
942
|
isDev
|
|
751
943
|
};
|
|
752
944
|
const turbopack = {
|
|
@@ -761,6 +953,24 @@ function createMDX(createOptions = {}) {
|
|
|
761
953
|
}
|
|
762
954
|
],
|
|
763
955
|
as: "*.js"
|
|
956
|
+
},
|
|
957
|
+
"*.json": {
|
|
958
|
+
loaders: [
|
|
959
|
+
{
|
|
960
|
+
loader: "fumadocs-mdx/loader-meta",
|
|
961
|
+
options: loaderOptions
|
|
962
|
+
}
|
|
963
|
+
],
|
|
964
|
+
as: "*.json"
|
|
965
|
+
},
|
|
966
|
+
"*.yaml": {
|
|
967
|
+
loaders: [
|
|
968
|
+
{
|
|
969
|
+
loader: "fumadocs-mdx/loader-meta",
|
|
970
|
+
options: loaderOptions
|
|
971
|
+
}
|
|
972
|
+
],
|
|
973
|
+
as: "*.js"
|
|
764
974
|
}
|
|
765
975
|
}
|
|
766
976
|
};
|
|
@@ -768,31 +978,42 @@ function createMDX(createOptions = {}) {
|
|
|
768
978
|
...nextConfig,
|
|
769
979
|
turbopack,
|
|
770
980
|
pageExtensions: nextConfig.pageExtensions ?? defaultPageExtensions,
|
|
771
|
-
webpack: (config,
|
|
981
|
+
webpack: (config, options) => {
|
|
772
982
|
config.resolve ||= {};
|
|
773
983
|
config.module ||= {};
|
|
774
984
|
config.module.rules ||= [];
|
|
775
|
-
config.module.rules.push(
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
985
|
+
config.module.rules.push(
|
|
986
|
+
{
|
|
987
|
+
test: mdxLoaderGlob,
|
|
988
|
+
use: [
|
|
989
|
+
options.defaultLoaders.babel,
|
|
990
|
+
{
|
|
991
|
+
loader: "fumadocs-mdx/loader-mdx",
|
|
992
|
+
options: loaderOptions
|
|
993
|
+
}
|
|
994
|
+
]
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
test: metaLoaderGlob,
|
|
998
|
+
use: [
|
|
999
|
+
options.defaultLoaders.babel,
|
|
1000
|
+
{
|
|
1001
|
+
loader: "fumadocs-mdx/loader-meta",
|
|
1002
|
+
options: loaderOptions
|
|
1003
|
+
}
|
|
1004
|
+
]
|
|
1005
|
+
}
|
|
1006
|
+
);
|
|
785
1007
|
config.plugins ||= [];
|
|
786
|
-
return nextConfig.webpack?.(config,
|
|
1008
|
+
return nextConfig.webpack?.(config, options) ?? config;
|
|
787
1009
|
}
|
|
788
1010
|
};
|
|
789
1011
|
};
|
|
790
1012
|
}
|
|
791
|
-
async function init(dev,
|
|
792
|
-
const core = createNextCore(options);
|
|
1013
|
+
async function init(dev, core) {
|
|
793
1014
|
async function initOrReload() {
|
|
794
1015
|
await core.init({
|
|
795
|
-
config: loadConfig(
|
|
1016
|
+
config: loadConfig(core, true)
|
|
796
1017
|
});
|
|
797
1018
|
await core.emitAndWrite();
|
|
798
1019
|
}
|
|
@@ -801,9 +1022,9 @@ async function init(dev, options) {
|
|
|
801
1022
|
const watcher = new FSWatcher({
|
|
802
1023
|
ignoreInitial: true,
|
|
803
1024
|
persistent: true,
|
|
804
|
-
ignored: [
|
|
1025
|
+
ignored: [core._options.outDir]
|
|
805
1026
|
});
|
|
806
|
-
watcher.add(
|
|
1027
|
+
watcher.add(core._options.configPath);
|
|
807
1028
|
for (const collection of core.getConfig().collectionList) {
|
|
808
1029
|
if (collection.type === "docs") {
|
|
809
1030
|
watcher.add(collection.docs.dir);
|
|
@@ -815,10 +1036,8 @@ async function init(dev, options) {
|
|
|
815
1036
|
watcher.on("ready", () => {
|
|
816
1037
|
console.log("[MDX] started dev server");
|
|
817
1038
|
});
|
|
818
|
-
watcher.on("all", async (
|
|
819
|
-
|
|
820
|
-
if (event === "change") removeFileCache(absolutePath);
|
|
821
|
-
if (absolutePath === path7.resolve(options.configPath)) {
|
|
1039
|
+
watcher.on("all", async (_event, file) => {
|
|
1040
|
+
if (path5.resolve(file) === path5.resolve(core._options.configPath)) {
|
|
822
1041
|
watcher.removeAllListeners();
|
|
823
1042
|
await watcher.close();
|
|
824
1043
|
await initOrReload();
|
|
@@ -838,32 +1057,28 @@ async function init(dev, options) {
|
|
|
838
1057
|
await devServer();
|
|
839
1058
|
}
|
|
840
1059
|
}
|
|
841
|
-
async function postInstall(
|
|
842
|
-
const core =
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}).init({
|
|
846
|
-
config: loadConfig(configPath, outDir, true)
|
|
1060
|
+
async function postInstall(options) {
|
|
1061
|
+
const core = createNextCore(applyDefaults(options));
|
|
1062
|
+
await core.init({
|
|
1063
|
+
config: loadConfig(core, true)
|
|
847
1064
|
});
|
|
848
1065
|
await core.emitAndWrite();
|
|
849
1066
|
}
|
|
850
1067
|
function applyDefaults(options) {
|
|
851
1068
|
return {
|
|
852
|
-
|
|
853
|
-
|
|
1069
|
+
index: {},
|
|
1070
|
+
outDir: options.outDir ?? _Defaults.outDir,
|
|
1071
|
+
configPath: options.configPath ?? _Defaults.configPath
|
|
854
1072
|
};
|
|
855
1073
|
}
|
|
856
|
-
function createNextCore({
|
|
857
|
-
outDir,
|
|
858
|
-
configPath
|
|
859
|
-
}) {
|
|
1074
|
+
function createNextCore(options) {
|
|
860
1075
|
const core = createCore(
|
|
861
1076
|
{
|
|
862
1077
|
environment: "next",
|
|
863
|
-
outDir,
|
|
864
|
-
configPath
|
|
1078
|
+
outDir: options.outDir,
|
|
1079
|
+
configPath: options.configPath
|
|
865
1080
|
},
|
|
866
|
-
[
|
|
1081
|
+
[options.index && indexFile(options.index)]
|
|
867
1082
|
);
|
|
868
1083
|
return {
|
|
869
1084
|
...core,
|
|
@@ -872,7 +1087,7 @@ function createNextCore({
|
|
|
872
1087
|
await core.emitAndWrite(...args);
|
|
873
1088
|
} catch (err) {
|
|
874
1089
|
if (err instanceof ValidationError) {
|
|
875
|
-
console.error(err.toStringFormatted());
|
|
1090
|
+
console.error(await err.toStringFormatted());
|
|
876
1091
|
} else {
|
|
877
1092
|
console.error(err);
|
|
878
1093
|
}
|
|
@@ -880,17 +1095,16 @@ function createNextCore({
|
|
|
880
1095
|
}
|
|
881
1096
|
};
|
|
882
1097
|
}
|
|
883
|
-
var
|
|
884
|
-
var
|
|
1098
|
+
var path5, defaultPageExtensions;
|
|
1099
|
+
var init_next = __esm({
|
|
885
1100
|
"src/next/index.ts"() {
|
|
886
1101
|
"use strict";
|
|
887
|
-
|
|
1102
|
+
path5 = __toESM(require("path"), 1);
|
|
888
1103
|
init_load_from_file();
|
|
889
|
-
init_file_cache();
|
|
890
1104
|
init_validation();
|
|
891
|
-
init_next();
|
|
892
1105
|
init_core();
|
|
893
1106
|
init_loaders();
|
|
1107
|
+
init_index_file();
|
|
894
1108
|
defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
|
|
895
1109
|
}
|
|
896
1110
|
});
|
|
@@ -945,6 +1159,19 @@ var init_remark_unravel = __esm({
|
|
|
945
1159
|
}
|
|
946
1160
|
});
|
|
947
1161
|
|
|
1162
|
+
// src/loaders/mdx/mdast-utils.ts
|
|
1163
|
+
function flattenNode(node) {
|
|
1164
|
+
if ("children" in node)
|
|
1165
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
1166
|
+
if ("value" in node) return node.value;
|
|
1167
|
+
return "";
|
|
1168
|
+
}
|
|
1169
|
+
var init_mdast_utils = __esm({
|
|
1170
|
+
"src/loaders/mdx/mdast-utils.ts"() {
|
|
1171
|
+
"use strict";
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
|
|
948
1175
|
// src/loaders/mdx/remark-include.ts
|
|
949
1176
|
function isElementLike(node) {
|
|
950
1177
|
return ElementLikeTypes.includes(node.type);
|
|
@@ -961,12 +1188,6 @@ function parseElementAttributes(element) {
|
|
|
961
1188
|
}
|
|
962
1189
|
return element.attributes ?? {};
|
|
963
1190
|
}
|
|
964
|
-
function flattenNode(node) {
|
|
965
|
-
if ("children" in node)
|
|
966
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
967
|
-
if ("value" in node) return node.value;
|
|
968
|
-
return "";
|
|
969
|
-
}
|
|
970
1191
|
function parseSpecifier(specifier) {
|
|
971
1192
|
const idx = specifier.lastIndexOf("#");
|
|
972
1193
|
if (idx === -1) return { file: specifier };
|
|
@@ -1021,7 +1242,7 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1021
1242
|
{ cause: e }
|
|
1022
1243
|
);
|
|
1023
1244
|
}
|
|
1024
|
-
const ext =
|
|
1245
|
+
const ext = path6.extname(file);
|
|
1025
1246
|
data._compiler?.addDependency(file);
|
|
1026
1247
|
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
1027
1248
|
const lang = params.lang ?? ext.slice(1);
|
|
@@ -1054,7 +1275,7 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1054
1275
|
} else {
|
|
1055
1276
|
mdast = await baseProcessor.run(mdast);
|
|
1056
1277
|
}
|
|
1057
|
-
await update(mdast,
|
|
1278
|
+
await update(mdast, path6.dirname(file), data);
|
|
1058
1279
|
return mdast;
|
|
1059
1280
|
};
|
|
1060
1281
|
async function update(tree, directory, data) {
|
|
@@ -1066,7 +1287,7 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1066
1287
|
if (specifier.length === 0) return "skip";
|
|
1067
1288
|
const attributes = parseElementAttributes(node);
|
|
1068
1289
|
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
1069
|
-
const file =
|
|
1290
|
+
const file = path6.resolve(
|
|
1070
1291
|
"cwd" in attributes ? process.cwd() : directory,
|
|
1071
1292
|
relativePath
|
|
1072
1293
|
);
|
|
@@ -1083,20 +1304,21 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1083
1304
|
await Promise.all(queue);
|
|
1084
1305
|
}
|
|
1085
1306
|
return async (tree, file) => {
|
|
1086
|
-
await update(tree,
|
|
1307
|
+
await update(tree, path6.dirname(file.path), file.data);
|
|
1087
1308
|
};
|
|
1088
1309
|
}
|
|
1089
|
-
var import_unified, import_unist_util_visit2,
|
|
1310
|
+
var import_unified, import_unist_util_visit2, path6, fs3, import_mdx_plugins, ElementLikeTypes;
|
|
1090
1311
|
var init_remark_include = __esm({
|
|
1091
1312
|
"src/loaders/mdx/remark-include.ts"() {
|
|
1092
1313
|
"use strict";
|
|
1093
1314
|
import_unified = require("unified");
|
|
1094
1315
|
import_unist_util_visit2 = require("unist-util-visit");
|
|
1095
|
-
|
|
1316
|
+
path6 = __toESM(require("path"), 1);
|
|
1096
1317
|
fs3 = __toESM(require("fs/promises"), 1);
|
|
1097
1318
|
init_fuma_matter();
|
|
1098
1319
|
import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
1099
1320
|
init_remark_unravel();
|
|
1321
|
+
init_mdast_utils();
|
|
1100
1322
|
ElementLikeTypes = [
|
|
1101
1323
|
"mdxJsxFlowElement",
|
|
1102
1324
|
"mdxJsxTextElement",
|
|
@@ -1112,48 +1334,66 @@ function remarkPostprocess({
|
|
|
1112
1334
|
_format,
|
|
1113
1335
|
includeProcessedMarkdown = false,
|
|
1114
1336
|
includeMDAST = false,
|
|
1337
|
+
extractLinkReferences = false,
|
|
1115
1338
|
valueToExport = []
|
|
1116
1339
|
}) {
|
|
1117
1340
|
let _stringifyProcessor;
|
|
1118
1341
|
const getStringifyProcessor = () => {
|
|
1119
|
-
|
|
1120
|
-
|
|
1342
|
+
return _stringifyProcessor ??= _format === "mdx" ? this : (
|
|
1343
|
+
// force Markdown processor to stringify MDX nodes
|
|
1344
|
+
this().use(import_remark_mdx.default).freeze()
|
|
1345
|
+
);
|
|
1121
1346
|
};
|
|
1122
1347
|
return (tree, file) => {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1348
|
+
const frontmatter = file.data.frontmatter ??= {};
|
|
1349
|
+
if (!frontmatter.title) {
|
|
1350
|
+
(0, import_unist_util_visit3.visit)(tree, "heading", (node) => {
|
|
1351
|
+
if (node.depth === 1) {
|
|
1352
|
+
frontmatter.title = flattenNode(node);
|
|
1353
|
+
return false;
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
file.data["mdx-export"] ??= [];
|
|
1358
|
+
if (extractLinkReferences) {
|
|
1359
|
+
const urls = [];
|
|
1360
|
+
(0, import_unist_util_visit3.visit)(tree, "link", (node) => {
|
|
1361
|
+
urls.push({
|
|
1362
|
+
href: node.url
|
|
1363
|
+
});
|
|
1364
|
+
return "skip";
|
|
1365
|
+
});
|
|
1366
|
+
file.data["mdx-export"].push({
|
|
1367
|
+
name: "extractedReferences",
|
|
1368
|
+
value: urls
|
|
1132
1369
|
});
|
|
1133
|
-
return "skip";
|
|
1134
|
-
});
|
|
1135
|
-
if (title) {
|
|
1136
|
-
file.data.frontmatter ??= {};
|
|
1137
|
-
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
1138
1370
|
}
|
|
1139
|
-
file.data.extractedReferences = urls;
|
|
1140
1371
|
if (includeProcessedMarkdown) {
|
|
1141
1372
|
const processor = getStringifyProcessor();
|
|
1142
|
-
|
|
1373
|
+
const markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
1143
1374
|
...processor.data("settings"),
|
|
1144
1375
|
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
1145
1376
|
extensions: processor.data("toMarkdownExtensions") || []
|
|
1146
1377
|
});
|
|
1378
|
+
file.data["mdx-export"].push({
|
|
1379
|
+
name: "_markdown",
|
|
1380
|
+
value: markdown
|
|
1381
|
+
});
|
|
1147
1382
|
}
|
|
1148
1383
|
if (includeMDAST) {
|
|
1149
1384
|
const options = includeMDAST === true ? {} : includeMDAST;
|
|
1150
|
-
|
|
1385
|
+
const mdast = JSON.stringify(
|
|
1151
1386
|
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
1152
1387
|
);
|
|
1388
|
+
file.data["mdx-export"].push({
|
|
1389
|
+
name: "_mdast",
|
|
1390
|
+
value: mdast
|
|
1391
|
+
});
|
|
1153
1392
|
}
|
|
1154
|
-
for (const { name, value } of file.data["mdx-export"]
|
|
1393
|
+
for (const { name, value } of file.data["mdx-export"]) {
|
|
1155
1394
|
tree.children.unshift(getMdastExport(name, value));
|
|
1156
1395
|
}
|
|
1396
|
+
file.data["mdx-export"] = [];
|
|
1157
1397
|
for (const name of valueToExport) {
|
|
1158
1398
|
if (!(name in file.data)) continue;
|
|
1159
1399
|
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
@@ -1194,12 +1434,6 @@ function getMdastExport(name, value) {
|
|
|
1194
1434
|
}
|
|
1195
1435
|
};
|
|
1196
1436
|
}
|
|
1197
|
-
function flattenNode2(node) {
|
|
1198
|
-
if ("children" in node)
|
|
1199
|
-
return node.children.map((child) => flattenNode2(child)).join("");
|
|
1200
|
-
if ("value" in node) return node.value;
|
|
1201
|
-
return "";
|
|
1202
|
-
}
|
|
1203
1437
|
var import_unist_util_visit3, import_mdast_util_to_markdown, import_estree_util_value_to_estree, import_unist_util_remove_position, import_remark_mdx;
|
|
1204
1438
|
var init_remark_postprocess = __esm({
|
|
1205
1439
|
"src/loaders/mdx/remark-postprocess.ts"() {
|
|
@@ -1209,66 +1443,71 @@ var init_remark_postprocess = __esm({
|
|
|
1209
1443
|
import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
1210
1444
|
import_unist_util_remove_position = require("unist-util-remove-position");
|
|
1211
1445
|
import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
1446
|
+
init_mdast_utils();
|
|
1212
1447
|
}
|
|
1213
1448
|
});
|
|
1214
1449
|
|
|
1215
1450
|
// src/loaders/mdx/build-mdx.ts
|
|
1216
|
-
|
|
1217
|
-
|
|
1451
|
+
var build_mdx_exports = {};
|
|
1452
|
+
__export(build_mdx_exports, {
|
|
1453
|
+
buildMDX: () => buildMDX
|
|
1454
|
+
});
|
|
1455
|
+
async function buildMDX(core, collection, {
|
|
1456
|
+
filePath,
|
|
1457
|
+
frontmatter,
|
|
1458
|
+
source,
|
|
1459
|
+
_compiler,
|
|
1460
|
+
environment,
|
|
1461
|
+
isDevelopment
|
|
1462
|
+
}) {
|
|
1463
|
+
const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);
|
|
1218
1464
|
function getProcessor(format) {
|
|
1219
|
-
const
|
|
1220
|
-
|
|
1465
|
+
const cache = core.cache;
|
|
1466
|
+
const key = `build-mdx:${collection?.name ?? "global"}:${format}`;
|
|
1467
|
+
let processor = cache.get(key);
|
|
1221
1468
|
if (!processor) {
|
|
1469
|
+
const postprocessOptions = {
|
|
1470
|
+
_format: format,
|
|
1471
|
+
...collection?.postprocess,
|
|
1472
|
+
valueToExport: [
|
|
1473
|
+
...collection?.postprocess?.valueToExport ?? [],
|
|
1474
|
+
"structuredData",
|
|
1475
|
+
"frontmatter"
|
|
1476
|
+
]
|
|
1477
|
+
};
|
|
1222
1478
|
processor = (0, import_mdx.createProcessor)({
|
|
1223
1479
|
outputFormat: "program",
|
|
1224
|
-
|
|
1480
|
+
development: isDevelopment,
|
|
1481
|
+
...mdxOptions,
|
|
1225
1482
|
remarkPlugins: [
|
|
1226
1483
|
remarkInclude,
|
|
1227
|
-
...
|
|
1228
|
-
[
|
|
1229
|
-
remarkPostprocess,
|
|
1230
|
-
{
|
|
1231
|
-
_format: format,
|
|
1232
|
-
...options.postprocess,
|
|
1233
|
-
valueToExport: [
|
|
1234
|
-
...options.postprocess?.valueToExport ?? [],
|
|
1235
|
-
"structuredData",
|
|
1236
|
-
"extractedReferences",
|
|
1237
|
-
"frontmatter",
|
|
1238
|
-
"lastModified",
|
|
1239
|
-
"_markdown",
|
|
1240
|
-
"_mdast"
|
|
1241
|
-
]
|
|
1242
|
-
}
|
|
1243
|
-
]
|
|
1484
|
+
...mdxOptions.remarkPlugins ?? [],
|
|
1485
|
+
[remarkPostprocess, postprocessOptions]
|
|
1244
1486
|
],
|
|
1245
1487
|
format
|
|
1246
1488
|
});
|
|
1247
|
-
|
|
1489
|
+
cache.set(key, processor);
|
|
1248
1490
|
}
|
|
1249
1491
|
return processor;
|
|
1250
1492
|
}
|
|
1251
|
-
|
|
1252
|
-
options.format ?? (filePath.endsWith(".mdx") ? "mdx" : "md")
|
|
1253
|
-
).process({
|
|
1493
|
+
let vfile = new import_vfile.VFile({
|
|
1254
1494
|
value: source,
|
|
1255
1495
|
path: filePath,
|
|
1256
|
-
data: {
|
|
1257
|
-
...data,
|
|
1258
|
-
frontmatter,
|
|
1259
|
-
_compiler,
|
|
1260
|
-
_getProcessor: getProcessor
|
|
1261
|
-
}
|
|
1496
|
+
data: { frontmatter, _compiler, _getProcessor: getProcessor }
|
|
1262
1497
|
});
|
|
1498
|
+
if (collection) {
|
|
1499
|
+
vfile = await core.transformVFile({ collection, filePath, source }, vfile);
|
|
1500
|
+
}
|
|
1501
|
+
return getProcessor(filePath.endsWith(".mdx") ? "mdx" : "md").process(vfile);
|
|
1263
1502
|
}
|
|
1264
|
-
var import_mdx,
|
|
1503
|
+
var import_mdx, import_vfile;
|
|
1265
1504
|
var init_build_mdx = __esm({
|
|
1266
1505
|
"src/loaders/mdx/build-mdx.ts"() {
|
|
1267
1506
|
"use strict";
|
|
1268
1507
|
import_mdx = require("@mdx-js/mdx");
|
|
1508
|
+
import_vfile = require("vfile");
|
|
1269
1509
|
init_remark_include();
|
|
1270
1510
|
init_remark_postprocess();
|
|
1271
|
-
cache2 = /* @__PURE__ */ new Map();
|
|
1272
1511
|
}
|
|
1273
1512
|
});
|
|
1274
1513
|
|
|
@@ -1283,20 +1522,20 @@ function createMdxLoader(configLoader) {
|
|
|
1283
1522
|
compiler,
|
|
1284
1523
|
filePath
|
|
1285
1524
|
}) {
|
|
1525
|
+
const config = await configLoader.getConfig();
|
|
1286
1526
|
const value = await getSource();
|
|
1287
1527
|
const matter = fumaMatter(value);
|
|
1288
1528
|
const parsed = querySchema.parse(query);
|
|
1289
|
-
const config = await configLoader.getConfig();
|
|
1290
1529
|
let after;
|
|
1291
1530
|
if (!isDevelopment && config.global.experimentalBuildCache) {
|
|
1292
1531
|
const cacheDir = config.global.experimentalBuildCache;
|
|
1293
1532
|
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
1294
|
-
const cached = await import_promises3.default.readFile(
|
|
1533
|
+
const cached = await import_promises3.default.readFile(import_node_path4.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
1295
1534
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
1296
1535
|
after = async () => {
|
|
1297
1536
|
await import_promises3.default.mkdir(cacheDir, { recursive: true });
|
|
1298
1537
|
await import_promises3.default.writeFile(
|
|
1299
|
-
|
|
1538
|
+
import_node_path4.default.join(cacheDir, cacheKey),
|
|
1300
1539
|
JSON.stringify({
|
|
1301
1540
|
...out,
|
|
1302
1541
|
hash: generateCacheHash(value)
|
|
@@ -1314,15 +1553,10 @@ function createMdxLoader(configLoader) {
|
|
|
1314
1553
|
docCollection = collection.docs;
|
|
1315
1554
|
break;
|
|
1316
1555
|
}
|
|
1317
|
-
if (docCollection
|
|
1318
|
-
matter.data = await
|
|
1319
|
-
docCollection
|
|
1320
|
-
matter.data
|
|
1321
|
-
{
|
|
1322
|
-
source: value,
|
|
1323
|
-
path: filePath
|
|
1324
|
-
},
|
|
1325
|
-
`invalid frontmatter in ${filePath}`
|
|
1556
|
+
if (docCollection) {
|
|
1557
|
+
matter.data = await configLoader.core.transformFrontmatter(
|
|
1558
|
+
{ collection: docCollection, filePath, source: value },
|
|
1559
|
+
matter.data
|
|
1326
1560
|
);
|
|
1327
1561
|
}
|
|
1328
1562
|
if (parsed.only === "frontmatter") {
|
|
@@ -1331,24 +1565,16 @@ function createMdxLoader(configLoader) {
|
|
|
1331
1565
|
map: null
|
|
1332
1566
|
};
|
|
1333
1567
|
}
|
|
1334
|
-
const data = {};
|
|
1335
|
-
if (config.global.lastModifiedTime === "git") {
|
|
1336
|
-
data.lastModified = (await getGitTimestamp(filePath))?.getTime();
|
|
1337
|
-
}
|
|
1338
1568
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
frontmatter: matter.data,
|
|
1349
|
-
_compiler: compiler
|
|
1350
|
-
}
|
|
1351
|
-
);
|
|
1569
|
+
const { buildMDX: buildMDX2 } = await Promise.resolve().then(() => (init_build_mdx(), build_mdx_exports));
|
|
1570
|
+
const compiled = await buildMDX2(configLoader.core, docCollection, {
|
|
1571
|
+
isDevelopment,
|
|
1572
|
+
source: "\n".repeat(lineOffset) + matter.content,
|
|
1573
|
+
filePath,
|
|
1574
|
+
frontmatter: matter.data,
|
|
1575
|
+
_compiler: compiler,
|
|
1576
|
+
environment: "bundler"
|
|
1577
|
+
});
|
|
1352
1578
|
const out = {
|
|
1353
1579
|
code: String(compiled.value),
|
|
1354
1580
|
map: compiled.map
|
|
@@ -1358,15 +1584,8 @@ function createMdxLoader(configLoader) {
|
|
|
1358
1584
|
}
|
|
1359
1585
|
};
|
|
1360
1586
|
}
|
|
1361
|
-
function getConfigHash(config) {
|
|
1362
|
-
let hash = hashes.get(config);
|
|
1363
|
-
if (hash) return hash;
|
|
1364
|
-
hash = Date.now().toString();
|
|
1365
|
-
hashes.set(config, hash);
|
|
1366
|
-
return hash;
|
|
1367
|
-
}
|
|
1368
1587
|
function generateCacheHash(input) {
|
|
1369
|
-
return (0,
|
|
1588
|
+
return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
|
|
1370
1589
|
}
|
|
1371
1590
|
function countLines(s) {
|
|
1372
1591
|
let num = 0;
|
|
@@ -1375,18 +1594,15 @@ function countLines(s) {
|
|
|
1375
1594
|
}
|
|
1376
1595
|
return num;
|
|
1377
1596
|
}
|
|
1378
|
-
var import_zod, import_promises3,
|
|
1597
|
+
var import_zod, import_promises3, import_node_path4, import_node_crypto, querySchema, cacheEntry;
|
|
1379
1598
|
var init_mdx = __esm({
|
|
1380
1599
|
"src/loaders/mdx/index.ts"() {
|
|
1381
1600
|
"use strict";
|
|
1382
1601
|
init_fuma_matter();
|
|
1383
|
-
init_validation();
|
|
1384
|
-
init_git_timestamp();
|
|
1385
|
-
init_build_mdx();
|
|
1386
1602
|
import_zod = require("zod");
|
|
1387
1603
|
import_promises3 = __toESM(require("fs/promises"), 1);
|
|
1388
|
-
|
|
1389
|
-
|
|
1604
|
+
import_node_path4 = __toESM(require("path"), 1);
|
|
1605
|
+
import_node_crypto = require("crypto");
|
|
1390
1606
|
init_loaders();
|
|
1391
1607
|
querySchema = import_zod.z.object({
|
|
1392
1608
|
only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
|
|
@@ -1397,7 +1613,6 @@ var init_mdx = __esm({
|
|
|
1397
1613
|
map: import_zod.z.any().optional(),
|
|
1398
1614
|
hash: import_zod.z.string().optional()
|
|
1399
1615
|
});
|
|
1400
|
-
hashes = /* @__PURE__ */ new WeakMap();
|
|
1401
1616
|
}
|
|
1402
1617
|
});
|
|
1403
1618
|
|
|
@@ -1430,7 +1645,7 @@ function toVite(loader) {
|
|
|
1430
1645
|
}
|
|
1431
1646
|
};
|
|
1432
1647
|
}
|
|
1433
|
-
var import_node_url2, import_promises4, import_node_querystring,
|
|
1648
|
+
var import_node_url2, import_promises4, import_node_querystring, import_node_path5, import_node_fs;
|
|
1434
1649
|
var init_adapter = __esm({
|
|
1435
1650
|
"src/loaders/adapter.ts"() {
|
|
1436
1651
|
"use strict";
|
|
@@ -1438,217 +1653,15 @@ var init_adapter = __esm({
|
|
|
1438
1653
|
import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1439
1654
|
import_node_querystring = require("querystring");
|
|
1440
1655
|
init_validation();
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
});
|
|
1444
|
-
|
|
1445
|
-
// src/utils/glob-import.ts
|
|
1446
|
-
function generateGlobImport(patterns, options) {
|
|
1447
|
-
let code = "{";
|
|
1448
|
-
const result = (0, import_tinyglobby.globSync)(patterns, {
|
|
1449
|
-
cwd: options.base
|
|
1450
|
-
});
|
|
1451
|
-
for (const item of result) {
|
|
1452
|
-
const fullPath = import_node_path7.default.join(options.base, item);
|
|
1453
|
-
const url = (0, import_node_url3.pathToFileURL)(fullPath);
|
|
1454
|
-
for (const [k, v] of Object.entries(options.query ?? {})) {
|
|
1455
|
-
url.searchParams.set(k, v);
|
|
1456
|
-
}
|
|
1457
|
-
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(url.href)})`;
|
|
1458
|
-
if (options.import) {
|
|
1459
|
-
line += `.then(mod => mod[${JSON.stringify(options.import)}])`;
|
|
1460
|
-
}
|
|
1461
|
-
code += `${line}, `;
|
|
1462
|
-
}
|
|
1463
|
-
code += "}";
|
|
1464
|
-
return code;
|
|
1465
|
-
}
|
|
1466
|
-
var import_tinyglobby, import_node_path7, import_node_url3;
|
|
1467
|
-
var init_glob_import = __esm({
|
|
1468
|
-
"src/utils/glob-import.ts"() {
|
|
1469
|
-
"use strict";
|
|
1470
|
-
import_tinyglobby = require("tinyglobby");
|
|
1471
|
-
import_node_path7 = __toESM(require("path"), 1);
|
|
1472
|
-
import_node_url3 = require("url");
|
|
1473
|
-
}
|
|
1474
|
-
});
|
|
1475
|
-
|
|
1476
|
-
// src/plugins/vite.ts
|
|
1477
|
-
function vite({
|
|
1478
|
-
index
|
|
1479
|
-
}) {
|
|
1480
|
-
let config;
|
|
1481
|
-
let indexOptions;
|
|
1482
|
-
if (index === false) indexOptions = false;
|
|
1483
|
-
else indexOptions = applyDefaults2(index === true ? {} : index);
|
|
1484
|
-
return {
|
|
1485
|
-
name: "vite",
|
|
1486
|
-
config(v) {
|
|
1487
|
-
config = v;
|
|
1488
|
-
},
|
|
1489
|
-
configureServer(server) {
|
|
1490
|
-
if (!server.watcher || indexOptions === false || indexOptions.runtime === false)
|
|
1491
|
-
return;
|
|
1492
|
-
server.watcher.on("all", (event, file) => {
|
|
1493
|
-
if (event === "change") return;
|
|
1494
|
-
const isUpdated = config.collectionList.some((collection) => {
|
|
1495
|
-
if (collection.type === "docs")
|
|
1496
|
-
return collection.docs.hasFile(file) || collection.meta.hasFile(file);
|
|
1497
|
-
return collection.hasFile(file);
|
|
1498
|
-
});
|
|
1499
|
-
if (isUpdated) {
|
|
1500
|
-
this.core.emitAndWrite({
|
|
1501
|
-
filterPlugin: (plugin) => plugin.name === "vite"
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
});
|
|
1505
|
-
},
|
|
1506
|
-
emit() {
|
|
1507
|
-
const out = [];
|
|
1508
|
-
if (indexOptions === false) return out;
|
|
1509
|
-
if (indexOptions.browser) {
|
|
1510
|
-
out.push({
|
|
1511
|
-
path: "browser.ts",
|
|
1512
|
-
content: indexFile2(this, config, indexOptions, "browser")
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1515
|
-
out.push({
|
|
1516
|
-
path: "index.ts",
|
|
1517
|
-
content: indexFile2(
|
|
1518
|
-
this,
|
|
1519
|
-
config,
|
|
1520
|
-
indexOptions,
|
|
1521
|
-
indexOptions.browser ? "server" : "all"
|
|
1522
|
-
)
|
|
1523
|
-
});
|
|
1524
|
-
return out;
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1528
|
-
function applyDefaults2(options) {
|
|
1529
|
-
return {
|
|
1530
|
-
addJsExtension: options.addJsExtension ?? false,
|
|
1531
|
-
browser: options.browser ?? false,
|
|
1532
|
-
runtime: options.runtime ?? false
|
|
1533
|
-
};
|
|
1534
|
-
}
|
|
1535
|
-
function indexFile2({ configPath, outDir }, config, { addJsExtension, runtime }, environment) {
|
|
1536
|
-
const runtimePath = {
|
|
1537
|
-
all: "fumadocs-mdx/runtime/vite",
|
|
1538
|
-
server: "fumadocs-mdx/runtime/vite.server",
|
|
1539
|
-
browser: "fumadocs-mdx/runtime/vite.browser"
|
|
1540
|
-
}[environment];
|
|
1541
|
-
const lines = [
|
|
1542
|
-
'/// <reference types="vite/client" />',
|
|
1543
|
-
`import { fromConfig } from '${runtimePath}';`,
|
|
1544
|
-
`import type * as Config from '${toImportPath(configPath, {
|
|
1545
|
-
relativeTo: outDir,
|
|
1546
|
-
jsExtension: addJsExtension
|
|
1547
|
-
})}';`,
|
|
1548
|
-
"",
|
|
1549
|
-
`export const create = fromConfig<typeof Config>();`
|
|
1550
|
-
];
|
|
1551
|
-
function generateCollectionGlob(collection) {
|
|
1552
|
-
if (collection.type === "docs") {
|
|
1553
|
-
const obj = [
|
|
1554
|
-
ident(`doc: ${generateCollectionGlob(collection.docs)}`),
|
|
1555
|
-
ident(`meta: ${generateCollectionGlob(collection.meta)}`)
|
|
1556
|
-
].join(",\n");
|
|
1557
|
-
return `{
|
|
1558
|
-
${obj}
|
|
1559
|
-
}`;
|
|
1560
|
-
}
|
|
1561
|
-
const dir = getCollectionDir(collection);
|
|
1562
|
-
if (collection.type === "doc") {
|
|
1563
|
-
const docGlob = generateGlob(collection.patterns, {
|
|
1564
|
-
query: {
|
|
1565
|
-
collection: collection.name
|
|
1566
|
-
},
|
|
1567
|
-
base: dir
|
|
1568
|
-
});
|
|
1569
|
-
if (collection.async) {
|
|
1570
|
-
const headBlob = generateGlob(collection.patterns, {
|
|
1571
|
-
query: {
|
|
1572
|
-
only: "frontmatter",
|
|
1573
|
-
collection: collection.name
|
|
1574
|
-
},
|
|
1575
|
-
import: "frontmatter",
|
|
1576
|
-
base: dir
|
|
1577
|
-
});
|
|
1578
|
-
return `create.docLazy("${collection.name}", "${dir}", ${headBlob}, ${docGlob})`;
|
|
1579
|
-
}
|
|
1580
|
-
return `create.doc("${collection.name}", "${dir}", ${docGlob})`;
|
|
1581
|
-
}
|
|
1582
|
-
return `create.meta("${collection.name}", "${dir}", ${generateGlob(
|
|
1583
|
-
collection.patterns,
|
|
1584
|
-
{
|
|
1585
|
-
import: "default",
|
|
1586
|
-
base: dir,
|
|
1587
|
-
query: {
|
|
1588
|
-
collection: collection.name
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
)})`;
|
|
1592
|
-
}
|
|
1593
|
-
function generateGlob(patterns, options) {
|
|
1594
|
-
patterns = patterns.map(normalizeGlobPath);
|
|
1595
|
-
if (runtime === "node" || runtime === "bun") {
|
|
1596
|
-
return generateGlobImport(patterns, options);
|
|
1597
|
-
} else {
|
|
1598
|
-
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
1599
|
-
{
|
|
1600
|
-
...options,
|
|
1601
|
-
base: normalizeGlobPath(import_node_path8.default.relative(outDir, options.base))
|
|
1602
|
-
},
|
|
1603
|
-
null,
|
|
1604
|
-
2
|
|
1605
|
-
)})`;
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
for (const collection of config.collectionList) {
|
|
1609
|
-
lines.push("");
|
|
1610
|
-
lines.push(
|
|
1611
|
-
`export const ${collection.name} = ${generateCollectionGlob(collection)};`
|
|
1612
|
-
);
|
|
1613
|
-
}
|
|
1614
|
-
return lines.join("\n");
|
|
1615
|
-
}
|
|
1616
|
-
function normalizeGlobPath(file) {
|
|
1617
|
-
file = slash(file);
|
|
1618
|
-
if (file.startsWith("./")) return file;
|
|
1619
|
-
if (file.startsWith("/")) return `.${file}`;
|
|
1620
|
-
return `./${file}`;
|
|
1621
|
-
}
|
|
1622
|
-
function getCollectionDir({ dir }) {
|
|
1623
|
-
if (Array.isArray(dir)) {
|
|
1624
|
-
if (dir.length !== 1)
|
|
1625
|
-
throw new Error(
|
|
1626
|
-
`[Fumadocs MDX] Vite Plugin doesn't support multiple \`dir\` for a collection at the moment.`
|
|
1627
|
-
);
|
|
1628
|
-
return dir[0];
|
|
1629
|
-
}
|
|
1630
|
-
return dir;
|
|
1631
|
-
}
|
|
1632
|
-
function slash(path13) {
|
|
1633
|
-
const isExtendedLengthPath = path13.startsWith("\\\\?\\");
|
|
1634
|
-
if (isExtendedLengthPath) {
|
|
1635
|
-
return path13;
|
|
1636
|
-
}
|
|
1637
|
-
return path13.replaceAll("\\", "/");
|
|
1638
|
-
}
|
|
1639
|
-
var import_node_path8;
|
|
1640
|
-
var init_vite = __esm({
|
|
1641
|
-
"src/plugins/vite.ts"() {
|
|
1642
|
-
"use strict";
|
|
1643
|
-
init_import_formatter();
|
|
1644
|
-
init_glob_import();
|
|
1645
|
-
import_node_path8 = __toESM(require("path"), 1);
|
|
1656
|
+
import_node_path5 = __toESM(require("path"), 1);
|
|
1657
|
+
import_node_fs = require("fs");
|
|
1646
1658
|
}
|
|
1647
1659
|
});
|
|
1648
1660
|
|
|
1649
1661
|
// src/loaders/config.ts
|
|
1650
1662
|
function createIntegratedConfigLoader(core) {
|
|
1651
1663
|
return {
|
|
1664
|
+
core,
|
|
1652
1665
|
getConfig() {
|
|
1653
1666
|
return core.getConfig();
|
|
1654
1667
|
}
|
|
@@ -1663,74 +1676,82 @@ var init_config = __esm({
|
|
|
1663
1676
|
});
|
|
1664
1677
|
|
|
1665
1678
|
// src/loaders/meta.ts
|
|
1666
|
-
function createMetaLoader(configLoader,
|
|
1667
|
-
const { json: resolveJson = "js", yaml: resolveYaml = "js" } =
|
|
1668
|
-
function
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1679
|
+
function createMetaLoader(configLoader, resolve3 = {}) {
|
|
1680
|
+
const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve3;
|
|
1681
|
+
function parse2(filePath, source) {
|
|
1682
|
+
try {
|
|
1683
|
+
if (filePath.endsWith(".json")) return JSON.parse(source);
|
|
1684
|
+
if (filePath.endsWith(".yaml")) return (0, import_js_yaml2.load)(source);
|
|
1685
|
+
} catch (e) {
|
|
1686
|
+
throw new Error(`invalid data in ${filePath}`, { cause: e });
|
|
1673
1687
|
}
|
|
1688
|
+
throw new Error("Unknown file type " + filePath);
|
|
1674
1689
|
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
const
|
|
1682
|
-
|
|
1683
|
-
let data;
|
|
1684
|
-
try {
|
|
1685
|
-
data = isJson ? JSON.parse(source) : (0, import_js_yaml3.load)(source);
|
|
1686
|
-
} catch (e) {
|
|
1687
|
-
throw new Error(`invalid data in ${filePath}`, { cause: e });
|
|
1688
|
-
}
|
|
1689
|
-
let schema;
|
|
1690
|
+
function onMeta(source, { filePath, query }) {
|
|
1691
|
+
const parsed = querySchema2.safeParse(query);
|
|
1692
|
+
if (!parsed.success || !parsed.data.collection) return null;
|
|
1693
|
+
const collectionName = parsed.data.collection;
|
|
1694
|
+
return async () => {
|
|
1695
|
+
const config = await configLoader.getConfig();
|
|
1696
|
+
const collection = config.getCollection(collectionName);
|
|
1697
|
+
let metaCollection;
|
|
1690
1698
|
switch (collection?.type) {
|
|
1691
1699
|
case "meta":
|
|
1692
|
-
|
|
1700
|
+
metaCollection = collection;
|
|
1693
1701
|
break;
|
|
1694
1702
|
case "docs":
|
|
1695
|
-
|
|
1703
|
+
metaCollection = collection.meta;
|
|
1696
1704
|
break;
|
|
1697
1705
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1706
|
+
const data = parse2(filePath, source);
|
|
1707
|
+
if (!metaCollection) return data;
|
|
1708
|
+
return configLoader.core.transformMeta(
|
|
1709
|
+
{
|
|
1710
|
+
collection: metaCollection,
|
|
1711
|
+
filePath,
|
|
1712
|
+
source
|
|
1713
|
+
},
|
|
1714
|
+
data
|
|
1715
|
+
);
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
return {
|
|
1719
|
+
test: metaLoaderGlob,
|
|
1720
|
+
async load(input) {
|
|
1721
|
+
const result = onMeta(await input.getSource(), input);
|
|
1722
|
+
if (result === null) return null;
|
|
1723
|
+
const data = await result();
|
|
1724
|
+
if (input.filePath.endsWith(".json")) {
|
|
1725
|
+
return {
|
|
1726
|
+
code: resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`
|
|
1727
|
+
};
|
|
1728
|
+
} else {
|
|
1729
|
+
return {
|
|
1730
|
+
code: resolveYaml === "yaml" ? (0, import_js_yaml2.dump)(data) : `export default ${JSON.stringify(data)}`
|
|
1731
|
+
};
|
|
1705
1732
|
}
|
|
1706
|
-
return {
|
|
1707
|
-
code: stringifyOutput(isJson, data)
|
|
1708
|
-
};
|
|
1709
1733
|
},
|
|
1710
1734
|
bun: {
|
|
1711
|
-
|
|
1712
|
-
const
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
}
|
|
1720
|
-
return {
|
|
1735
|
+
load(source, input) {
|
|
1736
|
+
const result = onMeta(source, input);
|
|
1737
|
+
if (result === null)
|
|
1738
|
+
return {
|
|
1739
|
+
loader: "object",
|
|
1740
|
+
exports: parse2(input.filePath, source)
|
|
1741
|
+
};
|
|
1742
|
+
return result().then((data) => ({
|
|
1721
1743
|
loader: "object",
|
|
1722
|
-
exports: data
|
|
1723
|
-
};
|
|
1744
|
+
exports: { default: data }
|
|
1745
|
+
}));
|
|
1724
1746
|
}
|
|
1725
1747
|
}
|
|
1726
1748
|
};
|
|
1727
1749
|
}
|
|
1728
|
-
var
|
|
1750
|
+
var import_js_yaml2, import_zod2, querySchema2;
|
|
1729
1751
|
var init_meta = __esm({
|
|
1730
1752
|
"src/loaders/meta.ts"() {
|
|
1731
1753
|
"use strict";
|
|
1732
|
-
|
|
1733
|
-
init_validation();
|
|
1754
|
+
import_js_yaml2 = require("js-yaml");
|
|
1734
1755
|
import_zod2 = require("zod");
|
|
1735
1756
|
init_loaders();
|
|
1736
1757
|
querySchema2 = import_zod2.z.object({
|
|
@@ -1746,7 +1767,7 @@ __export(vite_exports, {
|
|
|
1746
1767
|
postInstall: () => postInstall2
|
|
1747
1768
|
});
|
|
1748
1769
|
async function mdx(config, pluginOptions = {}) {
|
|
1749
|
-
const options =
|
|
1770
|
+
const options = applyDefaults2(pluginOptions);
|
|
1750
1771
|
const core = await createViteCore(options).init({
|
|
1751
1772
|
config: buildConfig(config)
|
|
1752
1773
|
});
|
|
@@ -1792,26 +1813,27 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1792
1813
|
}
|
|
1793
1814
|
} catch (e) {
|
|
1794
1815
|
if (e instanceof ValidationError) {
|
|
1795
|
-
throw new Error(e.toStringFormatted());
|
|
1816
|
+
throw new Error(await e.toStringFormatted());
|
|
1796
1817
|
}
|
|
1797
1818
|
throw e;
|
|
1798
1819
|
}
|
|
1799
1820
|
}
|
|
1800
1821
|
};
|
|
1801
1822
|
}
|
|
1802
|
-
async function postInstall2(
|
|
1823
|
+
async function postInstall2(pluginOptions = {}) {
|
|
1803
1824
|
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load_from_file(), load_from_file_exports));
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
config: loadConfig2(
|
|
1825
|
+
const core = createViteCore(applyDefaults2(pluginOptions));
|
|
1826
|
+
await core.init({
|
|
1827
|
+
config: loadConfig2(core, true)
|
|
1807
1828
|
});
|
|
1808
1829
|
await core.emitAndWrite();
|
|
1809
1830
|
}
|
|
1810
1831
|
function createViteCore({
|
|
1832
|
+
index,
|
|
1811
1833
|
configPath,
|
|
1812
|
-
outDir
|
|
1813
|
-
generateIndexFile
|
|
1834
|
+
outDir
|
|
1814
1835
|
}) {
|
|
1836
|
+
if (index === true) index = {};
|
|
1815
1837
|
return createCore(
|
|
1816
1838
|
{
|
|
1817
1839
|
environment: "vite",
|
|
@@ -1819,22 +1841,23 @@ function createViteCore({
|
|
|
1819
1841
|
outDir
|
|
1820
1842
|
},
|
|
1821
1843
|
[
|
|
1822
|
-
|
|
1823
|
-
index
|
|
1844
|
+
index && indexFile({
|
|
1845
|
+
...index,
|
|
1846
|
+
target: index.target ?? "vite"
|
|
1824
1847
|
})
|
|
1825
1848
|
]
|
|
1826
1849
|
);
|
|
1827
1850
|
}
|
|
1828
|
-
function
|
|
1851
|
+
function applyDefaults2(options) {
|
|
1829
1852
|
return {
|
|
1830
1853
|
updateViteConfig: options.updateViteConfig ?? true,
|
|
1831
|
-
|
|
1832
|
-
configPath: options.configPath ??
|
|
1833
|
-
outDir: options.outDir ??
|
|
1854
|
+
index: options.index ?? true,
|
|
1855
|
+
configPath: options.configPath ?? _Defaults.configPath,
|
|
1856
|
+
outDir: options.outDir ?? _Defaults.outDir
|
|
1834
1857
|
};
|
|
1835
1858
|
}
|
|
1836
1859
|
var import_vite, FumadocsDeps;
|
|
1837
|
-
var
|
|
1860
|
+
var init_vite = __esm({
|
|
1838
1861
|
"src/vite/index.ts"() {
|
|
1839
1862
|
"use strict";
|
|
1840
1863
|
import_vite = require("vite");
|
|
@@ -1842,25 +1865,25 @@ var init_vite2 = __esm({
|
|
|
1842
1865
|
init_validation();
|
|
1843
1866
|
init_mdx();
|
|
1844
1867
|
init_adapter();
|
|
1845
|
-
init_vite();
|
|
1846
1868
|
init_core();
|
|
1847
1869
|
init_config();
|
|
1848
1870
|
init_meta();
|
|
1871
|
+
init_index_file();
|
|
1849
1872
|
FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
1850
1873
|
}
|
|
1851
1874
|
});
|
|
1852
1875
|
|
|
1853
1876
|
// src/bin.ts
|
|
1854
|
-
var
|
|
1877
|
+
var import_node_fs2 = require("fs");
|
|
1855
1878
|
async function start() {
|
|
1856
|
-
const [configPath] = process.argv.slice(2);
|
|
1857
|
-
const isNext = (0,
|
|
1879
|
+
const [configPath, outDir] = process.argv.slice(2);
|
|
1880
|
+
const isNext = (0, import_node_fs2.existsSync)("next.config.js") || (0, import_node_fs2.existsSync)("next.config.mjs") || (0, import_node_fs2.existsSync)("next.config.mts") || (0, import_node_fs2.existsSync)("next.config.ts");
|
|
1858
1881
|
if (isNext) {
|
|
1859
|
-
const { postInstall: postInstall3 } = await Promise.resolve().then(() => (
|
|
1860
|
-
await postInstall3(configPath);
|
|
1882
|
+
const { postInstall: postInstall3 } = await Promise.resolve().then(() => (init_next(), next_exports));
|
|
1883
|
+
await postInstall3({ configPath, outDir });
|
|
1861
1884
|
} else {
|
|
1862
|
-
const { postInstall: postInstall3 } = await Promise.resolve().then(() => (
|
|
1863
|
-
await postInstall3(configPath);
|
|
1885
|
+
const { postInstall: postInstall3 } = await Promise.resolve().then(() => (init_vite(), vite_exports));
|
|
1886
|
+
await postInstall3({ configPath, outDir });
|
|
1864
1887
|
}
|
|
1865
1888
|
}
|
|
1866
1889
|
void start();
|