fumadocs-mdx 14.0.0 → 14.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-mdx-6UAK5FF5.js → build-mdx-W3233QBZ.js} +1 -1
- package/dist/bun/index.d.ts +7 -1
- package/dist/bun/index.js +9 -8
- package/dist/{chunk-5YXP7JLN.js → chunk-5OBUOALK.js} +8 -5
- package/dist/{chunk-ZY6UZ7NH.js → chunk-6RPNS75C.js} +1 -1
- package/dist/{chunk-XHJCLBZ4.js → chunk-ED3ON275.js} +86 -162
- package/dist/{chunk-7L2KNF6B.js → chunk-GB4W3YCZ.js} +51 -7
- package/dist/{chunk-SLY7WXTX.js → chunk-KOPLIEVQ.js} +5 -6
- package/dist/{chunk-OXSRIWQW.js → chunk-LPX7ZO66.js} +4 -3
- package/dist/{chunk-SRSRFOVI.js → chunk-OLL7FM7W.js} +3 -3
- package/dist/{chunk-5UMZCWKV.js → chunk-Q5OSGLJL.js} +1 -1
- package/dist/{chunk-E5DJTSIM.js → chunk-S7KOJHHO.js} +4 -1
- package/dist/{chunk-6NISOLQ6.js → chunk-USWQVJWR.js} +1 -1
- package/dist/chunk-WBIHDYMN.js +126 -0
- package/dist/config/index.d.ts +6 -1
- package/dist/config/index.js +1 -1
- package/dist/{index-D7JdSMpp.d.cts → core-C3QZSdEx.d.ts} +73 -4
- package/dist/{index-BlVBvy-z.d.ts → index-RVIZxMZG.d.ts} +1 -1
- package/dist/index.d.ts +56 -3
- package/dist/load-from-file-OZ5N7DXU.js +8 -0
- package/dist/next/index.cjs +263 -193
- package/dist/next/index.d.ts +7 -2
- package/dist/next/index.js +12 -10
- package/dist/node/loader.js +4 -4
- package/dist/plugins/index-file.d.ts +7 -22
- package/dist/plugins/index-file.js +2 -2
- package/dist/plugins/json-schema.d.ts +7 -1
- package/dist/plugins/last-modified.d.ts +15 -2
- package/dist/plugins/last-modified.js +43 -6
- package/dist/runtime/browser.d.ts +22 -19
- package/dist/runtime/browser.js +5 -6
- package/dist/runtime/dynamic.d.ts +12 -12
- package/dist/runtime/dynamic.js +12 -11
- package/dist/runtime/server.d.ts +10 -157
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/types.d.ts +61 -0
- package/dist/runtime/types.js +0 -0
- package/dist/vite/index.d.ts +7 -2
- package/dist/vite/index.js +10 -9
- package/dist/webpack/mdx.d.ts +8 -2
- package/dist/webpack/mdx.js +5 -5
- package/dist/webpack/meta.d.ts +8 -2
- package/dist/webpack/meta.js +4 -4
- package/package.json +4 -6
- package/dist/bin.cjs +0 -1889
- package/dist/bin.d.cts +0 -1
- package/dist/bun/index.cjs +0 -1112
- package/dist/bun/index.d.cts +0 -19
- package/dist/chunk-PKI7ZDA5.js +0 -29
- package/dist/config/index.cjs +0 -400
- package/dist/config/index.d.cts +0 -13
- package/dist/index-D7JdSMpp.d.ts +0 -272
- package/dist/index-P2NNUkHn.d.cts +0 -8
- package/dist/index.cjs +0 -18
- package/dist/index.d.cts +0 -8
- package/dist/load-from-file-I3ALLIVB.js +0 -8
- package/dist/next/index.d.cts +0 -28
- package/dist/node/loader.cjs +0 -1165
- package/dist/node/loader.d.cts +0 -5
- package/dist/plugins/index-file.cjs +0 -471
- package/dist/plugins/index-file.d.cts +0 -29
- package/dist/plugins/json-schema.cjs +0 -114
- package/dist/plugins/json-schema.d.cts +0 -25
- package/dist/plugins/last-modified.cjs +0 -75
- package/dist/plugins/last-modified.d.cts +0 -27
- package/dist/runtime/browser.cjs +0 -94
- package/dist/runtime/browser.d.cts +0 -50
- package/dist/runtime/dynamic.cjs +0 -985
- package/dist/runtime/dynamic.d.cts +0 -27
- package/dist/runtime/server.cjs +0 -173
- package/dist/runtime/server.d.cts +0 -161
- package/dist/vite/index.cjs +0 -1620
- package/dist/vite/index.d.cts +0 -39
- package/dist/webpack/mdx.cjs +0 -1089
- package/dist/webpack/mdx.d.cts +0 -14
- package/dist/webpack/meta.cjs +0 -649
- package/dist/webpack/meta.d.cts +0 -14
package/dist/next/index.cjs
CHANGED
|
@@ -91,7 +91,10 @@ function applyMdxPreset(options = {}) {
|
|
|
91
91
|
...v,
|
|
92
92
|
remarkStructureOptions !== false && [
|
|
93
93
|
plugins.remarkStructure,
|
|
94
|
-
|
|
94
|
+
{
|
|
95
|
+
exportAs: "structuredData",
|
|
96
|
+
...remarkStructureOptions
|
|
97
|
+
}
|
|
95
98
|
],
|
|
96
99
|
valueToExport.length > 0 && (() => {
|
|
97
100
|
return (_, file) => {
|
|
@@ -224,10 +227,11 @@ function buildConfig(config) {
|
|
|
224
227
|
// src/config/load-from-file.ts
|
|
225
228
|
async function compileConfig(core) {
|
|
226
229
|
const { build } = await import("esbuild");
|
|
230
|
+
const { configPath, outDir } = core.getOptions();
|
|
227
231
|
const transformed = await build({
|
|
228
|
-
entryPoints: [{ in:
|
|
232
|
+
entryPoints: [{ in: configPath, out: "source.config" }],
|
|
229
233
|
bundle: true,
|
|
230
|
-
outdir:
|
|
234
|
+
outdir: outDir,
|
|
231
235
|
target: "node20",
|
|
232
236
|
write: true,
|
|
233
237
|
platform: "node",
|
|
@@ -292,31 +296,128 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
292
296
|
|
|
293
297
|
// src/core.ts
|
|
294
298
|
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
299
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
300
|
+
|
|
301
|
+
// src/utils/codegen.ts
|
|
300
302
|
var import_node_path = __toESM(require("path"), 1);
|
|
301
|
-
var
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
303
|
+
var import_tinyglobby = require("tinyglobby");
|
|
304
|
+
function createCodegen({
|
|
305
|
+
target = "default",
|
|
306
|
+
outDir = "",
|
|
307
|
+
jsExtension = false,
|
|
308
|
+
globCache = /* @__PURE__ */ new Map()
|
|
309
|
+
}) {
|
|
310
|
+
let eagerImportId = 0;
|
|
311
|
+
const banner = ["// @ts-nocheck"];
|
|
312
|
+
if (target === "vite") {
|
|
313
|
+
banner.push('/// <reference types="vite/client" />');
|
|
307
314
|
}
|
|
308
|
-
return
|
|
315
|
+
return {
|
|
316
|
+
options: {
|
|
317
|
+
target,
|
|
318
|
+
outDir
|
|
319
|
+
},
|
|
320
|
+
lines: [],
|
|
321
|
+
addImport(statement) {
|
|
322
|
+
this.lines.unshift(statement);
|
|
323
|
+
},
|
|
324
|
+
async pushAsync(insert) {
|
|
325
|
+
for (const line of await Promise.all(insert)) {
|
|
326
|
+
if (line === void 0) continue;
|
|
327
|
+
this.lines.push(line);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
async generateGlobImport(patterns, options) {
|
|
331
|
+
if (target === "vite") {
|
|
332
|
+
return this.generateViteGlobImport(patterns, options);
|
|
333
|
+
}
|
|
334
|
+
return this.generateNodeGlobImport(patterns, options);
|
|
335
|
+
},
|
|
336
|
+
generateViteGlobImport(patterns, { base, ...rest }) {
|
|
337
|
+
patterns = (typeof patterns === "string" ? [patterns] : patterns).map(
|
|
338
|
+
normalizeViteGlobPath
|
|
339
|
+
);
|
|
340
|
+
return `import.meta.glob(${JSON.stringify(patterns)}, ${JSON.stringify(
|
|
341
|
+
{
|
|
342
|
+
base: normalizeViteGlobPath(import_node_path.default.relative(outDir, base)),
|
|
343
|
+
...rest
|
|
344
|
+
},
|
|
345
|
+
null,
|
|
346
|
+
2
|
|
347
|
+
)})`;
|
|
348
|
+
},
|
|
349
|
+
async generateNodeGlobImport(patterns, {
|
|
350
|
+
base,
|
|
351
|
+
eager = false,
|
|
352
|
+
query = {},
|
|
353
|
+
import: importName
|
|
354
|
+
}) {
|
|
355
|
+
const cacheKey = JSON.stringify({ patterns, base });
|
|
356
|
+
let files = globCache.get(cacheKey);
|
|
357
|
+
if (!files) {
|
|
358
|
+
files = (0, import_tinyglobby.glob)(patterns, {
|
|
359
|
+
cwd: base
|
|
360
|
+
});
|
|
361
|
+
globCache.set(cacheKey, files);
|
|
362
|
+
}
|
|
363
|
+
let code = "{";
|
|
364
|
+
for (const item of await files) {
|
|
365
|
+
const fullPath = import_node_path.default.join(base, item);
|
|
366
|
+
const searchParams = new URLSearchParams();
|
|
367
|
+
for (const [k, v] of Object.entries(query)) {
|
|
368
|
+
searchParams.set(k, v);
|
|
369
|
+
}
|
|
370
|
+
const importPath = this.formatImportPath(fullPath) + "?" + searchParams.toString();
|
|
371
|
+
if (eager) {
|
|
372
|
+
const name = `__fd_glob_${eagerImportId++}`;
|
|
373
|
+
this.lines.unshift(
|
|
374
|
+
importName ? `import { ${importName} as ${name} } from ${JSON.stringify(importPath)}` : `import * as ${name} from ${JSON.stringify(importPath)}`
|
|
375
|
+
);
|
|
376
|
+
code += `${JSON.stringify(item)}: ${name}, `;
|
|
377
|
+
} else {
|
|
378
|
+
let line = `${JSON.stringify(item)}: () => import(${JSON.stringify(importPath)})`;
|
|
379
|
+
if (importName) {
|
|
380
|
+
line += `.then(mod => mod.${importName})`;
|
|
381
|
+
}
|
|
382
|
+
code += `${line}, `;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
code += "}";
|
|
386
|
+
return code;
|
|
387
|
+
},
|
|
388
|
+
formatImportPath(file) {
|
|
389
|
+
const ext = import_node_path.default.extname(file);
|
|
390
|
+
let filename;
|
|
391
|
+
if (ext === ".ts" && jsExtension) {
|
|
392
|
+
filename = file.substring(0, file.length - ext.length) + ".js";
|
|
393
|
+
} else if (ext === ".ts") {
|
|
394
|
+
filename = file.substring(0, file.length - ext.length);
|
|
395
|
+
} else {
|
|
396
|
+
filename = file;
|
|
397
|
+
}
|
|
398
|
+
const importPath = slash(import_node_path.default.relative(outDir, filename));
|
|
399
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
400
|
+
},
|
|
401
|
+
toString() {
|
|
402
|
+
return [...banner, ...this.lines].join("\n");
|
|
403
|
+
}
|
|
404
|
+
};
|
|
309
405
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
map.set(fullPath, read);
|
|
316
|
-
return read;
|
|
406
|
+
function normalizeViteGlobPath(file) {
|
|
407
|
+
file = slash(file);
|
|
408
|
+
if (file.startsWith("./")) return file;
|
|
409
|
+
if (file.startsWith("/")) return `.${file}`;
|
|
410
|
+
return `./${file}`;
|
|
317
411
|
}
|
|
318
|
-
function
|
|
319
|
-
|
|
412
|
+
function slash(path6) {
|
|
413
|
+
const isExtendedLengthPath = path6.startsWith("\\\\?\\");
|
|
414
|
+
if (isExtendedLengthPath) {
|
|
415
|
+
return path6;
|
|
416
|
+
}
|
|
417
|
+
return path6.replaceAll("\\", "/");
|
|
418
|
+
}
|
|
419
|
+
function ident(code, tab = 1) {
|
|
420
|
+
return code.split("\n").map((v) => " ".repeat(tab) + v).join("\n");
|
|
320
421
|
}
|
|
321
422
|
|
|
322
423
|
// src/core.ts
|
|
@@ -352,7 +453,6 @@ function createCore(options, defaultPlugins = []) {
|
|
|
352
453
|
return data;
|
|
353
454
|
}
|
|
354
455
|
const core = {
|
|
355
|
-
_options: options,
|
|
356
456
|
/**
|
|
357
457
|
* Convenient cache store, reset when config changes
|
|
358
458
|
*/
|
|
@@ -361,6 +461,7 @@ function createCore(options, defaultPlugins = []) {
|
|
|
361
461
|
config = await newConfig;
|
|
362
462
|
this.cache.clear();
|
|
363
463
|
plugins = await getPlugins([
|
|
464
|
+
postprocessPlugin(),
|
|
364
465
|
...defaultPlugins,
|
|
365
466
|
...config.global.plugins ?? []
|
|
366
467
|
]);
|
|
@@ -368,7 +469,9 @@ function createCore(options, defaultPlugins = []) {
|
|
|
368
469
|
const out = await plugin.config?.call(pluginContext, config);
|
|
369
470
|
if (out) config = out;
|
|
370
471
|
}
|
|
371
|
-
|
|
472
|
+
},
|
|
473
|
+
getOptions() {
|
|
474
|
+
return options;
|
|
372
475
|
},
|
|
373
476
|
getConfig() {
|
|
374
477
|
return config;
|
|
@@ -379,10 +482,13 @@ function createCore(options, defaultPlugins = []) {
|
|
|
379
482
|
getCompiledConfigPath() {
|
|
380
483
|
return import_node_path2.default.join(options.outDir, "source.config.mjs");
|
|
381
484
|
},
|
|
485
|
+
getPlugins() {
|
|
486
|
+
return plugins;
|
|
487
|
+
},
|
|
488
|
+
getPluginContext() {
|
|
489
|
+
return pluginContext;
|
|
490
|
+
},
|
|
382
491
|
async initServer(server) {
|
|
383
|
-
server.watcher?.on("all", async (event, file) => {
|
|
384
|
-
if (event === "change") removeFileCache(file);
|
|
385
|
-
});
|
|
386
492
|
for (const plugin of plugins) {
|
|
387
493
|
await plugin.configureServer?.call(pluginContext, server);
|
|
388
494
|
}
|
|
@@ -401,8 +507,8 @@ function createCore(options, defaultPlugins = []) {
|
|
|
401
507
|
await Promise.all(
|
|
402
508
|
out.map(async (entry) => {
|
|
403
509
|
const file = import_node_path2.default.join(options.outDir, entry.path);
|
|
404
|
-
await
|
|
405
|
-
await
|
|
510
|
+
await import_promises.default.mkdir(import_node_path2.default.dirname(file), { recursive: true });
|
|
511
|
+
await import_promises.default.writeFile(file, entry.content);
|
|
406
512
|
})
|
|
407
513
|
);
|
|
408
514
|
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
@@ -449,6 +555,45 @@ function createCore(options, defaultPlugins = []) {
|
|
|
449
555
|
};
|
|
450
556
|
return core;
|
|
451
557
|
}
|
|
558
|
+
function postprocessPlugin() {
|
|
559
|
+
const LinkReferenceTypes = `{
|
|
560
|
+
/**
|
|
561
|
+
* extracted references (e.g. hrefs, paths), useful for analyzing relationships between pages.
|
|
562
|
+
*/
|
|
563
|
+
extractedReferences: import("fumadocs-mdx").ExtractedReference[];
|
|
564
|
+
}`;
|
|
565
|
+
return {
|
|
566
|
+
"index-file": {
|
|
567
|
+
generateTypeConfig() {
|
|
568
|
+
const lines = [];
|
|
569
|
+
lines.push("{");
|
|
570
|
+
lines.push(" DocData: {");
|
|
571
|
+
for (const collection of this.core.getConfig().collectionList) {
|
|
572
|
+
let postprocessOptions;
|
|
573
|
+
switch (collection.type) {
|
|
574
|
+
case "doc":
|
|
575
|
+
postprocessOptions = collection.postprocess;
|
|
576
|
+
break;
|
|
577
|
+
case "docs":
|
|
578
|
+
postprocessOptions = collection.docs.postprocess;
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
if (postprocessOptions?.extractLinkReferences) {
|
|
582
|
+
lines.push(ident(`${collection.name}: ${LinkReferenceTypes},`, 2));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
lines.push(" }");
|
|
586
|
+
lines.push("}");
|
|
587
|
+
return lines.join("\n");
|
|
588
|
+
},
|
|
589
|
+
serverOptions(options) {
|
|
590
|
+
options.doc ??= {};
|
|
591
|
+
options.doc.passthroughs ??= [];
|
|
592
|
+
options.doc.passthroughs.push("extractedReferences");
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
}
|
|
452
597
|
|
|
453
598
|
// src/loaders/index.ts
|
|
454
599
|
var metaLoaderGlob = /\.(json|yaml)(\?.+?)?$/;
|
|
@@ -456,131 +601,34 @@ var mdxLoaderGlob = /\.mdx?(\?.+?)?$/;
|
|
|
456
601
|
|
|
457
602
|
// src/plugins/index-file.ts
|
|
458
603
|
var import_path = __toESM(require("path"), 1);
|
|
604
|
+
var import_tinyglobby2 = require("tinyglobby");
|
|
459
605
|
|
|
460
|
-
// src/utils/
|
|
606
|
+
// src/utils/fs-cache.ts
|
|
607
|
+
var import_lru_cache = require("lru-cache");
|
|
608
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
461
609
|
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" />');
|
|
610
|
+
var map = new import_lru_cache.LRUCache({
|
|
611
|
+
max: 100
|
|
612
|
+
});
|
|
613
|
+
function toFullPath(file) {
|
|
614
|
+
if (import_node_path3.default.isAbsolute(file)) {
|
|
615
|
+
return import_node_path3.default.relative(process.cwd(), file);
|
|
473
616
|
}
|
|
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}`;
|
|
617
|
+
return file;
|
|
570
618
|
}
|
|
571
|
-
function
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
619
|
+
function readFileWithCache(file) {
|
|
620
|
+
const fullPath = toFullPath(file);
|
|
621
|
+
const cached = map.get(fullPath);
|
|
622
|
+
if (cached) return cached;
|
|
623
|
+
const read = import_promises2.default.readFile(fullPath).then((s) => s.toString());
|
|
624
|
+
map.set(fullPath, read);
|
|
625
|
+
return read;
|
|
577
626
|
}
|
|
578
|
-
function
|
|
579
|
-
|
|
627
|
+
function removeFileCache(file) {
|
|
628
|
+
map.delete(toFullPath(file));
|
|
580
629
|
}
|
|
581
630
|
|
|
582
631
|
// src/plugins/index-file.ts
|
|
583
|
-
var import_tinyglobby2 = require("tinyglobby");
|
|
584
632
|
var import_crypto = require("crypto");
|
|
585
633
|
|
|
586
634
|
// src/utils/fuma-matter.ts
|
|
@@ -612,6 +660,24 @@ function indexFile(options = {}) {
|
|
|
612
660
|
function isDynamic(collection) {
|
|
613
661
|
return collection.type === "docs" && collection.docs.dynamic || collection.type === "doc" && collection.dynamic;
|
|
614
662
|
}
|
|
663
|
+
function generateConfigs(core) {
|
|
664
|
+
const serverOptions = {};
|
|
665
|
+
const typeConfigs = [
|
|
666
|
+
'import("fumadocs-mdx/runtime/types").InternalTypeConfig'
|
|
667
|
+
];
|
|
668
|
+
const ctx = core.getPluginContext();
|
|
669
|
+
for (const plugin of core.getPlugins()) {
|
|
670
|
+
const indexFilePlugin = plugin["index-file"];
|
|
671
|
+
if (!indexFilePlugin) continue;
|
|
672
|
+
indexFilePlugin.serverOptions?.call(ctx, serverOptions);
|
|
673
|
+
const config2 = indexFilePlugin.generateTypeConfig?.call(ctx);
|
|
674
|
+
if (config2) typeConfigs.push(config2);
|
|
675
|
+
}
|
|
676
|
+
return {
|
|
677
|
+
serverOptions,
|
|
678
|
+
tc: typeConfigs.join(" & ")
|
|
679
|
+
};
|
|
680
|
+
}
|
|
615
681
|
return {
|
|
616
682
|
name: "index-file",
|
|
617
683
|
config(v) {
|
|
@@ -621,6 +687,7 @@ function indexFile(options = {}) {
|
|
|
621
687
|
configureServer(server) {
|
|
622
688
|
if (!server.watcher) return;
|
|
623
689
|
server.watcher.on("all", async (event, file) => {
|
|
690
|
+
removeFileCache(file);
|
|
624
691
|
if (dynamicCollections.length === 0) {
|
|
625
692
|
if (target === "vite") return;
|
|
626
693
|
if (target === "default" && event === "change") return;
|
|
@@ -640,48 +707,47 @@ function indexFile(options = {}) {
|
|
|
640
707
|
},
|
|
641
708
|
async emit() {
|
|
642
709
|
const globCache = /* @__PURE__ */ new Map();
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
710
|
+
const { serverOptions, tc } = generateConfigs(this.core);
|
|
711
|
+
const toEmitEntry = async (path6, content) => {
|
|
712
|
+
const codegen = createCodegen({
|
|
713
|
+
target,
|
|
714
|
+
outDir: this.outDir,
|
|
715
|
+
jsExtension: addJsExtension,
|
|
716
|
+
globCache
|
|
717
|
+
});
|
|
718
|
+
await content({
|
|
719
|
+
core: this.core,
|
|
720
|
+
codegen,
|
|
721
|
+
serverOptions,
|
|
722
|
+
tc
|
|
723
|
+
});
|
|
650
724
|
return {
|
|
651
725
|
path: path6,
|
|
652
|
-
content:
|
|
726
|
+
content: codegen.toString()
|
|
653
727
|
};
|
|
654
|
-
}
|
|
728
|
+
};
|
|
655
729
|
const out = [
|
|
656
|
-
toEmitEntry(
|
|
657
|
-
"server.ts",
|
|
658
|
-
generateServerIndexFile(makeCodeGen(), config, this.configPath)
|
|
659
|
-
)
|
|
730
|
+
toEmitEntry("server.ts", generateServerIndexFile)
|
|
660
731
|
];
|
|
661
732
|
if (dynamic)
|
|
662
|
-
out.push(
|
|
663
|
-
toEmitEntry(
|
|
664
|
-
"dynamic.ts",
|
|
665
|
-
generateDynamicIndexFile(this.core, makeCodeGen())
|
|
666
|
-
)
|
|
667
|
-
);
|
|
733
|
+
out.push(toEmitEntry("dynamic.ts", generateDynamicIndexFile));
|
|
668
734
|
if (browser)
|
|
669
|
-
out.push(
|
|
670
|
-
toEmitEntry(
|
|
671
|
-
"browser.ts",
|
|
672
|
-
generateBrowserIndexFile(makeCodeGen(), config, this.configPath)
|
|
673
|
-
)
|
|
674
|
-
);
|
|
735
|
+
out.push(toEmitEntry("browser.ts", generateBrowserIndexFile));
|
|
675
736
|
return await Promise.all(out);
|
|
676
737
|
}
|
|
677
738
|
};
|
|
678
739
|
}
|
|
679
|
-
async function generateServerIndexFile(
|
|
740
|
+
async function generateServerIndexFile({
|
|
741
|
+
core,
|
|
742
|
+
codegen,
|
|
743
|
+
serverOptions,
|
|
744
|
+
tc
|
|
745
|
+
}) {
|
|
680
746
|
codegen.lines.push(
|
|
681
|
-
`import {
|
|
682
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
747
|
+
`import { server } from 'fumadocs-mdx/runtime/server';`,
|
|
748
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
683
749
|
"",
|
|
684
|
-
`const create =
|
|
750
|
+
`const create = server<typeof Config, ${tc}>(${JSON.stringify(serverOptions)});`
|
|
685
751
|
);
|
|
686
752
|
async function generateCollectionObject(collection) {
|
|
687
753
|
switch (collection.type) {
|
|
@@ -728,22 +794,26 @@ async function generateServerIndexFile(codegen, config, configPath) {
|
|
|
728
794
|
}
|
|
729
795
|
}
|
|
730
796
|
await codegen.pushAsync(
|
|
731
|
-
|
|
797
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
732
798
|
const obj = await generateCollectionObject(collection);
|
|
733
799
|
if (!obj) return;
|
|
734
800
|
return `
|
|
735
801
|
export const ${collection.name} = ${obj};`;
|
|
736
802
|
})
|
|
737
803
|
);
|
|
738
|
-
return codegen.toString();
|
|
739
804
|
}
|
|
740
|
-
async function generateDynamicIndexFile(
|
|
741
|
-
|
|
805
|
+
async function generateDynamicIndexFile({
|
|
806
|
+
core,
|
|
807
|
+
codegen,
|
|
808
|
+
serverOptions,
|
|
809
|
+
tc
|
|
810
|
+
}) {
|
|
811
|
+
const { configPath } = core.getOptions();
|
|
742
812
|
codegen.lines.push(
|
|
743
|
-
`import {
|
|
813
|
+
`import { dynamic } from 'fumadocs-mdx/runtime/dynamic';`,
|
|
744
814
|
`import * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
745
815
|
"",
|
|
746
|
-
`const create = await
|
|
816
|
+
`const create = await dynamic<typeof Config, ${tc}>(Config, ${JSON.stringify(core.getOptions())}, ${JSON.stringify(serverOptions)});`
|
|
747
817
|
);
|
|
748
818
|
async function generateCollectionObjectEntry(collection, file) {
|
|
749
819
|
const fullPath = import_path.default.join(collection.dir, file);
|
|
@@ -806,14 +876,13 @@ async function generateDynamicIndexFile(core, codegen) {
|
|
|
806
876
|
export const ${collection.name} = ${obj};`;
|
|
807
877
|
})
|
|
808
878
|
);
|
|
809
|
-
return codegen.toString();
|
|
810
879
|
}
|
|
811
|
-
async function generateBrowserIndexFile(
|
|
880
|
+
async function generateBrowserIndexFile({ core, codegen, tc }) {
|
|
812
881
|
codegen.lines.push(
|
|
813
|
-
`import {
|
|
814
|
-
`import type * as Config from '${codegen.formatImportPath(configPath)}';`,
|
|
882
|
+
`import { browser } from 'fumadocs-mdx/runtime/browser';`,
|
|
883
|
+
`import type * as Config from '${codegen.formatImportPath(core.getOptions().configPath)}';`,
|
|
815
884
|
"",
|
|
816
|
-
`const create =
|
|
885
|
+
`const create = browser<typeof Config, ${tc}>();`
|
|
817
886
|
);
|
|
818
887
|
async function generateCollectionObject(collection) {
|
|
819
888
|
switch (collection.type) {
|
|
@@ -828,14 +897,13 @@ async function generateBrowserIndexFile(codegen, config, configPath) {
|
|
|
828
897
|
}
|
|
829
898
|
codegen.lines.push("const browserCollections = {");
|
|
830
899
|
await codegen.pushAsync(
|
|
831
|
-
|
|
900
|
+
core.getConfig().collectionList.map(async (collection) => {
|
|
832
901
|
const obj = await generateCollectionObject(collection);
|
|
833
902
|
if (!obj) return;
|
|
834
903
|
return ident(`${collection.name}: ${obj},`);
|
|
835
904
|
})
|
|
836
905
|
);
|
|
837
906
|
codegen.lines.push("};", "export default browserCollections;");
|
|
838
|
-
return codegen.toString();
|
|
839
907
|
}
|
|
840
908
|
function generateDocCollectionFrontmatterGlob(codegen, collection, eager = false) {
|
|
841
909
|
return codegen.generateGlobImport(collection.patterns, {
|
|
@@ -879,7 +947,7 @@ function createMDX(createOptions = {}) {
|
|
|
879
947
|
}
|
|
880
948
|
return (nextConfig = {}) => {
|
|
881
949
|
const loaderOptions = {
|
|
882
|
-
...core.
|
|
950
|
+
...core.getOptions(),
|
|
883
951
|
compiledConfigPath: core.getCompiledConfigPath(),
|
|
884
952
|
isDev
|
|
885
953
|
};
|
|
@@ -961,12 +1029,13 @@ async function init(dev, core) {
|
|
|
961
1029
|
}
|
|
962
1030
|
async function devServer() {
|
|
963
1031
|
const { FSWatcher } = await import("chokidar");
|
|
1032
|
+
const { configPath, outDir } = core.getOptions();
|
|
964
1033
|
const watcher = new FSWatcher({
|
|
965
1034
|
ignoreInitial: true,
|
|
966
1035
|
persistent: true,
|
|
967
|
-
ignored: [
|
|
1036
|
+
ignored: [outDir]
|
|
968
1037
|
});
|
|
969
|
-
watcher.add(
|
|
1038
|
+
watcher.add(configPath);
|
|
970
1039
|
for (const collection of core.getConfig().collectionList) {
|
|
971
1040
|
if (collection.type === "docs") {
|
|
972
1041
|
watcher.add(collection.docs.dir);
|
|
@@ -978,8 +1047,9 @@ async function init(dev, core) {
|
|
|
978
1047
|
watcher.on("ready", () => {
|
|
979
1048
|
console.log("[MDX] started dev server");
|
|
980
1049
|
});
|
|
1050
|
+
const absoluteConfigPath = path5.resolve(configPath);
|
|
981
1051
|
watcher.on("all", async (_event, file) => {
|
|
982
|
-
if (path5.resolve(file) ===
|
|
1052
|
+
if (path5.resolve(file) === absoluteConfigPath) {
|
|
983
1053
|
watcher.removeAllListeners();
|
|
984
1054
|
await watcher.close();
|
|
985
1055
|
await initOrReload();
|
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-C3QZSdEx.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
|
/**
|