UNPKG

unplugin-typegpu

Version:

Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.

33 lines (31 loc) 1.26 kB
import { n as defaultOptions, r as earlyPruneRegex } from "./common-CK7zOjbK.js"; import { t as unpluginFactory } from "./factory-W6dKP7m4.js"; import defu from "defu"; //#region src/bun.ts var bun_default = (rawOptions) => { const options = defu(rawOptions, defaultOptions); const include = options.include; if (!(include instanceof RegExp)) throw new Error(`Unsupported 'include' options in Bun plugin. Please provide a single regular expression`); if (options.exclude) throw new Error(`Unsupported 'exclude' option in Bun plugin`); const rawPlugin = unpluginFactory(rawOptions, { framework: "bun" }); return { name: "unplugin-typegpu", setup(build) { build.onLoad({ filter: include }, async (args) => { var _result$code; const codeIn = await Bun.file(args.path).text(); if (earlyPruneRegex.every((pattern) => !pattern.test(codeIn))) return { contents: codeIn, loader: args.loader }; const result = rawPlugin.transform.handler.apply({}, [codeIn, args.path]); return { contents: (_result$code = result === null || result === void 0 ? void 0 : result.code) !== null && _result$code !== void 0 ? _result$code : codeIn, loader: args.loader }; }); } }; }; //#endregion export { bun_default as t };