Skip to content

/config/deno/deno-json-tasks

deno.json "tasks": define and run scripts with deno task

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Deno
file
deno.json
key
tasks
type
object: task name to command string, or to { command, description, dependencies }
default
{} (no tasks)

The tasks object in deno.json maps a name to a command: "tasks": { "dev": "deno run --watch main.ts" }. Run it with deno task dev; deno task with no name lists every task. Deno runs the command with its own cross-platform shell, so &&, pipes, VAR=value cmd and redirections work the same on Windows, macOS and Linux. Deno 2 also runs scripts from package.json with the same command.

Example

bash
cat > deno.json <<'EOF'
{
  "tasks": {
    "hello": "echo hello from deno task",
    "greet": {
      "description": "Print a greeting with arguments",
      "command": "echo greeting:"
    },
    "build": {
      "command": "echo building",
      "dependencies": ["hello"]
    }
  }
}
EOF
echo "--- deno task"
npx --yes deno@2 task 2>&1
echo "--- deno task greet Ada"
npx --yes deno@2 task greet Ada 2>&1
echo "--- deno task build"
npx --yes deno@2 task build 2>&1

Output

--- deno task
Available tasks:
- hello
    echo hello from deno task
- greet
    // Print a greeting with arguments
    echo greeting:
- build
    echo building
    depends on: hello
--- deno task greet Ada
Task greet echo greeting: 'Ada'
greeting: Ada
--- deno task build
Task hello echo hello from deno task
hello from deno task
Task build echo building
building

Arguments after the task name are appended to the command. A task listed in dependencies runs first; independent dependencies run in parallel.

Value forms

FormExampleNotes
String"dev": "deno run -A --watch main.ts"The simplest form
Object with command"dev": { "command": "...", "description": "..." }The description is shown by deno task
Object with dependencies"build": { "command": "...", "dependencies": ["check"] }Runs the listed tasks first
Dependencies only"ci": { "dependencies": ["fmt", "lint", "test"] }A task that only groups others

Shell syntax inside tasks

Deno's task shell supports &&, ||, ;, pipes, > and 2> redirects, $VAR expansion, VAR=value command and globs. Built-in commands (cp, mv, rm, mkdir, echo, cat, sleep, exit) work on Windows without a POSIX shell. Use deno task --cwd DIR NAME to run from another directory; by default tasks run from the directory containing deno.json.

Sources