markmv - v1.41.7
    Preparing search index...

    Class DependencyGraph

    Builds and analyzes dependency relationships between markdown files.

    The DependencyGraph tracks file relationships through links, references, and imports to enable intelligent file operations. It supports cycle detection, topological sorting, impact analysis, and dependency-aware ordering for operations like joining and splitting.

    Building a dependency graph

    const graph = new DependencyGraph();

    // Add files to the graph
    await graph.addFile('intro.md');
    await graph.addFile('setup.md');
    await graph.addFile('usage.md');

    // Analyze dependencies
    const order = graph.getTopologicalOrder();
    console.log('Processing order:', order);

    // Check for circular dependencies
    const cycles = graph.detectCycles();
    if (cycles.length > 0) {
    console.warn('Circular dependencies detected');
    }

    Impact analysis

    const graph = new DependencyGraph(parsedFiles);

    // Find all files affected by changing api.md
    const impacted = graph.getImpactedFiles('api.md');
    console.log(`${impacted.length} files will be affected`);
    Index
    • Replaces the recorded dependency set for a file with the one on the parsed file. The node's own dependency set is updated too when the file already has a node.

      Parameters

      Returns void

    • Rebuilds the graph from scratch: clears existing state, creates a node for every file, records each file's dependencies and then derives the reverse (dependents) relationships. Each file's dependents field is updated to match.

      Parameters

      Returns void

    • Finds dependency cycles using a depth-first search over every node.

      Returns string[][]

      One path per cycle found, listed in traversal order with the first file repeated at the end; empty when the graph is acyclic.

    • Lists the paths of every node in the graph.

      Returns string[]

      The node paths in insertion order.

    • Lists the files a file directly depends on.

      Parameters

      • filePath: string

        Path of the file to inspect.

      Returns string[]

      The direct dependency paths, or an empty array when the path has no recorded dependencies.

    • Lists the files that directly depend on a file. Paths without a node of their own, such as linked images, are resolved by scanning the recorded dependencies of every file.

      Parameters

      • filePath: string

        Path of the file to inspect.

      Returns string[]

      The paths of the files that link to it.

    • Looks up the node for a file.

      Parameters

      • filePath: string

        Path the file was added under.

      Returns FileNode | undefined

      The node, or undefined when the path has no node (for example a linked asset that was never parsed as markdown).

    • Collects every file reachable by following dependencies from a file, directly or indirectly. Cycles are tolerated and each path appears once.

      Parameters

      • filePath: string

        Path of the file to start from.

      Returns string[]

      The distinct dependency paths, excluding the starting file unless a cycle leads back to it.

    • Collects every file that depends on a file, directly or through a chain of other files. Cycles are tolerated and each path appears once.

      Parameters

      • filePath: string

        Path of the file to start from.

      Returns string[]

      The distinct paths of all files affected by a change to the starting file.

    • Removes a file from the graph along with every reference to it in other nodes' dependency and dependent sets. Does nothing when the path has no node.

      Parameters

      • filePath: string

        Path of the file to remove.

      Returns void

    • Serialises the dependency edges for JSON.stringify.

      Returns Record<string, string[]>

      A map from each file path to the paths it depends on.

    • Orders the files so that each file appears after everything it depends on. In a graph with cycles, each cycle is broken at the point where the search first revisits a file.

      Returns string[]

      File paths in dependency-first order.

    • Renames a file throughout the graph: its node and edges are moved to the new path, and every other node's dependency and dependent sets that mention the old path are rewritten. Paths without a node of their own, such as linked assets, still have references to them rewritten.

      Parameters

      • oldPath: string

        Path the file is currently known by.

      • newPath: string

        Path to replace it with.

      Returns void