fumadocs-mdx 13.0.2 → 13.0.4
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 +381 -279
- package/dist/{build-mdx-D-r3_eQL.d.cts → build-mdx-BjXOmv0b.d.cts} +1 -1
- package/dist/{build-mdx-CCNr86q6.d.ts → build-mdx-CY5UldCO.d.ts} +1 -1
- package/dist/bun/index.cjs +177 -57
- package/dist/bun/index.d.cts +2 -2
- package/dist/bun/index.d.ts +2 -2
- package/dist/bun/index.js +26 -34
- package/dist/chunk-2HXTGJBI.js +101 -0
- package/dist/chunk-4JSFLXXT.js +8 -0
- package/dist/{chunk-JVZFH6ND.js → chunk-QXHN25N3.js} +2 -2
- package/dist/{chunk-EELYB2XC.js → chunk-TZ5EQBFW.js} +9 -103
- package/dist/chunk-VUEZTR2H.js +26 -0
- package/dist/{chunk-XQ5O7IPO.js → chunk-XYGORKQA.js} +5 -3
- package/dist/chunk-YAIPHUCZ.js +56 -0
- package/dist/chunk-ZNVPB2IR.js +170 -0
- package/dist/config/index.d.cts +2 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/{core-B6j6Fxse.d.cts → core-DB7TdlyC.d.cts} +23 -7
- package/dist/{core-B6j6Fxse.d.ts → core-DB7TdlyC.d.ts} +23 -7
- package/dist/index-D7s7kCc2.d.cts +7 -0
- package/dist/index-D7s7kCc2.d.ts +7 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/load-from-file-AVYOFOI7.js +7 -0
- package/dist/next/index.cjs +147 -142
- package/dist/next/index.js +58 -39
- package/dist/node/loader.cjs +242 -128
- package/dist/node/loader.d.cts +2 -2
- package/dist/node/loader.d.ts +2 -2
- package/dist/node/loader.js +29 -16
- package/dist/plugins/json-schema.cjs +22 -70
- package/dist/plugins/json-schema.d.cts +2 -2
- package/dist/plugins/json-schema.d.ts +2 -2
- package/dist/plugins/json-schema.js +19 -14
- package/dist/runtime/next/async.cjs +56 -11
- package/dist/runtime/next/async.d.cts +4 -6
- package/dist/runtime/next/async.d.ts +4 -6
- package/dist/runtime/next/async.js +3 -6
- package/dist/runtime/next/index.d.cts +5 -5
- package/dist/runtime/next/index.d.ts +5 -5
- package/dist/runtime/vite/browser.d.cts +3 -3
- package/dist/runtime/vite/browser.d.ts +3 -3
- package/dist/runtime/vite/server.d.cts +3 -3
- package/dist/runtime/vite/server.d.ts +3 -3
- package/dist/{types-DKGMoay5.d.cts → types-Bnh9n7mj.d.cts} +2 -2
- package/dist/{types-AGzTfBmf.d.ts → types-ey1AZqrg.d.ts} +2 -2
- package/dist/vite/index.cjs +265 -163
- package/dist/vite/index.d.cts +4 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.js +140 -122
- package/dist/webpack/{index.cjs → mdx.cjs} +126 -104
- package/dist/webpack/mdx.d.cts +6 -0
- package/dist/webpack/mdx.d.ts +6 -0
- package/dist/webpack/{index.js → mdx.js} +12 -14
- package/dist/webpack/meta.cjs +528 -0
- package/dist/webpack/meta.d.cts +6 -0
- package/dist/webpack/meta.d.ts +6 -0
- package/dist/webpack/meta.js +42 -0
- package/loader-mdx.cjs +1 -1
- package/loader-meta.cjs +7 -0
- package/package.json +11 -8
- package/dist/chunk-U4MQ44TS.js +0 -53
- package/dist/chunk-XZY2AWJI.js +0 -81
- package/dist/chunk-YVCR6FUH.js +0 -82
- package/dist/load-MNG3CLET.js +0 -7
- package/dist/webpack/index.d.cts +0 -15
- package/dist/webpack/index.d.ts +0 -15
package/dist/bin.cjs
CHANGED
|
@@ -30,19 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
-
// src/loaders/config/index.ts
|
|
34
|
-
function findConfigFile() {
|
|
35
|
-
return import_node_path.default.resolve("source.config.ts");
|
|
36
|
-
}
|
|
37
|
-
var import_node_path, import_promises;
|
|
38
|
-
var init_config = __esm({
|
|
39
|
-
"src/loaders/config/index.ts"() {
|
|
40
|
-
"use strict";
|
|
41
|
-
import_node_path = __toESM(require("path"), 1);
|
|
42
|
-
import_promises = __toESM(require("fs/promises"), 1);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
33
|
// src/loaders/mdx/preset.ts
|
|
47
34
|
var preset_exports = {};
|
|
48
35
|
__export(preset_exports, {
|
|
@@ -131,35 +118,78 @@ var init_preset = __esm({
|
|
|
131
118
|
});
|
|
132
119
|
|
|
133
120
|
// src/config/build.ts
|
|
121
|
+
function buildCollection(name, config) {
|
|
122
|
+
if (config.type === "docs") {
|
|
123
|
+
return {
|
|
124
|
+
...config,
|
|
125
|
+
name,
|
|
126
|
+
meta: buildPrimitiveCollection(name, config.meta),
|
|
127
|
+
docs: buildPrimitiveCollection(name, config.docs)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return buildPrimitiveCollection(name, config);
|
|
131
|
+
}
|
|
132
|
+
function buildPrimitiveCollection(name, { files, ...config }) {
|
|
133
|
+
const supportedFormats = SupportedFormats[config.type];
|
|
134
|
+
const patterns = files ?? [`**/*.{${supportedFormats.join(",")}}`];
|
|
135
|
+
let matchers;
|
|
136
|
+
return {
|
|
137
|
+
...config,
|
|
138
|
+
name,
|
|
139
|
+
patterns,
|
|
140
|
+
isFileSupported(filePath) {
|
|
141
|
+
return supportedFormats.some((format) => filePath.endsWith(`.${format}`));
|
|
142
|
+
},
|
|
143
|
+
hasFile(filePath) {
|
|
144
|
+
matchers ??= (Array.isArray(config.dir) ? config.dir : [config.dir]).map(
|
|
145
|
+
(dir) => (0, import_picomatch.default)(patterns, {
|
|
146
|
+
cwd: dir
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
return this.isFileSupported(filePath) && matchers.some((matcher) => matcher(filePath));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
134
153
|
function buildConfig(config) {
|
|
135
154
|
const collections = /* @__PURE__ */ new Map();
|
|
136
|
-
|
|
155
|
+
const loaded = {};
|
|
137
156
|
for (const [k, v] of Object.entries(config)) {
|
|
138
157
|
if (!v) {
|
|
139
158
|
continue;
|
|
140
159
|
}
|
|
141
160
|
if (typeof v === "object" && "type" in v) {
|
|
142
161
|
if (v.type === "docs") {
|
|
143
|
-
collections.set(k, v);
|
|
162
|
+
collections.set(k, buildCollection(k, v));
|
|
144
163
|
continue;
|
|
145
164
|
}
|
|
146
165
|
if (v.type === "doc" || v.type === "meta") {
|
|
147
|
-
collections.set(
|
|
166
|
+
collections.set(
|
|
167
|
+
k,
|
|
168
|
+
buildCollection(k, v)
|
|
169
|
+
);
|
|
148
170
|
continue;
|
|
149
171
|
}
|
|
150
172
|
}
|
|
151
173
|
if (k === "default" && v) {
|
|
152
|
-
|
|
174
|
+
Object.assign(loaded, v);
|
|
153
175
|
continue;
|
|
154
176
|
}
|
|
155
177
|
throw new Error(
|
|
156
178
|
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
157
179
|
);
|
|
158
180
|
}
|
|
181
|
+
if (loaded.collections) {
|
|
182
|
+
for (const [k, v] of Object.entries(loaded.collections)) {
|
|
183
|
+
collections.set(k, buildCollection(k, v));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
159
186
|
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
160
187
|
return {
|
|
161
|
-
global:
|
|
162
|
-
collections,
|
|
188
|
+
global: loaded,
|
|
189
|
+
collectionList: Array.from(collections.values()),
|
|
190
|
+
getCollection(name) {
|
|
191
|
+
return collections.get(name);
|
|
192
|
+
},
|
|
163
193
|
async getDefaultMDXOptions(mode = "default") {
|
|
164
194
|
const cached = mdxOptionsCache.get(mode);
|
|
165
195
|
if (cached) return cached;
|
|
@@ -179,15 +209,21 @@ function buildConfig(config) {
|
|
|
179
209
|
}
|
|
180
210
|
};
|
|
181
211
|
}
|
|
212
|
+
var import_picomatch, SupportedFormats;
|
|
182
213
|
var init_build = __esm({
|
|
183
214
|
"src/config/build.ts"() {
|
|
184
215
|
"use strict";
|
|
216
|
+
import_picomatch = __toESM(require("picomatch"), 1);
|
|
217
|
+
SupportedFormats = {
|
|
218
|
+
doc: ["mdx", "md"],
|
|
219
|
+
meta: ["json", "yaml"]
|
|
220
|
+
};
|
|
185
221
|
}
|
|
186
222
|
});
|
|
187
223
|
|
|
188
|
-
// src/
|
|
189
|
-
var
|
|
190
|
-
__export(
|
|
224
|
+
// src/config/load-from-file.ts
|
|
225
|
+
var load_from_file_exports = {};
|
|
226
|
+
__export(load_from_file_exports, {
|
|
191
227
|
loadConfig: () => loadConfig
|
|
192
228
|
});
|
|
193
229
|
async function compileConfig(configPath, outDir) {
|
|
@@ -212,18 +248,18 @@ async function compileConfig(configPath, outDir) {
|
|
|
212
248
|
}
|
|
213
249
|
async function loadConfig(configPath, outDir, build = false) {
|
|
214
250
|
if (build) await compileConfig(configPath, outDir);
|
|
215
|
-
const url = (0, import_node_url.pathToFileURL)(
|
|
251
|
+
const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
|
|
216
252
|
url.searchParams.set("hash", Date.now().toString());
|
|
217
253
|
const config = import(url.href).then(
|
|
218
254
|
(loaded) => buildConfig(loaded)
|
|
219
255
|
);
|
|
220
256
|
return await config;
|
|
221
257
|
}
|
|
222
|
-
var
|
|
223
|
-
var
|
|
224
|
-
"src/
|
|
258
|
+
var path, import_node_url;
|
|
259
|
+
var init_load_from_file = __esm({
|
|
260
|
+
"src/config/load-from-file.ts"() {
|
|
225
261
|
"use strict";
|
|
226
|
-
|
|
262
|
+
path = __toESM(require("path"), 1);
|
|
227
263
|
import_node_url = require("url");
|
|
228
264
|
init_build();
|
|
229
265
|
}
|
|
@@ -231,8 +267,8 @@ var init_load = __esm({
|
|
|
231
267
|
|
|
232
268
|
// src/next/file-cache.ts
|
|
233
269
|
function toFullPath(file) {
|
|
234
|
-
if (
|
|
235
|
-
return
|
|
270
|
+
if (import_node_path.default.isAbsolute(file)) {
|
|
271
|
+
return import_node_path.default.relative(process.cwd(), file);
|
|
236
272
|
}
|
|
237
273
|
return file;
|
|
238
274
|
}
|
|
@@ -240,20 +276,20 @@ async function readFileWithCache(file) {
|
|
|
240
276
|
const fullPath = toFullPath(file);
|
|
241
277
|
const cached = map.get(fullPath);
|
|
242
278
|
if (cached) return cached;
|
|
243
|
-
const read =
|
|
279
|
+
const read = import_promises.default.readFile(fullPath).then((s) => s.toString());
|
|
244
280
|
map.set(fullPath, read);
|
|
245
281
|
return read;
|
|
246
282
|
}
|
|
247
283
|
function removeFileCache(file) {
|
|
248
284
|
map.delete(toFullPath(file));
|
|
249
285
|
}
|
|
250
|
-
var import_lru_cache,
|
|
286
|
+
var import_lru_cache, import_promises, import_node_path, map;
|
|
251
287
|
var init_file_cache = __esm({
|
|
252
288
|
"src/next/file-cache.ts"() {
|
|
253
289
|
"use strict";
|
|
254
290
|
import_lru_cache = require("lru-cache");
|
|
255
|
-
|
|
256
|
-
|
|
291
|
+
import_promises = __toESM(require("fs/promises"), 1);
|
|
292
|
+
import_node_path = __toESM(require("path"), 1);
|
|
257
293
|
map = new import_lru_cache.LRUCache({
|
|
258
294
|
max: 100
|
|
259
295
|
});
|
|
@@ -311,7 +347,7 @@ async function getGitTimestamp(file) {
|
|
|
311
347
|
try {
|
|
312
348
|
const out = await (0, import_tinyexec.x)(
|
|
313
349
|
"git",
|
|
314
|
-
["log", "-1", '--pretty="%ai"',
|
|
350
|
+
["log", "-1", '--pretty="%ai"', import_node_path2.default.relative(process.cwd(), file)],
|
|
315
351
|
{
|
|
316
352
|
throwOnError: true
|
|
317
353
|
}
|
|
@@ -323,11 +359,11 @@ async function getGitTimestamp(file) {
|
|
|
323
359
|
return;
|
|
324
360
|
}
|
|
325
361
|
}
|
|
326
|
-
var
|
|
362
|
+
var import_node_path2, import_tinyexec, cache;
|
|
327
363
|
var init_git_timestamp = __esm({
|
|
328
364
|
"src/utils/git-timestamp.ts"() {
|
|
329
365
|
"use strict";
|
|
330
|
-
|
|
366
|
+
import_node_path2 = __toESM(require("path"), 1);
|
|
331
367
|
import_tinyexec = require("tinyexec");
|
|
332
368
|
cache = /* @__PURE__ */ new Map();
|
|
333
369
|
}
|
|
@@ -370,7 +406,7 @@ function getImportCode(info) {
|
|
|
370
406
|
return `import ${specifier}`;
|
|
371
407
|
}
|
|
372
408
|
function toImportPath(file, config) {
|
|
373
|
-
const ext =
|
|
409
|
+
const ext = import_node_path3.default.extname(file);
|
|
374
410
|
let filename;
|
|
375
411
|
if (ext === ".ts" && config.jsExtension) {
|
|
376
412
|
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
@@ -381,68 +417,23 @@ function toImportPath(file, config) {
|
|
|
381
417
|
}
|
|
382
418
|
let importPath;
|
|
383
419
|
if ("relativeTo" in config) {
|
|
384
|
-
importPath =
|
|
385
|
-
if (!
|
|
420
|
+
importPath = import_node_path3.default.relative(config.relativeTo, filename);
|
|
421
|
+
if (!import_node_path3.default.isAbsolute(importPath) && !importPath.startsWith(".")) {
|
|
386
422
|
importPath = `./${importPath}`;
|
|
387
423
|
}
|
|
388
424
|
} else {
|
|
389
|
-
importPath =
|
|
425
|
+
importPath = import_node_path3.default.resolve(filename);
|
|
390
426
|
}
|
|
391
|
-
return importPath.replaceAll(
|
|
427
|
+
return importPath.replaceAll(import_node_path3.default.sep, "/");
|
|
392
428
|
}
|
|
393
429
|
function ident(code, tab = 1) {
|
|
394
430
|
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
395
431
|
}
|
|
396
|
-
var
|
|
432
|
+
var import_node_path3;
|
|
397
433
|
var init_import_formatter = __esm({
|
|
398
434
|
"src/utils/import-formatter.ts"() {
|
|
399
435
|
"use strict";
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
// src/utils/collections.ts
|
|
405
|
-
function getGlobPatterns(collection) {
|
|
406
|
-
if (collection.files) return collection.files;
|
|
407
|
-
return [`**/*.{${SupportedFormats[collection.type].join(",")}}`];
|
|
408
|
-
}
|
|
409
|
-
function isFileSupported(filePath, collection) {
|
|
410
|
-
return SupportedFormats[collection.type].some(
|
|
411
|
-
(format) => filePath.endsWith(`.${format}`)
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
async function getCollectionFiles(collection) {
|
|
415
|
-
const files = /* @__PURE__ */ new Map();
|
|
416
|
-
const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
|
|
417
|
-
const patterns = getGlobPatterns(collection);
|
|
418
|
-
await Promise.all(
|
|
419
|
-
dirs.map(async (dir) => {
|
|
420
|
-
const result = await (0, import_tinyglobby.glob)(patterns, {
|
|
421
|
-
cwd: import_node_path5.default.resolve(dir)
|
|
422
|
-
});
|
|
423
|
-
for (const item of result) {
|
|
424
|
-
if (!isFileSupported(item, collection)) continue;
|
|
425
|
-
const fullPath = import_node_path5.default.join(dir, item);
|
|
426
|
-
files.set(fullPath, {
|
|
427
|
-
path: item,
|
|
428
|
-
fullPath
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
})
|
|
432
|
-
);
|
|
433
|
-
return Array.from(files.values());
|
|
434
|
-
}
|
|
435
|
-
var import_picomatch, import_tinyglobby, import_node_path5, SupportedFormats;
|
|
436
|
-
var init_collections = __esm({
|
|
437
|
-
"src/utils/collections.ts"() {
|
|
438
|
-
"use strict";
|
|
439
|
-
import_picomatch = __toESM(require("picomatch"), 1);
|
|
440
|
-
import_tinyglobby = require("tinyglobby");
|
|
441
|
-
import_node_path5 = __toESM(require("path"), 1);
|
|
442
|
-
SupportedFormats = {
|
|
443
|
-
doc: ["mdx", "md"],
|
|
444
|
-
meta: ["json", "yaml"]
|
|
445
|
-
};
|
|
436
|
+
import_node_path3 = __toESM(require("path"), 1);
|
|
446
437
|
}
|
|
447
438
|
});
|
|
448
439
|
|
|
@@ -454,17 +445,14 @@ function next() {
|
|
|
454
445
|
name: "next",
|
|
455
446
|
config(v) {
|
|
456
447
|
config = v;
|
|
457
|
-
shouldEmitOnChange =
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
shouldEmitOnChange = true;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
448
|
+
shouldEmitOnChange = config.collectionList.some((collection) => {
|
|
449
|
+
return collection.type === "doc" && collection.async || collection.type === "docs" || collection.type === "meta";
|
|
450
|
+
});
|
|
463
451
|
},
|
|
464
452
|
configureServer(server) {
|
|
465
453
|
if (!server.watcher) return;
|
|
466
|
-
server.watcher.on("all", async () => {
|
|
467
|
-
if (!shouldEmitOnChange) return;
|
|
454
|
+
server.watcher.on("all", async (event) => {
|
|
455
|
+
if (event === "change" && !shouldEmitOnChange) return;
|
|
468
456
|
await this.core.emitAndWrite({
|
|
469
457
|
filterPlugin: (plugin) => plugin.name === "next"
|
|
470
458
|
});
|
|
@@ -482,7 +470,7 @@ function next() {
|
|
|
482
470
|
}
|
|
483
471
|
};
|
|
484
472
|
}
|
|
485
|
-
async function indexFile(configPath, config, importPath
|
|
473
|
+
async function indexFile(configPath, config, importPath) {
|
|
486
474
|
let asyncInit = false;
|
|
487
475
|
const lines = [
|
|
488
476
|
getImportCode({
|
|
@@ -496,14 +484,10 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
496
484
|
name: "_source"
|
|
497
485
|
})
|
|
498
486
|
];
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
const params = [`collection=${collectionName}`];
|
|
504
|
-
if (configHash) {
|
|
505
|
-
params.push(`hash=${configHash}`);
|
|
506
|
-
}
|
|
487
|
+
function getDocEntries(collection, files) {
|
|
488
|
+
return files.map((file, i) => {
|
|
489
|
+
const importId = `d_${collection.name}_${i}`;
|
|
490
|
+
const params = [`collection=${collection.name}`];
|
|
507
491
|
lines.unshift(
|
|
508
492
|
getImportCode({
|
|
509
493
|
type: "namespace",
|
|
@@ -513,7 +497,6 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
513
497
|
);
|
|
514
498
|
return `{ info: ${JSON.stringify(file)}, data: ${importId} }`;
|
|
515
499
|
});
|
|
516
|
-
return Promise.all(items);
|
|
517
500
|
}
|
|
518
501
|
async function getMetaEntries(collection, files) {
|
|
519
502
|
const items = files.map(async (file) => {
|
|
@@ -554,7 +537,7 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
554
537
|
);
|
|
555
538
|
asyncInit = true;
|
|
556
539
|
}
|
|
557
|
-
const
|
|
540
|
+
const entries = files.map(async (file) => {
|
|
558
541
|
const content = await readFileWithCache(file.fullPath).catch(() => "");
|
|
559
542
|
const parsed = fumaMatter(content);
|
|
560
543
|
let data = parsed.data;
|
|
@@ -580,12 +563,13 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
580
563
|
);
|
|
581
564
|
return `{ info: { ${infoStr.join(", ")} }, lastModified: ${JSON.stringify(lastModified)}, data: ${JSON.stringify(data)} }`;
|
|
582
565
|
});
|
|
583
|
-
return Promise.all(
|
|
566
|
+
return Promise.all(entries);
|
|
584
567
|
}
|
|
585
|
-
const declares =
|
|
568
|
+
const declares = config.collectionList.map(async (collection) => {
|
|
569
|
+
const k = collection.name;
|
|
586
570
|
if (collection.type === "docs") {
|
|
587
|
-
const docs = await
|
|
588
|
-
const metas = await
|
|
571
|
+
const docs = await globCollectionFiles(collection.docs);
|
|
572
|
+
const metas = await globCollectionFiles(collection.meta);
|
|
589
573
|
const metaEntries = (await getMetaEntries(collection.meta, metas)).join(
|
|
590
574
|
", "
|
|
591
575
|
);
|
|
@@ -595,14 +579,17 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
595
579
|
);
|
|
596
580
|
return `export const ${k} = _runtimeAsync.docs<typeof _source.${k}>([${docsEntries2}], [${metaEntries}], "${k}", _sourceConfig)`;
|
|
597
581
|
}
|
|
598
|
-
const docsEntries =
|
|
582
|
+
const docsEntries = getDocEntries(collection.docs, docs).join(", ");
|
|
599
583
|
return `export const ${k} = _runtime.docs<typeof _source.${k}>([${docsEntries}], [${metaEntries}])`;
|
|
600
584
|
}
|
|
601
|
-
const files = await
|
|
602
|
-
if (collection.type === "
|
|
585
|
+
const files = await globCollectionFiles(collection);
|
|
586
|
+
if (collection.type === "meta") {
|
|
587
|
+
return `export const ${k} = _runtime.meta<typeof _source.${k}>([${(await getMetaEntries(collection, files)).join(", ")}]);`;
|
|
588
|
+
}
|
|
589
|
+
if (collection.async) {
|
|
603
590
|
return `export const ${k} = _runtimeAsync.doc<typeof _source.${k}>([${(await getAsyncEntries(collection, files)).join(", ")}], "${k}", _sourceConfig)`;
|
|
604
591
|
}
|
|
605
|
-
return `export const ${k} = _runtime
|
|
592
|
+
return `export const ${k} = _runtime.doc<typeof _source.${k}>([${getDocEntries(collection, files).join(", ")}]);`;
|
|
606
593
|
});
|
|
607
594
|
const resolvedDeclares = await Promise.all(declares);
|
|
608
595
|
return [
|
|
@@ -612,34 +599,57 @@ async function indexFile(configPath, config, importPath, configHash = false) {
|
|
|
612
599
|
].join("\n");
|
|
613
600
|
}
|
|
614
601
|
function parseMetaEntry(file, content) {
|
|
615
|
-
const
|
|
602
|
+
const extname3 = path5.extname(file);
|
|
616
603
|
try {
|
|
617
|
-
if (
|
|
618
|
-
if (
|
|
604
|
+
if (extname3 === ".json") return JSON.parse(content);
|
|
605
|
+
if (extname3 === ".yaml") return (0, import_js_yaml2.load)(content);
|
|
619
606
|
} catch (e) {
|
|
620
607
|
throw new Error(`Failed to parse meta file: ${file}.`, {
|
|
621
608
|
cause: e
|
|
622
609
|
});
|
|
623
610
|
}
|
|
624
|
-
throw new Error(`Unknown meta file format: ${
|
|
611
|
+
throw new Error(`Unknown meta file format: ${extname3}, in ${file}.`);
|
|
625
612
|
}
|
|
626
|
-
|
|
613
|
+
async function globCollectionFiles(collection) {
|
|
614
|
+
const { glob } = await import("tinyglobby");
|
|
615
|
+
const files = /* @__PURE__ */ new Map();
|
|
616
|
+
const dirs = Array.isArray(collection.dir) ? collection.dir : [collection.dir];
|
|
617
|
+
await Promise.all(
|
|
618
|
+
dirs.map(async (dir) => {
|
|
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
|
+
})
|
|
631
|
+
);
|
|
632
|
+
return Array.from(files.values());
|
|
633
|
+
}
|
|
634
|
+
var path5, import_node_crypto, import_js_yaml2;
|
|
627
635
|
var init_next = __esm({
|
|
628
636
|
"src/plugins/next.ts"() {
|
|
629
637
|
"use strict";
|
|
630
|
-
|
|
638
|
+
path5 = __toESM(require("path"), 1);
|
|
631
639
|
import_node_crypto = require("crypto");
|
|
632
640
|
init_validation();
|
|
633
641
|
init_file_cache();
|
|
634
|
-
import_js_yaml2 = require("js-yaml");
|
|
635
642
|
init_git_timestamp();
|
|
636
643
|
init_fuma_matter();
|
|
637
644
|
init_import_formatter();
|
|
638
|
-
|
|
645
|
+
import_js_yaml2 = require("js-yaml");
|
|
639
646
|
}
|
|
640
647
|
});
|
|
641
648
|
|
|
642
649
|
// src/core.ts
|
|
650
|
+
function findConfigFile() {
|
|
651
|
+
return import_node_path4.default.resolve("source.config.ts");
|
|
652
|
+
}
|
|
643
653
|
function createCore(options, defaultPlugins = []) {
|
|
644
654
|
let config;
|
|
645
655
|
let plugins2;
|
|
@@ -676,13 +686,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
676
686
|
getConfig() {
|
|
677
687
|
return config;
|
|
678
688
|
},
|
|
679
|
-
creatConfigLoader() {
|
|
680
|
-
return {
|
|
681
|
-
getConfig() {
|
|
682
|
-
return config;
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
},
|
|
686
689
|
async initServer(server) {
|
|
687
690
|
for (const plugin of plugins2) {
|
|
688
691
|
await plugin.configureServer?.call(this.getPluginContext(), server);
|
|
@@ -700,21 +703,31 @@ function createCore(options, defaultPlugins = []) {
|
|
|
700
703
|
);
|
|
701
704
|
await Promise.all(
|
|
702
705
|
out.flat().map(async (entry) => {
|
|
703
|
-
const file =
|
|
704
|
-
await
|
|
705
|
-
await
|
|
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);
|
|
706
709
|
})
|
|
707
710
|
);
|
|
708
711
|
console.log(`[MDX] generated files in ${performance.now() - start2}ms`);
|
|
709
712
|
}
|
|
710
713
|
};
|
|
711
714
|
}
|
|
712
|
-
var
|
|
715
|
+
var import_node_path4, import_promises2;
|
|
713
716
|
var init_core = __esm({
|
|
714
717
|
"src/core.ts"() {
|
|
715
718
|
"use strict";
|
|
716
|
-
|
|
717
|
-
|
|
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"() {
|
|
728
|
+
"use strict";
|
|
729
|
+
metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
730
|
+
mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
718
731
|
}
|
|
719
732
|
});
|
|
720
733
|
|
|
@@ -732,7 +745,7 @@ function createMDX(createOptions = {}) {
|
|
|
732
745
|
void init(isDev, options);
|
|
733
746
|
}
|
|
734
747
|
return (nextConfig = {}) => {
|
|
735
|
-
const
|
|
748
|
+
const loaderOptions = {
|
|
736
749
|
...options,
|
|
737
750
|
isDev
|
|
738
751
|
};
|
|
@@ -744,7 +757,7 @@ function createMDX(createOptions = {}) {
|
|
|
744
757
|
loaders: [
|
|
745
758
|
{
|
|
746
759
|
loader: "fumadocs-mdx/loader-mdx",
|
|
747
|
-
options:
|
|
760
|
+
options: loaderOptions
|
|
748
761
|
}
|
|
749
762
|
],
|
|
750
763
|
as: "*.js"
|
|
@@ -760,12 +773,12 @@ function createMDX(createOptions = {}) {
|
|
|
760
773
|
config.module ||= {};
|
|
761
774
|
config.module.rules ||= [];
|
|
762
775
|
config.module.rules.push({
|
|
763
|
-
test:
|
|
776
|
+
test: mdxLoaderGlob,
|
|
764
777
|
use: [
|
|
765
778
|
options2.defaultLoaders.babel,
|
|
766
779
|
{
|
|
767
780
|
loader: "fumadocs-mdx/loader-mdx",
|
|
768
|
-
options:
|
|
781
|
+
options: loaderOptions
|
|
769
782
|
}
|
|
770
783
|
]
|
|
771
784
|
});
|
|
@@ -791,7 +804,7 @@ async function init(dev, options) {
|
|
|
791
804
|
ignored: [options.outDir]
|
|
792
805
|
});
|
|
793
806
|
watcher.add(options.configPath);
|
|
794
|
-
for (const collection of core.getConfig().
|
|
807
|
+
for (const collection of core.getConfig().collectionList) {
|
|
795
808
|
if (collection.type === "docs") {
|
|
796
809
|
watcher.add(collection.docs.dir);
|
|
797
810
|
watcher.add(collection.meta.dir);
|
|
@@ -803,9 +816,9 @@ async function init(dev, options) {
|
|
|
803
816
|
console.log("[MDX] started dev server");
|
|
804
817
|
});
|
|
805
818
|
watcher.on("all", async (event, file) => {
|
|
806
|
-
const absolutePath =
|
|
819
|
+
const absolutePath = path7.resolve(file);
|
|
807
820
|
if (event === "change") removeFileCache(absolutePath);
|
|
808
|
-
if (absolutePath ===
|
|
821
|
+
if (absolutePath === path7.resolve(options.configPath)) {
|
|
809
822
|
watcher.removeAllListeners();
|
|
810
823
|
await watcher.close();
|
|
811
824
|
await initOrReload();
|
|
@@ -867,17 +880,17 @@ function createNextCore({
|
|
|
867
880
|
}
|
|
868
881
|
};
|
|
869
882
|
}
|
|
870
|
-
var
|
|
883
|
+
var path7, defaultPageExtensions;
|
|
871
884
|
var init_next2 = __esm({
|
|
872
885
|
"src/next/index.ts"() {
|
|
873
886
|
"use strict";
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
init_load();
|
|
887
|
+
path7 = __toESM(require("path"), 1);
|
|
888
|
+
init_load_from_file();
|
|
877
889
|
init_file_cache();
|
|
878
890
|
init_validation();
|
|
879
891
|
init_next();
|
|
880
892
|
init_core();
|
|
893
|
+
init_loaders();
|
|
881
894
|
defaultPageExtensions = ["mdx", "md", "jsx", "js", "tsx", "ts"];
|
|
882
895
|
}
|
|
883
896
|
});
|
|
@@ -1000,7 +1013,7 @@ function remarkInclude() {
|
|
|
1000
1013
|
const embedContent = async (file, heading, params, data) => {
|
|
1001
1014
|
let content;
|
|
1002
1015
|
try {
|
|
1003
|
-
content = (await
|
|
1016
|
+
content = (await fs3.readFile(file)).toString();
|
|
1004
1017
|
} catch (e) {
|
|
1005
1018
|
throw new Error(
|
|
1006
1019
|
`failed to read file ${file}
|
|
@@ -1008,7 +1021,7 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1008
1021
|
{ cause: e }
|
|
1009
1022
|
);
|
|
1010
1023
|
}
|
|
1011
|
-
const ext =
|
|
1024
|
+
const ext = path8.extname(file);
|
|
1012
1025
|
data._compiler?.addDependency(file);
|
|
1013
1026
|
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
1014
1027
|
const lang = params.lang ?? ext.slice(1);
|
|
@@ -1041,7 +1054,7 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1041
1054
|
} else {
|
|
1042
1055
|
mdast = await baseProcessor.run(mdast);
|
|
1043
1056
|
}
|
|
1044
|
-
await update(mdast,
|
|
1057
|
+
await update(mdast, path8.dirname(file), data);
|
|
1045
1058
|
return mdast;
|
|
1046
1059
|
};
|
|
1047
1060
|
async function update(tree, directory, data) {
|
|
@@ -1053,7 +1066,7 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1053
1066
|
if (specifier.length === 0) return "skip";
|
|
1054
1067
|
const attributes = parseElementAttributes(node);
|
|
1055
1068
|
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
1056
|
-
const file =
|
|
1069
|
+
const file = path8.resolve(
|
|
1057
1070
|
"cwd" in attributes ? process.cwd() : directory,
|
|
1058
1071
|
relativePath
|
|
1059
1072
|
);
|
|
@@ -1070,17 +1083,17 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
1070
1083
|
await Promise.all(queue);
|
|
1071
1084
|
}
|
|
1072
1085
|
return async (tree, file) => {
|
|
1073
|
-
await update(tree,
|
|
1086
|
+
await update(tree, path8.dirname(file.path), file.data);
|
|
1074
1087
|
};
|
|
1075
1088
|
}
|
|
1076
|
-
var import_unified, import_unist_util_visit2,
|
|
1089
|
+
var import_unified, import_unist_util_visit2, path8, fs3, import_mdx_plugins, ElementLikeTypes;
|
|
1077
1090
|
var init_remark_include = __esm({
|
|
1078
1091
|
"src/loaders/mdx/remark-include.ts"() {
|
|
1079
1092
|
"use strict";
|
|
1080
1093
|
import_unified = require("unified");
|
|
1081
1094
|
import_unist_util_visit2 = require("unist-util-visit");
|
|
1082
|
-
|
|
1083
|
-
|
|
1095
|
+
path8 = __toESM(require("path"), 1);
|
|
1096
|
+
fs3 = __toESM(require("fs/promises"), 1);
|
|
1084
1097
|
init_fuma_matter();
|
|
1085
1098
|
import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
1086
1099
|
init_remark_unravel();
|
|
@@ -1275,12 +1288,12 @@ function createMdxLoader(configLoader) {
|
|
|
1275
1288
|
if (!isDevelopment && config.global.experimentalBuildCache) {
|
|
1276
1289
|
const cacheDir = config.global.experimentalBuildCache;
|
|
1277
1290
|
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
1278
|
-
const cached = await
|
|
1291
|
+
const cached = await import_promises3.default.readFile(import_node_path5.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
1279
1292
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
1280
1293
|
after = async () => {
|
|
1281
|
-
await
|
|
1282
|
-
await
|
|
1283
|
-
|
|
1294
|
+
await import_promises3.default.mkdir(cacheDir, { recursive: true });
|
|
1295
|
+
await import_promises3.default.writeFile(
|
|
1296
|
+
import_node_path5.default.join(cacheDir, cacheKey),
|
|
1284
1297
|
JSON.stringify({
|
|
1285
1298
|
...out,
|
|
1286
1299
|
hash: generateCacheHash(value)
|
|
@@ -1288,7 +1301,7 @@ function createMdxLoader(configLoader) {
|
|
|
1288
1301
|
);
|
|
1289
1302
|
};
|
|
1290
1303
|
}
|
|
1291
|
-
const collection = parsed.collection ? config.
|
|
1304
|
+
const collection = parsed.collection ? config.getCollection(parsed.collection) : void 0;
|
|
1292
1305
|
let docCollection;
|
|
1293
1306
|
switch (collection?.type) {
|
|
1294
1307
|
case "doc":
|
|
@@ -1358,7 +1371,7 @@ function countLines(s) {
|
|
|
1358
1371
|
}
|
|
1359
1372
|
return num;
|
|
1360
1373
|
}
|
|
1361
|
-
var import_zod,
|
|
1374
|
+
var import_zod, import_promises3, import_node_path5, import_node_crypto2, querySchema, cacheEntry, hashes;
|
|
1362
1375
|
var init_mdx = __esm({
|
|
1363
1376
|
"src/loaders/mdx/index.ts"() {
|
|
1364
1377
|
"use strict";
|
|
@@ -1367,8 +1380,8 @@ var init_mdx = __esm({
|
|
|
1367
1380
|
init_git_timestamp();
|
|
1368
1381
|
init_build_mdx();
|
|
1369
1382
|
import_zod = require("zod");
|
|
1370
|
-
|
|
1371
|
-
|
|
1383
|
+
import_promises3 = __toESM(require("fs/promises"), 1);
|
|
1384
|
+
import_node_path5 = __toESM(require("path"), 1);
|
|
1372
1385
|
import_node_crypto2 = require("crypto");
|
|
1373
1386
|
querySchema = import_zod.z.object({
|
|
1374
1387
|
only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
|
|
@@ -1397,32 +1410,33 @@ function toVite(loader) {
|
|
|
1397
1410
|
}
|
|
1398
1411
|
}
|
|
1399
1412
|
});
|
|
1413
|
+
if (result === null) return null;
|
|
1400
1414
|
return {
|
|
1401
1415
|
code: result.code,
|
|
1402
1416
|
map: result.map
|
|
1403
1417
|
};
|
|
1404
1418
|
};
|
|
1405
1419
|
}
|
|
1406
|
-
var import_node_url2,
|
|
1420
|
+
var import_node_url2, import_promises4, import_node_querystring, import_node_path6;
|
|
1407
1421
|
var init_adapter = __esm({
|
|
1408
1422
|
"src/loaders/adapter.ts"() {
|
|
1409
1423
|
"use strict";
|
|
1410
1424
|
import_node_url2 = require("url");
|
|
1411
|
-
|
|
1425
|
+
import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1412
1426
|
import_node_querystring = require("querystring");
|
|
1413
1427
|
init_validation();
|
|
1414
|
-
|
|
1428
|
+
import_node_path6 = __toESM(require("path"), 1);
|
|
1415
1429
|
}
|
|
1416
1430
|
});
|
|
1417
1431
|
|
|
1418
1432
|
// src/utils/glob-import.ts
|
|
1419
1433
|
function generateGlobImport(patterns, options) {
|
|
1420
1434
|
let code = "{";
|
|
1421
|
-
const result = (0,
|
|
1435
|
+
const result = (0, import_tinyglobby.globSync)(patterns, {
|
|
1422
1436
|
cwd: options.base
|
|
1423
1437
|
});
|
|
1424
1438
|
for (const item of result) {
|
|
1425
|
-
const fullPath =
|
|
1439
|
+
const fullPath = import_node_path7.default.join(options.base, item);
|
|
1426
1440
|
const url = (0, import_node_url3.pathToFileURL)(fullPath);
|
|
1427
1441
|
for (const [k, v] of Object.entries(options.query ?? {})) {
|
|
1428
1442
|
url.searchParams.set(k, v);
|
|
@@ -1436,38 +1450,84 @@ function generateGlobImport(patterns, options) {
|
|
|
1436
1450
|
code += "}";
|
|
1437
1451
|
return code;
|
|
1438
1452
|
}
|
|
1439
|
-
var
|
|
1453
|
+
var import_tinyglobby, import_node_path7, import_node_url3;
|
|
1440
1454
|
var init_glob_import = __esm({
|
|
1441
1455
|
"src/utils/glob-import.ts"() {
|
|
1442
1456
|
"use strict";
|
|
1443
|
-
|
|
1444
|
-
|
|
1457
|
+
import_tinyglobby = require("tinyglobby");
|
|
1458
|
+
import_node_path7 = __toESM(require("path"), 1);
|
|
1445
1459
|
import_node_url3 = require("url");
|
|
1446
1460
|
}
|
|
1447
1461
|
});
|
|
1448
1462
|
|
|
1449
1463
|
// src/plugins/vite.ts
|
|
1450
|
-
function vite(
|
|
1464
|
+
function vite({
|
|
1465
|
+
index
|
|
1466
|
+
}) {
|
|
1451
1467
|
let config;
|
|
1468
|
+
let indexOptions;
|
|
1469
|
+
if (index === false) indexOptions = false;
|
|
1470
|
+
else indexOptions = applyDefaults2(index === true ? {} : index);
|
|
1452
1471
|
return {
|
|
1472
|
+
name: "vite",
|
|
1453
1473
|
config(v) {
|
|
1454
1474
|
config = v;
|
|
1455
1475
|
},
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1476
|
+
configureServer(server) {
|
|
1477
|
+
if (!server.watcher || indexOptions === false || indexOptions.runtime === false)
|
|
1478
|
+
return;
|
|
1479
|
+
server.watcher.on("all", (event, file) => {
|
|
1480
|
+
if (event === "change") return;
|
|
1481
|
+
const isUpdated = config.collectionList.some((collection) => {
|
|
1482
|
+
if (collection.type === "docs")
|
|
1483
|
+
return collection.docs.hasFile(file) || collection.meta.hasFile(file);
|
|
1484
|
+
return collection.hasFile(file);
|
|
1485
|
+
});
|
|
1486
|
+
if (isUpdated) {
|
|
1487
|
+
this.core.emitAndWrite({
|
|
1488
|
+
filterPlugin: (plugin) => plugin.name === "vite"
|
|
1489
|
+
});
|
|
1461
1490
|
}
|
|
1462
|
-
|
|
1491
|
+
});
|
|
1492
|
+
},
|
|
1493
|
+
emit() {
|
|
1494
|
+
const out = [];
|
|
1495
|
+
if (indexOptions === false) return out;
|
|
1496
|
+
if (indexOptions.browser) {
|
|
1497
|
+
out.push({
|
|
1498
|
+
path: "browser.ts",
|
|
1499
|
+
content: indexFile2(this, config, indexOptions, "browser")
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
out.push({
|
|
1503
|
+
path: "index.ts",
|
|
1504
|
+
content: indexFile2(
|
|
1505
|
+
this,
|
|
1506
|
+
config,
|
|
1507
|
+
indexOptions,
|
|
1508
|
+
indexOptions.browser ? "server" : "all"
|
|
1509
|
+
)
|
|
1510
|
+
});
|
|
1511
|
+
return out;
|
|
1463
1512
|
}
|
|
1464
1513
|
};
|
|
1465
1514
|
}
|
|
1466
|
-
function
|
|
1467
|
-
|
|
1515
|
+
function applyDefaults2(options) {
|
|
1516
|
+
return {
|
|
1517
|
+
addJsExtension: options.addJsExtension ?? false,
|
|
1518
|
+
browser: options.browser ?? false,
|
|
1519
|
+
runtime: options.runtime ?? false
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
function indexFile2({ configPath, outDir }, config, { addJsExtension, runtime }, environment) {
|
|
1523
|
+
const runtimePath = {
|
|
1524
|
+
all: "fumadocs-mdx/runtime/vite",
|
|
1525
|
+
server: "fumadocs-mdx/runtime/vite.server",
|
|
1526
|
+
browser: "fumadocs-mdx/runtime/vite.browser"
|
|
1527
|
+
}[environment];
|
|
1468
1528
|
const lines = [
|
|
1469
1529
|
'/// <reference types="vite/client" />',
|
|
1470
|
-
`import { fromConfig } from '
|
|
1530
|
+
`import { fromConfig } from '${runtimePath}';`,
|
|
1471
1531
|
`import type * as Config from '${toImportPath(configPath, {
|
|
1472
1532
|
relativeTo: outDir,
|
|
1473
1533
|
jsExtension: addJsExtension
|
|
@@ -1475,74 +1535,68 @@ function indexFile2(configPath, outDir, config, options) {
|
|
|
1475
1535
|
"",
|
|
1476
1536
|
`export const create = fromConfig<typeof Config>();`
|
|
1477
1537
|
];
|
|
1478
|
-
function
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1538
|
+
function generateCollectionGlob(collection) {
|
|
1539
|
+
if (collection.type === "docs") {
|
|
1540
|
+
const obj = [
|
|
1541
|
+
ident(`doc: ${generateCollectionGlob(collection.docs)}`),
|
|
1542
|
+
ident(`meta: ${generateCollectionGlob(collection.meta)}`)
|
|
1543
|
+
].join(",\n");
|
|
1544
|
+
return `{
|
|
1484
1545
|
${obj}
|
|
1485
1546
|
}`;
|
|
1486
|
-
|
|
1487
|
-
function doc(name, collection) {
|
|
1488
|
-
const patterns = getGlobPatterns(collection);
|
|
1547
|
+
}
|
|
1489
1548
|
const dir = getCollectionDir(collection);
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
collection: name
|
|
1493
|
-
},
|
|
1494
|
-
base: dir
|
|
1495
|
-
});
|
|
1496
|
-
if (collection.async) {
|
|
1497
|
-
const headBlob = generateGlob(patterns, {
|
|
1549
|
+
if (collection.type === "doc") {
|
|
1550
|
+
const docGlob = generateGlob(collection.patterns, {
|
|
1498
1551
|
query: {
|
|
1499
|
-
|
|
1500
|
-
collection: name
|
|
1552
|
+
collection: collection.name
|
|
1501
1553
|
},
|
|
1502
|
-
import: "frontmatter",
|
|
1503
1554
|
base: dir
|
|
1504
1555
|
});
|
|
1505
|
-
|
|
1556
|
+
if (collection.async) {
|
|
1557
|
+
const headBlob = generateGlob(collection.patterns, {
|
|
1558
|
+
query: {
|
|
1559
|
+
only: "frontmatter",
|
|
1560
|
+
collection: collection.name
|
|
1561
|
+
},
|
|
1562
|
+
import: "frontmatter",
|
|
1563
|
+
base: dir
|
|
1564
|
+
});
|
|
1565
|
+
return `create.docLazy("${collection.name}", "${dir}", ${headBlob}, ${docGlob})`;
|
|
1566
|
+
}
|
|
1567
|
+
return `create.doc("${collection.name}", "${dir}", ${docGlob})`;
|
|
1506
1568
|
}
|
|
1507
|
-
return `create.
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
query: {
|
|
1516
|
-
collection: name
|
|
1569
|
+
return `create.meta("${collection.name}", "${dir}", ${generateGlob(
|
|
1570
|
+
collection.patterns,
|
|
1571
|
+
{
|
|
1572
|
+
import: "default",
|
|
1573
|
+
base: dir,
|
|
1574
|
+
query: {
|
|
1575
|
+
collection: collection.name
|
|
1576
|
+
}
|
|
1517
1577
|
}
|
|
1518
|
-
|
|
1578
|
+
)})`;
|
|
1519
1579
|
}
|
|
1520
|
-
function generateGlob(patterns,
|
|
1580
|
+
function generateGlob(patterns, options) {
|
|
1521
1581
|
patterns = patterns.map(normalizeGlobPath);
|
|
1522
1582
|
if (runtime === "node" || runtime === "bun") {
|
|
1523
|
-
return generateGlobImport(patterns,
|
|
1583
|
+
return generateGlobImport(patterns, options);
|
|
1524
1584
|
} else {
|
|
1525
1585
|
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
1526
1586
|
{
|
|
1527
|
-
...
|
|
1528
|
-
base: normalizeGlobPath(
|
|
1587
|
+
...options,
|
|
1588
|
+
base: normalizeGlobPath(import_node_path8.default.relative(outDir, options.base))
|
|
1529
1589
|
},
|
|
1530
1590
|
null,
|
|
1531
1591
|
2
|
|
1532
1592
|
)})`;
|
|
1533
1593
|
}
|
|
1534
1594
|
}
|
|
1535
|
-
for (const
|
|
1536
|
-
let body;
|
|
1537
|
-
if (collection.type === "docs") {
|
|
1538
|
-
body = docs(name, collection);
|
|
1539
|
-
} else if (collection.type === "meta") {
|
|
1540
|
-
body = meta(name, collection);
|
|
1541
|
-
} else {
|
|
1542
|
-
body = doc(name, collection);
|
|
1543
|
-
}
|
|
1595
|
+
for (const collection of config.collectionList) {
|
|
1544
1596
|
lines.push("");
|
|
1545
|
-
lines.push(
|
|
1597
|
+
lines.push(
|
|
1598
|
+
`export const ${collection.name} = ${generateCollectionGlob(collection)};`
|
|
1599
|
+
);
|
|
1546
1600
|
}
|
|
1547
1601
|
return lines.join("\n");
|
|
1548
1602
|
}
|
|
@@ -1552,8 +1606,7 @@ function normalizeGlobPath(file) {
|
|
|
1552
1606
|
if (file.startsWith("/")) return `.${file}`;
|
|
1553
1607
|
return `./${file}`;
|
|
1554
1608
|
}
|
|
1555
|
-
function getCollectionDir(
|
|
1556
|
-
const dir = collection.dir;
|
|
1609
|
+
function getCollectionDir({ dir }) {
|
|
1557
1610
|
if (Array.isArray(dir)) {
|
|
1558
1611
|
if (dir.length !== 1)
|
|
1559
1612
|
throw new Error(
|
|
@@ -1563,43 +1616,55 @@ function getCollectionDir(collection) {
|
|
|
1563
1616
|
}
|
|
1564
1617
|
return dir;
|
|
1565
1618
|
}
|
|
1566
|
-
function slash(
|
|
1567
|
-
const isExtendedLengthPath =
|
|
1619
|
+
function slash(path13) {
|
|
1620
|
+
const isExtendedLengthPath = path13.startsWith("\\\\?\\");
|
|
1568
1621
|
if (isExtendedLengthPath) {
|
|
1569
|
-
return
|
|
1622
|
+
return path13;
|
|
1570
1623
|
}
|
|
1571
|
-
return
|
|
1624
|
+
return path13.replaceAll("\\", "/");
|
|
1572
1625
|
}
|
|
1573
|
-
var
|
|
1626
|
+
var import_node_path8;
|
|
1574
1627
|
var init_vite = __esm({
|
|
1575
1628
|
"src/plugins/vite.ts"() {
|
|
1576
1629
|
"use strict";
|
|
1577
1630
|
init_import_formatter();
|
|
1578
|
-
init_collections();
|
|
1579
1631
|
init_glob_import();
|
|
1580
|
-
|
|
1632
|
+
import_node_path8 = __toESM(require("path"), 1);
|
|
1581
1633
|
}
|
|
1582
1634
|
});
|
|
1583
1635
|
|
|
1584
|
-
// src/
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1636
|
+
// src/loaders/config.ts
|
|
1637
|
+
function createIntegratedConfigLoader(core) {
|
|
1638
|
+
return {
|
|
1639
|
+
getConfig() {
|
|
1640
|
+
return core.getConfig();
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
var import_promises5;
|
|
1645
|
+
var init_config = __esm({
|
|
1646
|
+
"src/loaders/config.ts"() {
|
|
1647
|
+
"use strict";
|
|
1648
|
+
import_promises5 = __toESM(require("fs/promises"), 1);
|
|
1649
|
+
}
|
|
1589
1650
|
});
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
})
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
const
|
|
1598
|
-
const parsed = (0, import_node_querystring2.parse)(query);
|
|
1599
|
-
const collection = parsed.collection ? core.getConfig().collections.get(parsed.collection) : void 0;
|
|
1651
|
+
|
|
1652
|
+
// src/loaders/meta.ts
|
|
1653
|
+
function createMetaLoader(configLoader, resolve5 = {}) {
|
|
1654
|
+
const { json: resolveJson = "js", yaml: resolveYaml = "js" } = resolve5;
|
|
1655
|
+
return async ({ filePath, query, source }) => {
|
|
1656
|
+
const isJson = filePath.endsWith(".json");
|
|
1657
|
+
const parsed = querySchema2.parse(query);
|
|
1658
|
+
const collection = parsed.collection ? (await configLoader.getConfig()).getCollection(parsed.collection) : void 0;
|
|
1600
1659
|
if (!collection) return null;
|
|
1660
|
+
let data;
|
|
1661
|
+
try {
|
|
1662
|
+
data = isJson ? JSON.parse(source) : (0, import_js_yaml3.load)(source);
|
|
1663
|
+
} catch (e) {
|
|
1664
|
+
throw new Error(`invalid data in ${filePath}`, { cause: e });
|
|
1665
|
+
}
|
|
1601
1666
|
let schema;
|
|
1602
|
-
switch (collection
|
|
1667
|
+
switch (collection?.type) {
|
|
1603
1668
|
case "meta":
|
|
1604
1669
|
schema = collection.schema;
|
|
1605
1670
|
break;
|
|
@@ -1607,24 +1672,58 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1607
1672
|
schema = collection.meta.schema;
|
|
1608
1673
|
break;
|
|
1609
1674
|
}
|
|
1610
|
-
if (
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1675
|
+
if (schema) {
|
|
1676
|
+
data = await validate(
|
|
1677
|
+
schema,
|
|
1678
|
+
data,
|
|
1679
|
+
{ path: filePath, source },
|
|
1680
|
+
`invalid data in ${filePath}`
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
let code;
|
|
1684
|
+
if (isJson) {
|
|
1685
|
+
code = resolveJson === "json" ? JSON.stringify(data) : `export default ${JSON.stringify(data)}`;
|
|
1686
|
+
} else {
|
|
1687
|
+
code = resolveYaml === "yaml" ? (0, import_js_yaml3.dump)(data) : `export default ${JSON.stringify(data)}`;
|
|
1616
1688
|
}
|
|
1617
|
-
const out = await validate(
|
|
1618
|
-
schema,
|
|
1619
|
-
data,
|
|
1620
|
-
{ path: path16, source: value },
|
|
1621
|
-
`invalid data in ${path16}`
|
|
1622
|
-
);
|
|
1623
1689
|
return {
|
|
1624
|
-
code
|
|
1690
|
+
code,
|
|
1625
1691
|
map: null
|
|
1626
1692
|
};
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
var import_js_yaml3, import_zod2, querySchema2;
|
|
1696
|
+
var init_meta = __esm({
|
|
1697
|
+
"src/loaders/meta.ts"() {
|
|
1698
|
+
"use strict";
|
|
1699
|
+
import_js_yaml3 = require("js-yaml");
|
|
1700
|
+
init_validation();
|
|
1701
|
+
import_zod2 = require("zod");
|
|
1702
|
+
querySchema2 = import_zod2.z.object({
|
|
1703
|
+
collection: import_zod2.z.string().optional()
|
|
1704
|
+
}).loose();
|
|
1627
1705
|
}
|
|
1706
|
+
});
|
|
1707
|
+
|
|
1708
|
+
// src/vite/index.ts
|
|
1709
|
+
var vite_exports = {};
|
|
1710
|
+
__export(vite_exports, {
|
|
1711
|
+
default: () => mdx,
|
|
1712
|
+
postInstall: () => postInstall2
|
|
1713
|
+
});
|
|
1714
|
+
async function mdx(config, pluginOptions = {}) {
|
|
1715
|
+
const options = applyDefaults3(pluginOptions);
|
|
1716
|
+
const core = await createViteCore(options).init({
|
|
1717
|
+
config: buildConfig(config)
|
|
1718
|
+
});
|
|
1719
|
+
const configLoader = createIntegratedConfigLoader(core);
|
|
1720
|
+
const mdxLoader = toVite(createMdxLoader(configLoader));
|
|
1721
|
+
const metaLoader = toVite(
|
|
1722
|
+
createMetaLoader(configLoader, {
|
|
1723
|
+
// vite has built-in plugin for JSON files
|
|
1724
|
+
json: "json"
|
|
1725
|
+
})
|
|
1726
|
+
);
|
|
1628
1727
|
return {
|
|
1629
1728
|
name: "fumadocs-mdx",
|
|
1630
1729
|
// needed, otherwise other plugins will be executed before our `transform`.
|
|
@@ -1650,13 +1749,15 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1650
1749
|
});
|
|
1651
1750
|
},
|
|
1652
1751
|
async transform(value, id) {
|
|
1653
|
-
const [file, query = ""] = id.split("?");
|
|
1654
|
-
const ext = path15.extname(file);
|
|
1655
1752
|
try {
|
|
1656
|
-
if (
|
|
1657
|
-
|
|
1658
|
-
|
|
1753
|
+
if (metaLoaderGlob.test(id)) {
|
|
1754
|
+
const [file, query = ""] = id.split("?", 2);
|
|
1755
|
+
return await metaLoader.call(this, file, query, value);
|
|
1756
|
+
}
|
|
1757
|
+
if (mdxLoaderGlob.test(id)) {
|
|
1758
|
+
const [file, query = ""] = id.split("?", 2);
|
|
1659
1759
|
return await mdxLoader.call(this, file, query, value);
|
|
1760
|
+
}
|
|
1660
1761
|
} catch (e) {
|
|
1661
1762
|
if (e instanceof ValidationError) {
|
|
1662
1763
|
throw new Error(e.toStringFormatted());
|
|
@@ -1667,8 +1768,8 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
1667
1768
|
};
|
|
1668
1769
|
}
|
|
1669
1770
|
async function postInstall2(configPath = findConfigFile(), pluginOptions = {}) {
|
|
1670
|
-
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (
|
|
1671
|
-
const options =
|
|
1771
|
+
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load_from_file(), load_from_file_exports));
|
|
1772
|
+
const options = applyDefaults3(pluginOptions);
|
|
1672
1773
|
const core = await createViteCore(options).init({
|
|
1673
1774
|
config: loadConfig2(configPath, options.outDir, true)
|
|
1674
1775
|
});
|
|
@@ -1686,11 +1787,13 @@ function createViteCore({
|
|
|
1686
1787
|
outDir
|
|
1687
1788
|
},
|
|
1688
1789
|
[
|
|
1689
|
-
|
|
1790
|
+
vite({
|
|
1791
|
+
index: generateIndexFile
|
|
1792
|
+
})
|
|
1690
1793
|
]
|
|
1691
1794
|
);
|
|
1692
1795
|
}
|
|
1693
|
-
function
|
|
1796
|
+
function applyDefaults3(options) {
|
|
1694
1797
|
return {
|
|
1695
1798
|
updateViteConfig: options.updateViteConfig ?? true,
|
|
1696
1799
|
generateIndexFile: options.generateIndexFile ?? true,
|
|
@@ -1698,21 +1801,20 @@ function applyDefaults2(options) {
|
|
|
1698
1801
|
outDir: options.outDir ?? ".source"
|
|
1699
1802
|
};
|
|
1700
1803
|
}
|
|
1701
|
-
var import_vite,
|
|
1804
|
+
var import_vite, FumadocsDeps;
|
|
1702
1805
|
var init_vite2 = __esm({
|
|
1703
1806
|
"src/vite/index.ts"() {
|
|
1704
1807
|
"use strict";
|
|
1705
1808
|
import_vite = require("vite");
|
|
1706
1809
|
init_build();
|
|
1707
|
-
import_node_querystring2 = require("querystring");
|
|
1708
1810
|
init_validation();
|
|
1709
|
-
path15 = __toESM(require("path"), 1);
|
|
1710
|
-
import_js_yaml3 = require("js-yaml");
|
|
1711
1811
|
init_mdx();
|
|
1712
|
-
init_config();
|
|
1713
1812
|
init_adapter();
|
|
1714
1813
|
init_vite();
|
|
1715
1814
|
init_core();
|
|
1815
|
+
init_config();
|
|
1816
|
+
init_meta();
|
|
1817
|
+
init_loaders();
|
|
1716
1818
|
FumadocsDeps = ["fumadocs-core", "fumadocs-ui", "fumadocs-openapi"];
|
|
1717
1819
|
}
|
|
1718
1820
|
});
|