fumadocs-mdx 14.0.0 → 14.0.1
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 +270 -201
- package/dist/bun/index.cjs +63 -28
- package/dist/bun/index.d.cts +7 -1
- package/dist/bun/index.d.ts +7 -1
- package/dist/bun/index.js +6 -5
- package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
- package/dist/{chunk-XHJCLBZ4.js → chunk-7UKSZSPY.js} +87 -162
- package/dist/{chunk-7L2KNF6B.js → chunk-BEBCWQC7.js} +51 -7
- package/dist/{chunk-5UMZCWKV.js → chunk-IQGEFL2B.js} +1 -1
- package/dist/{chunk-SRSRFOVI.js → chunk-K6HCOGOX.js} +3 -3
- package/dist/{chunk-OXSRIWQW.js → chunk-MTTISKQJ.js} +3 -2
- package/dist/chunk-WBIHDYMN.js +126 -0
- package/dist/config/index.d.cts +6 -1
- package/dist/config/index.d.ts +6 -1
- package/dist/{index-D7JdSMpp.d.cts → core-B9ZoS6sA.d.ts} +73 -4
- package/dist/{index-D7JdSMpp.d.ts → core-DTuP23zu.d.cts} +73 -4
- package/dist/{index-BlVBvy-z.d.ts → index-BD8Woo4m.d.cts} +1 -1
- package/dist/{index-P2NNUkHn.d.cts → index-CNOvhtOn.d.ts} +1 -1
- package/dist/index.d.cts +56 -3
- package/dist/index.d.ts +56 -3
- package/dist/{load-from-file-I3ALLIVB.js → load-from-file-5HUQN36V.js} +1 -1
- package/dist/next/index.cjs +260 -192
- package/dist/next/index.d.cts +7 -2
- package/dist/next/index.d.ts +7 -2
- package/dist/next/index.js +10 -8
- package/dist/node/loader.cjs +72 -37
- package/dist/node/loader.js +3 -3
- package/dist/plugins/index-file.cjs +69 -45
- package/dist/plugins/index-file.d.cts +7 -22
- package/dist/plugins/index-file.d.ts +7 -22
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.cts +7 -1
- package/dist/plugins/json-schema.d.ts +7 -1
- package/dist/plugins/last-modified.cjs +41 -6
- package/dist/plugins/last-modified.d.cts +11 -1
- package/dist/plugins/last-modified.d.ts +11 -1
- package/dist/plugins/last-modified.js +34 -4
- package/dist/runtime/browser.cjs +7 -8
- package/dist/runtime/browser.d.cts +22 -19
- package/dist/runtime/browser.d.ts +22 -19
- package/dist/runtime/browser.js +5 -6
- package/dist/runtime/dynamic.cjs +81 -43
- package/dist/runtime/dynamic.d.cts +12 -12
- package/dist/runtime/dynamic.d.ts +12 -12
- package/dist/runtime/dynamic.js +9 -8
- package/dist/runtime/server.cjs +9 -6
- package/dist/runtime/server.d.cts +10 -157
- package/dist/runtime/server.d.ts +10 -157
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/types.cjs +18 -0
- package/dist/runtime/types.d.cts +61 -0
- package/dist/runtime/types.d.ts +61 -0
- package/dist/runtime/types.js +0 -0
- package/dist/vite/index.cjs +257 -190
- package/dist/vite/index.d.cts +7 -2
- package/dist/vite/index.d.ts +7 -2
- package/dist/vite/index.js +7 -6
- package/dist/webpack/mdx.cjs +60 -25
- package/dist/webpack/mdx.d.cts +8 -2
- package/dist/webpack/mdx.d.ts +8 -2
- package/dist/webpack/mdx.js +4 -4
- package/dist/webpack/meta.cjs +60 -25
- package/dist/webpack/meta.d.cts +8 -2
- package/dist/webpack/meta.d.ts +8 -2
- package/dist/webpack/meta.js +4 -4
- package/package.json +2 -2
- package/dist/chunk-PKI7ZDA5.js +0 -29
package/dist/bin.cjs
CHANGED
|
@@ -229,10 +229,11 @@ __export(load_from_file_exports, {
|
|
|
229
229
|
});
|
|
230
230
|
async function compileConfig(core) {
|
|
231
231
|
const { build } = await import("esbuild");
|
|
232
|
+
const { configPath, outDir } = core.getOptions();
|
|
232
233
|
const transformed = await build({
|
|
233
|
-
entryPoints: [{ in:
|
|
234
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
234
235
|
bundle: true,
|
|
235
|
-
outdir:
|
|
236
|
+
outdir: outDir,
|
|
236
237
|
target: "node20",
|
|
237
238
|
write: true,
|
|
238
239
|
platform: "node",
|
|
@@ -309,34 +310,131 @@ ${issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`
|
|
|
309
310
|
}
|
|
310
311
|
});
|
|
311
312
|
|
|
312
|
-
// src/utils/codegen
|
|
313
|
-
function
|
|
314
|
-
|
|
315
|
-
|
|
313
|
+
// src/utils/codegen.ts
|
|
314
|
+
function createCodegen({
|
|
315
|
+
target = "default",
|
|
316
|
+
outDir = "",
|
|
317
|
+
jsExtension = false,
|
|
318
|
+
globCache = /* @__PURE__ */ new Map()
|
|
319
|
+
}) {
|
|
320
|
+
let eagerImportId = 0;
|
|
321
|
+
const banner = ["// @ts-nocheck"];
|
|
322
|
+
if (target === "vite") {
|
|
323
|
+
banner.push('/// <reference types="vite/client" />');
|
|
316
324
|
}
|
|
317
|
-
return
|
|
325
|
+
return {
|
|
326
|
+
options: {
|
|
327
|
+
target,
|
|
328
|
+
outDir
|
|
329
|
+
},
|
|
330
|
+
lines: [],
|
|
331
|
+
addImport(statement) {
|
|
332
|
+
this.lines.unshift(statement);
|
|
333
|
+
},
|
|
334
|
+
async pushAsync(insert) {
|
|
335
|
+
for (const line of await Promise.all(insert)) {
|
|
336
|
+
if (line === void 0) continue;
|
|
337
|
+
this.lines.push(line);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
async generateGlobImport(patterns, options) {
|
|
341
|
+
if (target === "vite") {
|
|
342
|
+
return this.generateViteGlobImport(patterns, options);
|
|
343
|
+
}
|
|
344
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
345
|
+
},
|
|
346
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
347
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
348
|
+
normalizeViteGlobPath
|
|
349
|
+
);
|
|
350
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
351
|
+
{
|
|
352
|
+
base: normalizeViteGlobPath(import_node_path.default.relative(outDir, base)),
|
|
353
|
+
...rest
|
|
354
|
+
},
|
|
355
|
+
null,
|
|
356
|
+
2
|
|
357
|
+
)})`;
|
|
358
|
+
},
|
|
359
|
+
async generateNodeGlobImport(patterns, {
|
|
360
|
+
base,
|
|
361
|
+
eager = false,
|
|
362
|
+
query = {},
|
|
363
|
+
import: importName
|
|
364
|
+
}) {
|
|
365
|
+
const cacheKey = JSON.stringify({ patterns, base });
|
|
366
|
+
let files = globCache.get(cacheKey);
|
|
367
|
+
if (!files) {
|
|
368
|
+
files = (0, import_tinyglobby.glob)(patterns, {
|
|
369
|
+
cwd: base
|
|
370
|
+
});
|
|
371
|
+
globCache.set(cacheKey, files);
|
|
372
|
+
}
|
|
373
|
+
let code = "{";
|
|
374
|
+
for (const item of await files) {
|
|
375
|
+
const fullPath = import_node_path.default.join(base, item);
|
|
376
|
+
const searchParams = new URLSearchParams();
|
|
377
|
+
for (const [k, v] of Object.entries(query)) {
|
|
378
|
+
searchParams.set(k, v);
|
|
379
|
+
}
|
|
380
|
+
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
381
|
+
if (eager) {
|
|
382
|
+
const name = `__fd_glob_${eagerImportId++}`;
|
|
383
|
+
this.lines.unshift(
|
|
384
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
385
|
+
);
|
|
386
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
387
|
+
} else {
|
|
388
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
389
|
+
if (importName) {
|
|
390
|
+
line += `.then(mod => mod.${importName})`;
|
|
391
|
+
}
|
|
392
|
+
code += `${line}, `;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
code += "}";
|
|
396
|
+
return code;
|
|
397
|
+
},
|
|
398
|
+
formatImportPath(file) {
|
|
399
|
+
const ext = import_node_path.default.extname(file);
|
|
400
|
+
let filename;
|
|
401
|
+
if (ext === ".ts" && jsExtension) {
|
|
402
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
403
|
+
} else if (ext === ".ts") {
|
|
404
|
+
filename = file.substring(0, file.length - ext.length);
|
|
405
|
+
} else {
|
|
406
|
+
filename = file;
|
|
407
|
+
}
|
|
408
|
+
const importPath = slash(import_node_path.default.relative(outDir, filename));
|
|
409
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
410
|
+
},
|
|
411
|
+
toString() {
|
|
412
|
+
return [...banner, ...this.lines].join("\n");
|
|
413
|
+
}
|
|
414
|
+
};
|
|
318
415
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
map.set(fullPath, read);
|
|
325
|
-
return read;
|
|
416
|
+
function normalizeViteGlobPath(file) {
|
|
417
|
+
file = slash(file);
|
|
418
|
+
if (file.startsWith("./")) return file;
|
|
419
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
420
|
+
return `./${file}`;
|
|
326
421
|
}
|
|
327
|
-
function
|
|
328
|
-
|
|
422
|
+
function slash(path9) {
|
|
423
|
+
const isExtendedLengthPath = path9.startsWith("\\\\?\\");
|
|
424
|
+
if (isExtendedLengthPath) {
|
|
425
|
+
return path9;
|
|
426
|
+
}
|
|
427
|
+
return path9.replaceAll("\\", "/");
|
|
428
|
+
}
|
|
429
|
+
function ident(code, tab = 1) {
|
|
430
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
329
431
|
}
|
|
330
|
-
var
|
|
331
|
-
var
|
|
332
|
-
"src/utils/codegen
|
|
432
|
+
var import_node_path, import_tinyglobby;
|
|
433
|
+
var init_codegen = __esm({
|
|
434
|
+
"src/utils/codegen.ts"() {
|
|
333
435
|
"use strict";
|
|
334
|
-
import_lru_cache = require("lru-cache");
|
|
335
|
-
import_promises = __toESM(require("fs/promises"), 1);
|
|
336
436
|
import_node_path = __toESM(require("path"), 1);
|
|
337
|
-
|
|
338
|
-
max: 100
|
|
339
|
-
});
|
|
437
|
+
import_tinyglobby = require("tinyglobby");
|
|
340
438
|
}
|
|
341
439
|
});
|
|
342
440
|
|
|
@@ -369,7 +467,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
369
467
|
return data;
|
|
370
468
|
}
|
|
371
469
|
const core = {
|
|
372
|
-
_options: options,
|
|
373
470
|
/**
|
|
374
471
|
* Convenient cache store, reset when config changes
|
|
375
472
|
*/
|
|
@@ -378,6 +475,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
378
475
|
config = await newConfig;
|
|
379
476
|
this.cache.clear();
|
|
380
477
|
plugins = await getPlugins([
|
|
478
|
+
postprocessPlugin(),
|
|
381
479
|
...defaultPlugins,
|
|
382
480
|
...config.global.plugins ?? []
|
|
383
481
|
]);
|
|
@@ -385,7 +483,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
385
483
|
const out = await plugin.config?.call(pluginContext, config);
|
|
386
484
|
if (out) config = out;
|
|
387
485
|
}
|
|
388
|
-
|
|
486
|
+
},
|
|
487
|
+
getOptions() {
|
|
488
|
+
return options;
|
|
389
489
|
},
|
|
390
490
|
getConfig() {
|
|
391
491
|
return config;
|
|
@@ -396,10 +496,13 @@ function createCore(options, defaultPlugins = []) {
|
|
|
396
496
|
getCompiledConfigPath() {
|
|
397
497
|
return import_node_path2.default.join(options.outDir, "source.config.mjs");
|
|
398
498
|
},
|
|
499
|
+
getPlugins() {
|
|
500
|
+
return plugins;
|
|
501
|
+
},
|
|
502
|
+
getPluginContext() {
|
|
503
|
+
return pluginContext;
|
|
504
|
+
},
|
|
399
505
|
async initServer(server) {
|
|
400
|
-
server.watcher?.on("all", async (event, file) => {
|
|
401
|
-
if (event === "change") removeFileCache(file);
|
|
402
|
-
});
|
|
403
506
|
for (const plugin of plugins) {
|
|
404
507
|
await plugin.configureServer?.call(pluginContext, server);
|
|
405
508
|
}
|
|
@@ -418,8 +521,8 @@ function createCore(options, defaultPlugins = []) {
|
|
|
418
521
|
await Promise.all(
|
|
419
522
|
out.map(async (entry) => {
|
|
420
523
|
const file = import_node_path2.default.join(options.outDir, entry.path);
|
|
421
|
-
await
|
|
422
|
-
await
|
|
524
|
+
await import_promises.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
|
|
525
|
+
await import_promises.default.writeFile(file, entry.content);
|
|
423
526
|
})
|
|
424
527
|
);
|
|
425
528
|
console.log(`[MDX] generated files in ${performance.now() - start2}ms`);
|
|
@@ -466,14 +569,53 @@ function createCore(options, defaultPlugins = []) {
|
|
|
466
569
|
};
|
|
467
570
|
return core;
|
|
468
571
|
}
|
|
469
|
-
|
|
572
|
+
function postprocessPlugin() {
|
|
573
|
+
const LinkReferenceTypes = `{
|
|
574
|
+
/**
|
|
575
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
576
|
+
*/
|
|
577
|
+
extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
|
|
578
|
+
}`;
|
|
579
|
+
return {
|
|
580
|
+
"index-file": {
|
|
581
|
+
generateTypeConfig() {
|
|
582
|
+
const lines = [];
|
|
583
|
+
lines.push("{");
|
|
584
|
+
lines.push(" DocData: {");
|
|
585
|
+
for (const collection of this.core.getConfig().collectionList) {
|
|
586
|
+
let postprocessOptions;
|
|
587
|
+
switch (collection.type) {
|
|
588
|
+
case "doc":
|
|
589
|
+
postprocessOptions = collection.postprocess;
|
|
590
|
+
break;
|
|
591
|
+
case "docs":
|
|
592
|
+
postprocessOptions = collection.docs.postprocess;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
if (postprocessOptions?.extractLinkReferences) {
|
|
596
|
+
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
lines.push(" }");
|
|
600
|
+
lines.push("}");
|
|
601
|
+
return lines.join("\n");
|
|
602
|
+
},
|
|
603
|
+
serverOptions(options) {
|
|
604
|
+
options.doc ??= {};
|
|
605
|
+
options.doc.passthroughs ??= [];
|
|
606
|
+
options.doc.passthroughs.push("extractedReferences");
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
var import_node_path2, import_promises, _Defaults;
|
|
470
612
|
var init_core = __esm({
|
|
471
613
|
"src/core.ts"() {
|
|
472
614
|
"use strict";
|
|
473
615
|
import_node_path2 = __toESM(require("path"), 1);
|
|
474
|
-
|
|
475
|
-
init_cache();
|
|
616
|
+
import_promises = __toESM(require("fs/promises"), 1);
|
|
476
617
|
init_validation();
|
|
618
|
+
init_codegen();
|
|
477
619
|
_Defaults = {
|
|
478
620
|
configPath: "source.config.ts",
|
|
479
621
|
outDir: ".source"
|
|
@@ -491,131 +633,34 @@ var init_loaders = __esm({
|
|
|
491
633
|
}
|
|
492
634
|
});
|
|
493
635
|
|
|
494
|
-
// src/utils/
|
|
495
|
-
function
|
|
496
|
-
|
|
497
|
-
|
|
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" />');
|
|
636
|
+
// src/utils/fs-cache.ts
|
|
637
|
+
function toFullPath(file) {
|
|
638
|
+
if (import_node_path3.default.isAbsolute(file)) {
|
|
639
|
+
return import_node_path3.default.relative(process.cwd(), file);
|
|
505
640
|
}
|
|
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}`;
|
|
641
|
+
return file;
|
|
602
642
|
}
|
|
603
|
-
function
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
643
|
+
function readFileWithCache(file) {
|
|
644
|
+
const fullPath = toFullPath(file);
|
|
645
|
+
const cached = map.get(fullPath);
|
|
646
|
+
if (cached) return cached;
|
|
647
|
+
const read = import_promises2.default.readFile(fullPath).then((s) => s.toString());
|
|
648
|
+
map.set(fullPath, read);
|
|
649
|
+
return read;
|
|
609
650
|
}
|
|
610
|
-
function
|
|
611
|
-
|
|
651
|
+
function removeFileCache(file) {
|
|
652
|
+
map.delete(toFullPath(file));
|
|
612
653
|
}
|
|
613
|
-
var import_node_path3,
|
|
614
|
-
var
|
|
615
|
-
"src/utils/
|
|
654
|
+
var import_lru_cache, import_promises2, import_node_path3, map;
|
|
655
|
+
var init_fs_cache = __esm({
|
|
656
|
+
"src/utils/fs-cache.ts"() {
|
|
616
657
|
"use strict";
|
|
658
|
+
import_lru_cache = require("lru-cache");
|
|
659
|
+
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
617
660
|
import_node_path3 = __toESM(require("path"), 1);
|
|
618
|
-
|
|
661
|
+
map = new import_lru_cache.LRUCache({
|
|
662
|
+
max: 100
|
|
663
|
+
});
|
|
619
664
|
}
|
|
620
665
|
});
|
|
621
666
|
|
|
@@ -654,6 +699,25 @@ function indexFile(options = {}) {
|
|
|
654
699
|
function isDynamic(collection) {
|
|
655
700
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
656
701
|
}
|
|
702
|
+
function generateConfigs(core) {
|
|
703
|
+
const serverOptions = {};
|
|
704
|
+
const typeConfigs = [];
|
|
705
|
+
const ctx = core.getPluginContext();
|
|
706
|
+
for (const plugin of core.getPlugins()) {
|
|
707
|
+
const indexFilePlugin = plugin["index-file"];
|
|
708
|
+
if (!indexFilePlugin) continue;
|
|
709
|
+
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
710
|
+
const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
711
|
+
if (config2) typeConfigs.push(config2);
|
|
712
|
+
}
|
|
713
|
+
if (typeConfigs.length === 0) {
|
|
714
|
+
typeConfigs.push("{ DocData: {} }");
|
|
715
|
+
}
|
|
716
|
+
return {
|
|
717
|
+
serverOptions,
|
|
718
|
+
tc: typeConfigs.join(" & ")
|
|
719
|
+
};
|
|
720
|
+
}
|
|
657
721
|
return {
|
|
658
722
|
name: "index-file",
|
|
659
723
|
config(v) {
|
|
@@ -663,6 +727,7 @@ function indexFile(options = {}) {
|
|
|
663
727
|
configureServer(server) {
|
|
664
728
|
if (!server.watcher) return;
|
|
665
729
|
server.watcher.on("all", async (event, file) => {
|
|
730
|
+
removeFileCache(file);
|
|
666
731
|
if (dynamicCollections.length === 0) {
|
|
667
732
|
if (target === "vite") return;
|
|
668
733
|
if (target === "default" && event === "change") return;
|
|
@@ -682,48 +747,47 @@ function indexFile(options = {}) {
|
|
|
682
747
|
},
|
|
683
748
|
async emit() {
|
|
684
749
|
const globCache = /* @__PURE__ */ new Map();
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
750
|
+
const { serverOptions, tc } = generateConfigs(this.core);
|
|
751
|
+
const toEmitEntry = async (path9, content) => {
|
|
752
|
+
const codegen = createCodegen({
|
|
753
|
+
target,
|
|
754
|
+
outDir: this.outDir,
|
|
755
|
+
jsExtension: addJsExtension,
|
|
756
|
+
globCache
|
|
757
|
+
});
|
|
758
|
+
await content({
|
|
759
|
+
core: this.core,
|
|
760
|
+
codegen,
|
|
761
|
+
serverOptions,
|
|
762
|
+
tc
|
|
763
|
+
});
|
|
692
764
|
return {
|
|
693
765
|
path: path9,
|
|
694
|
-
content:
|
|
766
|
+
content: codegen.toString()
|
|
695
767
|
};
|
|
696
|
-
}
|
|
768
|
+
};
|
|
697
769
|
const out = [
|
|
698
|
-
toEmitEntry(
|
|
699
|
-
"server.ts",
|
|
700
|
-
generateServerIndexFile(makeCodeGen(), config, this.configPath)
|
|
701
|
-
)
|
|
770
|
+
toEmitEntry("server.ts", generateServerIndexFile)
|
|
702
771
|
];
|
|
703
772
|
if (dynamic)
|
|
704
|
-
out.push(
|
|
705
|
-
toEmitEntry(
|
|
706
|
-
"dynamic.ts",
|
|
707
|
-
generateDynamicIndexFile(this.core, makeCodeGen())
|
|
708
|
-
)
|
|
709
|
-
);
|
|
773
|
+
out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
|
|
710
774
|
if (browser)
|
|
711
|
-
out.push(
|
|
712
|
-
toEmitEntry(
|
|
713
|
-
"browser.ts",
|
|
714
|
-
generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
|
|
715
|
-
)
|
|
716
|
-
);
|
|
775
|
+
out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
|
|
717
776
|
return await Promise.all(out);
|
|
718
777
|
}
|
|
719
778
|
};
|
|
720
779
|
}
|
|
721
|
-
async function generateServerIndexFile(
|
|
780
|
+
async function generateServerIndexFile({
|
|
781
|
+
core,
|
|
782
|
+
codegen,
|
|
783
|
+
serverOptions,
|
|
784
|
+
tc
|
|
785
|
+
}) {
|
|
722
786
|
codegen.lines.push(
|
|
723
|
-
`import {
|
|
724
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
787
|
+
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
788
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
725
789
|
"",
|
|
726
|
-
`const create =
|
|
790
|
+
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
727
791
|
);
|
|
728
792
|
async function generateCollectionObject(collection) {
|
|
729
793
|
switch (collection.type) {
|
|
@@ -770,22 +834,26 @@ async function generateServerIndexFile(codegen, config, configPath) {
|
|
|
770
834
|
}
|
|
771
835
|
}
|
|
772
836
|
await codegen.pushAsync(
|
|
773
|
-
|
|
837
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
774
838
|
const obj = await generateCollectionObject(collection);
|
|
775
839
|
if (!obj) return;
|
|
776
840
|
return `
|
|
777
841
|
export const ${collection.name} = ${obj};`;
|
|
778
842
|
})
|
|
779
843
|
);
|
|
780
|
-
return codegen.toString();
|
|
781
844
|
}
|
|
782
|
-
async function generateDynamicIndexFile(
|
|
783
|
-
|
|
845
|
+
async function generateDynamicIndexFile({
|
|
846
|
+
core,
|
|
847
|
+
codegen,
|
|
848
|
+
serverOptions,
|
|
849
|
+
tc
|
|
850
|
+
}) {
|
|
851
|
+
const { configPath } = core.getOptions();
|
|
784
852
|
codegen.lines.push(
|
|
785
|
-
`import {
|
|
853
|
+
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
786
854
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
787
855
|
"",
|
|
788
|
-
`const create = await
|
|
856
|
+
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
|
|
789
857
|
);
|
|
790
858
|
async function generateCollectionObjectEntry(collection, file) {
|
|
791
859
|
const fullPath = import_path.default.join(collection.dir, file);
|
|
@@ -848,14 +916,13 @@ async function generateDynamicIndexFile(core, codegen) {
|
|
|
848
916
|
export const ${collection.name} = ${obj};`;
|
|
849
917
|
})
|
|
850
918
|
);
|
|
851
|
-
return codegen.toString();
|
|
852
919
|
}
|
|
853
|
-
async function generateBrowserIndexFile(
|
|
920
|
+
async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
854
921
|
codegen.lines.push(
|
|
855
|
-
`import {
|
|
856
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
922
|
+
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
923
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
857
924
|
"",
|
|
858
|
-
`const create =
|
|
925
|
+
`const create = browser<typeof Config, ${tc}>();`
|
|
859
926
|
);
|
|
860
927
|
async function generateCollectionObject(collection) {
|
|
861
928
|
switch (collection.type) {
|
|
@@ -870,14 +937,13 @@ async function generateBrowserIndexFile(codegen, config, configPath) {
|
|
|
870
937
|
}
|
|
871
938
|
codegen.lines.push("const browserCollections = {");
|
|
872
939
|
await codegen.pushAsync(
|
|
873
|
-
|
|
940
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
874
941
|
const obj = await generateCollectionObject(collection);
|
|
875
942
|
if (!obj) return;
|
|
876
943
|
return ident(`${collection.name}: ${obj},`);
|
|
877
944
|
})
|
|
878
945
|
);
|
|
879
946
|
codegen.lines.push("};", "export default browserCollections;");
|
|
880
|
-
return codegen.toString();
|
|
881
947
|
}
|
|
882
948
|
function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
|
|
883
949
|
return codegen.generateGlobImport(collection.patterns, {
|
|
@@ -916,7 +982,7 @@ var init_index_file = __esm({
|
|
|
916
982
|
import_path = __toESM(require("path"), 1);
|
|
917
983
|
init_codegen();
|
|
918
984
|
import_tinyglobby2 = require("tinyglobby");
|
|
919
|
-
|
|
985
|
+
init_fs_cache();
|
|
920
986
|
import_crypto = require("crypto");
|
|
921
987
|
init_fuma_matter();
|
|
922
988
|
}
|
|
@@ -937,7 +1003,7 @@ function createMDX(createOptions = {}) {
|
|
|
937
1003
|
}
|
|
938
1004
|
return (nextConfig = {}) => {
|
|
939
1005
|
const loaderOptions = {
|
|
940
|
-
...core.
|
|
1006
|
+
...core.getOptions(),
|
|
941
1007
|
compiledConfigPath: core.getCompiledConfigPath(),
|
|
942
1008
|
isDev
|
|
943
1009
|
};
|
|
@@ -1019,12 +1085,13 @@ async function init(dev, core) {
|
|
|
1019
1085
|
}
|
|
1020
1086
|
async function devServer() {
|
|
1021
1087
|
const { FSWatcher } = await import("chokidar");
|
|
1088
|
+
const { configPath, outDir } = core.getOptions();
|
|
1022
1089
|
const watcher = new FSWatcher({
|
|
1023
1090
|
ignoreInitial: true,
|
|
1024
1091
|
persistent: true,
|
|
1025
|
-
ignored: [
|
|
1092
|
+
ignored: [outDir]
|
|
1026
1093
|
});
|
|
1027
|
-
watcher.add(
|
|
1094
|
+
watcher.add(configPath);
|
|
1028
1095
|
for (const collection of core.getConfig().collectionList) {
|
|
1029
1096
|
if (collection.type === "docs") {
|
|
1030
1097
|
watcher.add(collection.docs.dir);
|
|
@@ -1036,8 +1103,9 @@ async function init(dev, core) {
|
|
|
1036
1103
|
watcher.on("ready", () => {
|
|
1037
1104
|
console.log("[MDX] started dev server");
|
|
1038
1105
|
});
|
|
1106
|
+
const absoluteConfigPath = path5.resolve(configPath);
|
|
1039
1107
|
watcher.on("all", async (_event, file) => {
|
|
1040
|
-
if (path5.resolve(file) ===
|
|
1108
|
+
if (path5.resolve(file) === absoluteConfigPath) {
|
|
1041
1109
|
watcher.removeAllListeners();
|
|
1042
1110
|
await watcher.close();
|
|
1043
1111
|
await initOrReload();
|
|
@@ -1768,7 +1836,8 @@ __export(vite_exports, {
|
|
|
1768
1836
|
});
|
|
1769
1837
|
async function mdx(config, pluginOptions = {}) {
|
|
1770
1838
|
const options = applyDefaults2(pluginOptions);
|
|
1771
|
-
const core =
|
|
1839
|
+
const core = createViteCore(options);
|
|
1840
|
+
await core.init({
|
|
1772
1841
|
config: buildConfig(config)
|
|
1773
1842
|
});
|
|
1774
1843
|
const configLoader = createIntegratedConfigLoader(core);
|