UNPKG

@openpolicy/vite-auto-collect

Version:

Vite plugin that scans source files for @openpolicy/sdk collecting() calls and populates autoCollected() at build time

39 lines (38 loc) 1.38 kB
import { Plugin } from "vite"; //#region src/index.d.ts type AutoCollectOptions = { /** * Directory walked for `collecting()` calls. Resolved relative to the * Vite project root. Defaults to `"src"`. */ srcDir?: string; /** * File extensions scanned. Defaults to `[".ts", ".tsx"]`. */ extensions?: string[]; /** * Extra directory names skipped during the walk. Appended to the built-in * defaults (`node_modules`, `dist`, `.git`, `.next`, `.output`, * `.svelte-kit`, `.cache`). */ ignore?: string[]; thirdParties?: { usePackageJson?: boolean; }; }; /** * Vite plugin that scans source files for `@openpolicy/sdk` `collecting()` * calls at the start of each build and inlines the discovered categories into * the SDK's `dataCollected` sentinel. * * Internally the plugin intercepts `@openpolicy/sdk`'s own relative import of * `./auto-collected` and redirects it to a virtual module whose body is a * literal `export const dataCollected = { ... }`. Because the replacement * becomes part of the consumer's own module graph, the scanned data survives * any downstream bundler boundary (e.g. nitro's SSR output), which a shared * module-level registry would not. */ declare function autoCollect(options?: AutoCollectOptions): Plugin; //#endregion export { AutoCollectOptions, autoCollect }; //# sourceMappingURL=index.d.ts.map