import { ScanDependenciesOptions, scanDependencies } from "./ScanDependencies.js"; import { ModuleResolver, WeslAST, WeslBundle, WeslExtensions } from "wesl/core"; //#region src/FileModuleResolver.d.ts /** * Loads WESL modules from the filesystem on demand with caching. * * Resolves module paths like `package::foo::bar` to filesystem paths * like `baseDir/foo/bar.wesl` or `baseDir/foo/bar.wgsl`. */ declare class FileModuleResolver implements ModuleResolver { /** Cached parsed ASTs to avoid re-parsing the same module */ readonly astCache: Map; /** Root directory containing shader source files */ readonly baseDir: string; /** Package name that this resolver handles (in addition to generic "package") */ readonly packageName: string; /** Optional root path for debug file paths (for browser-clickable errors) */ readonly debugWeslRoot?: string; /** * @param baseDir - Root directory containing shader source files * @param packageName - Package name to resolve (defaults to "package") * @param debugWeslRoot - Optional root path for debug file paths. If provided, error messages * will show paths relative to this root (e.g., "shaders/foo.wesl") instead of absolute * filesystem paths. This is needed for clickable errors in browser dev tools. */ constructor(baseDir: string, packageName?: string, debugWeslRoot?: string); /** * Resolves and parses a module by its import path. * * Returns cached AST if available, otherwise loads from filesystem, * parses, caches, and returns the AST. Returns undefined if module * cannot be found. * * @param modulePath - Module path like "package::foo::bar" * @returns Parsed AST or undefined if module not found */ resolveModule(modulePath: string): WeslAST | undefined; /** Try .wesl first, then .wgsl */ private tryExtensions; private loadSource; /** Convert module path (package::foo::bar) to filesystem path (baseDir/foo/bar) */ private moduleToFilePath; /** Convert module path to debug path for error messages */ private modulePathToDebugPath; } //#endregion //#region src/LoadModules.d.ts /** * Load the wesl/wgsl shader sources. * * If baseDir or srcGlob are not provided, this function will attempt to read * configuration from wesl.toml in the projectDir. If no wesl.toml exists, * default values will be used. * * @param projectDir The project directory (typically cwd or directory containing package.json) * @param baseDir Optional base directory for shaders (overrides wesl.toml if provided) * @param srcGlob Optional glob pattern for shader files (overrides wesl.toml if provided) */ declare function loadModules(projectDir: string, baseDir?: string, srcGlob?: string): Promise>; declare function zip(as: A[], bs: B[]): [A, B][]; //#endregion //#region src/LoadProject.d.ts interface ProjectInfo { weslSrc: Record; rootModuleName: string; packageName: string; libs: WeslBundle[]; } interface LoadProjectOptions { /** Libraries provided at runtime, don't resolve from npm (e.g., ["test"]) */ virtualLibs?: string[]; } /** * Load everything needed to link a shader file. * * Discovers the project root, loads wesl.toml config, reads all shader modules, * and resolves external library dependencies from npm. * * @returns ProjectInfo with sources, libs, and module paths, or null if not in a project. */ declare function loadProject(filePath: string, opts?: LoadProjectOptions): Promise; /** Read package name from package.json, sanitized for WESL identifiers. */ declare function getPackageName(projectDir: string): Promise; //#endregion //#region src/LoadWeslToml.d.ts /** Configuration from wesl.toml */ interface WeslToml { /** WESL edition (e.g. "2026_pre") */ 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; } /** 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; } /** Default configuration when no wesl.toml is found */ declare const defaultWeslToml: WeslToml; /** * Load and parse a wesl.toml file from the fs. * Provide default values for any required WeslToml fields. */ declare function loadWeslToml(tomlFile: string): Promise; /** * Find and load the wesl.toml file, or use defaults if not found * * @param projectDir The directory to search for wesl.toml (typically cwd or project root) * @param specifiedToml Optional explicit path to a toml file * @returns Information about the loaded TOML configuration */ declare function findWeslToml(projectDir: string, specifiedToml?: string): Promise; //#endregion //#region src/ParseDependencies.d.ts /** * Find package dependencies in WESL source files. * * Partially binds identifiers and returns the longest resolvable npm subpath * for each referenced dependency. * * For example, 'foo::bar::baz' could resolve to: * - 'foo/bar' (package foo, export './bar' bundle) * - 'foo' (package foo, default export) * * @param weslSrc - Record of WESL source files by path * @param projectDir - Project directory for resolving package imports * @param virtualLibNames - Virtual lib names to exclude (e.g., ['env', 'constants']) * @param weslExtensions - Opt-in WESL extensions to enable while parsing * @returns Dependency paths in npm format (e.g., 'foo/bar', 'foo') */ declare function parseDependencies(weslSrc: Record, projectDir: string, virtualLibNames?: string[], weslExtensions?: WeslExtensions): string[]; /** Resolve pre-computed unbound refs to npm dependency paths. */ declare function resolvePkgDeps(refs: string[][], projectDir: string, virtualLibNames?: string[]): string[]; /** * Load WeslBundle instances referenced by WESL sources. * * Parses sources to find external module references, then dynamically imports * the corresponding weslBundle.js files. * * @param weslSrc - Record of WESL source files by path * @param projectDir - Project directory for resolving imports * @param packageName - Optional current package name * @param includeCurrentPackage - Include current package in results (default: false) * @param virtualLibNames - Virtual lib names to exclude from resolution * @param weslExtensions - Opt-in WESL extensions to enable while parsing * @returns Loaded WeslBundle instances */ declare function dependencyBundles(weslSrc: Record, projectDir: string, packageName?: string, includeCurrentPackage?: boolean, virtualLibNames?: string[], weslExtensions?: WeslExtensions): Promise; //#endregion //#region src/ResolveProjectDir.d.ts /** * Resolves a project directory by searching upward for package.json or wesl.toml. * * @param startPath - Optional starting path (file:// URL or filesystem path). * If a file URL is provided, uses its directory. * If omitted or falsy, defaults to process.cwd(). * @returns file:// URL string pointing to the project directory * (the first ancestor containing package.json or wesl.toml, or the start directory) */ declare function resolveProjectDir(startPath?: string): Promise; //#endregion //#region src/Version.d.ts /** Read package.json from a directory. * @param projectDir - file:// URL string to directory containing package.json * @returns the parsed package.json contents */ declare function readPackageJson(projectDir: string): Promise>; /** * @param projectDir - file:// URL string to directory containing package.json * @returns the 'version' field from the package.json in the `projectDir` */ declare function versionFromPackageJson(projectDir: string): Promise; //#endregion export { FileModuleResolver, LoadProjectOptions, ProjectInfo, ScanDependenciesOptions, WeslToml, WeslTomlInfo, defaultWeslToml, dependencyBundles, findWeslToml, getPackageName, loadModules, loadProject, loadWeslToml, parseDependencies, readPackageJson, resolvePkgDeps, resolveProjectDir, scanDependencies, versionFromPackageJson, zip };