fumadocs-mdx 12.0.3 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.cjs +1033 -308
- package/dist/bin.js +4 -4
- package/dist/build-mdx-BHG-_uxo.d.cts +53 -0
- package/dist/build-mdx-CzrQDBRZ.d.ts +53 -0
- package/dist/bun/index.cjs +92 -28
- package/dist/bun/index.js +6 -7
- package/dist/{chunk-QAUWMR5D.js → chunk-3J3WL7WN.js} +23 -5
- package/dist/chunk-4MAYA5QX.js +44 -0
- package/dist/{chunk-RMDXSZYE.js → chunk-CEA6MYJU.js} +13 -8
- package/dist/{chunk-IQAEAI4P.js → chunk-HI62EXSB.js} +63 -2
- package/dist/{chunk-46UPKP5R.js → chunk-II3H5ZVZ.js} +5 -5
- package/dist/{chunk-LGYVNESJ.js → chunk-JVZFH6ND.js} +6 -22
- package/dist/{chunk-LMG6UWCL.js → chunk-K5ZLPEIQ.js} +56 -16
- package/dist/{chunk-OMAMTKDE.js → chunk-KILFIBVW.js} +3 -12
- package/dist/chunk-NVRDCY6Z.js +30 -0
- package/dist/{chunk-VXEBLM4X.js → chunk-XV5Z4BFL.js} +1 -1
- package/dist/config/index.cjs +56 -16
- package/dist/config/index.d.cts +2 -1
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -1
- package/dist/{define-DJbJduHy.d.ts → define-BCNh3n4O.d.cts} +40 -16
- package/dist/{define-DJbJduHy.d.cts → define-bck_EB4t.d.ts} +40 -16
- package/dist/index.cjs +0 -109
- package/dist/index.d.cts +73 -12
- package/dist/index.d.ts +73 -12
- package/dist/index.js +0 -11
- package/dist/{load-UUXLUBHL.js → load-MNG3CLET.js} +1 -3
- package/dist/loader-mdx.cjs +153 -60
- package/dist/loader-mdx.d.cts +1 -0
- package/dist/loader-mdx.d.ts +1 -0
- package/dist/loader-mdx.js +23 -9
- package/dist/next/index.cjs +213 -181
- package/dist/next/index.d.cts +2 -11
- package/dist/next/index.d.ts +2 -11
- package/dist/next/index.js +145 -117
- package/dist/node/loader.cjs +128 -70
- package/dist/node/loader.js +14 -9
- package/dist/plugins/index.cjs +78 -0
- package/dist/plugins/index.d.cts +7 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/json-schema.cjs +61 -0
- package/dist/plugins/json-schema.d.cts +16 -0
- package/dist/plugins/json-schema.d.ts +16 -0
- package/dist/plugins/json-schema.js +40 -0
- package/dist/remark-postprocess-K233ZVBK.d.cts +22 -0
- package/dist/remark-postprocess-K233ZVBK.d.ts +22 -0
- package/dist/runtime/next/async.cjs +108 -70
- package/dist/runtime/next/async.d.cts +9 -6
- package/dist/runtime/next/async.d.ts +9 -6
- package/dist/runtime/next/async.js +9 -19
- package/dist/runtime/next/index.cjs +25 -14
- package/dist/runtime/next/index.d.cts +11 -8
- package/dist/runtime/next/index.d.ts +11 -8
- package/dist/runtime/next/index.js +2 -2
- package/dist/runtime/vite/browser.cjs +7 -3
- package/dist/runtime/vite/browser.d.cts +56 -7
- package/dist/runtime/vite/browser.d.ts +56 -7
- package/dist/runtime/vite/browser.js +2 -1
- package/dist/runtime/vite/server.cjs +40 -34
- package/dist/runtime/vite/server.d.cts +13 -10
- package/dist/runtime/vite/server.d.ts +13 -10
- package/dist/runtime/vite/server.js +8 -23
- package/dist/{types-TeHjsmja.d.ts → types-1cCFEzWt.d.ts} +3 -10
- package/dist/{types-BRx1QsIJ.d.cts → types-D5NhXTJY.d.cts} +3 -10
- package/dist/vite/index.cjs +386 -224
- package/dist/vite/index.d.cts +23 -10
- package/dist/vite/index.d.ts +23 -10
- package/dist/vite/index.js +211 -37
- package/dist/{watcher-HGOH3APP.js → watcher-WXJDWRZY.js} +1 -1
- package/package.json +28 -15
- package/dist/browser-BupUnhpC.d.ts +0 -98
- package/dist/browser-R0x9IPaQ.d.cts +0 -98
- package/dist/chunk-ADR6R7HM.js +0 -29
- package/dist/chunk-XMFLD5J6.js +0 -30
- package/dist/chunk-ZLCSVXCD.js +0 -10
- package/dist/chunk-ZX7TM4AR.js +0 -127
- package/dist/postinstall-SCSXM4IM.js +0 -10
- package/dist/shared-CfiiRctw.d.ts +0 -70
- package/dist/shared-fFqiuWJC.d.cts +0 -70
package/dist/node/loader.cjs
CHANGED
|
@@ -175,7 +175,6 @@ var init_build = __esm({
|
|
|
175
175
|
// src/loaders/config/load.ts
|
|
176
176
|
var load_exports = {};
|
|
177
177
|
__export(load_exports, {
|
|
178
|
-
getConfigHash: () => getConfigHash,
|
|
179
178
|
loadConfig: () => loadConfig
|
|
180
179
|
});
|
|
181
180
|
async function compileConfig(configPath, outDir) {
|
|
@@ -198,37 +197,22 @@ async function compileConfig(configPath, outDir) {
|
|
|
198
197
|
throw new Error("failed to compile configuration file");
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
|
-
async function loadConfig(configPath, outDir,
|
|
202
|
-
if (cache && cache.hash === hash) {
|
|
203
|
-
return await cache.config;
|
|
204
|
-
}
|
|
200
|
+
async function loadConfig(configPath, outDir, build = false) {
|
|
205
201
|
if (build) await compileConfig(configPath, outDir);
|
|
206
202
|
const url = (0, import_node_url.pathToFileURL)(path.resolve(outDir, "source.config.mjs"));
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
if (hash) cache = { config, hash };
|
|
203
|
+
url.searchParams.set("hash", Date.now().toString());
|
|
204
|
+
const config = import(url.href).then(
|
|
205
|
+
(loaded) => buildConfig(loaded)
|
|
206
|
+
);
|
|
214
207
|
return await config;
|
|
215
208
|
}
|
|
216
|
-
|
|
217
|
-
const stats = await fs.stat(configPath).catch(() => void 0);
|
|
218
|
-
if (stats) {
|
|
219
|
-
return stats.mtime.getTime().toString();
|
|
220
|
-
}
|
|
221
|
-
throw new Error("Cannot find config file");
|
|
222
|
-
}
|
|
223
|
-
var fs, path, import_node_url, cache;
|
|
209
|
+
var path, import_node_url;
|
|
224
210
|
var init_load = __esm({
|
|
225
211
|
"src/loaders/config/load.ts"() {
|
|
226
212
|
"use strict";
|
|
227
|
-
fs = __toESM(require("fs/promises"), 1);
|
|
228
213
|
path = __toESM(require("path"), 1);
|
|
229
214
|
import_node_url = require("url");
|
|
230
215
|
init_build();
|
|
231
|
-
cache = null;
|
|
232
216
|
}
|
|
233
217
|
});
|
|
234
218
|
|
|
@@ -241,18 +225,23 @@ module.exports = __toCommonJS(loader_exports);
|
|
|
241
225
|
|
|
242
226
|
// src/loaders/config/index.ts
|
|
243
227
|
var import_node_path = __toESM(require("path"), 1);
|
|
228
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
244
229
|
function findConfigFile() {
|
|
245
230
|
return import_node_path.default.resolve("source.config.ts");
|
|
246
231
|
}
|
|
247
|
-
function
|
|
232
|
+
function staticConfig({
|
|
233
|
+
outDir,
|
|
234
|
+
configPath,
|
|
235
|
+
buildConfig: buildConfig2
|
|
236
|
+
}) {
|
|
237
|
+
let cached;
|
|
248
238
|
return {
|
|
249
|
-
async getConfig(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
configPath,
|
|
253
|
-
outDir,
|
|
254
|
-
hash ?? await getConfigHash2(configPath)
|
|
239
|
+
async getConfig() {
|
|
240
|
+
if (cached) return cached;
|
|
241
|
+
cached = Promise.resolve().then(() => (init_load(), load_exports)).then(
|
|
242
|
+
(mod) => mod.loadConfig(configPath, outDir, buildConfig2)
|
|
255
243
|
);
|
|
244
|
+
return cached;
|
|
256
245
|
}
|
|
257
246
|
};
|
|
258
247
|
}
|
|
@@ -314,9 +303,9 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
314
303
|
// src/utils/git-timestamp.ts
|
|
315
304
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
316
305
|
var import_tinyexec = require("tinyexec");
|
|
317
|
-
var
|
|
306
|
+
var cache = /* @__PURE__ */ new Map();
|
|
318
307
|
async function getGitTimestamp(file) {
|
|
319
|
-
const cached =
|
|
308
|
+
const cached = cache.get(file);
|
|
320
309
|
if (cached) return cached;
|
|
321
310
|
try {
|
|
322
311
|
const out = await (0, import_tinyexec.x)(
|
|
@@ -327,7 +316,7 @@ async function getGitTimestamp(file) {
|
|
|
327
316
|
}
|
|
328
317
|
);
|
|
329
318
|
const time = new Date(out.stdout);
|
|
330
|
-
|
|
319
|
+
cache.set(file, time);
|
|
331
320
|
return time;
|
|
332
321
|
} catch {
|
|
333
322
|
return;
|
|
@@ -339,12 +328,56 @@ var import_mdx = require("@mdx-js/mdx");
|
|
|
339
328
|
|
|
340
329
|
// src/loaders/mdx/remark-include.ts
|
|
341
330
|
var import_unified = require("unified");
|
|
342
|
-
var
|
|
331
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
343
332
|
var path4 = __toESM(require("path"), 1);
|
|
344
333
|
var fs2 = __toESM(require("fs/promises"), 1);
|
|
345
|
-
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
346
|
-
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
347
334
|
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
335
|
+
|
|
336
|
+
// src/loaders/mdx/remark-unravel.ts
|
|
337
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
338
|
+
function remarkMarkAndUnravel() {
|
|
339
|
+
return (tree) => {
|
|
340
|
+
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
341
|
+
let offset = -1;
|
|
342
|
+
let all = true;
|
|
343
|
+
let oneOrMore = false;
|
|
344
|
+
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
345
|
+
const children = node.children;
|
|
346
|
+
while (++offset < children.length) {
|
|
347
|
+
const child = children[offset];
|
|
348
|
+
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
349
|
+
oneOrMore = true;
|
|
350
|
+
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
351
|
+
} else {
|
|
352
|
+
all = false;
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (all && oneOrMore) {
|
|
357
|
+
offset = -1;
|
|
358
|
+
const newChildren = [];
|
|
359
|
+
while (++offset < children.length) {
|
|
360
|
+
const child = children[offset];
|
|
361
|
+
if (child.type === "mdxJsxTextElement") {
|
|
362
|
+
child.type = "mdxJsxFlowElement";
|
|
363
|
+
}
|
|
364
|
+
if (child.type === "mdxTextExpression") {
|
|
365
|
+
child.type = "mdxFlowExpression";
|
|
366
|
+
}
|
|
367
|
+
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
368
|
+
} else {
|
|
369
|
+
newChildren.push(child);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
parent.children.splice(index, 1, ...newChildren);
|
|
373
|
+
return index;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/loaders/mdx/remark-include.ts
|
|
348
381
|
var ElementLikeTypes = [
|
|
349
382
|
"mdxJsxFlowElement",
|
|
350
383
|
"mdxJsxTextElement",
|
|
@@ -384,7 +417,7 @@ function parseSpecifier(specifier) {
|
|
|
384
417
|
function extractSection(root, section) {
|
|
385
418
|
let nodes;
|
|
386
419
|
let capturingHeadingContent = false;
|
|
387
|
-
(0,
|
|
420
|
+
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
388
421
|
if (node.type === "heading") {
|
|
389
422
|
if (capturingHeadingContent) {
|
|
390
423
|
return false;
|
|
@@ -416,7 +449,7 @@ function extractSection(root, section) {
|
|
|
416
449
|
}
|
|
417
450
|
function remarkInclude() {
|
|
418
451
|
const TagName = "include";
|
|
419
|
-
async
|
|
452
|
+
const embedContent = async (file, heading, params, data) => {
|
|
420
453
|
let content;
|
|
421
454
|
try {
|
|
422
455
|
content = (await fs2.readFile(file)).toString();
|
|
@@ -439,18 +472,17 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
439
472
|
data: {}
|
|
440
473
|
};
|
|
441
474
|
}
|
|
442
|
-
const parser =
|
|
443
|
-
ext === ".mdx" ? "mdx" : "md"
|
|
444
|
-
);
|
|
475
|
+
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
445
476
|
const parsed = fumaMatter(content);
|
|
446
477
|
let mdast = parser.parse({
|
|
447
478
|
path: file,
|
|
448
479
|
value: parsed.content,
|
|
449
480
|
data: { frontmatter: parsed.data }
|
|
450
481
|
});
|
|
482
|
+
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
451
483
|
if (heading) {
|
|
452
484
|
const extracted = extractSection(
|
|
453
|
-
await
|
|
485
|
+
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
454
486
|
heading
|
|
455
487
|
);
|
|
456
488
|
if (!extracted)
|
|
@@ -458,13 +490,15 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
458
490
|
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
|
|
459
491
|
);
|
|
460
492
|
mdast = extracted;
|
|
493
|
+
} else {
|
|
494
|
+
mdast = await baseProcessor.run(mdast);
|
|
461
495
|
}
|
|
462
496
|
await update(mdast, path4.dirname(file), data);
|
|
463
497
|
return mdast;
|
|
464
|
-
}
|
|
498
|
+
};
|
|
465
499
|
async function update(tree, directory, data) {
|
|
466
500
|
const queue = [];
|
|
467
|
-
(0,
|
|
501
|
+
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
468
502
|
const node = _node;
|
|
469
503
|
if (node.name !== TagName) return;
|
|
470
504
|
const specifier = flattenNode(node);
|
|
@@ -491,24 +525,28 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
491
525
|
await update(tree, path4.dirname(file.path), file.data);
|
|
492
526
|
};
|
|
493
527
|
}
|
|
494
|
-
function getDefaultProcessor(format) {
|
|
495
|
-
const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
|
|
496
|
-
if (format === "md") return mdProcessor;
|
|
497
|
-
return mdProcessor.use(import_remark_mdx.default);
|
|
498
|
-
}
|
|
499
528
|
|
|
500
529
|
// src/loaders/mdx/remark-postprocess.ts
|
|
501
|
-
var
|
|
530
|
+
var import_unist_util_visit3 = require("unist-util-visit");
|
|
502
531
|
var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
503
532
|
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
533
|
+
var import_unist_util_remove_position = require("unist-util-remove-position");
|
|
534
|
+
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
504
535
|
function remarkPostprocess({
|
|
536
|
+
_format,
|
|
505
537
|
includeProcessedMarkdown = false,
|
|
538
|
+
includeMDAST = false,
|
|
506
539
|
valueToExport = []
|
|
507
|
-
}
|
|
540
|
+
}) {
|
|
541
|
+
let _stringifyProcessor;
|
|
542
|
+
const getStringifyProcessor = () => {
|
|
543
|
+
if (_format === "mdx") return this;
|
|
544
|
+
return _stringifyProcessor ??= this().use(import_remark_mdx.default).freeze();
|
|
545
|
+
};
|
|
508
546
|
return (tree, file) => {
|
|
509
547
|
let title;
|
|
510
548
|
const urls = [];
|
|
511
|
-
(0,
|
|
549
|
+
(0, import_unist_util_visit3.visit)(tree, ["heading", "link"], (node) => {
|
|
512
550
|
if (node.type === "heading" && node.depth === 1) {
|
|
513
551
|
title = flattenNode2(node);
|
|
514
552
|
}
|
|
@@ -524,12 +562,19 @@ function remarkPostprocess({
|
|
|
524
562
|
}
|
|
525
563
|
file.data.extractedReferences = urls;
|
|
526
564
|
if (includeProcessedMarkdown) {
|
|
565
|
+
const processor = getStringifyProcessor();
|
|
527
566
|
file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
528
|
-
...
|
|
567
|
+
...processor.data("settings"),
|
|
529
568
|
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
530
|
-
extensions:
|
|
569
|
+
extensions: processor.data("toMarkdownExtensions") || []
|
|
531
570
|
});
|
|
532
571
|
}
|
|
572
|
+
if (includeMDAST) {
|
|
573
|
+
const options = includeMDAST === true ? {} : includeMDAST;
|
|
574
|
+
file.data._mdast = JSON.stringify(
|
|
575
|
+
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
576
|
+
);
|
|
577
|
+
}
|
|
533
578
|
for (const { name, value } of file.data["mdx-export"] ?? []) {
|
|
534
579
|
tree.children.unshift(getMdastExport(name, value));
|
|
535
580
|
}
|
|
@@ -581,12 +626,12 @@ function flattenNode2(node) {
|
|
|
581
626
|
}
|
|
582
627
|
|
|
583
628
|
// src/loaders/mdx/build-mdx.ts
|
|
584
|
-
var
|
|
629
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
585
630
|
async function buildMDX(cacheKey, source, options) {
|
|
586
631
|
const { filePath, frontmatter, data, _compiler, ...rest } = options;
|
|
587
632
|
function getProcessor(format) {
|
|
588
633
|
const key = `${cacheKey}:${format}`;
|
|
589
|
-
let processor =
|
|
634
|
+
let processor = cache2.get(key);
|
|
590
635
|
if (!processor) {
|
|
591
636
|
processor = (0, import_mdx.createProcessor)({
|
|
592
637
|
outputFormat: "program",
|
|
@@ -597,6 +642,7 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
597
642
|
[
|
|
598
643
|
remarkPostprocess,
|
|
599
644
|
{
|
|
645
|
+
_format: format,
|
|
600
646
|
...options.postprocess,
|
|
601
647
|
valueToExport: [
|
|
602
648
|
...options.postprocess?.valueToExport ?? [],
|
|
@@ -604,14 +650,15 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
604
650
|
"extractedReferences",
|
|
605
651
|
"frontmatter",
|
|
606
652
|
"lastModified",
|
|
607
|
-
"_markdown"
|
|
653
|
+
"_markdown",
|
|
654
|
+
"_mdast"
|
|
608
655
|
]
|
|
609
656
|
}
|
|
610
657
|
]
|
|
611
658
|
],
|
|
612
659
|
format
|
|
613
660
|
});
|
|
614
|
-
|
|
661
|
+
cache2.set(key, processor);
|
|
615
662
|
}
|
|
616
663
|
return processor;
|
|
617
664
|
}
|
|
@@ -631,21 +678,26 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
631
678
|
|
|
632
679
|
// src/loaders/mdx/index.ts
|
|
633
680
|
var import_zod = require("zod");
|
|
634
|
-
var
|
|
681
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
635
682
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
636
683
|
var import_node_crypto = require("crypto");
|
|
637
684
|
var querySchema = import_zod.z.object({
|
|
638
685
|
only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
|
|
639
|
-
collection: import_zod.z.string().optional()
|
|
640
|
-
hash: import_zod.z.string().describe(
|
|
641
|
-
"the hash of config, used for revalidation on Turbopack/Webpack."
|
|
642
|
-
).optional()
|
|
686
|
+
collection: import_zod.z.string().optional()
|
|
643
687
|
}).loose();
|
|
644
688
|
var cacheEntry = import_zod.z.object({
|
|
645
689
|
code: import_zod.z.string(),
|
|
646
690
|
map: import_zod.z.any().optional(),
|
|
647
691
|
hash: import_zod.z.string().optional()
|
|
648
692
|
});
|
|
693
|
+
var hashes = /* @__PURE__ */ new WeakMap();
|
|
694
|
+
function getConfigHash(config) {
|
|
695
|
+
let hash = hashes.get(config);
|
|
696
|
+
if (hash) return hash;
|
|
697
|
+
hash = Date.now().toString();
|
|
698
|
+
hashes.set(config, hash);
|
|
699
|
+
return hash;
|
|
700
|
+
}
|
|
649
701
|
function createMdxLoader(configLoader) {
|
|
650
702
|
return async ({
|
|
651
703
|
source: value,
|
|
@@ -656,11 +708,11 @@ function createMdxLoader(configLoader) {
|
|
|
656
708
|
}) => {
|
|
657
709
|
const matter = fumaMatter(value);
|
|
658
710
|
const parsed = querySchema.parse(query);
|
|
659
|
-
const loaded = await configLoader.getConfig(
|
|
711
|
+
const loaded = await configLoader.getConfig();
|
|
660
712
|
const cacheDir = isDevelopment ? void 0 : loaded.global.experimentalBuildCache;
|
|
661
713
|
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
662
714
|
if (cacheDir) {
|
|
663
|
-
const cached = await
|
|
715
|
+
const cached = await import_promises2.default.readFile(import_node_path3.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
664
716
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
665
717
|
}
|
|
666
718
|
const collection = parsed.collection ? loaded.collections.get(parsed.collection) : void 0;
|
|
@@ -696,7 +748,7 @@ function createMdxLoader(configLoader) {
|
|
|
696
748
|
}
|
|
697
749
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
698
750
|
const compiled = await buildMDX(
|
|
699
|
-
`${
|
|
751
|
+
`${getConfigHash(loaded)}:${parsed.collection ?? "global"}`,
|
|
700
752
|
"\n".repeat(lineOffset) + matter.content,
|
|
701
753
|
{
|
|
702
754
|
development: isDevelopment,
|
|
@@ -713,8 +765,8 @@ function createMdxLoader(configLoader) {
|
|
|
713
765
|
map: compiled.map
|
|
714
766
|
};
|
|
715
767
|
if (cacheDir) {
|
|
716
|
-
await
|
|
717
|
-
await
|
|
768
|
+
await import_promises2.default.mkdir(cacheDir, { recursive: true });
|
|
769
|
+
await import_promises2.default.writeFile(
|
|
718
770
|
import_node_path3.default.join(cacheDir, cacheKey),
|
|
719
771
|
JSON.stringify({
|
|
720
772
|
...out,
|
|
@@ -738,7 +790,7 @@ function countLines(s) {
|
|
|
738
790
|
|
|
739
791
|
// src/loaders/adapter.ts
|
|
740
792
|
var import_node_url2 = require("url");
|
|
741
|
-
var
|
|
793
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
742
794
|
var import_node_querystring = require("querystring");
|
|
743
795
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
744
796
|
function toNode(loader, filterByPath) {
|
|
@@ -747,7 +799,7 @@ function toNode(loader, filterByPath) {
|
|
|
747
799
|
const parsedUrl = new URL(url);
|
|
748
800
|
const filePath = (0, import_node_url2.fileURLToPath)(parsedUrl);
|
|
749
801
|
if (filterByPath(filePath)) {
|
|
750
|
-
const source = (await
|
|
802
|
+
const source = (await import_promises3.default.readFile(filePath)).toString();
|
|
751
803
|
const result = await loader({
|
|
752
804
|
filePath,
|
|
753
805
|
query: Object.fromEntries(parsedUrl.searchParams.entries()),
|
|
@@ -770,7 +822,13 @@ function toNode(loader, filterByPath) {
|
|
|
770
822
|
|
|
771
823
|
// src/node/loader.ts
|
|
772
824
|
var load2 = toNode(
|
|
773
|
-
createMdxLoader(
|
|
825
|
+
createMdxLoader(
|
|
826
|
+
staticConfig({
|
|
827
|
+
configPath: findConfigFile(),
|
|
828
|
+
outDir: ".source",
|
|
829
|
+
buildConfig: true
|
|
830
|
+
})
|
|
831
|
+
),
|
|
774
832
|
(filePath) => filePath.endsWith(".md") || filePath.endsWith(".mdx")
|
|
775
833
|
);
|
|
776
834
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/node/loader.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
toNode
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-XV5Z4BFL.js";
|
|
4
4
|
import {
|
|
5
5
|
createMdxLoader
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-IQAEAI4P.js";
|
|
6
|
+
} from "../chunk-CEA6MYJU.js";
|
|
7
|
+
import "../chunk-3J3WL7WN.js";
|
|
8
|
+
import "../chunk-K5ZLPEIQ.js";
|
|
10
9
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "../chunk-
|
|
10
|
+
findConfigFile,
|
|
11
|
+
staticConfig
|
|
12
|
+
} from "../chunk-HI62EXSB.js";
|
|
14
13
|
import "../chunk-VWJKRQZR.js";
|
|
15
14
|
|
|
16
15
|
// src/node/loader.ts
|
|
17
16
|
var load = toNode(
|
|
18
|
-
createMdxLoader(
|
|
17
|
+
createMdxLoader(
|
|
18
|
+
staticConfig({
|
|
19
|
+
configPath: findConfigFile(),
|
|
20
|
+
outDir: ".source",
|
|
21
|
+
buildConfig: true
|
|
22
|
+
})
|
|
23
|
+
),
|
|
19
24
|
(filePath) => filePath.endsWith(".md") || filePath.endsWith(".mdx")
|
|
20
25
|
);
|
|
21
26
|
export {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/plugins/index.ts
|
|
31
|
+
var plugins_exports = {};
|
|
32
|
+
__export(plugins_exports, {
|
|
33
|
+
createPluginHandler: () => createPluginHandler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(plugins_exports);
|
|
36
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
37
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
38
|
+
function createPluginHandler(context, defaultPlugins = []) {
|
|
39
|
+
const plugins = [];
|
|
40
|
+
async function write(entry) {
|
|
41
|
+
const file = import_node_path.default.join(context.outDir, entry.path);
|
|
42
|
+
await import_promises.default.mkdir(import_node_path.default.dirname(file), { recursive: true });
|
|
43
|
+
await import_promises.default.writeFile(file, entry.content);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
async init(config) {
|
|
47
|
+
if (config.global.plugins) {
|
|
48
|
+
defaultPlugins.push(...config.global.plugins);
|
|
49
|
+
}
|
|
50
|
+
for await (const option of defaultPlugins) {
|
|
51
|
+
if (!option) continue;
|
|
52
|
+
if (Array.isArray(option)) plugins.push(...option);
|
|
53
|
+
else plugins.push(option);
|
|
54
|
+
}
|
|
55
|
+
for (const plugin of plugins) {
|
|
56
|
+
const out = await plugin.config?.call(context, config);
|
|
57
|
+
if (out) config = out;
|
|
58
|
+
}
|
|
59
|
+
return config;
|
|
60
|
+
},
|
|
61
|
+
async emit() {
|
|
62
|
+
const out = await Promise.all(
|
|
63
|
+
plugins.map((plugin) => {
|
|
64
|
+
return plugin.emit?.call(context) ?? [];
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
return out.flat();
|
|
68
|
+
},
|
|
69
|
+
async emitAndWrite() {
|
|
70
|
+
const entries = await this.emit();
|
|
71
|
+
await Promise.all(entries.map(write));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
createPluginHandler
|
|
78
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { E as EmitEntry, P as Plugin, h as PluginContext, i as PluginOption, j as createPluginHandler } from '../define-BCNh3n4O.cjs';
|
|
2
|
+
import '@standard-schema/spec';
|
|
3
|
+
import 'fumadocs-core/mdx-plugins';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import 'unified';
|
|
6
|
+
import 'zod';
|
|
7
|
+
import '../remark-postprocess-K233ZVBK.cjs';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { E as EmitEntry, P as Plugin, h as PluginContext, i as PluginOption, j as createPluginHandler } from '../define-bck_EB4t.js';
|
|
2
|
+
import '@standard-schema/spec';
|
|
3
|
+
import 'fumadocs-core/mdx-plugins';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import 'unified';
|
|
6
|
+
import 'zod';
|
|
7
|
+
import '../remark-postprocess-K233ZVBK.js';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/plugins/json-schema.ts
|
|
21
|
+
var json_schema_exports = {};
|
|
22
|
+
__export(json_schema_exports, {
|
|
23
|
+
default: () => jsonSchema
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(json_schema_exports);
|
|
26
|
+
var import_zod = require("zod");
|
|
27
|
+
function jsonSchema() {
|
|
28
|
+
let config;
|
|
29
|
+
return {
|
|
30
|
+
config(v) {
|
|
31
|
+
config = v;
|
|
32
|
+
},
|
|
33
|
+
emit() {
|
|
34
|
+
const files = [];
|
|
35
|
+
function onSchema(name, schema) {
|
|
36
|
+
files.push({
|
|
37
|
+
path: `json-schema/${name}.json`,
|
|
38
|
+
content: JSON.stringify(
|
|
39
|
+
import_zod.z.toJSONSchema(schema, {
|
|
40
|
+
io: "input",
|
|
41
|
+
unrepresentable: "any"
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
for (const [name, collection] of config.collections) {
|
|
47
|
+
if (collection.type === "docs") {
|
|
48
|
+
if (collection.meta.schema instanceof import_zod.z.ZodType) {
|
|
49
|
+
onSchema(`${name}.meta`, collection.meta.schema);
|
|
50
|
+
}
|
|
51
|
+
if (collection.docs.schema instanceof import_zod.z.ZodType) {
|
|
52
|
+
onSchema(`${name}.docs`, collection.docs.schema);
|
|
53
|
+
}
|
|
54
|
+
} else if (collection.schema instanceof import_zod.z.ZodType) {
|
|
55
|
+
onSchema(name, collection.schema);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return files;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { P as Plugin } from '../define-BCNh3n4O.cjs';
|
|
2
|
+
import '@standard-schema/spec';
|
|
3
|
+
import 'fumadocs-core/mdx-plugins';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import 'unified';
|
|
6
|
+
import 'zod';
|
|
7
|
+
import '../remark-postprocess-K233ZVBK.cjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generate JSON schemas locally for collection schemas
|
|
11
|
+
*
|
|
12
|
+
* note: **it only works with Zod**
|
|
13
|
+
*/
|
|
14
|
+
declare function jsonSchema(): Plugin;
|
|
15
|
+
|
|
16
|
+
export { jsonSchema as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { P as Plugin } from '../define-bck_EB4t.js';
|
|
2
|
+
import '@standard-schema/spec';
|
|
3
|
+
import 'fumadocs-core/mdx-plugins';
|
|
4
|
+
import '@mdx-js/mdx';
|
|
5
|
+
import 'unified';
|
|
6
|
+
import 'zod';
|
|
7
|
+
import '../remark-postprocess-K233ZVBK.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Generate JSON schemas locally for collection schemas
|
|
11
|
+
*
|
|
12
|
+
* note: **it only works with Zod**
|
|
13
|
+
*/
|
|
14
|
+
declare function jsonSchema(): Plugin;
|
|
15
|
+
|
|
16
|
+
export { jsonSchema as default };
|