fumadocs-mdx 12.0.3 → 13.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 +1116 -359
- package/dist/bin.js +4 -4
- package/dist/build-mdx-CCNr86q6.d.ts +53 -0
- package/dist/build-mdx-D-r3_eQL.d.cts +53 -0
- package/dist/bun/index.cjs +196 -52
- package/dist/bun/index.d.cts +8 -3
- package/dist/bun/index.d.ts +8 -3
- package/dist/bun/index.js +19 -10
- package/dist/{chunk-QAUWMR5D.js → chunk-3J3WL7WN.js} +23 -5
- package/dist/{chunk-6Y5JDZHD.js → chunk-CXA4JO4Z.js} +1 -21
- package/dist/chunk-EELYB2XC.js +207 -0
- 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-RMDXSZYE.js → chunk-XQ5O7IPO.js} +31 -24
- package/dist/chunk-XZY2AWJI.js +81 -0
- package/dist/{chunk-VXEBLM4X.js → chunk-YVCR6FUH.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 → core-B6j6Fxse.d.cts} +89 -2
- package/dist/{define-DJbJduHy.d.cts → core-B6j6Fxse.d.ts} +89 -2
- package/dist/index.cjs +0 -109
- package/dist/index.d.cts +75 -9
- package/dist/index.d.ts +75 -9
- package/dist/index.js +0 -11
- package/dist/{load-UUXLUBHL.js → load-MNG3CLET.js} +1 -3
- package/dist/next/index.cjs +298 -234
- package/dist/next/index.d.cts +2 -11
- package/dist/next/index.d.ts +2 -11
- package/dist/next/index.js +177 -141
- package/dist/node/loader.cjs +228 -85
- package/dist/node/loader.js +19 -9
- package/dist/plugins/json-schema.cjs +162 -0
- package/dist/plugins/json-schema.d.cts +24 -0
- package/dist/plugins/json-schema.d.ts +24 -0
- package/dist/plugins/json-schema.js +78 -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 +8 -18
- 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-AGzTfBmf.d.ts} +3 -10
- package/dist/{types-BRx1QsIJ.d.cts → types-DKGMoay5.d.cts} +3 -10
- package/dist/vite/index.cjs +443 -249
- package/dist/vite/index.d.cts +23 -10
- package/dist/vite/index.d.ts +23 -10
- package/dist/vite/index.js +213 -36
- package/dist/{loader-mdx.cjs → webpack/index.cjs} +268 -82
- package/dist/{loader-mdx.d.ts → webpack/index.d.cts} +1 -0
- package/dist/{loader-mdx.d.cts → webpack/index.d.ts} +1 -0
- package/dist/webpack/index.js +44 -0
- package/loader-mdx.cjs +1 -1
- package/package.json +30 -16
- 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-IQAEAI4P.js +0 -66
- package/dist/chunk-XMFLD5J6.js +0 -30
- package/dist/chunk-ZLCSVXCD.js +0 -10
- package/dist/chunk-ZX7TM4AR.js +0 -127
- package/dist/loader-mdx.js +0 -25
- 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/watcher-HGOH3APP.js +0 -22
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,29 @@ 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
|
+
core: core2,
|
|
234
|
+
buildConfig: buildConfig2
|
|
235
|
+
}) {
|
|
236
|
+
let cached;
|
|
237
|
+
async function newConfig() {
|
|
238
|
+
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_load(), load_exports));
|
|
239
|
+
await core2.init({
|
|
240
|
+
config: loadConfig2(
|
|
241
|
+
core2._options.configPath,
|
|
242
|
+
core2._options.outDir,
|
|
243
|
+
buildConfig2
|
|
244
|
+
)
|
|
245
|
+
});
|
|
246
|
+
return core2.getConfig();
|
|
247
|
+
}
|
|
248
248
|
return {
|
|
249
|
-
async getConfig(
|
|
250
|
-
|
|
251
|
-
return loadConfig2(
|
|
252
|
-
configPath,
|
|
253
|
-
outDir,
|
|
254
|
-
hash ?? await getConfigHash2(configPath)
|
|
255
|
-
);
|
|
249
|
+
async getConfig() {
|
|
250
|
+
return cached ??= newConfig();
|
|
256
251
|
}
|
|
257
252
|
};
|
|
258
253
|
}
|
|
@@ -314,9 +309,9 @@ async function validate(schema, data, context, errorMessage) {
|
|
|
314
309
|
// src/utils/git-timestamp.ts
|
|
315
310
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
316
311
|
var import_tinyexec = require("tinyexec");
|
|
317
|
-
var
|
|
312
|
+
var cache = /* @__PURE__ */ new Map();
|
|
318
313
|
async function getGitTimestamp(file) {
|
|
319
|
-
const cached =
|
|
314
|
+
const cached = cache.get(file);
|
|
320
315
|
if (cached) return cached;
|
|
321
316
|
try {
|
|
322
317
|
const out = await (0, import_tinyexec.x)(
|
|
@@ -327,7 +322,7 @@ async function getGitTimestamp(file) {
|
|
|
327
322
|
}
|
|
328
323
|
);
|
|
329
324
|
const time = new Date(out.stdout);
|
|
330
|
-
|
|
325
|
+
cache.set(file, time);
|
|
331
326
|
return time;
|
|
332
327
|
} catch {
|
|
333
328
|
return;
|
|
@@ -339,12 +334,56 @@ var import_mdx = require("@mdx-js/mdx");
|
|
|
339
334
|
|
|
340
335
|
// src/loaders/mdx/remark-include.ts
|
|
341
336
|
var import_unified = require("unified");
|
|
342
|
-
var
|
|
337
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
343
338
|
var path4 = __toESM(require("path"), 1);
|
|
344
339
|
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
340
|
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
341
|
+
|
|
342
|
+
// src/loaders/mdx/remark-unravel.ts
|
|
343
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
344
|
+
function remarkMarkAndUnravel() {
|
|
345
|
+
return (tree) => {
|
|
346
|
+
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
347
|
+
let offset = -1;
|
|
348
|
+
let all = true;
|
|
349
|
+
let oneOrMore = false;
|
|
350
|
+
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
351
|
+
const children = node.children;
|
|
352
|
+
while (++offset < children.length) {
|
|
353
|
+
const child = children[offset];
|
|
354
|
+
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
355
|
+
oneOrMore = true;
|
|
356
|
+
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
357
|
+
} else {
|
|
358
|
+
all = false;
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (all && oneOrMore) {
|
|
363
|
+
offset = -1;
|
|
364
|
+
const newChildren = [];
|
|
365
|
+
while (++offset < children.length) {
|
|
366
|
+
const child = children[offset];
|
|
367
|
+
if (child.type === "mdxJsxTextElement") {
|
|
368
|
+
child.type = "mdxJsxFlowElement";
|
|
369
|
+
}
|
|
370
|
+
if (child.type === "mdxTextExpression") {
|
|
371
|
+
child.type = "mdxFlowExpression";
|
|
372
|
+
}
|
|
373
|
+
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
374
|
+
} else {
|
|
375
|
+
newChildren.push(child);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
parent.children.splice(index, 1, ...newChildren);
|
|
379
|
+
return index;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/loaders/mdx/remark-include.ts
|
|
348
387
|
var ElementLikeTypes = [
|
|
349
388
|
"mdxJsxFlowElement",
|
|
350
389
|
"mdxJsxTextElement",
|
|
@@ -384,7 +423,7 @@ function parseSpecifier(specifier) {
|
|
|
384
423
|
function extractSection(root, section) {
|
|
385
424
|
let nodes;
|
|
386
425
|
let capturingHeadingContent = false;
|
|
387
|
-
(0,
|
|
426
|
+
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
388
427
|
if (node.type === "heading") {
|
|
389
428
|
if (capturingHeadingContent) {
|
|
390
429
|
return false;
|
|
@@ -416,7 +455,7 @@ function extractSection(root, section) {
|
|
|
416
455
|
}
|
|
417
456
|
function remarkInclude() {
|
|
418
457
|
const TagName = "include";
|
|
419
|
-
async
|
|
458
|
+
const embedContent = async (file, heading, params, data) => {
|
|
420
459
|
let content;
|
|
421
460
|
try {
|
|
422
461
|
content = (await fs2.readFile(file)).toString();
|
|
@@ -439,18 +478,17 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
439
478
|
data: {}
|
|
440
479
|
};
|
|
441
480
|
}
|
|
442
|
-
const parser =
|
|
443
|
-
ext === ".mdx" ? "mdx" : "md"
|
|
444
|
-
);
|
|
481
|
+
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
445
482
|
const parsed = fumaMatter(content);
|
|
446
483
|
let mdast = parser.parse({
|
|
447
484
|
path: file,
|
|
448
485
|
value: parsed.content,
|
|
449
486
|
data: { frontmatter: parsed.data }
|
|
450
487
|
});
|
|
488
|
+
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
451
489
|
if (heading) {
|
|
452
490
|
const extracted = extractSection(
|
|
453
|
-
await
|
|
491
|
+
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
454
492
|
heading
|
|
455
493
|
);
|
|
456
494
|
if (!extracted)
|
|
@@ -458,13 +496,15 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
458
496
|
`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
497
|
);
|
|
460
498
|
mdast = extracted;
|
|
499
|
+
} else {
|
|
500
|
+
mdast = await baseProcessor.run(mdast);
|
|
461
501
|
}
|
|
462
502
|
await update(mdast, path4.dirname(file), data);
|
|
463
503
|
return mdast;
|
|
464
|
-
}
|
|
504
|
+
};
|
|
465
505
|
async function update(tree, directory, data) {
|
|
466
506
|
const queue = [];
|
|
467
|
-
(0,
|
|
507
|
+
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
468
508
|
const node = _node;
|
|
469
509
|
if (node.name !== TagName) return;
|
|
470
510
|
const specifier = flattenNode(node);
|
|
@@ -491,24 +531,28 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
491
531
|
await update(tree, path4.dirname(file.path), file.data);
|
|
492
532
|
};
|
|
493
533
|
}
|
|
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
534
|
|
|
500
535
|
// src/loaders/mdx/remark-postprocess.ts
|
|
501
|
-
var
|
|
536
|
+
var import_unist_util_visit3 = require("unist-util-visit");
|
|
502
537
|
var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
503
538
|
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
539
|
+
var import_unist_util_remove_position = require("unist-util-remove-position");
|
|
540
|
+
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
504
541
|
function remarkPostprocess({
|
|
542
|
+
_format,
|
|
505
543
|
includeProcessedMarkdown = false,
|
|
544
|
+
includeMDAST = false,
|
|
506
545
|
valueToExport = []
|
|
507
|
-
}
|
|
546
|
+
}) {
|
|
547
|
+
let _stringifyProcessor;
|
|
548
|
+
const getStringifyProcessor = () => {
|
|
549
|
+
if (_format === "mdx") return this;
|
|
550
|
+
return _stringifyProcessor ??= this().use(import_remark_mdx.default).freeze();
|
|
551
|
+
};
|
|
508
552
|
return (tree, file) => {
|
|
509
553
|
let title;
|
|
510
554
|
const urls = [];
|
|
511
|
-
(0,
|
|
555
|
+
(0, import_unist_util_visit3.visit)(tree, ["heading", "link"], (node) => {
|
|
512
556
|
if (node.type === "heading" && node.depth === 1) {
|
|
513
557
|
title = flattenNode2(node);
|
|
514
558
|
}
|
|
@@ -524,12 +568,19 @@ function remarkPostprocess({
|
|
|
524
568
|
}
|
|
525
569
|
file.data.extractedReferences = urls;
|
|
526
570
|
if (includeProcessedMarkdown) {
|
|
571
|
+
const processor = getStringifyProcessor();
|
|
527
572
|
file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
528
|
-
...
|
|
573
|
+
...processor.data("settings"),
|
|
529
574
|
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
530
|
-
extensions:
|
|
575
|
+
extensions: processor.data("toMarkdownExtensions") || []
|
|
531
576
|
});
|
|
532
577
|
}
|
|
578
|
+
if (includeMDAST) {
|
|
579
|
+
const options = includeMDAST === true ? {} : includeMDAST;
|
|
580
|
+
file.data._mdast = JSON.stringify(
|
|
581
|
+
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
582
|
+
);
|
|
583
|
+
}
|
|
533
584
|
for (const { name, value } of file.data["mdx-export"] ?? []) {
|
|
534
585
|
tree.children.unshift(getMdastExport(name, value));
|
|
535
586
|
}
|
|
@@ -581,12 +632,12 @@ function flattenNode2(node) {
|
|
|
581
632
|
}
|
|
582
633
|
|
|
583
634
|
// src/loaders/mdx/build-mdx.ts
|
|
584
|
-
var
|
|
635
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
585
636
|
async function buildMDX(cacheKey, source, options) {
|
|
586
637
|
const { filePath, frontmatter, data, _compiler, ...rest } = options;
|
|
587
638
|
function getProcessor(format) {
|
|
588
639
|
const key = `${cacheKey}:${format}`;
|
|
589
|
-
let processor =
|
|
640
|
+
let processor = cache2.get(key);
|
|
590
641
|
if (!processor) {
|
|
591
642
|
processor = (0, import_mdx.createProcessor)({
|
|
592
643
|
outputFormat: "program",
|
|
@@ -597,6 +648,7 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
597
648
|
[
|
|
598
649
|
remarkPostprocess,
|
|
599
650
|
{
|
|
651
|
+
_format: format,
|
|
600
652
|
...options.postprocess,
|
|
601
653
|
valueToExport: [
|
|
602
654
|
...options.postprocess?.valueToExport ?? [],
|
|
@@ -604,14 +656,15 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
604
656
|
"extractedReferences",
|
|
605
657
|
"frontmatter",
|
|
606
658
|
"lastModified",
|
|
607
|
-
"_markdown"
|
|
659
|
+
"_markdown",
|
|
660
|
+
"_mdast"
|
|
608
661
|
]
|
|
609
662
|
}
|
|
610
663
|
]
|
|
611
664
|
],
|
|
612
665
|
format
|
|
613
666
|
});
|
|
614
|
-
|
|
667
|
+
cache2.set(key, processor);
|
|
615
668
|
}
|
|
616
669
|
return processor;
|
|
617
670
|
}
|
|
@@ -631,15 +684,12 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
631
684
|
|
|
632
685
|
// src/loaders/mdx/index.ts
|
|
633
686
|
var import_zod = require("zod");
|
|
634
|
-
var
|
|
687
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
635
688
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
636
689
|
var import_node_crypto = require("crypto");
|
|
637
690
|
var querySchema = import_zod.z.object({
|
|
638
691
|
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()
|
|
692
|
+
collection: import_zod.z.string().optional()
|
|
643
693
|
}).loose();
|
|
644
694
|
var cacheEntry = import_zod.z.object({
|
|
645
695
|
code: import_zod.z.string(),
|
|
@@ -656,14 +706,25 @@ function createMdxLoader(configLoader) {
|
|
|
656
706
|
}) => {
|
|
657
707
|
const matter = fumaMatter(value);
|
|
658
708
|
const parsed = querySchema.parse(query);
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
const
|
|
709
|
+
const config = await configLoader.getConfig();
|
|
710
|
+
let after;
|
|
711
|
+
if (!isDevelopment && config.global.experimentalBuildCache) {
|
|
712
|
+
const cacheDir = config.global.experimentalBuildCache;
|
|
713
|
+
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
714
|
+
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
715
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
716
|
+
after = async () => {
|
|
717
|
+
await import_promises2.default.mkdir(cacheDir, { recursive: true });
|
|
718
|
+
await import_promises2.default.writeFile(
|
|
719
|
+
import_node_path3.default.join(cacheDir, cacheKey),
|
|
720
|
+
JSON.stringify({
|
|
721
|
+
...out,
|
|
722
|
+
hash: generateCacheHash(value)
|
|
723
|
+
})
|
|
724
|
+
);
|
|
725
|
+
};
|
|
665
726
|
}
|
|
666
|
-
const collection = parsed.collection ?
|
|
727
|
+
const collection = parsed.collection ? config.collections.get(parsed.collection) : void 0;
|
|
667
728
|
let docCollection;
|
|
668
729
|
switch (collection?.type) {
|
|
669
730
|
case "doc":
|
|
@@ -691,16 +752,16 @@ function createMdxLoader(configLoader) {
|
|
|
691
752
|
};
|
|
692
753
|
}
|
|
693
754
|
const data = {};
|
|
694
|
-
if (
|
|
755
|
+
if (config.global.lastModifiedTime === "git") {
|
|
695
756
|
data.lastModified = (await getGitTimestamp(filePath))?.getTime();
|
|
696
757
|
}
|
|
697
758
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
698
759
|
const compiled = await buildMDX(
|
|
699
|
-
`${
|
|
760
|
+
`${getConfigHash(config)}:${parsed.collection ?? "global"}`,
|
|
700
761
|
"\n".repeat(lineOffset) + matter.content,
|
|
701
762
|
{
|
|
702
763
|
development: isDevelopment,
|
|
703
|
-
...docCollection?.mdxOptions ?? await
|
|
764
|
+
...docCollection?.mdxOptions ?? await config.getDefaultMDXOptions(),
|
|
704
765
|
postprocess: docCollection?.postprocess,
|
|
705
766
|
data,
|
|
706
767
|
filePath,
|
|
@@ -712,19 +773,18 @@ function createMdxLoader(configLoader) {
|
|
|
712
773
|
code: String(compiled.value),
|
|
713
774
|
map: compiled.map
|
|
714
775
|
};
|
|
715
|
-
|
|
716
|
-
await import_promises.default.mkdir(cacheDir, { recursive: true });
|
|
717
|
-
await import_promises.default.writeFile(
|
|
718
|
-
import_node_path3.default.join(cacheDir, cacheKey),
|
|
719
|
-
JSON.stringify({
|
|
720
|
-
...out,
|
|
721
|
-
hash: generateCacheHash(value)
|
|
722
|
-
})
|
|
723
|
-
);
|
|
724
|
-
}
|
|
776
|
+
await after?.();
|
|
725
777
|
return out;
|
|
726
778
|
};
|
|
727
779
|
}
|
|
780
|
+
var hashes = /* @__PURE__ */ new WeakMap();
|
|
781
|
+
function getConfigHash(config) {
|
|
782
|
+
let hash = hashes.get(config);
|
|
783
|
+
if (hash) return hash;
|
|
784
|
+
hash = Date.now().toString();
|
|
785
|
+
hashes.set(config, hash);
|
|
786
|
+
return hash;
|
|
787
|
+
}
|
|
728
788
|
function generateCacheHash(input) {
|
|
729
789
|
return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
|
|
730
790
|
}
|
|
@@ -738,7 +798,7 @@ function countLines(s) {
|
|
|
738
798
|
|
|
739
799
|
// src/loaders/adapter.ts
|
|
740
800
|
var import_node_url2 = require("url");
|
|
741
|
-
var
|
|
801
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
742
802
|
var import_node_querystring = require("querystring");
|
|
743
803
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
744
804
|
function toNode(loader, filterByPath) {
|
|
@@ -747,7 +807,7 @@ function toNode(loader, filterByPath) {
|
|
|
747
807
|
const parsedUrl = new URL(url);
|
|
748
808
|
const filePath = (0, import_node_url2.fileURLToPath)(parsedUrl);
|
|
749
809
|
if (filterByPath(filePath)) {
|
|
750
|
-
const source = (await
|
|
810
|
+
const source = (await import_promises3.default.readFile(filePath)).toString();
|
|
751
811
|
const result = await loader({
|
|
752
812
|
filePath,
|
|
753
813
|
query: Object.fromEntries(parsedUrl.searchParams.entries()),
|
|
@@ -768,9 +828,92 @@ function toNode(loader, filterByPath) {
|
|
|
768
828
|
};
|
|
769
829
|
}
|
|
770
830
|
|
|
831
|
+
// src/core.ts
|
|
832
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
833
|
+
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
834
|
+
function createCore(options, defaultPlugins = []) {
|
|
835
|
+
let config;
|
|
836
|
+
let plugins2;
|
|
837
|
+
return {
|
|
838
|
+
_options: options,
|
|
839
|
+
getPluginContext() {
|
|
840
|
+
return {
|
|
841
|
+
core: this,
|
|
842
|
+
...options
|
|
843
|
+
};
|
|
844
|
+
},
|
|
845
|
+
/**
|
|
846
|
+
* Convenient cache store, reset when config changes
|
|
847
|
+
*/
|
|
848
|
+
cache: /* @__PURE__ */ new Map(),
|
|
849
|
+
async init({ config: newConfig }) {
|
|
850
|
+
config = await newConfig;
|
|
851
|
+
this.cache.clear();
|
|
852
|
+
plugins2 = [];
|
|
853
|
+
for await (const option of [
|
|
854
|
+
...defaultPlugins,
|
|
855
|
+
...config.global.plugins ?? []
|
|
856
|
+
]) {
|
|
857
|
+
if (!option) continue;
|
|
858
|
+
if (Array.isArray(option)) plugins2.push(...option);
|
|
859
|
+
else plugins2.push(option);
|
|
860
|
+
}
|
|
861
|
+
for (const plugin of plugins2) {
|
|
862
|
+
const out = await plugin.config?.call(this.getPluginContext(), config);
|
|
863
|
+
if (out) config = out;
|
|
864
|
+
}
|
|
865
|
+
return this;
|
|
866
|
+
},
|
|
867
|
+
getConfig() {
|
|
868
|
+
return config;
|
|
869
|
+
},
|
|
870
|
+
creatConfigLoader() {
|
|
871
|
+
return {
|
|
872
|
+
getConfig() {
|
|
873
|
+
return config;
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
},
|
|
877
|
+
async initServer(server) {
|
|
878
|
+
for (const plugin of plugins2) {
|
|
879
|
+
await plugin.configureServer?.call(this.getPluginContext(), server);
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
async emitAndWrite({
|
|
883
|
+
filterPlugin = () => true
|
|
884
|
+
} = {}) {
|
|
885
|
+
const start = performance.now();
|
|
886
|
+
const out = await Promise.all(
|
|
887
|
+
plugins2.map((plugin) => {
|
|
888
|
+
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
889
|
+
return plugin.emit.call(this.getPluginContext());
|
|
890
|
+
})
|
|
891
|
+
);
|
|
892
|
+
await Promise.all(
|
|
893
|
+
out.flat().map(async (entry) => {
|
|
894
|
+
const file = import_node_path5.default.join(options.outDir, entry.path);
|
|
895
|
+
await import_promises4.default.mkdir(import_node_path5.default.dirname(file), { recursive: true });
|
|
896
|
+
await import_promises4.default.writeFile(file, entry.content);
|
|
897
|
+
})
|
|
898
|
+
);
|
|
899
|
+
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
|
|
771
904
|
// src/node/loader.ts
|
|
905
|
+
var core = createCore({
|
|
906
|
+
environment: "node",
|
|
907
|
+
configPath: findConfigFile(),
|
|
908
|
+
outDir: ".source"
|
|
909
|
+
});
|
|
772
910
|
var load2 = toNode(
|
|
773
|
-
createMdxLoader(
|
|
911
|
+
createMdxLoader(
|
|
912
|
+
staticConfig({
|
|
913
|
+
core,
|
|
914
|
+
buildConfig: true
|
|
915
|
+
})
|
|
916
|
+
),
|
|
774
917
|
(filePath) => filePath.endsWith(".md") || filePath.endsWith(".mdx")
|
|
775
918
|
);
|
|
776
919
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/node/loader.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
toNode
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-YVCR6FUH.js";
|
|
4
4
|
import {
|
|
5
5
|
createMdxLoader
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-IQAEAI4P.js";
|
|
6
|
+
} from "../chunk-XQ5O7IPO.js";
|
|
7
|
+
import "../chunk-3J3WL7WN.js";
|
|
8
|
+
import "../chunk-K5ZLPEIQ.js";
|
|
10
9
|
import {
|
|
11
|
-
|
|
12
|
-
findConfigFile
|
|
13
|
-
|
|
10
|
+
createCore,
|
|
11
|
+
findConfigFile,
|
|
12
|
+
staticConfig
|
|
13
|
+
} from "../chunk-EELYB2XC.js";
|
|
14
14
|
import "../chunk-VWJKRQZR.js";
|
|
15
15
|
|
|
16
16
|
// src/node/loader.ts
|
|
17
|
+
var core = createCore({
|
|
18
|
+
environment: "node",
|
|
19
|
+
configPath: findConfigFile(),
|
|
20
|
+
outDir: ".source"
|
|
21
|
+
});
|
|
17
22
|
var load = toNode(
|
|
18
|
-
createMdxLoader(
|
|
23
|
+
createMdxLoader(
|
|
24
|
+
staticConfig({
|
|
25
|
+
core,
|
|
26
|
+
buildConfig: true
|
|
27
|
+
})
|
|
28
|
+
),
|
|
19
29
|
(filePath) => filePath.endsWith(".md") || filePath.endsWith(".mdx")
|
|
20
30
|
);
|
|
21
31
|
export {
|