Volt.JS.Transforms.GlobImports (Volt v0.14.0)

Copy Markdown View Source

Transforms import.meta.glob() calls into static import maps.

Supported forms include lazy and eager imports, arrays of patterns, negative patterns, named imports, string or object query options, base, and TypeScript generic syntax. The transform runs after framework/plugin output is compiled, so glob calls emitted by SFC compilers or plugins participate in the same graph as source-authored calls.

Generated import modules are built from OXC templates or encoded literals; avoid adding string-built JavaScript syntax unless the syntax is validated by the parser before use.

Summary

Functions

Extracts static glob patterns from import.meta.glob() calls.

Transforms import.meta.glob() calls in source code.

Functions

patterns(source, filename \\ "glob.ts")

@spec patterns(String.t(), String.t()) :: [String.t()]

Extracts static glob patterns from import.meta.glob() calls.

Returns an empty list when parsing fails or no supported glob call is found. Patterns are returned exactly as authored, including negative patterns prefixed with !.

transform(source, base_dir, filename \\ "glob.ts")

@spec transform(String.t(), String.t(), String.t()) :: String.t()

Transforms import.meta.glob() calls in source code.

base_dir is the directory of the file containing the glob call and is used to resolve patterns to files. filename is only used for parser diagnostics. Returns the original source unchanged when parsing fails or no glob call is found.