The Deno task runner provides a cross-platform shell for executing scripts defined in deno.json or package.json. It eliminates the need for platform-specific shell dependencies (like sh on Windows) by implementing a subset of POSIX shell functionality in Rust via the deno_task_shell crate.
The entry point for the task runner is execute_script, which initializes the necessary services and resolves the tasks to be executed based on the provided flags.
Deno searches for tasks in the following order:
--filter flag cli/tools/task.rs86-88deno.json(c) or package.json in the current directory or parent directories cli/tools/task.rs64-69The TaskRunner struct encapsulates the dependencies required to execute a task, including the NPM resolver, node resolver, and environment variables cli/tools/task.rs212-224
The following diagram illustrates the flow from the CLI command to the shell execution, mapping CLI logic to the underlying execution entities.
Task Runner Component Interaction
Sources: cli/tools/task.rs58-63 cli/tools/task.rs212-224 cli/task_runner.rs178-223
Deno uses a custom shell implementation to ensure that tasks run identically on Windows, macOS, and Linux. This shell supports piping, redirection, and sequential/parallel execution operators.
Deno determines the number of concurrent tasks using the DENO_JOBS environment variable or the available system parallelism cli/tools/task.rs201-210
When multiple tasks run in parallel, Deno prefixes the output of each task with its name to maintain readability cli/task_runner.rs100-124 The PrefixedWriter handles line-buffering and prefix insertion cli/task_runner.rs47-63 Additionally, Deno uses a ProgressBar system to provide visual feedback during long-running tasks or downloads cli/util/progress_bar/mod.rs87-146
Code Entity Mapping: Shell Execution and IO
Sources: cli/task_runner.rs100-124 cli/task_runner.rs178-183 cli/task_runner.rs216-223
Deno's task runner is workspace-aware. It can resolve tasks defined in different members of a workspace and handle dependencies between them.
| Feature | Description | Implementation |
|---|---|---|
| Recursive Execution | Runs tasks in all workspace members using --recursive. | cli/tools/task.rs110-120 |
| Filtering | Filters packages by name using --filter. | cli/tools/task.rs86-88 |
| Dependency Resolution | Sorts configuration folders by their internal dependencies. | cli/tools/task.rs107-108 |
| Package.json Support | Can be forced to use package.json scripts via environment variables. | cli/tools/task.rs70-83 |
When running tasks in a workspace, Deno ensures that members are processed in an order that respects their dependencies:
Workspace object retrieves all member configurations.config_folders_sorted_by_dependencies() cli/tools/task.rs107-108TaskRunner iterates through packages_task_info and executes the matched tasks cli/tools/task.rs142-156Deno manages terminal state to ensure a consistent user experience, especially during interactive tasks.
ConsoleStaticText utility allows for rendering persistent UI elements (like progress bars) at the bottom of the terminal without interfering with standard output cli/util/console.rs25-34DrawThreadRenderer instances to stderr cli/util/draw_thread.rs76-82TaskRunnerThe central struct in cli/tools/task.rs managing the execution state. It holds references to:
npm_resolver: For resolving node modules required by tasks cli/tools/task.rs215cli_options: To access workspace and configuration data cli/tools/task.rs219env_vars: A map of environment variables to be injected into the shell cli/tools/task.rs218run_taskDefined in cli/task_runner.rs, this function bridges the CLI tool logic with the deno_task_shell crate. It:
INIT_CWD and PATH adjustments for node_modules/.bin cli/task_runner.rs184-185deno command into the shell's custom commands cli/task_runner.rs186-190ShellState and executes the parsed script cli/task_runner.rs191-223TaskDefinitionRepresents the structure of a task as defined in the configuration file, including the command string and optional metadata cli/tools/task.rs235-237
Sources:
cli/tools/task.rs (Lines 58-224)cli/task_runner.rs (Lines 30-239)cli/util/progress_bar/mod.rs (Lines 87-209)cli/util/console.rs (Lines 25-167)cli/util/draw_thread.rs (Lines 76-171)Refresh this wiki