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/next/index.cjs
CHANGED
|
@@ -224,10 +224,11 @@ function buildConfig(config) {
|
|
|
224
224
|
// src/config/load-from-file.ts
|
|
225
225
|
async function compileConfig(core) {
|
|
226
226
|
const { build } = await import("esbuild");
|
|
227
|
+
const { configPath, outDir } = core.getOptions();
|
|
227
228
|
const transformed = await build({
|
|
228
|
-
entryPoints: [{ in:
|
|
229
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
229
230
|
bundle: true,
|
|
230
|
-
outdir:
|
|
231
|
+
outdir: outDir,
|
|
231
232
|
target: "node20",
|
|
232
233
|
write: true,
|
|
233
234
|
platform: "node",
|
|
@@ -292,31 +293,128 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
292
293
|
|
|
293
294
|
// src/core.ts
|
|
294
295
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
295
|
-
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
296
|
-
|
|
297
|
-
// src/utils/codegen/cache.ts
|
|
298
|
-
var import_lru_cache = require("lru-cache");
|
|
299
296
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
297
|
+
|
|
298
|
+
// src/utils/codegen.ts
|
|
300
299
|
var import_node_path = __toESM(require("path"), 1);
|
|
301
|
-
var
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
300
|
+
var import_tinyglobby = require("tinyglobby");
|
|
301
|
+
function createCodegen({
|
|
302
|
+
target = "default",
|
|
303
|
+
outDir = "",
|
|
304
|
+
jsExtension = false,
|
|
305
|
+
globCache = /* @__PURE__ */ new Map()
|
|
306
|
+
}) {
|
|
307
|
+
let eagerImportId = 0;
|
|
308
|
+
const banner = ["// @ts-nocheck"];
|
|
309
|
+
if (target === "vite") {
|
|
310
|
+
banner.push('/// <reference types="vite/client" />');
|
|
307
311
|
}
|
|
308
|
-
return
|
|
312
|
+
return {
|
|
313
|
+
options: {
|
|
314
|
+
target,
|
|
315
|
+
outDir
|
|
316
|
+
},
|
|
317
|
+
lines: [],
|
|
318
|
+
addImport(statement) {
|
|
319
|
+
this.lines.unshift(statement);
|
|
320
|
+
},
|
|
321
|
+
async pushAsync(insert) {
|
|
322
|
+
for (const line of await Promise.all(insert)) {
|
|
323
|
+
if (line === void 0) continue;
|
|
324
|
+
this.lines.push(line);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
async generateGlobImport(patterns, options) {
|
|
328
|
+
if (target === "vite") {
|
|
329
|
+
return this.generateViteGlobImport(patterns, options);
|
|
330
|
+
}
|
|
331
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
332
|
+
},
|
|
333
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
334
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
335
|
+
normalizeViteGlobPath
|
|
336
|
+
);
|
|
337
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
338
|
+
{
|
|
339
|
+
base: normalizeViteGlobPath(import_node_path.default.relative(outDir, base)),
|
|
340
|
+
...rest
|
|
341
|
+
},
|
|
342
|
+
null,
|
|
343
|
+
2
|
|
344
|
+
)})`;
|
|
345
|
+
},
|
|
346
|
+
async generateNodeGlobImport(patterns, {
|
|
347
|
+
base,
|
|
348
|
+
eager = false,
|
|
349
|
+
query = {},
|
|
350
|
+
import: importName
|
|
351
|
+
}) {
|
|
352
|
+
const cacheKey = JSON.stringify({ patterns, base });
|
|
353
|
+
let files = globCache.get(cacheKey);
|
|
354
|
+
if (!files) {
|
|
355
|
+
files = (0, import_tinyglobby.glob)(patterns, {
|
|
356
|
+
cwd: base
|
|
357
|
+
});
|
|
358
|
+
globCache.set(cacheKey, files);
|
|
359
|
+
}
|
|
360
|
+
let code = "{";
|
|
361
|
+
for (const item of await files) {
|
|
362
|
+
const fullPath = import_node_path.default.join(base, item);
|
|
363
|
+
const searchParams = new URLSearchParams();
|
|
364
|
+
for (const [k, v] of Object.entries(query)) {
|
|
365
|
+
searchParams.set(k, v);
|
|
366
|
+
}
|
|
367
|
+
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
368
|
+
if (eager) {
|
|
369
|
+
const name = `__fd_glob_${eagerImportId++}`;
|
|
370
|
+
this.lines.unshift(
|
|
371
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
372
|
+
);
|
|
373
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
374
|
+
} else {
|
|
375
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
376
|
+
if (importName) {
|
|
377
|
+
line += `.then(mod => mod.${importName})`;
|
|
378
|
+
}
|
|
379
|
+
code += `${line}, `;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
code += "}";
|
|
383
|
+
return code;
|
|
384
|
+
},
|
|
385
|
+
formatImportPath(file) {
|
|
386
|
+
const ext = import_node_path.default.extname(file);
|
|
387
|
+
let filename;
|
|
388
|
+
if (ext === ".ts" && jsExtension) {
|
|
389
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
390
|
+
} else if (ext === ".ts") {
|
|
391
|
+
filename = file.substring(0, file.length - ext.length);
|
|
392
|
+
} else {
|
|
393
|
+
filename = file;
|
|
394
|
+
}
|
|
395
|
+
const importPath = slash(import_node_path.default.relative(outDir, filename));
|
|
396
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
397
|
+
},
|
|
398
|
+
toString() {
|
|
399
|
+
return [...banner, ...this.lines].join("\n");
|
|
400
|
+
}
|
|
401
|
+
};
|
|
309
402
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
map.set(fullPath, read);
|
|
316
|
-
return read;
|
|
403
|
+
function normalizeViteGlobPath(file) {
|
|
404
|
+
file = slash(file);
|
|
405
|
+
if (file.startsWith("./")) return file;
|
|
406
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
407
|
+
return `./${file}`;
|
|
317
408
|
}
|
|
318
|
-
function
|
|
319
|
-
|
|
409
|
+
function slash(path6) {
|
|
410
|
+
const isExtendedLengthPath = path6.startsWith("\\\\?\\");
|
|
411
|
+
if (isExtendedLengthPath) {
|
|
412
|
+
return path6;
|
|
413
|
+
}
|
|
414
|
+
return path6.replaceAll("\\", "/");
|
|
415
|
+
}
|
|
416
|
+
function ident(code, tab = 1) {
|
|
417
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
320
418
|
}
|
|
321
419
|
|
|
322
420
|
// src/core.ts
|
|
@@ -352,7 +450,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
352
450
|
return data;
|
|
353
451
|
}
|
|
354
452
|
const core = {
|
|
355
|
-
_options: options,
|
|
356
453
|
/**
|
|
357
454
|
* Convenient cache store, reset when config changes
|
|
358
455
|
*/
|
|
@@ -361,6 +458,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
361
458
|
config = await newConfig;
|
|
362
459
|
this.cache.clear();
|
|
363
460
|
plugins = await getPlugins([
|
|
461
|
+
postprocessPlugin(),
|
|
364
462
|
...defaultPlugins,
|
|
365
463
|
...config.global.plugins ?? []
|
|
366
464
|
]);
|
|
@@ -368,7 +466,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
368
466
|
const out = await plugin.config?.call(pluginContext, config);
|
|
369
467
|
if (out) config = out;
|
|
370
468
|
}
|
|
371
|
-
|
|
469
|
+
},
|
|
470
|
+
getOptions() {
|
|
471
|
+
return options;
|
|
372
472
|
},
|
|
373
473
|
getConfig() {
|
|
374
474
|
return config;
|
|
@@ -379,10 +479,13 @@ function createCore(options, defaultPlugins = []) {
|
|
|
379
479
|
getCompiledConfigPath() {
|
|
380
480
|
return import_node_path2.default.join(options.outDir, "source.config.mjs");
|
|
381
481
|
},
|
|
482
|
+
getPlugins() {
|
|
483
|
+
return plugins;
|
|
484
|
+
},
|
|
485
|
+
getPluginContext() {
|
|
486
|
+
return pluginContext;
|
|
487
|
+
},
|
|
382
488
|
async initServer(server) {
|
|
383
|
-
server.watcher?.on("all", async (event, file) => {
|
|
384
|
-
if (event === "change") removeFileCache(file);
|
|
385
|
-
});
|
|
386
489
|
for (const plugin of plugins) {
|
|
387
490
|
await plugin.configureServer?.call(pluginContext, server);
|
|
388
491
|
}
|
|
@@ -401,8 +504,8 @@ function createCore(options, defaultPlugins = []) {
|
|
|
401
504
|
await Promise.all(
|
|
402
505
|
out.map(async (entry) => {
|
|
403
506
|
const file = import_node_path2.default.join(options.outDir, entry.path);
|
|
404
|
-
await
|
|
405
|
-
await
|
|
507
|
+
await import_promises.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
|
|
508
|
+
await import_promises.default.writeFile(file, entry.content);
|
|
406
509
|
})
|
|
407
510
|
);
|
|
408
511
|
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
@@ -449,6 +552,45 @@ function createCore(options, defaultPlugins = []) {
|
|
|
449
552
|
};
|
|
450
553
|
return core;
|
|
451
554
|
}
|
|
555
|
+
function postprocessPlugin() {
|
|
556
|
+
const LinkReferenceTypes = `{
|
|
557
|
+
/**
|
|
558
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
559
|
+
*/
|
|
560
|
+
extractedReferences?: import('fumadocs-mdx').ExtractedReference[];
|
|
561
|
+
}`;
|
|
562
|
+
return {
|
|
563
|
+
"index-file": {
|
|
564
|
+
generateTypeConfig() {
|
|
565
|
+
const lines = [];
|
|
566
|
+
lines.push("{");
|
|
567
|
+
lines.push(" DocData: {");
|
|
568
|
+
for (const collection of this.core.getConfig().collectionList) {
|
|
569
|
+
let postprocessOptions;
|
|
570
|
+
switch (collection.type) {
|
|
571
|
+
case "doc":
|
|
572
|
+
postprocessOptions = collection.postprocess;
|
|
573
|
+
break;
|
|
574
|
+
case "docs":
|
|
575
|
+
postprocessOptions = collection.docs.postprocess;
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
if (postprocessOptions?.extractLinkReferences) {
|
|
579
|
+
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
lines.push(" }");
|
|
583
|
+
lines.push("}");
|
|
584
|
+
return lines.join("\n");
|
|
585
|
+
},
|
|
586
|
+
serverOptions(options) {
|
|
587
|
+
options.doc ??= {};
|
|
588
|
+
options.doc.passthroughs ??= [];
|
|
589
|
+
options.doc.passthroughs.push("extractedReferences");
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
}
|
|
452
594
|
|
|
453
595
|
// src/loaders/index.ts
|
|
454
596
|
var metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
@@ -456,131 +598,34 @@ var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
|
456
598
|
|
|
457
599
|
// src/plugins/index-file.ts
|
|
458
600
|
var import_path = __toESM(require("path"), 1);
|
|
601
|
+
var import_tinyglobby2 = require("tinyglobby");
|
|
459
602
|
|
|
460
|
-
// src/utils/
|
|
603
|
+
// src/utils/fs-cache.ts
|
|
604
|
+
var import_lru_cache = require("lru-cache");
|
|
605
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
461
606
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}) {
|
|
469
|
-
let eagerImportId = 0;
|
|
470
|
-
const banner = ["// @ts-nocheck"];
|
|
471
|
-
if (target === "vite") {
|
|
472
|
-
banner.push('/// <reference types="vite/client" />');
|
|
607
|
+
var map = new import_lru_cache.LRUCache({
|
|
608
|
+
max: 100
|
|
609
|
+
});
|
|
610
|
+
function toFullPath(file) {
|
|
611
|
+
if (import_node_path3.default.isAbsolute(file)) {
|
|
612
|
+
return import_node_path3.default.relative(process.cwd(), file);
|
|
473
613
|
}
|
|
474
|
-
return
|
|
475
|
-
options: {
|
|
476
|
-
target,
|
|
477
|
-
outDir
|
|
478
|
-
},
|
|
479
|
-
lines: [],
|
|
480
|
-
addImport(statement) {
|
|
481
|
-
this.lines.unshift(statement);
|
|
482
|
-
},
|
|
483
|
-
async pushAsync(insert) {
|
|
484
|
-
for (const line of await Promise.all(insert)) {
|
|
485
|
-
if (line === void 0) continue;
|
|
486
|
-
this.lines.push(line);
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
async generateGlobImport(patterns, options) {
|
|
490
|
-
if (target === "vite") {
|
|
491
|
-
return this.generateViteGlobImport(patterns, options);
|
|
492
|
-
}
|
|
493
|
-
return this.generateNodeGlobImport(patterns, options);
|
|
494
|
-
},
|
|
495
|
-
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
496
|
-
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
497
|
-
normalizeViteGlobPath
|
|
498
|
-
);
|
|
499
|
-
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
500
|
-
{
|
|
501
|
-
base: normalizeViteGlobPath(import_node_path3.default.relative(outDir, base)),
|
|
502
|
-
...rest
|
|
503
|
-
},
|
|
504
|
-
null,
|
|
505
|
-
2
|
|
506
|
-
)})`;
|
|
507
|
-
},
|
|
508
|
-
async generateNodeGlobImport(patterns, {
|
|
509
|
-
base,
|
|
510
|
-
eager = false,
|
|
511
|
-
query = {},
|
|
512
|
-
import: importName
|
|
513
|
-
}) {
|
|
514
|
-
const cacheKey = JSON.stringify({ patterns, base });
|
|
515
|
-
let files = globCache.get(cacheKey);
|
|
516
|
-
if (!files) {
|
|
517
|
-
files = (0, import_tinyglobby.glob)(patterns, {
|
|
518
|
-
cwd: base
|
|
519
|
-
});
|
|
520
|
-
globCache.set(cacheKey, files);
|
|
521
|
-
}
|
|
522
|
-
let code = "{";
|
|
523
|
-
for (const item of await files) {
|
|
524
|
-
const fullPath = import_node_path3.default.join(base, item);
|
|
525
|
-
const searchParams = new URLSearchParams();
|
|
526
|
-
for (const [k, v] of Object.entries(query)) {
|
|
527
|
-
searchParams.set(k, v);
|
|
528
|
-
}
|
|
529
|
-
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
530
|
-
if (eager) {
|
|
531
|
-
const name = `__fd_glob_${eagerImportId++}`;
|
|
532
|
-
this.lines.unshift(
|
|
533
|
-
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
534
|
-
);
|
|
535
|
-
code += `${JSON.stringify(item)}: ${name}, `;
|
|
536
|
-
} else {
|
|
537
|
-
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
538
|
-
if (importName) {
|
|
539
|
-
line += `.then(mod => mod.${importName})`;
|
|
540
|
-
}
|
|
541
|
-
code += `${line}, `;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
code += "}";
|
|
545
|
-
return code;
|
|
546
|
-
},
|
|
547
|
-
formatImportPath(file) {
|
|
548
|
-
const ext = import_node_path3.default.extname(file);
|
|
549
|
-
let filename;
|
|
550
|
-
if (ext === ".ts" && jsExtension) {
|
|
551
|
-
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
552
|
-
} else if (ext === ".ts") {
|
|
553
|
-
filename = file.substring(0, file.length - ext.length);
|
|
554
|
-
} else {
|
|
555
|
-
filename = file;
|
|
556
|
-
}
|
|
557
|
-
const importPath = slash(import_node_path3.default.relative(outDir, filename));
|
|
558
|
-
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
559
|
-
},
|
|
560
|
-
toString() {
|
|
561
|
-
return [...banner, ...this.lines].join("\n");
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
function normalizeViteGlobPath(file) {
|
|
566
|
-
file = slash(file);
|
|
567
|
-
if (file.startsWith("./")) return file;
|
|
568
|
-
if (file.startsWith("/")) return `.${file}`;
|
|
569
|
-
return `./${file}`;
|
|
614
|
+
return file;
|
|
570
615
|
}
|
|
571
|
-
function
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
616
|
+
function readFileWithCache(file) {
|
|
617
|
+
const fullPath = toFullPath(file);
|
|
618
|
+
const cached = map.get(fullPath);
|
|
619
|
+
if (cached) return cached;
|
|
620
|
+
const read = import_promises2.default.readFile(fullPath).then((s) => s.toString());
|
|
621
|
+
map.set(fullPath, read);
|
|
622
|
+
return read;
|
|
577
623
|
}
|
|
578
|
-
function
|
|
579
|
-
|
|
624
|
+
function removeFileCache(file) {
|
|
625
|
+
map.delete(toFullPath(file));
|
|
580
626
|
}
|
|
581
627
|
|
|
582
628
|
// src/plugins/index-file.ts
|
|
583
|
-
var import_tinyglobby2 = require("tinyglobby");
|
|
584
629
|
var import_crypto = require("crypto");
|
|
585
630
|
|
|
586
631
|
// src/utils/fuma-matter.ts
|
|
@@ -612,6 +657,25 @@ function indexFile(options = {}) {
|
|
|
612
657
|
function isDynamic(collection) {
|
|
613
658
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
614
659
|
}
|
|
660
|
+
function generateConfigs(core) {
|
|
661
|
+
const serverOptions = {};
|
|
662
|
+
const typeConfigs = [];
|
|
663
|
+
const ctx = core.getPluginContext();
|
|
664
|
+
for (const plugin of core.getPlugins()) {
|
|
665
|
+
const indexFilePlugin = plugin["index-file"];
|
|
666
|
+
if (!indexFilePlugin) continue;
|
|
667
|
+
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
668
|
+
const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
669
|
+
if (config2) typeConfigs.push(config2);
|
|
670
|
+
}
|
|
671
|
+
if (typeConfigs.length === 0) {
|
|
672
|
+
typeConfigs.push("{ DocData: {} }");
|
|
673
|
+
}
|
|
674
|
+
return {
|
|
675
|
+
serverOptions,
|
|
676
|
+
tc: typeConfigs.join(" & ")
|
|
677
|
+
};
|
|
678
|
+
}
|
|
615
679
|
return {
|
|
616
680
|
name: "index-file",
|
|
617
681
|
config(v) {
|
|
@@ -621,6 +685,7 @@ function indexFile(options = {}) {
|
|
|
621
685
|
configureServer(server) {
|
|
622
686
|
if (!server.watcher) return;
|
|
623
687
|
server.watcher.on("all", async (event, file) => {
|
|
688
|
+
removeFileCache(file);
|
|
624
689
|
if (dynamicCollections.length === 0) {
|
|
625
690
|
if (target === "vite") return;
|
|
626
691
|
if (target === "default" && event === "change") return;
|
|
@@ -640,48 +705,47 @@ function indexFile(options = {}) {
|
|
|
640
705
|
},
|
|
641
706
|
async emit() {
|
|
642
707
|
const globCache = /* @__PURE__ */ new Map();
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
708
|
+
const { serverOptions, tc } = generateConfigs(this.core);
|
|
709
|
+
const toEmitEntry = async (path6, content) => {
|
|
710
|
+
const codegen = createCodegen({
|
|
711
|
+
target,
|
|
712
|
+
outDir: this.outDir,
|
|
713
|
+
jsExtension: addJsExtension,
|
|
714
|
+
globCache
|
|
715
|
+
});
|
|
716
|
+
await content({
|
|
717
|
+
core: this.core,
|
|
718
|
+
codegen,
|
|
719
|
+
serverOptions,
|
|
720
|
+
tc
|
|
721
|
+
});
|
|
650
722
|
return {
|
|
651
723
|
path: path6,
|
|
652
|
-
content:
|
|
724
|
+
content: codegen.toString()
|
|
653
725
|
};
|
|
654
|
-
}
|
|
726
|
+
};
|
|
655
727
|
const out = [
|
|
656
|
-
toEmitEntry(
|
|
657
|
-
"server.ts",
|
|
658
|
-
generateServerIndexFile(makeCodeGen(), config, this.configPath)
|
|
659
|
-
)
|
|
728
|
+
toEmitEntry("server.ts", generateServerIndexFile)
|
|
660
729
|
];
|
|
661
730
|
if (dynamic)
|
|
662
|
-
out.push(
|
|
663
|
-
toEmitEntry(
|
|
664
|
-
"dynamic.ts",
|
|
665
|
-
generateDynamicIndexFile(this.core, makeCodeGen())
|
|
666
|
-
)
|
|
667
|
-
);
|
|
731
|
+
out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
|
|
668
732
|
if (browser)
|
|
669
|
-
out.push(
|
|
670
|
-
toEmitEntry(
|
|
671
|
-
"browser.ts",
|
|
672
|
-
generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
|
|
673
|
-
)
|
|
674
|
-
);
|
|
733
|
+
out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
|
|
675
734
|
return await Promise.all(out);
|
|
676
735
|
}
|
|
677
736
|
};
|
|
678
737
|
}
|
|
679
|
-
async function generateServerIndexFile(
|
|
738
|
+
async function generateServerIndexFile({
|
|
739
|
+
core,
|
|
740
|
+
codegen,
|
|
741
|
+
serverOptions,
|
|
742
|
+
tc
|
|
743
|
+
}) {
|
|
680
744
|
codegen.lines.push(
|
|
681
|
-
`import {
|
|
682
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
745
|
+
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
746
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
683
747
|
"",
|
|
684
|
-
`const create =
|
|
748
|
+
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
685
749
|
);
|
|
686
750
|
async function generateCollectionObject(collection) {
|
|
687
751
|
switch (collection.type) {
|
|
@@ -728,22 +792,26 @@ async function generateServerIndexFile(codegen, config, configPath) {
|
|
|
728
792
|
}
|
|
729
793
|
}
|
|
730
794
|
await codegen.pushAsync(
|
|
731
|
-
|
|
795
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
732
796
|
const obj = await generateCollectionObject(collection);
|
|
733
797
|
if (!obj) return;
|
|
734
798
|
return `
|
|
735
799
|
export const ${collection.name} = ${obj};`;
|
|
736
800
|
})
|
|
737
801
|
);
|
|
738
|
-
return codegen.toString();
|
|
739
802
|
}
|
|
740
|
-
async function generateDynamicIndexFile(
|
|
741
|
-
|
|
803
|
+
async function generateDynamicIndexFile({
|
|
804
|
+
core,
|
|
805
|
+
codegen,
|
|
806
|
+
serverOptions,
|
|
807
|
+
tc
|
|
808
|
+
}) {
|
|
809
|
+
const { configPath } = core.getOptions();
|
|
742
810
|
codegen.lines.push(
|
|
743
|
-
`import {
|
|
811
|
+
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
744
812
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
745
813
|
"",
|
|
746
|
-
`const create = await
|
|
814
|
+
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
|
|
747
815
|
);
|
|
748
816
|
async function generateCollectionObjectEntry(collection, file) {
|
|
749
817
|
const fullPath = import_path.default.join(collection.dir, file);
|
|
@@ -806,14 +874,13 @@ async function generateDynamicIndexFile(core, codegen) {
|
|
|
806
874
|
export const ${collection.name} = ${obj};`;
|
|
807
875
|
})
|
|
808
876
|
);
|
|
809
|
-
return codegen.toString();
|
|
810
877
|
}
|
|
811
|
-
async function generateBrowserIndexFile(
|
|
878
|
+
async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
812
879
|
codegen.lines.push(
|
|
813
|
-
`import {
|
|
814
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
880
|
+
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
881
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
815
882
|
"",
|
|
816
|
-
`const create =
|
|
883
|
+
`const create = browser<typeof Config, ${tc}>();`
|
|
817
884
|
);
|
|
818
885
|
async function generateCollectionObject(collection) {
|
|
819
886
|
switch (collection.type) {
|
|
@@ -828,14 +895,13 @@ async function generateBrowserIndexFile(codegen, config, configPath) {
|
|
|
828
895
|
}
|
|
829
896
|
codegen.lines.push("const browserCollections = {");
|
|
830
897
|
await codegen.pushAsync(
|
|
831
|
-
|
|
898
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
832
899
|
const obj = await generateCollectionObject(collection);
|
|
833
900
|
if (!obj) return;
|
|
834
901
|
return ident(`${collection.name}: ${obj},`);
|
|
835
902
|
})
|
|
836
903
|
);
|
|
837
904
|
codegen.lines.push("};", "export default browserCollections;");
|
|
838
|
-
return codegen.toString();
|
|
839
905
|
}
|
|
840
906
|
function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
|
|
841
907
|
return codegen.generateGlobImport(collection.patterns, {
|
|
@@ -879,7 +945,7 @@ function createMDX(createOptions = {}) {
|
|
|
879
945
|
}
|
|
880
946
|
return (nextConfig = {}) => {
|
|
881
947
|
const loaderOptions = {
|
|
882
|
-
...core.
|
|
948
|
+
...core.getOptions(),
|
|
883
949
|
compiledConfigPath: core.getCompiledConfigPath(),
|
|
884
950
|
isDev
|
|
885
951
|
};
|
|
@@ -961,12 +1027,13 @@ async function init(dev, core) {
|
|
|
961
1027
|
}
|
|
962
1028
|
async function devServer() {
|
|
963
1029
|
const { FSWatcher } = await import("chokidar");
|
|
1030
|
+
const { configPath, outDir } = core.getOptions();
|
|
964
1031
|
const watcher = new FSWatcher({
|
|
965
1032
|
ignoreInitial: true,
|
|
966
1033
|
persistent: true,
|
|
967
|
-
ignored: [
|
|
1034
|
+
ignored: [outDir]
|
|
968
1035
|
});
|
|
969
|
-
watcher.add(
|
|
1036
|
+
watcher.add(configPath);
|
|
970
1037
|
for (const collection of core.getConfig().collectionList) {
|
|
971
1038
|
if (collection.type === "docs") {
|
|
972
1039
|
watcher.add(collection.docs.dir);
|
|
@@ -978,8 +1045,9 @@ async function init(dev, core) {
|
|
|
978
1045
|
watcher.on("ready", () => {
|
|
979
1046
|
console.log("[MDX] started dev server");
|
|
980
1047
|
});
|
|
1048
|
+
const absoluteConfigPath = path5.resolve(configPath);
|
|
981
1049
|
watcher.on("all", async (_event, file) => {
|
|
982
|
-
if (path5.resolve(file) ===
|
|
1050
|
+
if (path5.resolve(file) === absoluteConfigPath) {
|
|
983
1051
|
watcher.removeAllListeners();
|
|
984
1052
|
await watcher.close();
|
|
985
1053
|
await initOrReload();
|
package/dist/next/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
|
-
import { IndexFilePluginOptions } from '../
|
|
3
|
-
import '../index-D7JdSMpp.cjs';
|
|
2
|
+
import { I as IndexFilePluginOptions } from '../core-DTuP23zu.cjs';
|
|
4
3
|
import '@mdx-js/mdx';
|
|
5
4
|
import '@standard-schema/spec';
|
|
6
5
|
import 'unified';
|
|
@@ -8,6 +7,12 @@ import 'fumadocs-core/mdx-plugins';
|
|
|
8
7
|
import 'zod';
|
|
9
8
|
import 'chokidar';
|
|
10
9
|
import 'vfile';
|
|
10
|
+
import 'fumadocs-core/source';
|
|
11
|
+
import '../runtime/types.cjs';
|
|
12
|
+
import 'fumadocs-core/mdx-plugins/remark-structure';
|
|
13
|
+
import 'fumadocs-core/toc';
|
|
14
|
+
import 'mdast';
|
|
15
|
+
import 'mdx/types';
|
|
11
16
|
|
|
12
17
|
interface CreateMDXOptions {
|
|
13
18
|
/**
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
|
-
import { IndexFilePluginOptions } from '../
|
|
3
|
-
import '../index-D7JdSMpp.js';
|
|
2
|
+
import { I as IndexFilePluginOptions } from '../core-B9ZoS6sA.js';
|
|
4
3
|
import '@mdx-js/mdx';
|
|
5
4
|
import '@standard-schema/spec';
|
|
6
5
|
import 'unified';
|
|
@@ -8,6 +7,12 @@ import 'fumadocs-core/mdx-plugins';
|
|
|
8
7
|
import 'zod';
|
|
9
8
|
import 'chokidar';
|
|
10
9
|
import 'vfile';
|
|
10
|
+
import 'fumadocs-core/source';
|
|
11
|
+
import '../runtime/types.js';
|
|
12
|
+
import 'fumadocs-core/mdx-plugins/remark-structure';
|
|
13
|
+
import 'fumadocs-core/toc';
|
|
14
|
+
import 'mdast';
|
|
15
|
+
import 'mdx/types';
|
|
11
16
|
|
|
12
17
|
interface CreateMDXOptions {
|
|
13
18
|
/**
|