UNPKG

comptime.ts

Version:

<div align="center"> <img src="https://raw.githubusercontent.com/feathers-studio/comptime.ts/master/docs/comptime.ts.svg" alt="Hyperactive"> </div>

29 lines 1.08 kB
import {} from "bun"; import { getComptimeReplacements } from "./comptime.js"; import MagicString from "magic-string"; export const comptime = (opts) => { const filter = opts?.filter && ((id) => opts.filter.test(id)); let replacements; return { name: "bun-plugin-comptime", setup(build) { build .onStart(async () => { replacements = await getComptimeReplacements({ ...opts, filter }); }) .onLoad({ filter: opts?.filter ?? /\.(ts|tsx|js|jsx|mjs|cjs)$/ }, async (args) => { const id = args.path; const replacement = replacements[id]; if (!replacement) return; const code = await Bun.file(id).text(); const s = new MagicString(code); for (const r of replacement) { s.overwrite(r.start, r.end, r.replacement); } return { contents: s.toString() }; }); }, }; }; //# sourceMappingURL=bun.js.map