Task runnerConceptsTask Graph

Task Graph

Understanding task graphs and dependency-aware scheduling

Task Graph

The task graph is the foundation of the task runner. It defines tasks, their dependencies, and determines execution order.

Structure

A task graph consists of:

  • Tasks - Individual units of work (e.g., app:build, lib:test)
  • Dependencies - Edges between tasks that define execution order
  • Roots - Tasks with no dependencies (entry points)
import { createTaskGraph } from "@visulima/task-runner";

const taskGraph = createTaskGraph(tasks, {
    projectGraph,
    targetDefaults: {
        build: { dependsOn: ["^build"] }, // Run dependency builds first
    },
    workspace,
});

Task IDs

Tasks are identified by the format project:target:configuration:

import { getTaskId, parseTaskId } from "@visulima/task-runner";

const id = getTaskId({ project: "my-app", target: "build", configuration: "production" });
// → "my-app:build:production"

const parsed = parseTaskId("my-app:build");
// → { project: "my-app", target: "build" }

Dependency Resolution

The ^ prefix in dependsOn means "run this target in dependency projects first":

const targetDefaults = {
    build: {
        dependsOn: ["^build"], // Build all dependencies before this project
    },
    test: {
        dependsOn: ["build"], // Build this project before testing
    },
};

Graph Utilities

import {
    findCycle,
    makeAcyclic,
    walkTaskGraph,
    getDependentTasks,
    getTransitiveDependencies,
} from "@visulima/task-runner";

// Detect cycles
const cycle = findCycle(taskGraph);

// Remove cycle-forming edges
const acyclicGraph = makeAcyclic(taskGraph);

// Walk in topological order
walkTaskGraph(taskGraph, (taskId) => {
    console.log(`Processing ${taskId}`);
});

Scheduling

The TaskScheduler handles parallel execution with priority-based ordering:

  1. Tasks with more dependents are scheduled first (unblocks more work)
  2. Deeper projects in the dependency graph go first
  3. Respects maxParallel concurrency limits
import { TaskScheduler } from "@visulima/task-runner";

const scheduler = new TaskScheduler(taskGraph, projectGraph, 4);

while (!scheduler.isComplete()) {
    const batch = scheduler.getNextBatch();
    // Execute batch in parallel...
}
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues