Back to blog

Turborepo 2.2

Friday, October 18th, 2024
Tom Knickman
Name
Tom Knickman
X
@tknickman
Anthony Shew
Name
Anthony Shew
X
@anthonysheww
Chris Olszewski
Name
Chris Olszewski
Nicholas Yang
Name
Nicholas Yang
X
@nicholaslyang
Dimitri Mitropoulos
Name
Dimitri Mitropoulos

Turborepo 2.2 brings a new repository query command, along with other improvements, including:

Update today by running npx @turbo/codemod migrate or get started with npx create-turbo@latest.

Query your repository Experimental

In Turborepo 2.2, we're introducing turbo query—a new command that allows running GraphQL queries against Turborepo's repository data. Turborepo computes lots of data about your repository in order to execute your tasks with maximum efficiency. This includes your package dependency graph, changed packages, task dependencies, log output from your tasks, and more. This data can be useful for scripting, refactoring, determine what to run in CI, and discovering other insights into your codebase.

To get started, run turbo query to open GraphiQL—a local IDE for writing GraphQL queries that supports interactive schema exploration, documentation, and sending queries.

You can also pass queries directly as a string or file path:

Terminal
turbo query "query { package(name: \"web\") { name } }"
turbo query query.gql

Examples

Get the name and path for all affected packages that have a test task.

affected-packages.gql
{
  affectedPackages(
    base: "main"
    head: "HEAD"
    filter: { has: { field: TASK_NAME, value: "test" } }
  ) {
    items {
      name
      path
    }
  }
}

Get a specific package and its direct dependencies.

direct-dependencies.gql
query {
  package(name: "cli") {
    directDependencies {
      name
    }
  }
}

Find all packages with more than 10 immediate dependents.

filter.gql
query {
  packages(
    filter: { greaterThan: { field: DIRECT_DEPENDENT_COUNT, value: 10 } }
  ) {
    name
  }
}

Turborepo has added APIs for structured data in the past, such as run summaries, dry run, and ls. However, these APIs have some limitations. First, they're centered around a single run, not general repository info. Second, as we added more fields, the output quickly became very large. We needed a way to query repository data in a run-agnostic fashion, and make the returned data more customizable.

We would like to thank @maschwenk, @rafaeltab and @weyert for their early feedback on this feature.

To learn more, visit the documentation, and leave feedback for this new experimental command on the turbo query RFC.

Improved cache safety

Caching tasks is one of the most powerful features of Turborepo, speeding up builds and other tasks by only re-running what has changed. With Turborepo 2.2, we're releasing some improvements to help configure cache inputs and outputs, and warn you when things don't look quite correct.

Platform environment variables

When deploying your applications, you likely already have environment variables configured in your production environment. Now, for supported platforms, Turborepo will automatically check these environment variables against your turbo.json configuration to ensure that you've correctly accounted for them, and will warn you about any missing environment variables.

Any platform can support this feature by implementing the TURBO_PLATFORM_ENV environment variable in to the build environment.

Vercel is supported today, and we will update documentation as more platforms become available.

Learn more about platform environment variables.

Warnings for empty cache configurations

When running tasks, Turborepo will now warn you if a task is configured to cache an empty directory. This can be a common mistake, and can lead to accidental broken builds. This is enabled by default in 2.2.

Learn more about configuring outputs.

Improvements to eslint-config-turbo

Turborepo automatically adds prefix wildcards to your env key for common frameworks. If you're using one of the supported frameworks, you don't need to specify environment variables that begin with the framework's prefix.

Now in Turborepo 2.2, eslint-config-turbo supports this feature as well, ensuring the warnings from the plugin are accurate and actionable.

Learn more about eslint-config-turbo.

Zero-configuration comparisons with --affected

In Turborepo 2.1, we released the --affected flag which can be used with turbo run and turbo ls to automatically target changed packages. In 2.2, we're taking it a step further by introducing automatic comparisons when running --affected in a GitHub workflow—making common use cases even smarter.

Learn more about --affected.

Community

Since releasing Turborepo 2.1 we've seen incredible adoption and community growth:

Turborepo is the result of the combined work of all of its contributors, including our core team.

View the full changelog.

Thank you for your continued support, feedback, and collaboration to make Turborepo your build tool of choice.