Documentation
    Preparing search index...

    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.

    const vfs = new VirtualFileSystem('/src', { glob: ['**/*.ts'] })
    await vfs.scan()
    const fileTree = vfs.asTree()
    const astNode = await vfs.get('/src/app.ts')
    Index

    Constructors

    Methods

    • 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.

      Returns Promise<void>

    • 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.

      Parameters

      • filePath: string

        Absolute file path to check

      Returns boolean

      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.

      Parameters

      • Optionaloptions: {
            transformKey?: (key: string) => string;
            transformValue?: (filePath: string) => string;
        }

        Optional transformation functions for keys and values

      Returns { [key: string]: string }

      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.

      Parameters

      • Optionaloptions: {
            transformKey?: (key: string) => string;
            transformValue?: (filePath: string) => string;
        }

        Optional transformation functions for keys and values

      Returns RecursiveFileTree

      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.

      Parameters

      • filePath: string

        Absolute path of the file to add

      Returns boolean

      True if the file was added, false if it doesn't match filters

    • Remove a file from the virtual file system

      Parameters

      • filePath: string

        Absolute path of the file to remove

      Returns boolean

      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.

      Parameters

      • filePath: string

        The absolute path to the file to parse

      Returns Promise<SgNode<TypesMap, Kinds<TypesMap>>>

      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.

      Parameters

      • OptionalfilePath: string

        Optional file path to clear. If omitted, clears entire cache

      Returns void

    • Clear all scanned files from memory

      Removes all tracked files from the internal file list, effectively resetting the virtual file system.

      Returns void