wesl-plugin
Version:
[](https://www.npmjs.com/package/wesl-plugin) [](https://wesl-lang.dev/)
55 lines (54 loc) • 2.43 kB
TypeScript
import { BatchModuleResolver, WeslJsPlugin } from "wesl";
//#region ../wesl-tooling/src/LoadWeslToml.d.ts
/** Configuration from wesl.toml */
interface WeslToml {
/** WESL edition (e.g. "unstable_2025") */
edition: string;
/** glob patterns to find .wesl/.wgsl files. Relative to the toml directory. */
include: string[];
/** base directory for wesl files. Relative to the toml directory. */
root: string;
/** glob patterns to exclude directories. */
exclude?: string[];
/** package manager ("npm" or "cargo") */
"package-manager"?: string;
/** names of directly referenced wesl shader packages (e.g. npm package names), or "auto" for auto-detection */
dependencies?: string[] | string;
}
/** Information about the loaded wesl.toml file and its location */
interface WeslTomlInfo {
/** The path to the toml file, relative to the cwd, undefined if no toml file */
tomlFile: string | undefined;
/** The absolute path to the directory that contains the toml.
* Paths inside the toml are relative to this. */
tomlDir: string;
/** The wesl root, relative to the projectDir.
* This lets loadModules do `path.resolve(projectDir, resolvedRoot)` */
resolvedRoot: string;
/** The underlying toml file */
toml: WeslToml;
}
//#endregion
//#region src/PluginExtension.d.ts
/** function type required for for emit extensions */
type ExtensionEmitFn = (/** absolute path to the shader to which the extension is attached */
shaderPath: string, /** support functions available to plugin extensions */
pluginApi: PluginExtensionApi, /** static conditions specified on the js import */conditions?: Record<string, boolean>) => Promise<string>;
/** an extension that runs inside the wesl-js build plugin */
interface PluginExtension extends WeslJsPlugin {
/** javascript imports with this suffix will trigger the plugin */
extensionName: string;
/** generate javascript text for js/ts importers to use.
* e.g. import myPluginJs from "./foo.wesl?myPlugin"; */
emitFn: ExtensionEmitFn;
}
/** api supplied to plugin extensions */
interface PluginExtensionApi {
weslToml: () => Promise<WeslTomlInfo>;
weslSrc: () => Promise<Record<string, string>>;
weslRegistry: () => Promise<BatchModuleResolver>;
weslMain: (baseId: string) => Promise<string>;
weslDependencies: () => Promise<string[]>;
}
//#endregion
export { PluginExtension as n, PluginExtensionApi as r, ExtensionEmitFn as t };