Running concurrent and persistent tasks using Turborepo

I have a conventional Turborepo setup and running turbo dev in the root will run the dev script in all my applications as expected and consolidate them the in the classic TUI output window. One of my apps needs two concurrently running tasks as well which are basically a dev server for another tool and a tunnel for webhooks which I have been manually starting in separate terminal windows for now.

Technically I am aware that I could literally use concurrently for the app’s dev script but dislike that the console output of the three would be mixed together. Instead, I’d prefer to have the other two tasks appear in the TUI list as well to be able to nicely go through the logs and switch between them. If I am not mistaken though, persistent tasks cannot be dependencies so I was wondering whether there is a reasonable setup to instruct Turborepo to run the additional concurrent tasks just like all the other dev tasks in one go.

Hi Christian,

You should be able set up Turborepo to run multiple persistent tasks as separate entries in the TUI. This is a common need for projects that require multiple concurrent services. The key is to define each of your persistent tasks separately in your turbo.json file. Turborepo will run them in parallel and display them as separate entries in the TUI.

{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    "dev": {
      "persistent": true,
      "cache": false
    },
    "dev:server": {
      "persistent": true,
      "cache": false
    },
    "dev:tunnel": {
      "persistent": true,
      "cache": false
    }
  }
}

Then in your package.json for the specific app that needs multiple tasks:

{
  "scripts": {
    "dev": "next dev",
    "dev:server": "your-other-tool serve",
    "dev:tunnel": "your-tunnel-command"
  }
}

Then you can run all three tasks with:

turbo dev dev:server dev:tunnel

If you’re in a monorepo with multiple packages, you can use filtering to run these tasks only for the specific app that needs them:

turbo dev dev:server dev:tunnel --filter=your-app-name

Ah yes indeed this works even though I have to admit that I don’t like that the the root command needs to be extended with unique names instead of being able to keep this kind of “dependency” local to the single app. A way to setup this within the local turbo.json inside the app itself would have been much nicer. It is probably for that reason that I haven’t thought about polluting the global commands and tasks and thus did not come up with that solution.

Maybe it is something I should bring up for discussion to Anthony unless this has been discussed previously.

No worries, I have pinged Anthony internally. He will check once he comes online tomorrow :slight_smile:

Hi Christian,

In Turborepo 2.5 we just released a new feature with which can let you declare tasks that should run “with” your task. You can use this to make sure the tunnel will always get started alongside your standard dev task.

Blog post: Turborepo 2.5 | Turborepo
Documentation: Configuring turbo.json | Turborepo

1 Like

Marvelous. I’ll be looking into it. Thank you for following up on this!

Small note since I was confused why a month old release wasn’t appearing via renovate in my repository until I realized that your blog post’s date is wrong. It says 3 Mar instead of 3 April :sweat_smile:

I can confirm that the new sidecar feature works exactly as expected, love it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.