fumadocs-mdx15.6.43.4 kB
import { t as createMdxLoader } from "../mdx-oiwGpmIR.js";
import { r as buildConfig } from "../build-Dc0aOaCg.js";
import { t as createCore } from "../core-r1WHKfaI.js";
import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-DJT55ieR.js";
import { t as createMetaLoader } from "../meta-CsSsB7_T.js";
import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-3R0gLmlP.js";
import { i as resolveMacroOptions, n as NodeModulesRegex, r as createMacroMatcher } from "../options-DZSjmVhY.js";
import fs from "node:fs/promises";
import { randomUUID } from "node:crypto";
import { pathToFileURL } from "node:url";
// src/bun/index.ts
const EvalQueryKey = "fd-macro-eval";
/**
* JS/TS modules outside of `node_modules`, with an optional import query.
*
* @internal
*/
const macroFilter = new RegExp(String.raw`^(?!.*${NodeModulesRegex.source}).*\.(?:[cm]?[jt]s|[jt]sx)(?:\?.*)?$`);
function bunLoader(file) {
if (file.endsWith(".tsx")) return "tsx";
if (file.endsWith(".jsx")) return "jsx";
if (/\.[cm]?ts$/.test(file)) return "ts";
return "js";
}
function createMdxPlugin(options = {}) {
const { disableMetaFile = false } = options;
const macroOptions = resolveMacroOptions(options.macro);
return {
name: "bun-plugin-fumadocs-mdx",
async setup(build) {
const core = createCore({
environment: "bun",
outDir: options.outDir,
configPath: options.configPath,
plugins: options.plugins
});
const importPath = pathToFileURL(core.configPath).href;
const configExports = await fs.access(core.configPath).then(() => true, () => false) ? await import(importPath) : {};
await core.init({ config: buildConfig(configExports, process.cwd()) });
if (macroOptions) {
const root = process.cwd();
const { MacroCollector } = await import("../eval-Ch9sPj_e.js").then((n) => n.r);
const pendingEvals = /* @__PURE__ */ new Map();
core.macro = new MacroCollector({
root,
outDir: core.outDir,
isDev: false,
async evaluator({ entry, transform }) {
const token = randomUUID();
pendingEvals.set(token, transform);
try {
await import(`${entry}?${EvalQueryKey}=${token}`);
} finally {
pendingEvals.delete(token);
}
return { inputs: [entry] };
}
});
const matcher = createMacroMatcher(root, macroOptions);
build.onLoad({ filter: macroFilter }, async (args) => {
const [file, query = ""] = args.path.split("?", 2);
const loader = bunLoader(file);
const source = await Bun.file(file).text();
if (!matcher(file) || !source.includes("fumadocs-mdx/macro")) return {
contents: source,
loader
};
const token = new URLSearchParams(query).get(EvalQueryKey);
const transform = token ? pendingEvals.get(token) : void 0;
if (transform) return {
contents: await transform(source, file) ?? source,
loader
};
const { transformMacroModule } = await import("../transform-CAcchC26.js").then((n) => n.i);
return {
contents: (await transformMacroModule({
code: source,
file,
root,
target: "import"
}))?.code ?? source,
loader
};
});
}
const configLoader = createIntegratedConfigLoader(core);
toBun(mdxLoaderGlob, createMdxLoader(configLoader))(build);
if (!disableMetaFile) toBun(metaLoaderGlob, createMetaLoader(configLoader, {}))(build);
}
};
}
export { createMdxPlugin, macroFilter };
Shown as plain text from the published tarball, after apm checked it against the version's checksum. Nothing in it runs on this page.