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/bin.js
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
// src/bin.ts
|
|
4
4
|
import { existsSync } from "fs";
|
|
5
5
|
async function start() {
|
|
6
|
-
const
|
|
6
|
+
const [configPath] = process.argv.slice(2);
|
|
7
7
|
const isNext = existsSync("next.config.js") || existsSync("next.config.mjs") || existsSync("next.config.ts");
|
|
8
8
|
if (isNext) {
|
|
9
9
|
const { postInstall } = await import("./next/index.js");
|
|
10
|
-
await postInstall(
|
|
10
|
+
await postInstall(configPath);
|
|
11
11
|
} else {
|
|
12
|
-
const { postInstall } = await import("./
|
|
13
|
-
await postInstall(
|
|
12
|
+
const { postInstall } = await import("./vite/index.js");
|
|
13
|
+
await postInstall(configPath);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
void start();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createProcessor } from '@mdx-js/mdx';
|
|
2
|
+
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
3
|
+
import { TOCItemType } from 'fumadocs-core/toc';
|
|
4
|
+
import { FC } from 'react';
|
|
5
|
+
import { MDXProps } from 'mdx/types';
|
|
6
|
+
import { E as ExtractedReference } from './core-B6j6Fxse.js';
|
|
7
|
+
|
|
8
|
+
type Processor = ReturnType<typeof createProcessor>;
|
|
9
|
+
interface CompilerOptions {
|
|
10
|
+
addDependency: (file: string) => void;
|
|
11
|
+
}
|
|
12
|
+
interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
|
|
13
|
+
frontmatter: Frontmatter;
|
|
14
|
+
structuredData: StructuredData;
|
|
15
|
+
toc: TOCItemType[];
|
|
16
|
+
default: FC<MDXProps>;
|
|
17
|
+
/**
|
|
18
|
+
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
19
|
+
*/
|
|
20
|
+
lastModified?: Date;
|
|
21
|
+
extractedReferences?: ExtractedReference[];
|
|
22
|
+
_markdown?: string;
|
|
23
|
+
_mdast?: string;
|
|
24
|
+
}
|
|
25
|
+
interface FumadocsDataMap {
|
|
26
|
+
/**
|
|
27
|
+
* [Fumadocs MDX] raw frontmatter, you can modify it
|
|
28
|
+
*/
|
|
29
|
+
frontmatter?: Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* [Fumadocs MDX] additional ESM exports to write
|
|
32
|
+
*/
|
|
33
|
+
'mdx-export'?: {
|
|
34
|
+
name: string;
|
|
35
|
+
value: unknown;
|
|
36
|
+
}[];
|
|
37
|
+
extractedReferences: ExtractedReference[];
|
|
38
|
+
/**
|
|
39
|
+
* [Fumadocs MDX] The compiler object from loader
|
|
40
|
+
*/
|
|
41
|
+
_compiler?: CompilerOptions;
|
|
42
|
+
_getProcessor?: (format: 'md' | 'mdx') => Processor;
|
|
43
|
+
/**
|
|
44
|
+
* [Fumadocs MDX] Processed Markdown content before `remark-rehype`.
|
|
45
|
+
*/
|
|
46
|
+
_markdown?: string;
|
|
47
|
+
}
|
|
48
|
+
declare module 'vfile' {
|
|
49
|
+
interface DataMap extends FumadocsDataMap {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { CompiledMDXProperties as C };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createProcessor } from '@mdx-js/mdx';
|
|
2
|
+
import { StructuredData } from 'fumadocs-core/mdx-plugins';
|
|
3
|
+
import { TOCItemType } from 'fumadocs-core/toc';
|
|
4
|
+
import { FC } from 'react';
|
|
5
|
+
import { MDXProps } from 'mdx/types';
|
|
6
|
+
import { E as ExtractedReference } from './core-B6j6Fxse.cjs';
|
|
7
|
+
|
|
8
|
+
type Processor = ReturnType<typeof createProcessor>;
|
|
9
|
+
interface CompilerOptions {
|
|
10
|
+
addDependency: (file: string) => void;
|
|
11
|
+
}
|
|
12
|
+
interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
|
|
13
|
+
frontmatter: Frontmatter;
|
|
14
|
+
structuredData: StructuredData;
|
|
15
|
+
toc: TOCItemType[];
|
|
16
|
+
default: FC<MDXProps>;
|
|
17
|
+
/**
|
|
18
|
+
* Only available when `lastModifiedTime` is enabled on MDX loader
|
|
19
|
+
*/
|
|
20
|
+
lastModified?: Date;
|
|
21
|
+
extractedReferences?: ExtractedReference[];
|
|
22
|
+
_markdown?: string;
|
|
23
|
+
_mdast?: string;
|
|
24
|
+
}
|
|
25
|
+
interface FumadocsDataMap {
|
|
26
|
+
/**
|
|
27
|
+
* [Fumadocs MDX] raw frontmatter, you can modify it
|
|
28
|
+
*/
|
|
29
|
+
frontmatter?: Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* [Fumadocs MDX] additional ESM exports to write
|
|
32
|
+
*/
|
|
33
|
+
'mdx-export'?: {
|
|
34
|
+
name: string;
|
|
35
|
+
value: unknown;
|
|
36
|
+
}[];
|
|
37
|
+
extractedReferences: ExtractedReference[];
|
|
38
|
+
/**
|
|
39
|
+
* [Fumadocs MDX] The compiler object from loader
|
|
40
|
+
*/
|
|
41
|
+
_compiler?: CompilerOptions;
|
|
42
|
+
_getProcessor?: (format: 'md' | 'mdx') => Processor;
|
|
43
|
+
/**
|
|
44
|
+
* [Fumadocs MDX] Processed Markdown content before `remark-rehype`.
|
|
45
|
+
*/
|
|
46
|
+
_markdown?: string;
|
|
47
|
+
}
|
|
48
|
+
declare module 'vfile' {
|
|
49
|
+
interface DataMap extends FumadocsDataMap {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { CompiledMDXProperties as C };
|
package/dist/bun/index.cjs
CHANGED
|
@@ -261,12 +261,56 @@ var import_mdx = require("@mdx-js/mdx");
|
|
|
261
261
|
|
|
262
262
|
// src/loaders/mdx/remark-include.ts
|
|
263
263
|
var import_unified = require("unified");
|
|
264
|
-
var
|
|
264
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
265
265
|
var path2 = __toESM(require("path"), 1);
|
|
266
266
|
var fs = __toESM(require("fs/promises"), 1);
|
|
267
|
-
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
268
|
-
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
269
267
|
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
268
|
+
|
|
269
|
+
// src/loaders/mdx/remark-unravel.ts
|
|
270
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
271
|
+
function remarkMarkAndUnravel() {
|
|
272
|
+
return (tree) => {
|
|
273
|
+
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
274
|
+
let offset = -1;
|
|
275
|
+
let all = true;
|
|
276
|
+
let oneOrMore = false;
|
|
277
|
+
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
278
|
+
const children = node.children;
|
|
279
|
+
while (++offset < children.length) {
|
|
280
|
+
const child = children[offset];
|
|
281
|
+
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
282
|
+
oneOrMore = true;
|
|
283
|
+
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
284
|
+
} else {
|
|
285
|
+
all = false;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (all && oneOrMore) {
|
|
290
|
+
offset = -1;
|
|
291
|
+
const newChildren = [];
|
|
292
|
+
while (++offset < children.length) {
|
|
293
|
+
const child = children[offset];
|
|
294
|
+
if (child.type === "mdxJsxTextElement") {
|
|
295
|
+
child.type = "mdxJsxFlowElement";
|
|
296
|
+
}
|
|
297
|
+
if (child.type === "mdxTextExpression") {
|
|
298
|
+
child.type = "mdxFlowExpression";
|
|
299
|
+
}
|
|
300
|
+
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
301
|
+
} else {
|
|
302
|
+
newChildren.push(child);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
parent.children.splice(index, 1, ...newChildren);
|
|
306
|
+
return index;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/loaders/mdx/remark-include.ts
|
|
270
314
|
var ElementLikeTypes = [
|
|
271
315
|
"mdxJsxFlowElement",
|
|
272
316
|
"mdxJsxTextElement",
|
|
@@ -306,7 +350,7 @@ function parseSpecifier(specifier) {
|
|
|
306
350
|
function extractSection(root, section) {
|
|
307
351
|
let nodes;
|
|
308
352
|
let capturingHeadingContent = false;
|
|
309
|
-
(0,
|
|
353
|
+
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
310
354
|
if (node.type === "heading") {
|
|
311
355
|
if (capturingHeadingContent) {
|
|
312
356
|
return false;
|
|
@@ -338,7 +382,7 @@ function extractSection(root, section) {
|
|
|
338
382
|
}
|
|
339
383
|
function remarkInclude() {
|
|
340
384
|
const TagName = "include";
|
|
341
|
-
async
|
|
385
|
+
const embedContent = async (file, heading, params, data) => {
|
|
342
386
|
let content;
|
|
343
387
|
try {
|
|
344
388
|
content = (await fs.readFile(file)).toString();
|
|
@@ -361,18 +405,17 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
361
405
|
data: {}
|
|
362
406
|
};
|
|
363
407
|
}
|
|
364
|
-
const parser =
|
|
365
|
-
ext === ".mdx" ? "mdx" : "md"
|
|
366
|
-
);
|
|
408
|
+
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
367
409
|
const parsed = fumaMatter(content);
|
|
368
410
|
let mdast = parser.parse({
|
|
369
411
|
path: file,
|
|
370
412
|
value: parsed.content,
|
|
371
413
|
data: { frontmatter: parsed.data }
|
|
372
414
|
});
|
|
415
|
+
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
373
416
|
if (heading) {
|
|
374
417
|
const extracted = extractSection(
|
|
375
|
-
await
|
|
418
|
+
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
376
419
|
heading
|
|
377
420
|
);
|
|
378
421
|
if (!extracted)
|
|
@@ -380,13 +423,15 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
380
423
|
`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.`
|
|
381
424
|
);
|
|
382
425
|
mdast = extracted;
|
|
426
|
+
} else {
|
|
427
|
+
mdast = await baseProcessor.run(mdast);
|
|
383
428
|
}
|
|
384
429
|
await update(mdast, path2.dirname(file), data);
|
|
385
430
|
return mdast;
|
|
386
|
-
}
|
|
431
|
+
};
|
|
387
432
|
async function update(tree, directory, data) {
|
|
388
433
|
const queue = [];
|
|
389
|
-
(0,
|
|
434
|
+
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
390
435
|
const node = _node;
|
|
391
436
|
if (node.name !== TagName) return;
|
|
392
437
|
const specifier = flattenNode(node);
|
|
@@ -413,24 +458,28 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
413
458
|
await update(tree, path2.dirname(file.path), file.data);
|
|
414
459
|
};
|
|
415
460
|
}
|
|
416
|
-
function getDefaultProcessor(format) {
|
|
417
|
-
const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
|
|
418
|
-
if (format === "md") return mdProcessor;
|
|
419
|
-
return mdProcessor.use(import_remark_mdx.default);
|
|
420
|
-
}
|
|
421
461
|
|
|
422
462
|
// src/loaders/mdx/remark-postprocess.ts
|
|
423
|
-
var
|
|
463
|
+
var import_unist_util_visit3 = require("unist-util-visit");
|
|
424
464
|
var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
425
465
|
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
466
|
+
var import_unist_util_remove_position = require("unist-util-remove-position");
|
|
467
|
+
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
426
468
|
function remarkPostprocess({
|
|
469
|
+
_format,
|
|
427
470
|
includeProcessedMarkdown = false,
|
|
471
|
+
includeMDAST = false,
|
|
428
472
|
valueToExport = []
|
|
429
|
-
}
|
|
473
|
+
}) {
|
|
474
|
+
let _stringifyProcessor;
|
|
475
|
+
const getStringifyProcessor = () => {
|
|
476
|
+
if (_format === "mdx") return this;
|
|
477
|
+
return _stringifyProcessor ??= this().use(import_remark_mdx.default).freeze();
|
|
478
|
+
};
|
|
430
479
|
return (tree, file) => {
|
|
431
480
|
let title;
|
|
432
481
|
const urls = [];
|
|
433
|
-
(0,
|
|
482
|
+
(0, import_unist_util_visit3.visit)(tree, ["heading", "link"], (node) => {
|
|
434
483
|
if (node.type === "heading" && node.depth === 1) {
|
|
435
484
|
title = flattenNode2(node);
|
|
436
485
|
}
|
|
@@ -446,12 +495,19 @@ function remarkPostprocess({
|
|
|
446
495
|
}
|
|
447
496
|
file.data.extractedReferences = urls;
|
|
448
497
|
if (includeProcessedMarkdown) {
|
|
498
|
+
const processor = getStringifyProcessor();
|
|
449
499
|
file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
450
|
-
...
|
|
500
|
+
...processor.data("settings"),
|
|
451
501
|
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
452
|
-
extensions:
|
|
502
|
+
extensions: processor.data("toMarkdownExtensions") || []
|
|
453
503
|
});
|
|
454
504
|
}
|
|
505
|
+
if (includeMDAST) {
|
|
506
|
+
const options = includeMDAST === true ? {} : includeMDAST;
|
|
507
|
+
file.data._mdast = JSON.stringify(
|
|
508
|
+
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
509
|
+
);
|
|
510
|
+
}
|
|
455
511
|
for (const { name, value } of file.data["mdx-export"] ?? []) {
|
|
456
512
|
tree.children.unshift(getMdastExport(name, value));
|
|
457
513
|
}
|
|
@@ -519,6 +575,7 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
519
575
|
[
|
|
520
576
|
remarkPostprocess,
|
|
521
577
|
{
|
|
578
|
+
_format: format,
|
|
522
579
|
...options.postprocess,
|
|
523
580
|
valueToExport: [
|
|
524
581
|
...options.postprocess?.valueToExport ?? [],
|
|
@@ -526,7 +583,8 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
526
583
|
"extractedReferences",
|
|
527
584
|
"frontmatter",
|
|
528
585
|
"lastModified",
|
|
529
|
-
"_markdown"
|
|
586
|
+
"_markdown",
|
|
587
|
+
"_mdast"
|
|
530
588
|
]
|
|
531
589
|
}
|
|
532
590
|
]
|
|
@@ -558,10 +616,7 @@ var import_node_path2 = __toESM(require("path"), 1);
|
|
|
558
616
|
var import_node_crypto = require("crypto");
|
|
559
617
|
var querySchema = import_zod.z.object({
|
|
560
618
|
only: import_zod.z.literal(["frontmatter", "all"]).default("all"),
|
|
561
|
-
collection: import_zod.z.string().optional()
|
|
562
|
-
hash: import_zod.z.string().describe(
|
|
563
|
-
"the hash of config, used for revalidation on Turbopack/Webpack."
|
|
564
|
-
).optional()
|
|
619
|
+
collection: import_zod.z.string().optional()
|
|
565
620
|
}).loose();
|
|
566
621
|
var cacheEntry = import_zod.z.object({
|
|
567
622
|
code: import_zod.z.string(),
|
|
@@ -578,14 +633,25 @@ function createMdxLoader(configLoader) {
|
|
|
578
633
|
}) => {
|
|
579
634
|
const matter = fumaMatter(value);
|
|
580
635
|
const parsed = querySchema.parse(query);
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
636
|
+
const config = await configLoader.getConfig();
|
|
637
|
+
let after;
|
|
638
|
+
if (!isDevelopment && config.global.experimentalBuildCache) {
|
|
639
|
+
const cacheDir = config.global.experimentalBuildCache;
|
|
640
|
+
const cacheKey = `${parsed.hash}_${parsed.collection ?? "global"}_${generateCacheHash(filePath)}`;
|
|
585
641
|
const cached = await import_promises.default.readFile(import_node_path2.default.join(cacheDir, cacheKey)).then((content) => cacheEntry.parse(JSON.parse(content.toString()))).catch(() => null);
|
|
586
642
|
if (cached && cached.hash === generateCacheHash(value)) return cached;
|
|
643
|
+
after = async () => {
|
|
644
|
+
await import_promises.default.mkdir(cacheDir, { recursive: true });
|
|
645
|
+
await import_promises.default.writeFile(
|
|
646
|
+
import_node_path2.default.join(cacheDir, cacheKey),
|
|
647
|
+
JSON.stringify({
|
|
648
|
+
...out,
|
|
649
|
+
hash: generateCacheHash(value)
|
|
650
|
+
})
|
|
651
|
+
);
|
|
652
|
+
};
|
|
587
653
|
}
|
|
588
|
-
const collection = parsed.collection ?
|
|
654
|
+
const collection = parsed.collection ? config.collections.get(parsed.collection) : void 0;
|
|
589
655
|
let docCollection;
|
|
590
656
|
switch (collection?.type) {
|
|
591
657
|
case "doc":
|
|
@@ -613,16 +679,16 @@ function createMdxLoader(configLoader) {
|
|
|
613
679
|
};
|
|
614
680
|
}
|
|
615
681
|
const data = {};
|
|
616
|
-
if (
|
|
682
|
+
if (config.global.lastModifiedTime === "git") {
|
|
617
683
|
data.lastModified = (await getGitTimestamp(filePath))?.getTime();
|
|
618
684
|
}
|
|
619
685
|
const lineOffset = isDevelopment ? countLines(matter.matter) : 0;
|
|
620
686
|
const compiled = await buildMDX(
|
|
621
|
-
`${
|
|
687
|
+
`${getConfigHash(config)}:${parsed.collection ?? "global"}`,
|
|
622
688
|
"\n".repeat(lineOffset) + matter.content,
|
|
623
689
|
{
|
|
624
690
|
development: isDevelopment,
|
|
625
|
-
...docCollection?.mdxOptions ?? await
|
|
691
|
+
...docCollection?.mdxOptions ?? await config.getDefaultMDXOptions(),
|
|
626
692
|
postprocess: docCollection?.postprocess,
|
|
627
693
|
data,
|
|
628
694
|
filePath,
|
|
@@ -634,19 +700,18 @@ function createMdxLoader(configLoader) {
|
|
|
634
700
|
code: String(compiled.value),
|
|
635
701
|
map: compiled.map
|
|
636
702
|
};
|
|
637
|
-
|
|
638
|
-
await import_promises.default.mkdir(cacheDir, { recursive: true });
|
|
639
|
-
await import_promises.default.writeFile(
|
|
640
|
-
import_node_path2.default.join(cacheDir, cacheKey),
|
|
641
|
-
JSON.stringify({
|
|
642
|
-
...out,
|
|
643
|
-
hash: generateCacheHash(value)
|
|
644
|
-
})
|
|
645
|
-
);
|
|
646
|
-
}
|
|
703
|
+
await after?.();
|
|
647
704
|
return out;
|
|
648
705
|
};
|
|
649
706
|
}
|
|
707
|
+
var hashes = /* @__PURE__ */ new WeakMap();
|
|
708
|
+
function getConfigHash(config) {
|
|
709
|
+
let hash = hashes.get(config);
|
|
710
|
+
if (hash) return hash;
|
|
711
|
+
hash = Date.now().toString();
|
|
712
|
+
hashes.set(config, hash);
|
|
713
|
+
return hash;
|
|
714
|
+
}
|
|
650
715
|
function generateCacheHash(input) {
|
|
651
716
|
return (0, import_node_crypto.createHash)("md5").update(input).digest("hex");
|
|
652
717
|
}
|
|
@@ -660,27 +725,106 @@ function countLines(s) {
|
|
|
660
725
|
|
|
661
726
|
// src/loaders/config/index.ts
|
|
662
727
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
728
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
663
729
|
function findConfigFile() {
|
|
664
730
|
return import_node_path3.default.resolve("source.config.ts");
|
|
665
731
|
}
|
|
666
|
-
|
|
732
|
+
|
|
733
|
+
// src/bun/index.ts
|
|
734
|
+
init_build();
|
|
735
|
+
var import_node_querystring = require("querystring");
|
|
736
|
+
var import_node_url = require("url");
|
|
737
|
+
|
|
738
|
+
// src/core.ts
|
|
739
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
740
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
741
|
+
function createCore(options, defaultPlugins = []) {
|
|
742
|
+
let config;
|
|
743
|
+
let plugins2;
|
|
667
744
|
return {
|
|
745
|
+
_options: options,
|
|
746
|
+
getPluginContext() {
|
|
747
|
+
return {
|
|
748
|
+
core: this,
|
|
749
|
+
...options
|
|
750
|
+
};
|
|
751
|
+
},
|
|
752
|
+
/**
|
|
753
|
+
* Convenient cache store, reset when config changes
|
|
754
|
+
*/
|
|
755
|
+
cache: /* @__PURE__ */ new Map(),
|
|
756
|
+
async init({ config: newConfig }) {
|
|
757
|
+
config = await newConfig;
|
|
758
|
+
this.cache.clear();
|
|
759
|
+
plugins2 = [];
|
|
760
|
+
for await (const option of [
|
|
761
|
+
...defaultPlugins,
|
|
762
|
+
...config.global.plugins ?? []
|
|
763
|
+
]) {
|
|
764
|
+
if (!option) continue;
|
|
765
|
+
if (Array.isArray(option)) plugins2.push(...option);
|
|
766
|
+
else plugins2.push(option);
|
|
767
|
+
}
|
|
768
|
+
for (const plugin of plugins2) {
|
|
769
|
+
const out = await plugin.config?.call(this.getPluginContext(), config);
|
|
770
|
+
if (out) config = out;
|
|
771
|
+
}
|
|
772
|
+
return this;
|
|
773
|
+
},
|
|
668
774
|
getConfig() {
|
|
669
|
-
return
|
|
775
|
+
return config;
|
|
776
|
+
},
|
|
777
|
+
creatConfigLoader() {
|
|
778
|
+
return {
|
|
779
|
+
getConfig() {
|
|
780
|
+
return config;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
},
|
|
784
|
+
async initServer(server) {
|
|
785
|
+
for (const plugin of plugins2) {
|
|
786
|
+
await plugin.configureServer?.call(this.getPluginContext(), server);
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
async emitAndWrite({
|
|
790
|
+
filterPlugin = () => true
|
|
791
|
+
} = {}) {
|
|
792
|
+
const start = performance.now();
|
|
793
|
+
const out = await Promise.all(
|
|
794
|
+
plugins2.map((plugin) => {
|
|
795
|
+
if (!filterPlugin(plugin) || !plugin.emit) return [];
|
|
796
|
+
return plugin.emit.call(this.getPluginContext());
|
|
797
|
+
})
|
|
798
|
+
);
|
|
799
|
+
await Promise.all(
|
|
800
|
+
out.flat().map(async (entry) => {
|
|
801
|
+
const file = import_node_path4.default.join(options.outDir, entry.path);
|
|
802
|
+
await import_promises3.default.mkdir(import_node_path4.default.dirname(file), { recursive: true });
|
|
803
|
+
await import_promises3.default.writeFile(file, entry.content);
|
|
804
|
+
})
|
|
805
|
+
);
|
|
806
|
+
console.log(`[MDX] generated files in ${performance.now() - start}ms`);
|
|
670
807
|
}
|
|
671
808
|
};
|
|
672
809
|
}
|
|
673
810
|
|
|
674
811
|
// src/bun/index.ts
|
|
675
|
-
init_build();
|
|
676
|
-
var import_node_querystring = require("querystring");
|
|
677
|
-
var import_node_url = require("url");
|
|
678
812
|
function createMdxPlugin(options = {}) {
|
|
679
|
-
const {
|
|
813
|
+
const {
|
|
814
|
+
environment = "bun",
|
|
815
|
+
outDir = ".source",
|
|
816
|
+
configPath = findConfigFile()
|
|
817
|
+
} = options;
|
|
680
818
|
async function getMdxLoader() {
|
|
681
819
|
const importPath = (0, import_node_url.pathToFileURL)(configPath).href;
|
|
682
|
-
const
|
|
683
|
-
|
|
820
|
+
const core = await createCore({
|
|
821
|
+
environment,
|
|
822
|
+
outDir,
|
|
823
|
+
configPath
|
|
824
|
+
}).init({
|
|
825
|
+
config: buildConfig(await import(importPath))
|
|
826
|
+
});
|
|
827
|
+
return createMdxLoader(core.creatConfigLoader());
|
|
684
828
|
}
|
|
685
829
|
return {
|
|
686
830
|
name: "bun-plugin-fumadocs-mdx",
|
package/dist/bun/index.d.cts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { BunPlugin } from 'bun';
|
|
2
|
+
import { C as CoreOptions } from '../core-B6j6Fxse.cjs';
|
|
3
|
+
import '@standard-schema/spec';
|
|
4
|
+
import 'fumadocs-core/mdx-plugins';
|
|
5
|
+
import '@mdx-js/mdx';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'zod';
|
|
8
|
+
import 'chokidar';
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
configPath?: string;
|
|
5
|
-
}
|
|
10
|
+
type MdxPluginOptions = Partial<CoreOptions>;
|
|
6
11
|
declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
|
|
7
12
|
|
|
8
13
|
export { type MdxPluginOptions, createMdxPlugin };
|
package/dist/bun/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { BunPlugin } from 'bun';
|
|
2
|
+
import { C as CoreOptions } from '../core-B6j6Fxse.js';
|
|
3
|
+
import '@standard-schema/spec';
|
|
4
|
+
import 'fumadocs-core/mdx-plugins';
|
|
5
|
+
import '@mdx-js/mdx';
|
|
6
|
+
import 'unified';
|
|
7
|
+
import 'zod';
|
|
8
|
+
import 'chokidar';
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
configPath?: string;
|
|
5
|
-
}
|
|
10
|
+
type MdxPluginOptions = Partial<CoreOptions>;
|
|
6
11
|
declare function createMdxPlugin(options?: MdxPluginOptions): BunPlugin;
|
|
7
12
|
|
|
8
13
|
export { type MdxPluginOptions, createMdxPlugin };
|
package/dist/bun/index.js
CHANGED
|
@@ -3,25 +3,34 @@ import {
|
|
|
3
3
|
} from "../chunk-U4MQ44TS.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
|
-
|
|
13
|
-
} from "../chunk-
|
|
10
|
+
createCore,
|
|
11
|
+
findConfigFile
|
|
12
|
+
} from "../chunk-EELYB2XC.js";
|
|
14
13
|
import "../chunk-VWJKRQZR.js";
|
|
15
14
|
|
|
16
15
|
// src/bun/index.ts
|
|
17
16
|
import { parse } from "querystring";
|
|
18
17
|
import { pathToFileURL } from "url";
|
|
19
18
|
function createMdxPlugin(options = {}) {
|
|
20
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
environment = "bun",
|
|
21
|
+
outDir = ".source",
|
|
22
|
+
configPath = findConfigFile()
|
|
23
|
+
} = options;
|
|
21
24
|
async function getMdxLoader() {
|
|
22
25
|
const importPath = pathToFileURL(configPath).href;
|
|
23
|
-
const
|
|
24
|
-
|
|
26
|
+
const core = await createCore({
|
|
27
|
+
environment,
|
|
28
|
+
outDir,
|
|
29
|
+
configPath
|
|
30
|
+
}).init({
|
|
31
|
+
config: buildConfig(await import(importPath))
|
|
32
|
+
});
|
|
33
|
+
return createMdxLoader(core.creatConfigLoader());
|
|
25
34
|
}
|
|
26
35
|
return {
|
|
27
36
|
name: "bun-plugin-fumadocs-mdx",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
remarkInclude
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-K5ZLPEIQ.js";
|
|
4
4
|
|
|
5
5
|
// src/loaders/mdx/build-mdx.ts
|
|
6
6
|
import { createProcessor } from "@mdx-js/mdx";
|
|
@@ -9,10 +9,19 @@ import { createProcessor } from "@mdx-js/mdx";
|
|
|
9
9
|
import { visit } from "unist-util-visit";
|
|
10
10
|
import { toMarkdown } from "mdast-util-to-markdown";
|
|
11
11
|
import { valueToEstree } from "estree-util-value-to-estree";
|
|
12
|
+
import { removePosition } from "unist-util-remove-position";
|
|
13
|
+
import remarkMdx from "remark-mdx";
|
|
12
14
|
function remarkPostprocess({
|
|
15
|
+
_format,
|
|
13
16
|
includeProcessedMarkdown = false,
|
|
17
|
+
includeMDAST = false,
|
|
14
18
|
valueToExport = []
|
|
15
|
-
}
|
|
19
|
+
}) {
|
|
20
|
+
let _stringifyProcessor;
|
|
21
|
+
const getStringifyProcessor = () => {
|
|
22
|
+
if (_format === "mdx") return this;
|
|
23
|
+
return _stringifyProcessor ??= this().use(remarkMdx).freeze();
|
|
24
|
+
};
|
|
16
25
|
return (tree, file) => {
|
|
17
26
|
let title;
|
|
18
27
|
const urls = [];
|
|
@@ -32,12 +41,19 @@ function remarkPostprocess({
|
|
|
32
41
|
}
|
|
33
42
|
file.data.extractedReferences = urls;
|
|
34
43
|
if (includeProcessedMarkdown) {
|
|
44
|
+
const processor = getStringifyProcessor();
|
|
35
45
|
file.data._markdown = toMarkdown(tree, {
|
|
36
|
-
...
|
|
46
|
+
...processor.data("settings"),
|
|
37
47
|
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
38
|
-
extensions:
|
|
48
|
+
extensions: processor.data("toMarkdownExtensions") || []
|
|
39
49
|
});
|
|
40
50
|
}
|
|
51
|
+
if (includeMDAST) {
|
|
52
|
+
const options = includeMDAST === true ? {} : includeMDAST;
|
|
53
|
+
file.data._mdast = JSON.stringify(
|
|
54
|
+
options.removePosition ? removePosition(structuredClone(tree)) : tree
|
|
55
|
+
);
|
|
56
|
+
}
|
|
41
57
|
for (const { name, value } of file.data["mdx-export"] ?? []) {
|
|
42
58
|
tree.children.unshift(getMdastExport(name, value));
|
|
43
59
|
}
|
|
@@ -105,6 +121,7 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
105
121
|
[
|
|
106
122
|
remarkPostprocess,
|
|
107
123
|
{
|
|
124
|
+
_format: format,
|
|
108
125
|
...options.postprocess,
|
|
109
126
|
valueToExport: [
|
|
110
127
|
...options.postprocess?.valueToExport ?? [],
|
|
@@ -112,7 +129,8 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
112
129
|
"extractedReferences",
|
|
113
130
|
"frontmatter",
|
|
114
131
|
"lastModified",
|
|
115
|
-
"_markdown"
|
|
132
|
+
"_markdown",
|
|
133
|
+
"_mdast"
|
|
116
134
|
]
|
|
117
135
|
}
|
|
118
136
|
]
|