fumadocs-mdx 14.2.12 → 14.2.14
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/{adapter-CzI6jiMm.js → adapter-CrnPUO1X.js} +3 -5
- package/dist/adapter-CrnPUO1X.js.map +1 -0
- package/dist/{build-mdx-LmiB2qsc.js → build-mdx-iu_4pINO.js} +6 -6
- package/dist/build-mdx-iu_4pINO.js.map +1 -0
- package/dist/bun/index.js +3 -3
- package/dist/config/index.js +1 -1
- package/dist/{load-from-file-vlVZ_DdD.js → load-from-file-CEpo5Sqi.js} +2 -2
- package/dist/{load-from-file-vlVZ_DdD.js.map → load-from-file-CEpo5Sqi.js.map} +1 -1
- package/dist/{mdx-D95UF4l1.js → mdx-Cd17PhOW.js} +2 -2
- package/dist/{mdx-D95UF4l1.js.map → mdx-Cd17PhOW.js.map} +1 -1
- package/dist/{meta-Di0sMUh5.js → meta-DV1ZTafU.js} +1 -1
- package/dist/{meta-Di0sMUh5.js.map → meta-DV1ZTafU.js.map} +1 -1
- package/dist/next/index.cjs +1 -1
- package/dist/next/index.js +1 -1
- package/dist/node/loader.js +3 -3
- package/dist/{remark-include-CgjB4_2e.js → remark-include-naMKDvrK.js} +1 -1
- package/dist/{remark-include-CgjB4_2e.js.map → remark-include-naMKDvrK.js.map} +1 -1
- package/dist/runtime/dynamic.d.ts.map +1 -1
- package/dist/runtime/dynamic.js +17 -2
- package/dist/runtime/dynamic.js.map +1 -1
- package/dist/vite/index.js +4 -4
- package/dist/webpack/mdx.js +2 -2
- package/dist/webpack/meta.js +2 -2
- package/package.json +4 -9
- package/dist/adapter-CzI6jiMm.js.map +0 -1
- package/dist/build-mdx-LmiB2qsc.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { r as ValidationError } from "./core-BluWnx7f.js";
|
|
2
|
+
import { t as loadConfig } from "./load-from-file-CEpo5Sqi.js";
|
|
2
3
|
import { readFileSync } from "node:fs";
|
|
3
4
|
import fs from "node:fs/promises";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -16,10 +17,7 @@ function createStandaloneConfigLoader({ core, buildConfig, mode }) {
|
|
|
16
17
|
const hash = await getConfigHash();
|
|
17
18
|
if (!prev || hash !== prev.hash) prev = {
|
|
18
19
|
hash,
|
|
19
|
-
init: (
|
|
20
|
-
const { loadConfig } = await import("./load-from-file-vlVZ_DdD.js").then((n) => n.n);
|
|
21
|
-
await core.init({ config: loadConfig(core, buildConfig) });
|
|
22
|
-
})()
|
|
20
|
+
init: core.init({ config: loadConfig(core, buildConfig) })
|
|
23
21
|
};
|
|
24
22
|
await prev.init;
|
|
25
23
|
return core;
|
|
@@ -140,4 +138,4 @@ function toBun(loader) {
|
|
|
140
138
|
//#endregion
|
|
141
139
|
export { createIntegratedConfigLoader as a, toWebpack as i, toNode as n, createStandaloneConfigLoader as o, toVite as r, toBun as t };
|
|
142
140
|
|
|
143
|
-
//# sourceMappingURL=adapter-
|
|
141
|
+
//# sourceMappingURL=adapter-CrnPUO1X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-CrnPUO1X.js","names":[],"sources":["../src/loaders/config.ts","../src/loaders/adapter.ts"],"sourcesContent":["import { loadConfig } from '@/config/load-from-file';\nimport type { Core } from '@/core';\nimport fs from 'node:fs/promises';\n\nexport interface ConfigLoader {\n getCore(): Promise<Core>;\n}\n\nexport function createStandaloneConfigLoader({\n core,\n buildConfig,\n mode,\n}: {\n /**\n * core (not initialized)\n */\n core: Core;\n buildConfig: boolean;\n /**\n * In dev mode, the config file is dynamically re-loaded when it's updated.\n */\n mode: 'dev' | 'production';\n}): ConfigLoader {\n let prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined;\n\n async function getConfigHash(): Promise<string> {\n if (mode === 'production') return 'static';\n\n const stats = await fs.stat(core.getOptions().configPath).catch(() => {\n throw new Error('Cannot find config file');\n });\n\n return stats.mtime.getTime().toString();\n }\n\n return {\n async getCore() {\n const hash = await getConfigHash();\n if (!prev || hash !== prev.hash) {\n prev = {\n hash,\n init: core.init({\n config: loadConfig(core, buildConfig),\n }),\n };\n }\n\n await prev.init;\n return core;\n },\n };\n}\n\n/**\n * create config loader from initialized core\n */\nexport function createIntegratedConfigLoader(core: Core): ConfigLoader {\n return {\n async getCore() {\n return core;\n },\n };\n}\n","import type { CompilerOptions } from '@/loaders/mdx/build-mdx';\nimport type { LoadFnOutput, LoadHook } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport type { TransformPluginContext } from 'rolldown';\nimport type { Environment, TransformResult } from 'vite';\nimport { parse } from 'node:querystring';\nimport { ValidationError } from '@/utils/validation';\nimport type { LoaderContext } from 'webpack';\nimport { readFileSync } from 'node:fs';\n\nexport interface LoaderInput {\n development: boolean;\n compiler: CompilerOptions;\n\n filePath: string;\n query: Record<string, string | string[] | undefined>;\n getSource: () => string | Promise<string>;\n}\n\nexport interface LoaderOutput {\n code: string;\n map?: unknown;\n\n /**\n * Only supported in Vite 8.\n *\n * Explicitly define the transformed module type, for unsupported environments, you need to consider the differences between each bundler.\n */\n moduleType?: 'js' | 'json';\n}\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface Loader {\n /**\n * Filter file paths, the input can be either a file URL or file path.\n *\n * Must take resource query into consideration.\n */\n test?: RegExp;\n\n /**\n * Transform input into JavaScript.\n *\n * Returns:\n * - `LoaderOutput`: JavaScript code & source map.\n * - `null`: skip the loader. Fallback to default behaviour if possible, otherwise the adapter will try workarounds.\n */\n load: (input: LoaderInput) => Awaitable<LoaderOutput | null>;\n\n bun?: {\n /**\n * 1. Bun doesn't allow `null` in loaders.\n * 2. Bun requires sync result to support dynamic require().\n */\n load?: (source: string, input: LoaderInput) => Awaitable<Bun.OnLoadResult>;\n };\n}\n\nexport function toNode(loader: Loader): LoadHook {\n return async (url, _context, nextLoad): Promise<LoadFnOutput> => {\n if (url.startsWith('file:///') && (!loader.test || loader.test.test(url))) {\n const parsedUrl = new URL(url);\n const filePath = fileURLToPath(parsedUrl);\n\n const result = await loader.load({\n filePath,\n query: Object.fromEntries(parsedUrl.searchParams.entries()),\n async getSource() {\n return await fs.readFile(filePath, 'utf-8');\n },\n development: false,\n compiler: {\n addDependency() {},\n },\n });\n\n if (result) {\n return {\n source: result.code,\n format: 'module',\n shortCircuit: true,\n };\n }\n }\n\n return nextLoad(url);\n };\n}\n\nexport interface ViteLoader {\n filter: (id: string) => boolean;\n\n transform: (\n this: TransformPluginContext & { environment: Environment },\n value: string,\n id: string,\n ) => Promise<TransformResult | null>;\n}\n\nexport function toVite(loader: Loader): ViteLoader {\n return {\n filter(id) {\n return !loader.test || loader.test.test(id);\n },\n async transform(value, id) {\n const environment = this.environment;\n const [file, query = ''] = id.split('?', 2);\n\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: environment.mode === 'dev',\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as TransformResult['map'],\n moduleType: result.moduleType,\n };\n },\n };\n}\n\nexport type WebpackLoader = (\n this: LoaderContext<unknown>,\n source: string,\n callback: LoaderContext<unknown>['callback'],\n) => Promise<void>;\n\n/**\n * need to handle the `test` regex in Webpack config instead.\n */\nexport function toWebpack(loader: Loader): WebpackLoader {\n return async function (source, callback) {\n try {\n const result = await loader.load({\n filePath: this.resourcePath,\n query: parse(this.resourceQuery.slice(1)),\n getSource() {\n return source;\n },\n development: this.mode === 'development',\n compiler: this,\n });\n\n if (result === null) {\n callback(undefined, source);\n } else {\n callback(undefined, result.code, result.map as string);\n }\n } catch (error) {\n if (error instanceof ValidationError) {\n return callback(new Error(await error.toStringFormatted()));\n }\n\n if (!(error instanceof Error)) throw error;\n callback(error);\n }\n };\n}\n\nexport function toBun(loader: Loader) {\n function toResult(output: LoaderOutput | null): Bun.OnLoadResult {\n // it errors, treat this as an exception\n if (!output) return;\n\n return {\n contents: output.code,\n loader: output.moduleType ?? 'js',\n };\n }\n\n return (build: Bun.PluginBuilder) => {\n // avoid using async here, because it will cause dynamic require() to fail\n build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {\n const [filePath, query = ''] = args.path.split('?', 2);\n const input: LoaderInput = {\n async getSource() {\n return Bun.file(filePath).text();\n },\n query: parse(query),\n filePath,\n development: false,\n compiler: {\n addDependency() {},\n },\n };\n\n if (loader.bun?.load) {\n return loader.bun.load(readFileSync(filePath, 'utf-8'), input);\n }\n\n const result = loader.load(input);\n if (result instanceof Promise) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,6BAA6B,EAC3C,MACA,aACA,QAWe;CACf,IAAI;CAOJ,eAAe,gBAAiC;AAC9C,MAAI,SAAS,aAAc,QAAO;AAMlC,UAJc,MAAM,GAAG,KAAK,KAAK,YAAY,CAAC,WAAW,CAAC,YAAY;AACpE,SAAM,IAAI,MAAM,0BAA0B;IAC1C,EAEW,MAAM,SAAS,CAAC,UAAU;;AAGzC,QAAO,EACL,MAAM,UAAU;EACd,MAAM,OAAO,MAAM,eAAe;AAClC,MAAI,CAAC,QAAQ,SAAS,KAAK,KACzB,QAAO;GACL;GACA,MAAM,KAAK,KAAK,EACd,QAAQ,WAAW,MAAM,YAAY,EACtC,CAAC;GACH;AAGH,QAAM,KAAK;AACX,SAAO;IAEV;;;;;AAMH,SAAgB,6BAA6B,MAA0B;AACrE,QAAO,EACL,MAAM,UAAU;AACd,SAAO;IAEV;;;;ACNH,SAAgB,OAAO,QAA0B;AAC/C,QAAO,OAAO,KAAK,UAAU,aAAoC;AAC/D,MAAI,IAAI,WAAW,WAAW,KAAK,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,IAAI,GAAG;GACzE,MAAM,YAAY,IAAI,IAAI,IAAI;GAC9B,MAAM,WAAW,cAAc,UAAU;GAEzC,MAAM,SAAS,MAAM,OAAO,KAAK;IAC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AAC;AAG7D,OAAI,EAAE,iBAAiB,OAAQ,OAAM;AACrC,YAAS,MAAM;;;;AAKrB,SAAgB,MAAM,QAAgB;CACpC,SAAS,SAAS,QAA+C;AAE/D,MAAI,CAAC,OAAQ;AAEb,SAAO;GACL,UAAU,OAAO;GACjB,QAAQ,OAAO,cAAc;GAC9B;;AAGH,SAAQ,UAA6B;AAEnC,QAAM,OAAO,EAAE,QAAQ,OAAO,QAAQ,MAAM,GAAG,SAAS;GACtD,MAAM,CAAC,UAAU,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,EAAE;GACtD,MAAM,QAAqB;IACzB,MAAM,YAAY;AAChB,YAAO,IAAI,KAAK,SAAS,CAAC,MAAM;;IAElC,OAAO,MAAM,MAAM;IACnB;IACA,aAAa;IACb,UAAU,EACR,gBAAgB,IACjB;IACF;AAED,OAAI,OAAO,KAAK,KACd,QAAO,OAAO,IAAI,KAAK,aAAa,UAAU,QAAQ,EAAE,MAAM;GAGhE,MAAM,SAAS,OAAO,KAAK,MAAM;AACjC,OAAI,kBAAkB,QACpB,QAAO,OAAO,KAAK,SAAS;AAE9B,UAAO,SAAS,OAAO;IACvB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-CiIaOW0V.js";
|
|
2
|
-
import { n as flattenNode, t as remarkInclude } from "./remark-include-
|
|
2
|
+
import { n as flattenNode, t as remarkInclude } from "./remark-include-naMKDvrK.js";
|
|
3
3
|
import { visit } from "unist-util-visit";
|
|
4
4
|
import { VFile } from "vfile";
|
|
5
5
|
import { createProcessor } from "@mdx-js/mdx";
|
|
6
6
|
import { valueToEstree } from "estree-util-value-to-estree";
|
|
7
7
|
import { removePosition } from "unist-util-remove-position";
|
|
8
8
|
import { mdxToMarkdown } from "mdast-util-mdx";
|
|
9
|
-
import { toMarkdown } from "mdast-util-to-markdown";
|
|
10
|
-
//#region ../core/dist/utils-
|
|
9
|
+
import { defaultHandlers, toMarkdown } from "mdast-util-to-markdown";
|
|
10
|
+
//#region ../core/dist/utils-pSG8hSr9.js
|
|
11
11
|
function toMdxExport(name, value) {
|
|
12
12
|
return toMdxExportRaw(name, valueToEstree(value));
|
|
13
13
|
}
|
|
@@ -148,8 +148,8 @@ function remarkLLMs({ as = "_markdown", headingIds = true, _data = false, mdxAsP
|
|
|
148
148
|
handlers: {
|
|
149
149
|
heading(node, _p, state, info) {
|
|
150
150
|
const id = node.data?.hProperties?.id;
|
|
151
|
-
const
|
|
152
|
-
return headingIds && id ? `${
|
|
151
|
+
const defaultValue = defaultHandlers.heading(node, _p, state, info);
|
|
152
|
+
return headingIds && id ? `${defaultValue} [#${id}]` : defaultValue;
|
|
153
153
|
},
|
|
154
154
|
...rest.handlers
|
|
155
155
|
}
|
|
@@ -304,4 +304,4 @@ async function buildMDX(core, collection, { filePath, frontmatter, source, _comp
|
|
|
304
304
|
//#endregion
|
|
305
305
|
export { build_mdx_exports as n, buildMDX as t };
|
|
306
306
|
|
|
307
|
-
//# sourceMappingURL=build-mdx-
|
|
307
|
+
//# sourceMappingURL=build-mdx-iu_4pINO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-mdx-iu_4pINO.js","names":[],"sources":["../../core/dist/utils-pSG8hSr9.js","../../core/dist/mdx-plugins/stringifier.js","../../core/dist/mdx-plugins/remark-llms.js","../src/loaders/mdx/remark-postprocess.ts","../src/loaders/mdx/build-mdx.ts"],"sourcesContent":["import { valueToEstree } from \"estree-util-value-to-estree\";\n//#region src/mdx-plugins/utils.ts\nfunction flattenNode(node) {\n\tif (\"children\" in node) return node.children.map(flattenNode).join(\"\");\n\tif (\"value\" in node && typeof node.value === \"string\") return node.value;\n\treturn \"\";\n}\nfunction flattenNodeHast(node) {\n\tif (\"children\" in node) return node.children.map(flattenNodeHast).join(\"\");\n\treturn \"value\" in node && typeof node.value === \"string\" ? node.value : \"\";\n}\nfunction toMdxExport(name, value) {\n\treturn toMdxExportRaw(name, valueToEstree(value));\n}\nfunction toMdxExportRaw(name, expression) {\n\treturn {\n\t\ttype: \"mdxjsEsm\",\n\t\tvalue: \"\",\n\t\tdata: { estree: {\n\t\t\ttype: \"Program\",\n\t\t\tsourceType: \"module\",\n\t\t\tbody: [{\n\t\t\t\ttype: \"ExportNamedDeclaration\",\n\t\t\t\tattributes: [],\n\t\t\t\tspecifiers: [],\n\t\t\t\tdeclaration: {\n\t\t\t\t\ttype: \"VariableDeclaration\",\n\t\t\t\t\tkind: \"let\",\n\t\t\t\t\tdeclarations: [{\n\t\t\t\t\t\ttype: \"VariableDeclarator\",\n\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\ttype: \"Identifier\",\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinit: expression\n\t\t\t\t\t}]\n\t\t\t\t}\n\t\t\t}]\n\t\t} }\n\t};\n}\nfunction handleTag(value, tag) {\n\tconst idx = value.indexOf(tag);\n\tif (idx !== -1) return value.slice(0, idx).trimEnd() + value.slice(idx + tag.length);\n\treturn false;\n}\n//#endregion\nexport { toMdxExportRaw as a, toMdxExport as i, flattenNodeHast as n, handleTag as r, flattenNode as t };\n","import { mdxToMarkdown } from \"mdast-util-mdx\";\nimport { toMarkdown } from \"mdast-util-to-markdown\";\n//#region src/mdx-plugins/stringifier.ts\nfunction defaultStringifier(config = {}) {\n\tconst { filterMdxAttributes, filterElement = (node) => {\n\t\tswitch (node.type) {\n\t\t\tcase \"mdxJsxFlowElement\":\n\t\t\tcase \"mdxJsxTextElement\":\n\t\t\t\tswitch (node.name) {\n\t\t\t\t\tcase \"File\":\n\t\t\t\t\tcase \"TypeTable\":\n\t\t\t\t\tcase \"Callout\":\n\t\t\t\t\tcase \"Card\": return true;\n\t\t\t\t}\n\t\t\t\treturn \"children-only\";\n\t\t}\n\t\treturn true;\n\t}, stringify, ...customExtension } = config;\n\tfunction modHandler(handler, ctx) {\n\t\treturn function(node, parent, state, info) {\n\t\t\tlet visibility = filterElement(node);\n\t\t\tif (visibility === false) return \"\";\n\t\t\tif (stringify) {\n\t\t\t\tconst v = stringify(node, parent, state, info, ctx);\n\t\t\t\tif (v) return v;\n\t\t\t}\n\t\t\tconst extraInfo = node.data?._stringify;\n\t\t\tif (extraInfo) if (extraInfo === \"children-only\") visibility = \"children-only\";\n\t\t\telse if (\"text\" in extraInfo) return extraInfo.text;\n\t\t\telse node = extraInfo.node;\n\t\t\tif (visibility === \"children-only\") {\n\t\t\t\tif (!(\"children\" in node)) return \"\";\n\t\t\t\tswitch (node.type) {\n\t\t\t\t\tcase \"mdxJsxTextElement\":\n\t\t\t\t\tcase \"paragraph\": return state.containerPhrasing(node, info);\n\t\t\t\t\tcase \"mdxJsxFlowElement\": return state.containerFlow(node, info);\n\t\t\t\t\tdefault: return state.containerFlow({\n\t\t\t\t\t\ttype: \"root\",\n\t\t\t\t\t\tchildren: node.children\n\t\t\t\t\t}, info);\n\t\t\t\t}\n\t\t\t}\n\t\t\tswitch (node.type) {\n\t\t\t\tcase \"mdxJsxFlowElement\":\n\t\t\t\tcase \"mdxJsxTextElement\": {\n\t\t\t\t\tconst stringifiedAttributes = [];\n\t\t\t\t\tfor (const attr of node.attributes) {\n\t\t\t\t\t\tif (attr.type === \"mdxJsxExpressionAttribute\") continue;\n\t\t\t\t\t\tif (filterMdxAttributes && !filterMdxAttributes(node, attr)) continue;\n\t\t\t\t\t\tconst str = typeof attr.value === \"string\" ? attr.value : attr.value?.value;\n\t\t\t\t\t\tif (!str) continue;\n\t\t\t\t\t\tstringifiedAttributes.push({\n\t\t\t\t\t\t\ttype: \"mdxJsxAttribute\",\n\t\t\t\t\t\t\tname: attr.name,\n\t\t\t\t\t\t\tvalue: str\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn handler({\n\t\t\t\t\t\t...node,\n\t\t\t\t\t\tattributes: stringifiedAttributes\n\t\t\t\t\t}, parent, state, info);\n\t\t\t\t}\n\t\t\t\tdefault: return handler(node, parent, state, info);\n\t\t\t}\n\t\t};\n\t}\n\tconst customToMarkdown = { handlers: { _custom(node, _, state, info) {\n\t\tconst handlers = state.handlers;\n\t\tfor (const k in handlers) handlers[k] = modHandler(handlers[k], node.ctx);\n\t\treturn state.handle(node.root, void 0, state, info);\n\t} } };\n\treturn function(root, ctx) {\n\t\treturn toMarkdown({\n\t\t\ttype: \"_custom\",\n\t\t\troot,\n\t\t\tctx\n\t\t}, {\n\t\t\t...this?.data(\"settings\"),\n\t\t\textensions: [\n\t\t\t\tmdxToMarkdown(),\n\t\t\t\t...this?.data(\"toMarkdownExtensions\") ?? [],\n\t\t\t\tcustomToMarkdown,\n\t\t\t\tcustomExtension\n\t\t\t]\n\t\t});\n\t};\n}\n//#endregion\nexport { defaultStringifier };\n","import { i as toMdxExport } from \"../utils-pSG8hSr9.js\";\nimport { defaultStringifier } from \"./stringifier.js\";\nimport { defaultHandlers } from \"mdast-util-to-markdown\";\n//#region src/mdx-plugins/remark-llms.ts\n/**\n* generate `llms.txt` for markdown.\n*/\nfunction remarkLLMs({ as = \"_markdown\", headingIds = true, _data = false, mdxAsPlaceholder, ...rest } = {}) {\n\tconst stringifier = defaultStringifier({\n\t\t...rest,\n\t\tfilterElement(node) {\n\t\t\tswitch (node.type) {\n\t\t\t\tcase \"mdxjsEsm\": return false;\n\t\t\t\tdefault: return true;\n\t\t\t}\n\t\t},\n\t\tstringify(node, parent, state, info, ctx) {\n\t\t\tif (mdxAsPlaceholder) switch (node.type) {\n\t\t\t\tcase \"mdxJsxFlowElement\":\n\t\t\t\tcase \"mdxJsxTextElement\": if (node.name && mdxAsPlaceholder.includes(node.name)) return placeholder(node, parent, state, info);\n\t\t\t}\n\t\t\treturn rest.stringify?.(node, parent, state, info, ctx);\n\t\t},\n\t\thandlers: {\n\t\t\theading(node, _p, state, info) {\n\t\t\t\tconst id = node.data?.hProperties?.id;\n\t\t\t\tconst defaultValue = defaultHandlers.heading(node, _p, state, info);\n\t\t\t\treturn headingIds && id ? `${defaultValue} [#${id}]` : defaultValue;\n\t\t\t},\n\t\t\t...rest.handlers\n\t\t}\n\t});\n\treturn (node, file) => {\n\t\tconst value = stringifier.call(this, node, void 0);\n\t\tnode.children.unshift(toMdxExport(as, value));\n\t\tif (_data) file.data.markdown = value;\n\t};\n}\n/**\n* Preserve AST data to render the MDX component at runtime, use `renderPlaceholder()` to render the placeholders.\n*/\nfunction placeholder(node, _parent, state, info) {\n\tconst attributes = {};\n\tfor (const attr of node.attributes) {\n\t\tif (attr.type === \"mdxJsxExpressionAttribute\") continue;\n\t\tattributes[attr.name] = attr.value;\n\t}\n\treturn `\\0${JSON.stringify({\n\t\tname: node.name,\n\t\tchildren: state.containerPhrasing(node, info),\n\t\tattributes\n\t})}\\0`;\n}\n//#endregion\nexport { placeholder, remarkLLMs };\n","import type { Processor, Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport { valueToEstree } from 'estree-util-value-to-estree';\nimport { removePosition } from 'unist-util-remove-position';\nimport { flattenNode } from './mdast-utils';\nimport type { LLMsOptions } from 'fumadocs-core/mdx-plugins';\nimport { remarkLLMs } from 'fumadocs-core/mdx-plugins/remark-llms';\n\nexport interface ExtractedReference {\n href: string;\n}\n\nexport interface PostprocessOptions {\n _format: 'md' | 'mdx';\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n /**\n * stringify MDAST and export via `_markdown`.\n */\n includeProcessedMarkdown?: boolean | LLMsOptions;\n\n /**\n * extract link references, export via `extractedReferences`.\n */\n extractLinkReferences?: boolean;\n\n /**\n * store MDAST and export via `_mdast`.\n */\n includeMDAST?:\n | boolean\n | {\n removePosition?: boolean;\n };\n}\n\n/**\n * - collect references\n * - write frontmatter (auto-title & description)\n */\nexport function remarkPostprocess(\n this: Processor,\n {\n includeProcessedMarkdown = false,\n includeMDAST = false,\n extractLinkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\n return (tree, file) => {\n const frontmatter = (file.data.frontmatter ??= {});\n if (!frontmatter.title) {\n visit(tree, 'heading', (node) => {\n if (node.depth === 1) {\n frontmatter.title = flattenNode(node);\n return false;\n }\n });\n }\n\n file.data['mdx-export'] ??= [];\n file.data['mdx-export'].push({\n name: 'frontmatter',\n value: frontmatter,\n });\n\n if (extractLinkReferences) {\n const urls: ExtractedReference[] = [];\n\n visit(tree, 'link', (node) => {\n urls.push({\n href: node.url,\n });\n return 'skip';\n });\n\n file.data['mdx-export'].push({\n name: 'extractedReferences',\n value: urls,\n });\n }\n\n if (includeProcessedMarkdown) {\n const llms = remarkLLMs.call(\n this,\n typeof includeProcessedMarkdown === 'object' ? includeProcessedMarkdown : undefined,\n );\n llms(tree, file, () => undefined);\n }\n\n if (includeMDAST) {\n const options = includeMDAST === true ? {} : includeMDAST;\n const mdast = JSON.stringify(\n options.removePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data['mdx-export'].push({\n name: '_mdast',\n value: mdast,\n });\n }\n\n for (const { name, value } of file.data['mdx-export']) {\n tree.children.unshift(getMdastExport(name, value));\n }\n\n // reset the data to reduce memory usage\n file.data['mdx-export'] = [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n tree.children.unshift(getMdastExport(name, file.data[name]));\n }\n };\n}\n\n/**\n * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins\n *\n * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node\n */\nfunction getMdastExport(name: string, value: unknown): RootContent {\n return {\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExportNamedDeclaration',\n attributes: [],\n specifiers: [],\n source: null,\n declaration: {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n","import { createProcessor } from '@mdx-js/mdx';\nimport { VFile } from 'vfile';\nimport { remarkInclude } from '@/loaders/mdx/remark-include';\nimport type { StructuredData } from 'fumadocs-core/mdx-plugins';\nimport type { TOCItemType } from 'fumadocs-core/toc';\nimport type { FC } from 'react';\nimport type { MDXProps } from 'mdx/types';\nimport { type PostprocessOptions, remarkPostprocess } from '@/loaders/mdx/remark-postprocess';\nimport type { Core } from '@/core';\nimport type { DocCollectionItem } from '@/config/build';\n\ntype Processor = ReturnType<typeof createProcessor>;\n\ninterface BuildMDXOptions {\n /**\n * Specify a file path for source\n */\n filePath: string;\n source: string;\n frontmatter?: Record<string, unknown>;\n\n environment: 'bundler' | 'runtime';\n isDevelopment: boolean;\n _compiler?: CompilerOptions;\n}\n\nexport interface CompilerOptions {\n addDependency: (file: string) => void;\n}\n\nexport interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {\n frontmatter: Frontmatter;\n structuredData: StructuredData;\n toc: TOCItemType[];\n default: FC<MDXProps>;\n\n /**\n * Enable from `postprocess` option.\n */\n _markdown?: string;\n /**\n * Enable from `postprocess` option.\n */\n _mdast?: string;\n}\n\nexport interface FumadocsDataMap {\n /**\n * [Fumadocs MDX] raw frontmatter, you can modify it\n */\n frontmatter?: Record<string, unknown>;\n\n /**\n * [Fumadocs MDX] additional ESM exports to write\n */\n 'mdx-export'?: { name: string; value: unknown }[];\n\n /**\n * [Fumadocs MDX] The compiler object from loader\n */\n _compiler?: CompilerOptions;\n\n /**\n * [Fumadocs MDX] get internal processor, do not use this on user land.\n */\n _getProcessor?: (format: 'md' | 'mdx') => Processor;\n}\n\ndeclare module 'vfile' {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap extends FumadocsDataMap {}\n}\n\nexport async function buildMDX(\n core: Core,\n collection: DocCollectionItem | undefined,\n { filePath, frontmatter, source, _compiler, environment, isDevelopment }: BuildMDXOptions,\n): Promise<VFile> {\n const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);\n\n function getProcessor(format: 'md' | 'mdx') {\n const cache = core.cache as Map<string, Processor>;\n const key = `build-mdx:${collection?.name ?? 'global'}:${format}`;\n let processor = cache.get(key);\n\n if (!processor) {\n const postprocessOptions: PostprocessOptions = {\n _format: format,\n ...collection?.postprocess,\n };\n\n processor = createProcessor({\n outputFormat: 'program',\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins: [\n remarkInclude,\n ...(mdxOptions.remarkPlugins ?? []),\n [remarkPostprocess, postprocessOptions],\n ],\n format,\n });\n\n cache.set(key, processor);\n }\n\n return processor;\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: collection?.cwd,\n data: { frontmatter, _compiler, _getProcessor: getProcessor },\n });\n\n if (collection) {\n vfile = await core.transformVFile({ collection, filePath, source }, vfile);\n }\n\n return getProcessor(filePath.endsWith('.mdx') ? 'mdx' : 'md').process(vfile);\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAS,YAAY,MAAM,OAAO;AACjC,QAAO,eAAe,MAAM,cAAc,MAAM,CAAC;;AAElD,SAAS,eAAe,MAAM,YAAY;AACzC,QAAO;EACN,MAAM;EACN,OAAO;EACP,MAAM,EAAE,QAAQ;GACf,MAAM;GACN,YAAY;GACZ,MAAM,CAAC;IACN,MAAM;IACN,YAAY,EAAE;IACd,YAAY,EAAE;IACd,aAAa;KACZ,MAAM;KACN,MAAM;KACN,cAAc,CAAC;MACd,MAAM;MACN,IAAI;OACH,MAAM;OACN;OACA;MACD,MAAM;MACN,CAAC;KACF;IACD,CAAC;GACF,EAAE;EACH;;;;ACpCF,SAAS,mBAAmB,SAAS,EAAE,EAAE;CACxC,MAAM,EAAE,qBAAqB,iBAAiB,SAAS;AACtD,UAAQ,KAAK,MAAb;GACC,KAAK;GACL,KAAK;AACJ,YAAQ,KAAK,MAAb;KACC,KAAK;KACL,KAAK;KACL,KAAK;KACL,KAAK,OAAQ,QAAO;;AAErB,WAAO;;AAET,SAAO;IACL,WAAW,GAAG,oBAAoB;CACrC,SAAS,WAAW,SAAS,KAA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D,CAAC;AAEF,KAAI,WACF,SAAQ,MAAM,KAAK,eAAe;EAAE;EAAY;EAAU;EAAQ,EAAE,MAAM;AAG5E,QAAO,aAAa,SAAS,SAAS,OAAO,GAAG,QAAQ,KAAK,CAAC,QAAQ,MAAM"}
|
package/dist/bun/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cd17PhOW.js";
|
|
2
2
|
import { t as buildConfig } from "../build-DxkMdv29.js";
|
|
3
3
|
import { n as createCore, t as _Defaults } from "../core-BluWnx7f.js";
|
|
4
|
-
import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-
|
|
5
|
-
import { t as createMetaLoader } from "../meta-
|
|
4
|
+
import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-CrnPUO1X.js";
|
|
5
|
+
import { t as createMetaLoader } from "../meta-DV1ZTafU.js";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
//#region src/bun/index.ts
|
|
8
8
|
function createMdxPlugin(options = {}) {
|
package/dist/config/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as applyMdxPreset } from "../preset-BjHACE1Z.js";
|
|
2
|
-
import { t as remarkInclude } from "../remark-include-
|
|
2
|
+
import { t as remarkInclude } from "../remark-include-naMKDvrK.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region ../core/dist/source/schema.js
|
|
5
5
|
/**
|
|
@@ -13,7 +13,7 @@ async function compileConfig(core) {
|
|
|
13
13
|
}],
|
|
14
14
|
bundle: true,
|
|
15
15
|
outdir: outDir,
|
|
16
|
-
target: "
|
|
16
|
+
target: "node22",
|
|
17
17
|
write: true,
|
|
18
18
|
platform: "node",
|
|
19
19
|
format: "esm",
|
|
@@ -36,4 +36,4 @@ async function loadConfig(core, build = false) {
|
|
|
36
36
|
//#endregion
|
|
37
37
|
export { load_from_file_exports as n, loadConfig as t };
|
|
38
38
|
|
|
39
|
-
//# sourceMappingURL=load-from-file-
|
|
39
|
+
//# sourceMappingURL=load-from-file-CEpo5Sqi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-from-file-
|
|
1
|
+
{"version":3,"file":"load-from-file-CEpo5Sqi.js","names":[],"sources":["../src/config/load-from-file.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\nimport type { LoadedConfig } from '@/config/build';\nimport { buildConfig } from '@/config/build';\nimport type { Core } from '@/core';\n\nasync function compileConfig(core: Core) {\n const { build } = await import('esbuild');\n const { configPath, outDir } = core.getOptions();\n\n const transformed = await build({\n entryPoints: [{ in: configPath, out: 'source.config' }],\n bundle: true,\n outdir: outDir,\n target: 'node22',\n write: true,\n platform: 'node',\n format: 'esm',\n packages: 'external',\n outExtension: {\n '.js': '.mjs',\n },\n allowOverwrite: true,\n });\n\n if (transformed.errors.length > 0) {\n throw new Error('failed to compile configuration file');\n }\n}\n\n/**\n * Load config\n *\n * @param build - By default, it assumes the config file has been compiled. Set this `true` to compile the config first.\n */\nexport async function loadConfig(core: Core, build = false): Promise<LoadedConfig> {\n if (build) await compileConfig(core);\n\n const url = pathToFileURL(core.getCompiledConfigPath());\n // always return a new config\n url.searchParams.set('hash', Date.now().toString());\n\n const config = import(url.href).then((loaded) => buildConfig(loaded as Record<string, unknown>));\n\n return await config;\n}\n"],"mappings":";;;;;AAKA,eAAe,cAAc,MAAY;CACvC,MAAM,EAAE,UAAU,MAAM,OAAO;CAC/B,MAAM,EAAE,YAAY,WAAW,KAAK,YAAY;AAiBhD,MAfoB,MAAM,MAAM;EAC9B,aAAa,CAAC;GAAE,IAAI;GAAY,KAAK;GAAiB,CAAC;EACvD,QAAQ;EACR,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,UAAU;EACV,QAAQ;EACR,UAAU;EACV,cAAc,EACZ,OAAO,QACR;EACD,gBAAgB;EACjB,CAAC,EAEc,OAAO,SAAS,EAC9B,OAAM,IAAI,MAAM,uCAAuC;;;;;;;AAS3D,eAAsB,WAAW,MAAY,QAAQ,OAA8B;AACjF,KAAI,MAAO,OAAM,cAAc,KAAK;CAEpC,MAAM,MAAM,cAAc,KAAK,uBAAuB,CAAC;AAEvD,KAAI,aAAa,IAAI,QAAQ,KAAK,KAAK,CAAC,UAAU,CAAC;AAInD,QAAO,MAFQ,OAAO,IAAI,MAAM,MAAM,WAAW,YAAY,OAAkC,CAAC"}
|
|
@@ -58,7 +58,7 @@ function createMdxLoader({ getCore }) {
|
|
|
58
58
|
code: `export const frontmatter = ${JSON.stringify(matter.data)}`,
|
|
59
59
|
map: null
|
|
60
60
|
};
|
|
61
|
-
const { buildMDX } = await import("./build-mdx-
|
|
61
|
+
const { buildMDX } = await import("./build-mdx-iu_4pINO.js").then((n) => n.n);
|
|
62
62
|
const compiled = await buildMDX(core, docCollection, {
|
|
63
63
|
isDevelopment,
|
|
64
64
|
source: "\n".repeat(countLines(matter.matter)) + matter.content,
|
|
@@ -87,4 +87,4 @@ function countLines(s) {
|
|
|
87
87
|
//#endregion
|
|
88
88
|
export { createMdxLoader as t };
|
|
89
89
|
|
|
90
|
-
//# sourceMappingURL=mdx-
|
|
90
|
+
//# sourceMappingURL=mdx-Cd17PhOW.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx-
|
|
1
|
+
{"version":3,"file":"mdx-Cd17PhOW.js","names":[],"sources":["../src/loaders/mdx/index.ts"],"sourcesContent":["import { fumaMatter } from '@/utils/fuma-matter';\nimport type { Loader } from '@/loaders/adapter';\nimport { z } from 'zod';\nimport type { DocCollectionItem } from '@/config/build';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { createHash } from 'node:crypto';\nimport type { ConfigLoader } from '@/loaders/config';\nimport { mdxLoaderGlob } from '..';\n\nconst querySchema = z.looseObject({\n only: z.literal(['frontmatter', 'all']).default('all'),\n collection: z.string().optional(),\n workspace: z.string().optional(),\n});\n\nconst cacheEntry = z.object({\n code: z.string(),\n map: z.any().optional(),\n hash: z.string().optional(),\n});\n\ntype CacheEntry = z.infer<typeof cacheEntry>;\n\nexport function createMdxLoader({ getCore }: ConfigLoader): Loader {\n return {\n test: mdxLoaderGlob,\n async load({ getSource, development: isDevelopment, query, compiler, filePath }) {\n let core = await getCore();\n const value = await getSource();\n const matter = fumaMatter(value);\n const { collection: collectionName, workspace, only } = querySchema.parse(query);\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n let after: (() => Promise<void>) | undefined;\n\n const { experimentalBuildCache = false } = core.getConfig().global;\n if (!isDevelopment && experimentalBuildCache) {\n const cacheDir = experimentalBuildCache;\n const cacheKey = `${collectionName ?? 'global'}_${generateCacheHash(filePath)}`;\n\n const cached = await fs\n .readFile(path.join(cacheDir, cacheKey))\n .then((content) => cacheEntry.parse(JSON.parse(content.toString())))\n .catch(() => null);\n\n if (cached && cached.hash === generateCacheHash(value)) return cached;\n after = async () => {\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.writeFile(\n path.join(cacheDir, cacheKey),\n JSON.stringify({\n ...out,\n hash: generateCacheHash(value),\n } satisfies CacheEntry),\n );\n };\n }\n\n const collection = collectionName ? core.getCollection(collectionName) : undefined;\n\n let docCollection: DocCollectionItem | undefined;\n switch (collection?.type) {\n case 'doc':\n docCollection = collection;\n break;\n case 'docs':\n docCollection = collection.docs;\n break;\n }\n\n if (docCollection) {\n matter.data = await core.transformFrontmatter(\n { collection: docCollection, filePath, source: value },\n matter.data as Record<string, unknown>,\n );\n }\n\n if (only === 'frontmatter') {\n return {\n code: `export const frontmatter = ${JSON.stringify(matter.data)}`,\n map: null,\n };\n }\n\n const { buildMDX } = await import('@/loaders/mdx/build-mdx');\n const compiled = await buildMDX(core, docCollection, {\n isDevelopment,\n // ensure the line number is correct in errors\n source: '\\n'.repeat(countLines(matter.matter)) + matter.content,\n filePath,\n frontmatter: matter.data as Record<string, unknown>,\n _compiler: compiler,\n environment: 'bundler',\n });\n\n const out = {\n code: String(compiled.value),\n map: compiled.map,\n };\n\n await after?.();\n return out;\n },\n };\n}\n\nfunction generateCacheHash(input: string): string {\n return createHash('md5').update(input).digest('hex');\n}\n\nfunction countLines(s: string) {\n let num = 0;\n\n for (const c of s) {\n if (c === '\\n') num++;\n }\n\n return num;\n}\n"],"mappings":";;;;;;;AAUA,MAAM,cAAc,EAAE,YAAY;CAChC,MAAM,EAAE,QAAQ,CAAC,eAAe,MAAM,CAAC,CAAC,QAAQ,MAAM;CACtD,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC;AAEF,MAAM,aAAa,EAAE,OAAO;CAC1B,MAAM,EAAE,QAAQ;CAChB,KAAK,EAAE,KAAK,CAAC,UAAU;CACvB,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC5B,CAAC;AAIF,SAAgB,gBAAgB,EAAE,WAAiC;AACjE,QAAO;EACL,MAAM;EACN,MAAM,KAAK,EAAE,WAAW,aAAa,eAAe,OAAO,UAAU,YAAY;GAC/E,IAAI,OAAO,MAAM,SAAS;GAC1B,MAAM,QAAQ,MAAM,WAAW;GAC/B,MAAM,SAAS,WAAW,MAAM;GAChC,MAAM,EAAE,YAAY,gBAAgB,WAAW,SAAS,YAAY,MAAM,MAAM;AAChF,OAAI,UACF,QAAO,KAAK,eAAe,CAAC,IAAI,UAAU,IAAI;GAGhD,IAAI;GAEJ,MAAM,EAAE,yBAAyB,UAAU,KAAK,WAAW,CAAC;AAC5D,OAAI,CAAC,iBAAiB,wBAAwB;IAC5C,MAAM,WAAW;IACjB,MAAM,WAAW,GAAG,kBAAkB,SAAS,GAAG,kBAAkB,SAAS;IAE7E,MAAM,SAAS,MAAM,GAClB,SAAS,KAAK,KAAK,UAAU,SAAS,CAAC,CACvC,MAAM,YAAY,WAAW,MAAM,KAAK,MAAM,QAAQ,UAAU,CAAC,CAAC,CAAC,CACnE,YAAY,KAAK;AAEpB,QAAI,UAAU,OA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["../src/loaders/meta.ts"],"sourcesContent":["import type { Loader, LoaderInput } from '@/loaders/adapter';\nimport type { ConfigLoader } from '@/loaders/config';\nimport { load } from 'js-yaml';\nimport { z } from 'zod';\nimport { metaLoaderGlob } from '.';\nimport type { MetaCollectionItem } from '@/config/build';\n\nconst querySchema = z.looseObject({\n collection: z.string().optional(),\n workspace: z.string().optional(),\n});\n\n/**\n * load meta files, fallback to bundler's built-in plugins when ?collection is unspecified.\n */\nexport function createMetaLoader(\n { getCore }: ConfigLoader,\n resolve: {\n json?: 'json' | 'js';\n yaml?: 'js';\n } = {},\n): Loader {\n const { json: resolveJson = 'js' } = resolve;\n\n function parse(filePath: string, source: string) {\n try {\n if (filePath.endsWith('.json')) return JSON.parse(source);\n if (filePath.endsWith('.yaml')) return load(source);\n } catch (e) {\n throw new Error(`invalid data in ${filePath}`, { cause: e });\n }\n\n throw new Error('Unknown file type ' + filePath);\n }\n\n function onMeta(source: string, { filePath, query }: LoaderInput) {\n const parsed = querySchema.safeParse(query);\n if (!parsed.success || !parsed.data.collection) return null;\n const { collection: collectionName, workspace } = parsed.data;\n\n return async (): Promise<unknown> => {\n let core = await getCore();\n if (workspace) {\n core = core.getWorkspaces().get(workspace) ?? core;\n }\n\n const collection = core.getCollection(collectionName);\n let metaCollection: MetaCollectionItem | undefined;\n\n switch (collection?.type) {\n case 'meta':\n metaCollection = collection;\n break;\n case 'docs':\n metaCollection = collection.meta;\n break;\n }\n\n const data = parse(filePath, source);\n\n if (!metaCollection) return data;\n return core.transformMeta(\n {\n collection: metaCollection,\n filePath,\n source,\n },\n data,\n );\n };\n }\n\n return {\n test: metaLoaderGlob,\n async load(input) {\n const result = onMeta(await input.getSource(), input);\n if (result === null) return null;\n const data = await result();\n\n if (input.filePath.endsWith('.json')) {\n return {\n moduleType: resolveJson,\n code:\n resolveJson === 'json'\n ? JSON.stringify(data)\n : `export default ${JSON.stringify(data)}`,\n };\n } else {\n return {\n moduleType: 'js',\n code: `export default ${JSON.stringify(data)}`,\n };\n }\n },\n bun: {\n load(source, input) {\n const result = onMeta(source, input);\n if (result === null)\n return {\n loader: 'object',\n exports: parse(input.filePath, source),\n };\n\n return result().then((data) => ({\n loader: 'object',\n exports: { default: data },\n }));\n },\n },\n };\n}\n"],"mappings":";;;;AAOA,MAAM,cAAc,EAAE,YAAY;CAChC,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,WAAW,EAAE,QAAQ,CAAC,UAAU;CACjC,CAAC;;;;AAKF,SAAgB,iBACd,EAAE,WACF,UAGI,EAAE,EACE;CACR,MAAM,EAAE,MAAM,cAAc,SAAS;CAErC,SAAS,MAAM,UAAkB,QAAgB;AAC/C,MAAI;AACF,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,MAAM,OAAO;AACzD,OAAI,SAAS,SAAS,QAAQ,CAAE,QAAO,KAAK,OAAO;WAC5C,GAAG;AACV,SAAM,IAAI,MAAM,mBAAmB,YAAY,EAAE,OAAO,GAAG,CAAC;;AAG9D,QAAM,IAAI,MAAM,uBAAuB,SAAS;;CAGlD,SAAS,OAAO,QAAgB,EAAE,UAAU,SAAsB;EAChE,MAAM,SAAS,YAAY,UAAU,MAAM;AAC3C,MAAI,CAAC,OAAO,WAAW,CAAC,OAAO,KAAK,WAAY,QAAO;EACvD,MAAM,EAAE,YAAY,gBAAgB,cAAc,OAAO;AAEzD,SAAO,YAA8B;GACnC,IAAI,OAAO,MAAM,SAAS;AAC1B,OAAI,UACF,QAAO,KAAK,eAAe,CAAC,IAAI,UAAU,IAAI;GAGhD,MAAM,aAAa,KAAK,cAAc,eAAe;GACrD,IAAI;AAEJ,WAAQ,YAAY,MAApB;IACE,KAAK;AACH,sBAAiB;AACjB;IACF,KAAK;AACH,sBAAiB,WAAW;AAC5B;;GAGJ,MAAM,OAAO,MAAM,UAAU,OAAO;AAEpC,OAAI,CAAC,eAAgB,QAAO;AAC5B,UAAO,KAAK,cACV;IACE,YAAY;IACZ;IACA;IACD,EACD,KACD;;;AAIL,QAAO;EACL,MAAM;EACN,MAAM,KAAK,OAAO;GAChB,MAAM,SAAS,OAAO,MAAM,MAAM,WAAW,EAAE,MAAM;AACrD,OAAI,WAAW,KAAM,QAAO;GAC5B,MAAM,OAAO,MAAM,QAAQ;AAE3B,OAAI,MAAM,SAAS,SAAS,QAAQ,CAClC,QAAO;IACL,YAAY;IACZ,MACE,gBAAgB,SACZ,KAAK,UAAU,KAAK,GACpB,kBAAkB,KAAK,UAAU,KAAK;IAC7C;OAED,QAAO;IACL,YAAY;IACZ,MAAM,kBAAkB,KAAK,UAAU,KAAK;IAC7C;;EAGL,KAAK,EACH,KAAK,QAAQ,OAAO;GAClB,MAAM,SAAS,OAAO,QAAQ,MAAM;AACpC,OAAI,WAAW,KACb,QAAO;IACL,QAAQ;IACR,SAAS,MAAM,MAAM,UAAU,OAAO;IACvC;AAEH,UAAO,QAAQ,CAAC,MAAM,UAAU;IAC9B,QAAQ;IACR,SAAS,EAAE,SAAS,MAAM;IAC3B,EAAE;KAEN;EACF"}
|
package/dist/next/index.cjs
CHANGED
package/dist/next/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-BauN_my2.js";
|
|
2
2
|
import { n as createCore, t as _Defaults } from "../core-BluWnx7f.js";
|
|
3
|
-
import { t as loadConfig } from "../load-from-file-
|
|
3
|
+
import { t as loadConfig } from "../load-from-file-CEpo5Sqi.js";
|
|
4
4
|
import { t as indexFile } from "../index-file-4qOxhCQn.js";
|
|
5
5
|
import * as path$1 from "node:path";
|
|
6
6
|
//#region src/next/index.ts
|
package/dist/node/loader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cd17PhOW.js";
|
|
2
2
|
import { n as createCore, t as _Defaults } from "../core-BluWnx7f.js";
|
|
3
|
-
import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-
|
|
4
|
-
import { t as createMetaLoader } from "../meta-
|
|
3
|
+
import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-CrnPUO1X.js";
|
|
4
|
+
import { t as createMetaLoader } from "../meta-DV1ZTafU.js";
|
|
5
5
|
//#region src/node/loader.ts
|
|
6
6
|
const configLoader = createStandaloneConfigLoader({
|
|
7
7
|
core: createCore({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-include-CgjB4_2e.js","names":["fs","path"],"sources":["../src/loaders/mdx/remark-unravel.ts","../src/loaders/mdx/mdast-utils.ts","../src/loaders/mdx/remark-include.ts"],"sourcesContent":["// from internal remark plugins in https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/remark-mark-and-unravel.js\n// we need to ensure consistency with MDX.js when parsing embed content in `remark-include`\nimport { visit } from 'unist-util-visit';\nimport type { Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\n\nexport function remarkMarkAndUnravel(): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, function (node, index, parent) {\n let offset = -1;\n let all = true;\n let oneOrMore = false;\n\n if (parent && typeof index === 'number' && node.type === 'paragraph') {\n const children = node.children;\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement' || child.type === 'mdxTextExpression') {\n oneOrMore = true;\n } else if (child.type === 'text' && child.value.trim().length === 0) {\n // Empty.\n } else {\n all = false;\n break;\n }\n }\n\n if (all && oneOrMore) {\n offset = -1;\n const newChildren: RootContent[] = [];\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxJsxFlowElement';\n }\n\n if (child.type === 'mdxTextExpression') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxFlowExpression';\n }\n\n if (child.type === 'text' && /^[\\t\\r\\n ]+$/.test(String(child.value))) {\n // Empty.\n } else {\n newChildren.push(child);\n }\n }\n\n parent.children.splice(index, 1, ...newChildren);\n return index;\n }\n }\n });\n };\n}\n","import type { RootContent } from 'mdast';\n\nexport function flattenNode(node: RootContent): string {\n if ('children' in node) return node.children.map((child) => flattenNode(child)).join('');\n\n if ('value' in node) return node.value;\n\n return '';\n}\n","import { type Processor, type Transformer, unified } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { Code, Node, Root, RootContent } from 'mdast';\nimport * as path from 'node:path';\nimport * as fs from 'node:fs/promises';\nimport { fumaMatter } from '@/utils/fuma-matter';\nimport type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';\nimport { remarkHeading } from 'fumadocs-core/mdx-plugins';\nimport { VFile } from 'vfile';\nimport type { Directives } from 'mdast-util-directive';\nimport { remarkMarkAndUnravel } from '@/loaders/mdx/remark-unravel';\nimport { flattenNode } from './mdast-utils';\n\n/**\n * VS Code–style region extraction\n * Adapted from VitePress:\n * https://github.com/vuejs/vitepress/blob/main/src/node/markdown/plugins/snippet.ts\n */\n\n// region marker regexes\nconst REGION_MARKERS = [\n {\n start: /^\\s*\\/\\/\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*\\/\\/\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*<!--\\s*#?region\\b\\s*(.*?)\\s*-->/,\n end: /^\\s*<!--\\s*#?endregion\\b\\s*(.*?)\\s*-->/,\n },\n {\n start: /^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\//,\n end: /^\\s*\\/\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\//,\n },\n {\n start: /^\\s*#[rR]egion\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#[eE]nd ?[rR]egion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*(?:--|::|@?REM)\\s*#region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*(?:--|::|@?REM)\\s*#endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#pragma\\s+region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#pragma\\s+endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*\\(\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\)/,\n end: /^\\s*\\(\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\)/,\n },\n];\n\nfunction dedent(lines: string[]): string {\n const minIndent = lines.reduce((min, line) => {\n const match = line.match(/^(\\s*)\\S/);\n return match ? Math.min(min, match[1].length) : min;\n }, Infinity);\n\n return minIndent === Infinity\n ? lines.join('\\n')\n : lines.map((l) => l.slice(minIndent)).join('\\n');\n}\n\nfunction extractCodeRegion(content: string, regionName: string): string {\n const lines = content.split('\\n');\n\n for (let i = 0; i < lines.length; i++) {\n for (const re of REGION_MARKERS) {\n let match = re.start.exec(lines[i]);\n if (match?.[1] !== regionName) continue;\n\n let depth = 1;\n const extractedLines: string[] = [];\n for (let j = i + 1; j < lines.length; j++) {\n match = re.start.exec(lines[j]);\n if (match) {\n depth++;\n continue;\n }\n\n match = re.end.exec(lines[j]);\n if (match) {\n if (match[1] === regionName) depth = 0;\n else if (match[1] === '') depth--;\n else continue;\n\n if (depth > 0) continue;\n return dedent(extractedLines);\n } else {\n extractedLines.push(lines[j]);\n }\n }\n }\n }\n throw new Error(`Region \"${regionName}\" not found`);\n}\n\nexport interface Params {\n lang?: string;\n meta?: string;\n}\n\nconst ElementLikeTypes: ElementLikeContent['type'][] = [\n 'mdxJsxFlowElement',\n 'mdxJsxTextElement',\n 'containerDirective',\n 'textDirective',\n 'leafDirective',\n];\ntype ElementLikeContent = MdxJsxFlowElement | MdxJsxTextElement | Directives;\n\nfunction isElementLike(node: Node): node is ElementLikeContent {\n return ElementLikeTypes.includes(node.type as ElementLikeContent['type']);\n}\n\nfunction parseElementAttributes(\n element: ElementLikeContent,\n): Record<string, string | null | undefined> {\n if (Array.isArray(element.attributes)) {\n const attributes: Record<string, string | null> = {};\n\n for (const attr of element.attributes) {\n if (\n attr.type === 'mdxJsxAttribute' &&\n (typeof attr.value === 'string' || attr.value === null)\n ) {\n attributes[attr.name] = attr.value;\n }\n }\n\n return attributes;\n }\n\n return element.attributes ?? {};\n}\n\nfunction parseSpecifier(specifier: string): {\n file: string;\n section?: string;\n} {\n const idx = specifier.lastIndexOf('#');\n if (idx === -1) return { file: specifier };\n\n return {\n file: specifier.slice(0, idx),\n section: specifier.slice(idx + 1),\n };\n}\n\nfunction extractSection(root: Root, section: string): Root | undefined {\n let nodes: RootContent[] | undefined;\n let capturingHeadingContent = false;\n\n visit(root, (node) => {\n if (node.type === 'heading') {\n if (capturingHeadingContent) {\n return false;\n }\n\n if (node.data?.hProperties?.id === section) {\n capturingHeadingContent = true;\n nodes = [node];\n return 'skip';\n }\n\n return;\n }\n\n if (capturingHeadingContent) {\n nodes?.push(node as RootContent);\n return 'skip';\n }\n\n if (isElementLike(node) && node.name === 'section') {\n const attributes = parseElementAttributes(node);\n\n if (attributes.id === section) {\n nodes = node.children;\n return false;\n }\n }\n });\n\n if (nodes)\n return {\n type: 'root',\n children: nodes,\n };\n}\n\nexport function remarkInclude(this: Processor): Transformer<Root, Root> {\n const TagName = 'include';\n\n const embedContent = async (\n targetPath: string,\n heading: string | undefined,\n params: Params,\n parent: VFile,\n ) => {\n const { _getProcessor = () => this, _compiler } = parent.data;\n let content: string;\n try {\n content = await fs.readFile(targetPath, 'utf-8');\n } catch (e) {\n throw new Error(\n `failed to read file ${targetPath}\\n${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n );\n }\n\n const ext = path.extname(targetPath);\n _compiler?.addDependency(targetPath);\n // For non-Markdown files, support VS Code–style region extraction\n if (params.lang || (ext !== '.md' && ext !== '.mdx')) {\n const lang = params.lang ?? ext.slice(1);\n let value = content;\n if (heading) {\n value = extractCodeRegion(content, heading.trim());\n }\n return {\n type: 'code',\n lang,\n meta: params.meta,\n value,\n data: {},\n } satisfies Code;\n }\n\n const parser = _getProcessor(ext === '.mdx' ? 'mdx' : 'md');\n const parsed = fumaMatter(content);\n const targetFile = new VFile({\n path: targetPath,\n value: parsed.content,\n data: {\n ...parent.data,\n frontmatter: parsed.data as Record<string, unknown>,\n },\n });\n let mdast = parser.parse(targetFile) as Root;\n const baseProcessor = unified().use(remarkMarkAndUnravel);\n\n if (heading) {\n // parse headings before extraction\n const extracted = extractSection(await baseProcessor.use(remarkHeading).run(mdast), heading);\n if (!extracted)\n throw new Error(\n `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id=\"${heading}\"> tag, or a :::section directive with remark-directive configured.`,\n );\n\n mdast = extracted;\n } else {\n mdast = await baseProcessor.run(mdast);\n }\n\n await update(mdast, targetFile);\n return mdast;\n };\n\n async function update(tree: Root, file: VFile) {\n const queue: Promise<void>[] = [];\n\n visit(tree, ElementLikeTypes, (_node, _, parent) => {\n const node = _node as ElementLikeContent;\n if (node.name !== TagName) return;\n\n const specifier = flattenNode(node);\n if (specifier.length === 0) return 'skip';\n\n const attributes = parseElementAttributes(node);\n const { file: relativePath, section } = parseSpecifier(specifier);\n const targetPath = path.resolve('cwd' in attributes ? file.cwd : file.dirname!, relativePath);\n\n queue.push(\n embedContent(targetPath, section, attributes, file).then((replace) => {\n Object.assign(parent && parent.type === 'paragraph' ? parent : node, replace);\n }),\n );\n\n return 'skip';\n });\n\n await Promise.all(queue);\n }\n\n return async (tree, file) => {\n await update(tree, file);\n };\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,uBAAgD;AAC9D,SAAQ,SAAS;AACf,QAAM,MAAM,SAAU,MAAM,OAAO,QAAQ;GACzC,IAAI,SAAS;GACb,IAAI,MAAM;GACV,IAAI,YAAY;AAEhB,OAAI,UAAU,OAAO,UAAU,YAAY,KAAK,SAAS,aAAa;IACpE,MAAM,WAAW,KAAK;AAEtB,WAAO,EAAE,SAAS,SAAS,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MKDvrK.js","names":["fs","path"],"sources":["../src/loaders/mdx/remark-unravel.ts","../src/loaders/mdx/mdast-utils.ts","../src/loaders/mdx/remark-include.ts"],"sourcesContent":["// from internal remark plugins in https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/remark-mark-and-unravel.js\n// we need to ensure consistency with MDX.js when parsing embed content in `remark-include`\nimport { visit } from 'unist-util-visit';\nimport type { Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\n\nexport function remarkMarkAndUnravel(): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, function (node, index, parent) {\n let offset = -1;\n let all = true;\n let oneOrMore = false;\n\n if (parent && typeof index === 'number' && node.type === 'paragraph') {\n const children = node.children;\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement' || child.type === 'mdxTextExpression') {\n oneOrMore = true;\n } else if (child.type === 'text' && child.value.trim().length === 0) {\n // Empty.\n } else {\n all = false;\n break;\n }\n }\n\n if (all && oneOrMore) {\n offset = -1;\n const newChildren: RootContent[] = [];\n\n while (++offset < children.length) {\n const child = children[offset];\n\n if (child.type === 'mdxJsxTextElement') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxJsxFlowElement';\n }\n\n if (child.type === 'mdxTextExpression') {\n // @ts-expect-error: mutate because it is faster; content model is fine.\n child.type = 'mdxFlowExpression';\n }\n\n if (child.type === 'text' && /^[\\t\\r\\n ]+$/.test(String(child.value))) {\n // Empty.\n } else {\n newChildren.push(child);\n }\n }\n\n parent.children.splice(index, 1, ...newChildren);\n return index;\n }\n }\n });\n };\n}\n","import type { RootContent } from 'mdast';\n\nexport function flattenNode(node: RootContent): string {\n if ('children' in node) return node.children.map((child) => flattenNode(child)).join('');\n\n if ('value' in node) return node.value;\n\n return '';\n}\n","import { type Processor, type Transformer, unified } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { Code, Node, Root, RootContent } from 'mdast';\nimport * as path from 'node:path';\nimport * as fs from 'node:fs/promises';\nimport { fumaMatter } from '@/utils/fuma-matter';\nimport type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';\nimport { remarkHeading } from 'fumadocs-core/mdx-plugins';\nimport { VFile } from 'vfile';\nimport type { Directives } from 'mdast-util-directive';\nimport { remarkMarkAndUnravel } from '@/loaders/mdx/remark-unravel';\nimport { flattenNode } from './mdast-utils';\n\n/**\n * VS Code–style region extraction\n * Adapted from VitePress:\n * https://github.com/vuejs/vitepress/blob/main/src/node/markdown/plugins/snippet.ts\n */\n\n// region marker regexes\nconst REGION_MARKERS = [\n {\n start: /^\\s*\\/\\/\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*\\/\\/\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*<!--\\s*#?region\\b\\s*(.*?)\\s*-->/,\n end: /^\\s*<!--\\s*#?endregion\\b\\s*(.*?)\\s*-->/,\n },\n {\n start: /^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\//,\n end: /^\\s*\\/\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\//,\n },\n {\n start: /^\\s*#[rR]egion\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#[eE]nd ?[rR]egion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#\\s*#?region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#\\s*#?endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*(?:--|::|@?REM)\\s*#region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*(?:--|::|@?REM)\\s*#endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*#pragma\\s+region\\b\\s*(.*?)\\s*$/,\n end: /^\\s*#pragma\\s+endregion\\b\\s*(.*?)\\s*$/,\n },\n {\n start: /^\\s*\\(\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\)/,\n end: /^\\s*\\(\\*\\s*#endregion\\b\\s*(.*?)\\s*\\*\\)/,\n },\n];\n\nfunction dedent(lines: string[]): string {\n const minIndent = lines.reduce((min, line) => {\n const match = line.match(/^(\\s*)\\S/);\n return match ? Math.min(min, match[1].length) : min;\n }, Infinity);\n\n return minIndent === Infinity\n ? lines.join('\\n')\n : lines.map((l) => l.slice(minIndent)).join('\\n');\n}\n\nfunction extractCodeRegion(content: string, regionName: string): string {\n const lines = content.split('\\n');\n\n for (let i = 0; i < lines.length; i++) {\n for (const re of REGION_MARKERS) {\n let match = re.start.exec(lines[i]);\n if (match?.[1] !== regionName) continue;\n\n let depth = 1;\n const extractedLines: string[] = [];\n for (let j = i + 1; j < lines.length; j++) {\n match = re.start.exec(lines[j]);\n if (match) {\n depth++;\n continue;\n }\n\n match = re.end.exec(lines[j]);\n if (match) {\n if (match[1] === regionName) depth = 0;\n else if (match[1] === '') depth--;\n else continue;\n\n if (depth > 0) continue;\n return dedent(extractedLines);\n } else {\n extractedLines.push(lines[j]);\n }\n }\n }\n }\n throw new Error(`Region \"${regionName}\" not found`);\n}\n\nexport interface Params {\n lang?: string;\n meta?: string;\n}\n\nconst ElementLikeTypes: ElementLikeContent['type'][] = [\n 'mdxJsxFlowElement',\n 'mdxJsxTextElement',\n 'containerDirective',\n 'textDirective',\n 'leafDirective',\n];\ntype ElementLikeContent = MdxJsxFlowElement | MdxJsxTextElement | Directives;\n\nfunction isElementLike(node: Node): node is ElementLikeContent {\n return ElementLikeTypes.includes(node.type as ElementLikeContent['type']);\n}\n\nfunction parseElementAttributes(\n element: ElementLikeContent,\n): Record<string, string | null | undefined> {\n if (Array.isArray(element.attributes)) {\n const attributes: Record<string, string | null> = {};\n\n for (const attr of element.attributes) {\n if (\n attr.type === 'mdxJsxAttribute' &&\n (typeof attr.value === 'string' || attr.value === null)\n ) {\n attributes[attr.name] = attr.value;\n }\n }\n\n return attributes;\n }\n\n return element.attributes ?? {};\n}\n\nfunction parseSpecifier(specifier: string): {\n file: string;\n section?: string;\n} {\n const idx = specifier.lastIndexOf('#');\n if (idx === -1) return { file: specifier };\n\n return {\n file: specifier.slice(0, idx),\n section: specifier.slice(idx + 1),\n };\n}\n\nfunction extractSection(root: Root, section: string): Root | undefined {\n let nodes: RootContent[] | undefined;\n let capturingHeadingContent = false;\n\n visit(root, (node) => {\n if (node.type === 'heading') {\n if (capturingHeadingContent) {\n return false;\n }\n\n if (node.data?.hProperties?.id === section) {\n capturingHeadingContent = true;\n nodes = [node];\n return 'skip';\n }\n\n return;\n }\n\n if (capturingHeadingContent) {\n nodes?.push(node as RootContent);\n return 'skip';\n }\n\n if (isElementLike(node) && node.name === 'section') {\n const attributes = parseElementAttributes(node);\n\n if (attributes.id === section) {\n nodes = node.children;\n return false;\n }\n }\n });\n\n if (nodes)\n return {\n type: 'root',\n children: nodes,\n };\n}\n\nexport function remarkInclude(this: Processor): Transformer<Root, Root> {\n const TagName = 'include';\n\n const embedContent = async (\n targetPath: string,\n heading: string | undefined,\n params: Params,\n parent: VFile,\n ) => {\n const { _getProcessor = () => this, _compiler } = parent.data;\n let content: string;\n try {\n content = await fs.readFile(targetPath, 'utf-8');\n } catch (e) {\n throw new Error(\n `failed to read file ${targetPath}\\n${e instanceof Error ? e.message : String(e)}`,\n { cause: e },\n );\n }\n\n const ext = path.extname(targetPath);\n _compiler?.addDependency(targetPath);\n // For non-Markdown files, support VS Code–style region extraction\n if (params.lang || (ext !== '.md' && ext !== '.mdx')) {\n const lang = params.lang ?? ext.slice(1);\n let value = content;\n if (heading) {\n value = extractCodeRegion(content, heading.trim());\n }\n return {\n type: 'code',\n lang,\n meta: params.meta,\n value,\n data: {},\n } satisfies Code;\n }\n\n const parser = _getProcessor(ext === '.mdx' ? 'mdx' : 'md');\n const parsed = fumaMatter(content);\n const targetFile = new VFile({\n path: targetPath,\n value: parsed.content,\n data: {\n ...parent.data,\n frontmatter: parsed.data as Record<string, unknown>,\n },\n });\n let mdast = parser.parse(targetFile) as Root;\n const baseProcessor = unified().use(remarkMarkAndUnravel);\n\n if (heading) {\n // parse headings before extraction\n const extracted = extractSection(await baseProcessor.use(remarkHeading).run(mdast), heading);\n if (!extracted)\n throw new Error(\n `Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id=\"${heading}\"> tag, or a :::section directive with remark-directive configured.`,\n );\n\n mdast = extracted;\n } else {\n mdast = await baseProcessor.run(mdast);\n }\n\n await update(mdast, targetFile);\n return mdast;\n };\n\n async function update(tree: Root, file: VFile) {\n const queue: Promise<void>[] = [];\n\n visit(tree, ElementLikeTypes, (_node, _, parent) => {\n const node = _node as ElementLikeContent;\n if (node.name !== TagName) return;\n\n const specifier = flattenNode(node);\n if (specifier.length === 0) return 'skip';\n\n const attributes = parseElementAttributes(node);\n const { file: relativePath, section } = parseSpecifier(specifier);\n const targetPath = path.resolve('cwd' in attributes ? file.cwd : file.dirname!, relativePath);\n\n queue.push(\n embedContent(targetPath, section, attributes, file).then((replace) => {\n Object.assign(parent && parent.type === 'paragraph' ? parent : node, replace);\n }),\n );\n\n return 'skip';\n });\n\n await Promise.all(queue);\n }\n\n return async (tree, file) => {\n await update(tree, file);\n };\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,uBAAgD;AAC9D,SAAQ,SAAS;AACf,QAAM,MAAM,SAAU,MAAM,OAAO,QAAQ;GACzC,IAAI,SAAS;GACb,IAAI,MAAM;GACV,IAAI,YAAY;AAEhB,OAAI,UAAU,OAAO,UAAU,YAAY,KAAK,SAAS,aAAa;IACpE,MAAM,WAAW,KAAK;AAEtB,WAAO,EAAE,SAAS,SAAS,QAAQ;KACjC,MAAM,QAAQ,SAAS;AAEvB,SAAI,MAAM,SAAS,uBAAuB,MAAM,SAAS,oBACvD,aAAY;cACH,MAAM,SAAS,UAAU,MAAM,MAAM,MAAM,CAAC,WAAW,GAAG,QAE9D;AACL,YAAM;AACN;;;AAIJ,QAAI,OAAO,WAAW;AACpB,cAAS;KACT,MAAM,cAA6B,EAAE;AAErC,YAAO,EAAE,SAAS,SAAS,QAAQ;MACjC,MAAM,QAAQ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atter } from "../fuma-matter-Fge-qpw1.js";
|
|
2
2
|
import { t as buildConfig } from "../build-DxkMdv29.js";
|
|
3
3
|
import { n as createCore } from "../core-BluWnx7f.js";
|
|
4
|
-
import { t as buildMDX } from "../build-mdx-
|
|
4
|
+
import { t as buildMDX } from "../build-mdx-iu_4pINO.js";
|
|
5
5
|
import { server } from "./server.js";
|
|
6
6
|
import fs from "node:fs/promises";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
|
-
import
|
|
8
|
+
import jsxRuntimeDefault from "react/jsx-runtime";
|
|
9
9
|
//#region src/runtime/dynamic.ts
|
|
10
|
+
const AsyncFunction = Object.getPrototypeOf(executeMdx).constructor;
|
|
11
|
+
/** we always assume the input code is safe and execute it directly */
|
|
12
|
+
async function executeMdx(compiled, options = {}) {
|
|
13
|
+
const { opts: scopeOpts, ...scope } = options.scope ?? {};
|
|
14
|
+
const fullScope = {
|
|
15
|
+
opts: {
|
|
16
|
+
...scopeOpts,
|
|
17
|
+
...options.jsxRuntime ?? jsxRuntimeDefault,
|
|
18
|
+
baseUrl: options.baseUrl
|
|
19
|
+
},
|
|
20
|
+
...scope
|
|
21
|
+
};
|
|
22
|
+
const hydrateFn = new AsyncFunction(...Object.keys(fullScope), compiled);
|
|
23
|
+
return await hydrateFn.apply(hydrateFn, Object.values(fullScope));
|
|
24
|
+
}
|
|
10
25
|
async function dynamic(configExports, coreOptions, serverOptions) {
|
|
11
26
|
const core = createCore(coreOptions);
|
|
12
27
|
await core.init({ config: buildConfig(configExports) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic.js","names":[],"sources":["../../src/runtime/dynamic.ts"],"sourcesContent":["import { buildConfig, type DocCollectionItem } from '@/config/build';\nimport { buildMDX, type CompiledMDXProperties } from '@/loaders/mdx/build-mdx';\nimport {
|
|
1
|
+
{"version":3,"file":"dynamic.js","names":[],"sources":["../../src/runtime/dynamic.ts"],"sourcesContent":["import { buildConfig, type DocCollectionItem } from '@/config/build';\nimport { buildMDX, type CompiledMDXProperties } from '@/loaders/mdx/build-mdx';\nimport { pathToFileURL } from 'node:url';\nimport { fumaMatter } from '@/utils/fuma-matter';\nimport fs from 'node:fs/promises';\nimport { server, type ServerOptions } from './server';\nimport { type CoreOptions, createCore } from '@/core';\nimport type { FileInfo, InternalTypeConfig } from './types';\nimport jsxRuntimeDefault from 'react/jsx-runtime';\n\nexport interface LazyEntry<Data = unknown> {\n info: FileInfo;\n data: Data;\n\n hash?: string;\n}\n\nexport type CreateDynamic<Config, TC extends InternalTypeConfig = InternalTypeConfig> = ReturnType<\n typeof dynamic<Config, TC>\n>;\n\ninterface ExecuteOptions {\n scope?: Record<string, unknown>;\n baseUrl?: string | URL;\n jsxRuntime?: unknown;\n}\n\nconst AsyncFunction: new (...args: string[]) => (...args: unknown[]) => Promise<unknown> =\n Object.getPrototypeOf(executeMdx).constructor;\n\n/** we always assume the input code is safe and execute it directly */\nasync function executeMdx(compiled: string, options: ExecuteOptions = {}) {\n const { opts: scopeOpts, ...scope } = options.scope ?? {};\n const fullScope = {\n opts: {\n ...(scopeOpts as object),\n ...(options.jsxRuntime ?? jsxRuntimeDefault),\n baseUrl: options.baseUrl,\n },\n ...scope,\n };\n\n const hydrateFn = new AsyncFunction(...Object.keys(fullScope), compiled);\n return await hydrateFn.apply(hydrateFn, Object.values(fullScope));\n}\n\nexport async function dynamic<Config, TC extends InternalTypeConfig>(\n configExports: Config,\n coreOptions: CoreOptions,\n serverOptions?: ServerOptions,\n) {\n const core = createCore(coreOptions);\n await core.init({\n config: buildConfig(configExports as Record<string, unknown>),\n });\n\n const create = server<Config, TC>(serverOptions);\n\n function getDocCollection(name: string): DocCollectionItem | undefined {\n const collection = core.getCollection(name);\n if (!collection) return;\n\n if (collection.type === 'docs') return collection.docs;\n else if (collection.type === 'doc') return collection;\n }\n\n function convertLazyEntries(collection: DocCollectionItem, entries: LazyEntry[]) {\n const head: Record<string, () => unknown> = {};\n const body: Record<string, () => Promise<unknown>> = {};\n\n async function compile({ info, data }: LazyEntry<unknown>) {\n let content = await fs.readFile(info.fullPath, 'utf-8');\n content = fumaMatter(content).content;\n\n const compiled = await buildMDX(core, collection, {\n filePath: info.fullPath,\n source: content,\n frontmatter: data as Record<string, unknown>,\n isDevelopment: false,\n environment: 'runtime',\n });\n\n return (await executeMdx(String(compiled.value), {\n baseUrl: pathToFileURL(info.fullPath),\n })) as CompiledMDXProperties;\n }\n\n for (const entry of entries) {\n head[entry.info.path] = () => entry.data;\n let cachedResult: Promise<CompiledMDXProperties> | undefined;\n body[entry.info.path] = () => (cachedResult ??= compile(entry));\n }\n\n return { head, body };\n }\n\n return {\n async doc<Name extends keyof Config & string>(\n name: Name,\n base: string,\n entries: LazyEntry<unknown>[],\n ) {\n const collection = getDocCollection(name as string);\n if (!collection) throw new Error(`the doc collection ${name as string} doesn't exist.`);\n\n const { head, body } = convertLazyEntries(collection, entries);\n\n return create.docLazy(name, base, head, body);\n },\n async docs<Name extends keyof Config & string>(\n name: Name,\n base: string,\n meta: Record<string, unknown>,\n entries: LazyEntry<unknown>[],\n ) {\n const collection = getDocCollection(name as string);\n if (!collection) throw new Error(`the doc collection ${name as string} doesn't exist.`);\n\n const docs = convertLazyEntries(collection, entries);\n return create.docsLazy(name, base, meta, docs.head, docs.body);\n },\n };\n}\n"],"mappings":";;;;;;;;;AA2BA,MAAM,gBACJ,OAAO,eAAe,WAAW,CAAC;;AAGpC,eAAe,WAAW,UAAkB,UAA0B,EAAE,EAAE;CACxE,MAAM,EAAE,MAAM,WAAW,GAAG,UAAU,QAAQ,SAAS,EAAE;CACzD,MAAM,YAAY;EAChB,MAAM;GACJ,GAAI;GACJ,GAAI,QAAQ,cAAc;GAC1B,SAAS,QAAQ;GAClB;EACD,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,cAAc,GAAG,OAAO,KAAK,UAAU,EAAE,SAAS;AACxE,QAAO,MAAM,UAAU,MAAM,WAAW,OAAO,OAAO,UAAU,CAAC;;AAGnE,eAA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CAAC,WAAY,OAAM,IAAI,MAAM,sBAAsB,KAAe,iBAAiB;GAEvF,MAAM,OAAO,mBAAmB,YAAY,QAAQ;AACpD,UAAO,OAAO,SAAS,MAAM,MAAM,MAAM,KAAK,MAAM,KAAK,KAAK;;EAEjE"}
|
package/dist/vite/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cd17PhOW.js";
|
|
2
2
|
import { t as buildConfig } from "../build-DxkMdv29.js";
|
|
3
3
|
import { n as createCore, r as ValidationError, t as _Defaults } from "../core-BluWnx7f.js";
|
|
4
|
-
import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-
|
|
5
|
-
import { t as createMetaLoader } from "../meta-
|
|
4
|
+
import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-CrnPUO1X.js";
|
|
5
|
+
import { t as createMetaLoader } from "../meta-DV1ZTafU.js";
|
|
6
6
|
import { t as indexFile } from "../index-file-4qOxhCQn.js";
|
|
7
7
|
import { mergeConfig } from "vite";
|
|
8
8
|
//#region src/vite/index.ts
|
|
@@ -51,7 +51,7 @@ async function mdx(config, pluginOptions = {}) {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
async function postInstall(pluginOptions = {}) {
|
|
54
|
-
const { loadConfig } = await import("../load-from-file-
|
|
54
|
+
const { loadConfig } = await import("../load-from-file-CEpo5Sqi.js").then((n) => n.n);
|
|
55
55
|
const core = createViteCore(applyDefaults(pluginOptions));
|
|
56
56
|
await core.init({ config: loadConfig(core, true) });
|
|
57
57
|
await core.emit({ write: true });
|
package/dist/webpack/mdx.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
2
|
-
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cd17PhOW.js";
|
|
2
|
+
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-CrnPUO1X.js";
|
|
3
3
|
import { t as getCore } from "../webpack-sTIanFoi.js";
|
|
4
4
|
//#region src/webpack/mdx.ts
|
|
5
5
|
let instance;
|
package/dist/webpack/meta.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-
|
|
2
|
-
import { t as createMetaLoader } from "../meta-
|
|
1
|
+
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-CrnPUO1X.js";
|
|
2
|
+
import { t as createMetaLoader } from "../meta-DV1ZTafU.js";
|
|
3
3
|
import { t as getCore } from "../webpack-sTIanFoi.js";
|
|
4
4
|
//#region src/webpack/meta.ts
|
|
5
5
|
let instance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-mdx",
|
|
3
|
-
"version": "14.2.
|
|
3
|
+
"version": "14.2.14",
|
|
4
4
|
"description": "The built-in source for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"loader-mdx.cjs",
|
|
16
16
|
"loader-meta.cjs",
|
|
17
|
-
"dist
|
|
17
|
+
"dist"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
20
|
"main": "./dist/index.js",
|
|
@@ -96,19 +96,17 @@
|
|
|
96
96
|
"tsdown": "0.21.7",
|
|
97
97
|
"vite": "^8.0.8",
|
|
98
98
|
"webpack": "^5.106.1",
|
|
99
|
-
"
|
|
100
|
-
"fumadocs-core": "16.7.13",
|
|
99
|
+
"fumadocs-core": "16.7.15",
|
|
101
100
|
"tsconfig": "0.0.0"
|
|
102
101
|
},
|
|
103
102
|
"peerDependencies": {
|
|
104
|
-
"@fumadocs/mdx-remote": "^1.4.0",
|
|
105
103
|
"@types/mdast": "*",
|
|
106
104
|
"@types/mdx": "*",
|
|
107
105
|
"@types/react": "*",
|
|
108
106
|
"fumadocs-core": "^15.0.0 || ^16.0.0",
|
|
109
107
|
"mdast-util-directive": "*",
|
|
110
108
|
"next": "^15.3.0 || ^16.0.0",
|
|
111
|
-
"react": "
|
|
109
|
+
"react": "^19.2.0",
|
|
112
110
|
"vite": "6.x.x || 7.x.x || 8.x.x"
|
|
113
111
|
},
|
|
114
112
|
"peerDependenciesMeta": {
|
|
@@ -132,9 +130,6 @@
|
|
|
132
130
|
},
|
|
133
131
|
"vite": {
|
|
134
132
|
"optional": true
|
|
135
|
-
},
|
|
136
|
-
"@fumadocs/mdx-remote": {
|
|
137
|
-
"optional": true
|
|
138
133
|
}
|
|
139
134
|
},
|
|
140
135
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-CzI6jiMm.js","names":[],"sources":["../src/loaders/config.ts","../src/loaders/adapter.ts"],"sourcesContent":["import type { Core } from '@/core';\nimport fs from 'node:fs/promises';\n\nexport interface ConfigLoader {\n getCore(): Promise<Core>;\n}\n\nexport function createStandaloneConfigLoader({\n core,\n buildConfig,\n mode,\n}: {\n /**\n * core (not initialized)\n */\n core: Core;\n buildConfig: boolean;\n /**\n * In dev mode, the config file is dynamically re-loaded when it's updated.\n */\n mode: 'dev' | 'production';\n}): ConfigLoader {\n let prev:\n | {\n hash: string;\n init: Promise<void>;\n }\n | undefined;\n\n async function getConfigHash(): Promise<string> {\n if (mode === 'production') return 'static';\n\n const stats = await fs.stat(core.getOptions().configPath).catch(() => {\n throw new Error('Cannot find config file');\n });\n\n return stats.mtime.getTime().toString();\n }\n\n return {\n async getCore() {\n const hash = await getConfigHash();\n if (!prev || hash !== prev.hash) {\n prev = {\n hash,\n init: (async () => {\n const { loadConfig } = await import('../config/load-from-file');\n\n await core.init({\n config: loadConfig(core, buildConfig),\n });\n })(),\n };\n }\n\n await prev.init;\n return core;\n },\n };\n}\n\n/**\n * create config loader from initialized core\n */\nexport function createIntegratedConfigLoader(core: Core): ConfigLoader {\n return {\n async getCore() {\n return core;\n },\n };\n}\n","import type { CompilerOptions } from '@/loaders/mdx/build-mdx';\nimport type { LoadFnOutput, LoadHook } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport type { TransformPluginContext } from 'rolldown';\nimport type { Environment, TransformResult } from 'vite';\nimport { parse } from 'node:querystring';\nimport { ValidationError } from '@/utils/validation';\nimport type { LoaderContext } from 'webpack';\nimport { readFileSync } from 'node:fs';\n\nexport interface LoaderInput {\n development: boolean;\n compiler: CompilerOptions;\n\n filePath: string;\n query: Record<string, string | string[] | undefined>;\n getSource: () => string | Promise<string>;\n}\n\nexport interface LoaderOutput {\n code: string;\n map?: unknown;\n\n /**\n * Only supported in Vite 8.\n *\n * Explicitly define the transformed module type, for unsupported environments, you need to consider the differences between each bundler.\n */\n moduleType?: 'js' | 'json';\n}\n\ntype Awaitable<T> = T | Promise<T>;\n\nexport interface Loader {\n /**\n * Filter file paths, the input can be either a file URL or file path.\n *\n * Must take resource query into consideration.\n */\n test?: RegExp;\n\n /**\n * Transform input into JavaScript.\n *\n * Returns:\n * - `LoaderOutput`: JavaScript code & source map.\n * - `null`: skip the loader. Fallback to default behaviour if possible, otherwise the adapter will try workarounds.\n */\n load: (input: LoaderInput) => Awaitable<LoaderOutput | null>;\n\n bun?: {\n /**\n * 1. Bun doesn't allow `null` in loaders.\n * 2. Bun requires sync result to support dynamic require().\n */\n load?: (source: string, input: LoaderInput) => Awaitable<Bun.OnLoadResult>;\n };\n}\n\nexport function toNode(loader: Loader): LoadHook {\n return async (url, _context, nextLoad): Promise<LoadFnOutput> => {\n if (url.startsWith('file:///') && (!loader.test || loader.test.test(url))) {\n const parsedUrl = new URL(url);\n const filePath = fileURLToPath(parsedUrl);\n\n const result = await loader.load({\n filePath,\n query: Object.fromEntries(parsedUrl.searchParams.entries()),\n async getSource() {\n return await fs.readFile(filePath, 'utf-8');\n },\n development: false,\n compiler: {\n addDependency() {},\n },\n });\n\n if (result) {\n return {\n source: result.code,\n format: 'module',\n shortCircuit: true,\n };\n }\n }\n\n return nextLoad(url);\n };\n}\n\nexport interface ViteLoader {\n filter: (id: string) => boolean;\n\n transform: (\n this: TransformPluginContext & { environment: Environment },\n value: string,\n id: string,\n ) => Promise<TransformResult | null>;\n}\n\nexport function toVite(loader: Loader): ViteLoader {\n return {\n filter(id) {\n return !loader.test || loader.test.test(id);\n },\n async transform(value, id) {\n const environment = this.environment;\n const [file, query = ''] = id.split('?', 2);\n\n const result = await loader.load({\n filePath: file,\n query: parse(query),\n getSource() {\n return value;\n },\n development: environment.mode === 'dev',\n compiler: {\n addDependency: (file) => {\n this.addWatchFile(file);\n },\n },\n });\n\n if (result === null) return null;\n return {\n code: result.code,\n map: result.map as TransformResult['map'],\n moduleType: result.moduleType,\n };\n },\n };\n}\n\nexport type WebpackLoader = (\n this: LoaderContext<unknown>,\n source: string,\n callback: LoaderContext<unknown>['callback'],\n) => Promise<void>;\n\n/**\n * need to handle the `test` regex in Webpack config instead.\n */\nexport function toWebpack(loader: Loader): WebpackLoader {\n return async function (source, callback) {\n try {\n const result = await loader.load({\n filePath: this.resourcePath,\n query: parse(this.resourceQuery.slice(1)),\n getSource() {\n return source;\n },\n development: this.mode === 'development',\n compiler: this,\n });\n\n if (result === null) {\n callback(undefined, source);\n } else {\n callback(undefined, result.code, result.map as string);\n }\n } catch (error) {\n if (error instanceof ValidationError) {\n return callback(new Error(await error.toStringFormatted()));\n }\n\n if (!(error instanceof Error)) throw error;\n callback(error);\n }\n };\n}\n\nexport function toBun(loader: Loader) {\n function toResult(output: LoaderOutput | null): Bun.OnLoadResult {\n // it errors, treat this as an exception\n if (!output) return;\n\n return {\n contents: output.code,\n loader: output.moduleType ?? 'js',\n };\n }\n\n return (build: Bun.PluginBuilder) => {\n // avoid using async here, because it will cause dynamic require() to fail\n build.onLoad({ filter: loader.test ?? /.+/ }, (args) => {\n const [filePath, query = ''] = args.path.split('?', 2);\n const input: LoaderInput = {\n async getSource() {\n return Bun.file(filePath).text();\n },\n query: parse(query),\n filePath,\n development: false,\n compiler: {\n addDependency() {},\n },\n };\n\n if (loader.bun?.load) {\n return loader.bun.load(readFileSync(filePath, 'utf-8'), input);\n }\n\n const result = loader.load(input);\n if (result instanceof Promise) {\n return result.then(toResult);\n }\n return toResult(result);\n });\n };\n}\n"],"mappings":";;;;;;AAOA,SAAgB,6BAA6B,EAC3C,MACA,aACA,QAWe;CACf,IAAI;CAOJ,eAAe,gBAAiC;AAC9C,MAAI,SAAS,aAAc,QAAO;AAMlC,UAJc,MAAM,GAAG,KAAK,KAAK,YAAY,CAAC,WAAW,CAAC,YAAY;AACpE,SAAM,IAAI,MAAM,0BAA0B;IAC1C,EAEW,MAAM,SAAS,CAAC,UAAU;;AAGzC,QAAO,EACL,MAAM,UAAU;EACd,MAAM,OAAO,MAAM,eAAe;AAClC,MAAI,CAAC,QAAQ,SAAS,KAAK,KACzB,QAAO;GACL;GACA,OAAO,YAAY;IACjB,MAAM,EAAE,eAAe,MAAM,OAAO,gCAAA,MAAA,MAAA,EAAA,EAAA;AAEpC,UAAM,KAAK,KAAK,EACd,QAAQ,WAAW,MAAM,YAAY,EACtC,CAAC;OACA;GACL;AAGH,QAAM,KAAK;AACX,SAAO;IAEV;;;;;AAMH,SAAgB,6BAA6B,MAA0B;AACrE,QAAO,EACL,MAAM,UAAU;AACd,SAAO;IAEV;;;;ACTH,SAAgB,OAAO,QAA0B;AAC/C,QAAO,OAAO,KAAK,UAAU,aAAoC;AAC/D,MAAI,IAAI,WAAW,WAAW,KAAK,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,IAAI,GAAG;GACzE,MAAM,YAAY,IAAI,IAAI,IAAI;GAC9B,MAAM,WAAW,cAAc,UAAU;GAEzC,MAAM,SAAS,MAAM,OAAO,KAAK;IAC/B;IACA,OAAO,OAAO,YAAY,UAAU,aAAa,SAAS,CAAC;IAC3D,MAAM,YAAY;AAChB,YAAO,MAAM,GA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AgB;CACpC,SAAS,SAAS,QAA+C;AAE/D,MAAI,CAAC,OAAQ;AAEb,SAAO;GACL,UAAU,OAAO;GACjB,QAAQ,OAAO,cAAc;GAC9B;;AAGH,SAAQ,UAA6B;AAEnC,QAAM,OAAO,EAAE,QAAQ,OAAO,QAAQ,MAAM,GAAG,SAAS;GACtD,MAAM,CAAC,UAAU,QAAQ,MAAM,KAAK,KAAK,MAAM,KAAK,EAAE;GACtD,MAAM,QAAqB;IACzB,MAAM,YAAY;AAChB,YAAO,IAAI,KAAK,SAAS,CAAC,MAAM;;IAElC,OAAO,MAAM,MAAM;IACnB;IACA,aAAa;IACb,UAAU,EACR,gBAAgB,IACjB;IACF;AAED,OAAI,OAAO,KAAK,KACd,QAAO,OAAO,IAAI,KAAK,aAAa,UAAU,QAAQ,EAAE,MAAM;GAGhE,MAAM,SAAS,OAAO,KAAK,MAAM;AACjC,OAAI,kBAAkB,QACpB,QAAO,OAAO,KAAK,SAAS;AAE9B,UAAO,SAAS,OAAO;IACvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-mdx-LmiB2qsc.js","names":[],"sources":["../../core/dist/utils-C73VXFR0.js","../../core/dist/mdx-plugins/stringifier.js","../../core/dist/mdx-plugins/remark-llms.js","../src/loaders/mdx/remark-postprocess.ts","../src/loaders/mdx/build-mdx.ts"],"sourcesContent":["import { valueToEstree } from \"estree-util-value-to-estree\";\n//#region src/mdx-plugins/utils.ts\nfunction flattenNode(node) {\n\tif (\"children\" in node) return node.children.map((child) => flattenNode(child)).join(\"\");\n\tif (\"value\" in node && typeof node.value === \"string\") return node.value;\n\treturn \"\";\n}\nfunction toMdxExport(name, value) {\n\treturn toMdxExportRaw(name, valueToEstree(value));\n}\nfunction toMdxExportRaw(name, expression) {\n\treturn {\n\t\ttype: \"mdxjsEsm\",\n\t\tvalue: \"\",\n\t\tdata: { estree: {\n\t\t\ttype: \"Program\",\n\t\t\tsourceType: \"module\",\n\t\t\tbody: [{\n\t\t\t\ttype: \"ExportNamedDeclaration\",\n\t\t\t\tattributes: [],\n\t\t\t\tspecifiers: [],\n\t\t\t\tdeclaration: {\n\t\t\t\t\ttype: \"VariableDeclaration\",\n\t\t\t\t\tkind: \"let\",\n\t\t\t\t\tdeclarations: [{\n\t\t\t\t\t\ttype: \"VariableDeclarator\",\n\t\t\t\t\t\tid: {\n\t\t\t\t\t\t\ttype: \"Identifier\",\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinit: expression\n\t\t\t\t\t}]\n\t\t\t\t}\n\t\t\t}]\n\t\t} }\n\t};\n}\nfunction handleTag(value, tag) {\n\tconst idx = value.indexOf(tag);\n\tif (idx !== -1) return value.slice(0, idx).trimEnd() + value.slice(idx + tag.length);\n\treturn false;\n}\n//#endregion\nexport { toMdxExportRaw as i, handleTag as n, toMdxExport as r, flattenNode as t };\n","import { mdxToMarkdown } from \"mdast-util-mdx\";\nimport { toMarkdown } from \"mdast-util-to-markdown\";\n//#region src/mdx-plugins/stringifier.ts\nfunction defaultStringifier(config = {}) {\n\tconst { filterMdxAttributes, filterElement = (node) => {\n\t\tswitch (node.type) {\n\t\t\tcase \"mdxJsxFlowElement\":\n\t\t\tcase \"mdxJsxTextElement\":\n\t\t\t\tswitch (node.name) {\n\t\t\t\t\tcase \"File\":\n\t\t\t\t\tcase \"TypeTable\":\n\t\t\t\t\tcase \"Callout\":\n\t\t\t\t\tcase \"Card\": return true;\n\t\t\t\t}\n\t\t\t\treturn \"children-only\";\n\t\t}\n\t\treturn true;\n\t}, stringify, ...customExtension } = config;\n\tfunction modHandler(handler, ctx) {\n\t\treturn function(node, parent, state, info) {\n\t\t\tlet visibility = filterElement(node);\n\t\t\tif (visibility === false) return \"\";\n\t\t\tif (stringify) {\n\t\t\t\tconst v = stringify(node, parent, state, info, ctx);\n\t\t\t\tif (v) return v;\n\t\t\t}\n\t\t\tconst extraInfo = node.data?._stringify;\n\t\t\tif (extraInfo) if (extraInfo === \"children-only\") visibility = \"children-only\";\n\t\t\telse if (\"text\" in extraInfo) return extraInfo.text;\n\t\t\telse node = extraInfo.node;\n\t\t\tif (visibility === \"children-only\") {\n\t\t\t\tif (!(\"children\" in node)) return \"\";\n\t\t\t\tswitch (node.type) {\n\t\t\t\t\tcase \"mdxJsxTextElement\":\n\t\t\t\t\tcase \"paragraph\": return state.containerPhrasing(node, info);\n\t\t\t\t\tcase \"mdxJsxFlowElement\": return state.containerFlow(node, info);\n\t\t\t\t\tdefault: return state.containerFlow({\n\t\t\t\t\t\ttype: \"root\",\n\t\t\t\t\t\tchildren: node.children\n\t\t\t\t\t}, info);\n\t\t\t\t}\n\t\t\t}\n\t\t\tswitch (node.type) {\n\t\t\t\tcase \"mdxJsxFlowElement\":\n\t\t\t\tcase \"mdxJsxTextElement\": {\n\t\t\t\t\tconst stringifiedAttributes = [];\n\t\t\t\t\tfor (const attr of node.attributes) {\n\t\t\t\t\t\tif (attr.type === \"mdxJsxExpressionAttribute\") continue;\n\t\t\t\t\t\tif (filterMdxAttributes && !filterMdxAttributes(node, attr)) continue;\n\t\t\t\t\t\tconst str = typeof attr.value === \"string\" ? attr.value : attr.value?.value;\n\t\t\t\t\t\tif (!str) continue;\n\t\t\t\t\t\tstringifiedAttributes.push({\n\t\t\t\t\t\t\ttype: \"mdxJsxAttribute\",\n\t\t\t\t\t\t\tname: attr.name,\n\t\t\t\t\t\t\tvalue: str\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\treturn handler({\n\t\t\t\t\t\t...node,\n\t\t\t\t\t\tattributes: stringifiedAttributes\n\t\t\t\t\t}, parent, state, info);\n\t\t\t\t}\n\t\t\t\tdefault: return handler(node, parent, state, info);\n\t\t\t}\n\t\t};\n\t}\n\tconst customToMarkdown = { handlers: { _custom(node, _, state, info) {\n\t\tconst handlers = state.handlers;\n\t\tfor (const k in handlers) handlers[k] = modHandler(handlers[k], node.ctx);\n\t\treturn state.handle(node.root, void 0, state, info);\n\t} } };\n\treturn function(root, ctx) {\n\t\treturn toMarkdown({\n\t\t\ttype: \"_custom\",\n\t\t\troot,\n\t\t\tctx\n\t\t}, {\n\t\t\t...this?.data(\"settings\"),\n\t\t\textensions: [\n\t\t\t\tmdxToMarkdown(),\n\t\t\t\t...this?.data(\"toMarkdownExtensions\") ?? [],\n\t\t\t\tcustomToMarkdown,\n\t\t\t\tcustomExtension\n\t\t\t]\n\t\t});\n\t};\n}\n//#endregion\nexport { defaultStringifier };\n","import { r as toMdxExport } from \"../utils-C73VXFR0.js\";\nimport { defaultStringifier } from \"./stringifier.js\";\n//#region src/mdx-plugins/remark-llms.ts\n/**\n* generate `llms.txt` for markdown.\n*/\nfunction remarkLLMs({ as = \"_markdown\", headingIds = true, _data = false, mdxAsPlaceholder, ...rest } = {}) {\n\tconst stringifier = defaultStringifier({\n\t\t...rest,\n\t\tfilterElement(node) {\n\t\t\tswitch (node.type) {\n\t\t\t\tcase \"mdxjsEsm\": return false;\n\t\t\t\tdefault: return true;\n\t\t\t}\n\t\t},\n\t\tstringify(node, parent, state, info, ctx) {\n\t\t\tif (mdxAsPlaceholder) switch (node.type) {\n\t\t\t\tcase \"mdxJsxFlowElement\":\n\t\t\t\tcase \"mdxJsxTextElement\": if (node.name && mdxAsPlaceholder.includes(node.name)) return placeholder(node, parent, state, info);\n\t\t\t}\n\t\t\treturn rest.stringify?.(node, parent, state, info, ctx);\n\t\t},\n\t\thandlers: {\n\t\t\theading(node, _p, state, info) {\n\t\t\t\tconst id = node.data?.hProperties?.id;\n\t\t\t\tconst content = state.containerPhrasing(node, info);\n\t\t\t\treturn headingIds && id ? `${content} [#${id}]` : content;\n\t\t\t},\n\t\t\t...rest.handlers\n\t\t}\n\t});\n\treturn (node, file) => {\n\t\tconst value = stringifier.call(this, node, void 0);\n\t\tnode.children.unshift(toMdxExport(as, value));\n\t\tif (_data) file.data.markdown = value;\n\t};\n}\n/**\n* Preserve AST data to render the MDX component at runtime, use `renderPlaceholder()` to render the placeholders.\n*/\nfunction placeholder(node, _parent, state, info) {\n\tconst attributes = {};\n\tfor (const attr of node.attributes) {\n\t\tif (attr.type === \"mdxJsxExpressionAttribute\") continue;\n\t\tattributes[attr.name] = attr.value;\n\t}\n\treturn `\\0${JSON.stringify({\n\t\tname: node.name,\n\t\tchildren: state.containerPhrasing(node, info),\n\t\tattributes\n\t})}\\0`;\n}\n//#endregion\nexport { placeholder, remarkLLMs };\n","import type { Processor, Transformer } from 'unified';\nimport type { Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport { valueToEstree } from 'estree-util-value-to-estree';\nimport { removePosition } from 'unist-util-remove-position';\nimport { flattenNode } from './mdast-utils';\nimport type { LLMsOptions } from 'fumadocs-core/mdx-plugins';\nimport { remarkLLMs } from 'fumadocs-core/mdx-plugins/remark-llms';\n\nexport interface ExtractedReference {\n href: string;\n}\n\nexport interface PostprocessOptions {\n _format: 'md' | 'mdx';\n\n /**\n * Properties to export from `vfile.data`\n */\n valueToExport?: string[];\n\n /**\n * stringify MDAST and export via `_markdown`.\n */\n includeProcessedMarkdown?: boolean | LLMsOptions;\n\n /**\n * extract link references, export via `extractedReferences`.\n */\n extractLinkReferences?: boolean;\n\n /**\n * store MDAST and export via `_mdast`.\n */\n includeMDAST?:\n | boolean\n | {\n removePosition?: boolean;\n };\n}\n\n/**\n * - collect references\n * - write frontmatter (auto-title & description)\n */\nexport function remarkPostprocess(\n this: Processor,\n {\n includeProcessedMarkdown = false,\n includeMDAST = false,\n extractLinkReferences = false,\n valueToExport = [],\n }: PostprocessOptions,\n): Transformer<Root, Root> {\n return (tree, file) => {\n const frontmatter = (file.data.frontmatter ??= {});\n if (!frontmatter.title) {\n visit(tree, 'heading', (node) => {\n if (node.depth === 1) {\n frontmatter.title = flattenNode(node);\n return false;\n }\n });\n }\n\n file.data['mdx-export'] ??= [];\n file.data['mdx-export'].push({\n name: 'frontmatter',\n value: frontmatter,\n });\n\n if (extractLinkReferences) {\n const urls: ExtractedReference[] = [];\n\n visit(tree, 'link', (node) => {\n urls.push({\n href: node.url,\n });\n return 'skip';\n });\n\n file.data['mdx-export'].push({\n name: 'extractedReferences',\n value: urls,\n });\n }\n\n if (includeProcessedMarkdown) {\n const llms = remarkLLMs.call(\n this,\n typeof includeProcessedMarkdown === 'object' ? includeProcessedMarkdown : undefined,\n );\n llms(tree, file, () => undefined);\n }\n\n if (includeMDAST) {\n const options = includeMDAST === true ? {} : includeMDAST;\n const mdast = JSON.stringify(\n options.removePosition ? removePosition(structuredClone(tree)) : tree,\n );\n\n file.data['mdx-export'].push({\n name: '_mdast',\n value: mdast,\n });\n }\n\n for (const { name, value } of file.data['mdx-export']) {\n tree.children.unshift(getMdastExport(name, value));\n }\n\n // reset the data to reduce memory usage\n file.data['mdx-export'] = [];\n\n for (const name of valueToExport) {\n if (!(name in file.data)) continue;\n\n tree.children.unshift(getMdastExport(name, file.data[name]));\n }\n };\n}\n\n/**\n * MDX.js first converts javascript (with esm support) into mdast nodes with remark-mdx, then handle the other remark plugins\n *\n * Therefore, if we want to inject an export, we must convert the object into AST, then add the mdast node\n */\nfunction getMdastExport(name: string, value: unknown): RootContent {\n return {\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ExportNamedDeclaration',\n attributes: [],\n specifiers: [],\n source: null,\n declaration: {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name,\n },\n init: valueToEstree(value),\n },\n ],\n },\n },\n ],\n },\n },\n };\n}\n","import { createProcessor } from '@mdx-js/mdx';\nimport { VFile } from 'vfile';\nimport { remarkInclude } from '@/loaders/mdx/remark-include';\nimport type { StructuredData } from 'fumadocs-core/mdx-plugins';\nimport type { TOCItemType } from 'fumadocs-core/toc';\nimport type { FC } from 'react';\nimport type { MDXProps } from 'mdx/types';\nimport { type PostprocessOptions, remarkPostprocess } from '@/loaders/mdx/remark-postprocess';\nimport type { Core } from '@/core';\nimport type { DocCollectionItem } from '@/config/build';\n\ntype Processor = ReturnType<typeof createProcessor>;\n\ninterface BuildMDXOptions {\n /**\n * Specify a file path for source\n */\n filePath: string;\n source: string;\n frontmatter?: Record<string, unknown>;\n\n environment: 'bundler' | 'runtime';\n isDevelopment: boolean;\n _compiler?: CompilerOptions;\n}\n\nexport interface CompilerOptions {\n addDependency: (file: string) => void;\n}\n\nexport interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {\n frontmatter: Frontmatter;\n structuredData: StructuredData;\n toc: TOCItemType[];\n default: FC<MDXProps>;\n\n /**\n * Enable from `postprocess` option.\n */\n _markdown?: string;\n /**\n * Enable from `postprocess` option.\n */\n _mdast?: string;\n}\n\nexport interface FumadocsDataMap {\n /**\n * [Fumadocs MDX] raw frontmatter, you can modify it\n */\n frontmatter?: Record<string, unknown>;\n\n /**\n * [Fumadocs MDX] additional ESM exports to write\n */\n 'mdx-export'?: { name: string; value: unknown }[];\n\n /**\n * [Fumadocs MDX] The compiler object from loader\n */\n _compiler?: CompilerOptions;\n\n /**\n * [Fumadocs MDX] get internal processor, do not use this on user land.\n */\n _getProcessor?: (format: 'md' | 'mdx') => Processor;\n}\n\ndeclare module 'vfile' {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- extend data map\n interface DataMap extends FumadocsDataMap {}\n}\n\nexport async function buildMDX(\n core: Core,\n collection: DocCollectionItem | undefined,\n { filePath, frontmatter, source, _compiler, environment, isDevelopment }: BuildMDXOptions,\n): Promise<VFile> {\n const mdxOptions = await core.getConfig().getMDXOptions(collection, environment);\n\n function getProcessor(format: 'md' | 'mdx') {\n const cache = core.cache as Map<string, Processor>;\n const key = `build-mdx:${collection?.name ?? 'global'}:${format}`;\n let processor = cache.get(key);\n\n if (!processor) {\n const postprocessOptions: PostprocessOptions = {\n _format: format,\n ...collection?.postprocess,\n };\n\n processor = createProcessor({\n outputFormat: 'program',\n development: isDevelopment,\n ...mdxOptions,\n remarkPlugins: [\n remarkInclude,\n ...(mdxOptions.remarkPlugins ?? []),\n [remarkPostprocess, postprocessOptions],\n ],\n format,\n });\n\n cache.set(key, processor);\n }\n\n return processor;\n }\n\n let vfile = new VFile({\n value: source,\n path: filePath,\n cwd: collection?.cwd,\n data: { frontmatter, _compiler, _getProcessor: getProcessor },\n });\n\n if (collection) {\n vfile = await core.transformVFile({ collection, filePath, source }, vfile);\n }\n\n return getProcessor(filePath.endsWith('.mdx') ? 'mdx' : 'md').process(vfile);\n}\n"],"mappings":";;;;;;;;;;AAOA,SAAS,YAAY,MAAM,OAAO;AACjC,QAAO,eAAe,MAAM,cAAc,MAAM,CAAC;;AAElD,SAAS,eAAe,MAAM,YAAY;AACzC,QAAO;EACN,MAAM;EACN,OAAO;EACP,MAAM,EAAE,QAAQ;GACf,MAAM;GACN,YAAY;GACZ,MAAM,CAAC;IACN,MAAM;IACN,YAAY,EAAE;IACd,YAAY,EAAE;IACd,aAAa;KACZ,MAAM;KACN,MAAM;KACN,cAAc,CAAC;MACd,MAAM;MACN,IAAI;OACH,MAAM;OACN;OACA;MACD,MAAM;MACN,CAAC;KACF;IACD,CAAC;GACF,EAAE;EACH;;;;AChCF,SAAS,mBAAmB,SAAS,EAAE,EAAE;CACxC,MAAM,EAAE,qBAAqB,iBAAiB,SAAS;AACtD,UAAQ,KAAK,MAAb;GACC,KAAK;GACL,KAAK;AACJ,YAAQ,KAAK,MAAb;KACC,KAAK;KACL,KAAK;KACL,KAAK;KACL,KAAK,OAAQ,QAAO;;AAErB,WAAO;;AAET,SAAO;IACL,WAAW,GAAG,oBAAoB;CACrC,SAAS,WAAW,SAAS,KAAK;AACjC,SAAO,SAAS,MAAM,QAAQ,OAAO,MAAM;GAC1C,IAAI,aAAa,cAAc,KAAK;AACpC,OAAI,eAAe,MAAO,QAAO;AACjC,OAAI,WAAW;IACd,MAAM,IAAI,UAAU,MAAM,QAAQ,OAAO,MAAM,IAAI;AACnD,QAAI,EAAG,QAAO;;GAEf,MAAM,YAAY,KAAK,M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