Create a new VirtualFileSystem instance
Absolute path to the source directory
Optionaloptions: VirtualFileSystemOptionsOptional configuration for file filtering and processing
Scans the filesystem to collect the files. Newly files must be added via the ".add" method.
This method performs an initial scan of the source directory using the configured glob patterns and populates the internal file list.
Check if a given file is part of the virtual file system. The method checks for the scanned files as well as glob pattern matches.
Absolute file path to check
True if the file is tracked or matches the configured patterns
Returns the files as a flat list of key-value pairs
Converts the tracked files into a flat object where keys are relative paths (without extensions) and values are absolute file paths.
Optionaloptions: {Optional transformation functions for keys and values
Object with file mappings
Returns the files as a nested tree structure
Converts the tracked files into a hierarchical object structure that mirrors the directory structure of the source files.
Optionaloptions: {Optional transformation functions for keys and values
Nested object representing the file tree
Add a new file to the virtual file system. File is only added when it matches the pre-defined filters.
Absolute path of the file to add
True if the file was added, false if it doesn't match filters
Remove a file from the virtual file system
Absolute path of the file to remove
True if the file was removed, false if it wasn't tracked
Returns the file contents as AST-grep node and caches it forever. Use the "invalidate" method to remove it from the cache.
This method reads the file content, parses it into an AST using ast-grep, and caches the result for future requests to improve performance.
The absolute path to the file to parse
Promise resolving to the AST-grep node
Invalidates AST cache for a single file or all files
Use this method when files have been modified to ensure fresh AST parsing on subsequent get() calls.
OptionalfilePath: stringOptional file path to clear. If omitted, clears entire cache
Clear all scanned files from memory
Removes all tracked files from the internal file list, effectively resetting the virtual file system.
Virtual file system for managing and tracking files with AST parsing capabilities.
The VirtualFileSystem provides an abstraction layer over the physical file system, allowing efficient file scanning, filtering, and AST parsing with caching. It's designed to work with TypeScript/JavaScript files and provides various output formats for different use cases.
Example