Turborepo 1.1

Jared Palmer
Name
Jared Palmer
Twitter
@jaredpalmer
Becca Z.
Name
Becca Z.
Twitter
@becca__z
Gaspar Garcia
Name
Gaspar Garcia
Twitter
@gaspargarcia_
Greg Soltis
Name
Greg Soltis
Twitter
@gsoltis

Since releasing Turborepo v1.0 in mid-December, we've seen incredible adoption:

Weekly npm downloads of turbo

We're further improving build performance and caching with Turborepo v1.1, featuring:

Update today by running npm install turbo@latest. After running turbo, you'll see instructions about how to use @turbo/codemod to run automatic migrations for v1.1.

Automatic Migrations

Turborepo now provides idempotent code transformations and automatic migration scripts (a.k.a "codemods") to help upgrade your Turborepo codebase when a feature is deprecated or will be deprecated in the future.

Codemods are transformations that run on your codebase programmatically. This saves you time by applying a large number of changes to your code automatically, without having to manually go through and edit every file.

Usage

npx @turbo/codemod <transform> <path>
  • transform - the name of transform, see available transforms in the docs.
  • path - files or directory to transform.
  • --dry - Do a dry run, no code will be edited.
  • --print - Prints the changed output for comparison.

For more information about specific transforms, check out the new Codemods documentation.

turbo.json Support

Turborepo configuration is now defined in a turbo.json file in the root of your monorepo. This is an improvement over having a turbo key in package.json for those who want to quickly jump straight to their Turborepo configuration in their code editors.

To automatically migrate from your current configuration in package.json, check out a new branch, navigate to the root of your monorepo and run the following codemod:

npx @turbo/codemod create-turbo-config .

For more information on this transformation, check out the documentation.

Faster Package Manager Detection

Turborepo now supports the recently established packageManager field in package.json for faster package manager detection. Previously, turbo would check for specific files to infer this information. To automatically set this field, check out a new branch, navigate to the root of your monorepo and run:

npx @turbo/codemod add-package-manager .

For more information on this transformation, check out the documentation.

Environment Variable Dependencies

When you use turbo with tools that inline environment variables at build time (e.g. Next.js or Create React App), it is important you tell turbo about it to avoid shipping a cached artifact with the wrong environment variables.

You can now control turbo's cache fingerprinting (a.k.a. hashing) behavior based on the values of both environment variables and the contents of files:

  • Including environment variables in a dependsOn in your pipeline definition prefixed by a $ will impact the cache fingerprint on a per-task or per-package-task basis.
  • Including environment variables in globalDependencies list prefixed by a $ will impact the cache fingerprint of all tasks.
  • Including files or globs of files in globalDependencies will impact the cache fingerprint of all tasks.
  • The value of any environment variable that includes THASH in its name will impact the cache fingerprint of all tasks.
{
  "pipeline": {
    "build": {
      "dependsOn": {
        "^build"
        // env vars will impact hashes of all "build" tasks
        "$SOME_ENV_VAR"
      },
      "outputs": ["dist/**"]
    },
    "web#build": { // override settings for the "build" task for the "web" app
      "dependsOn": [
        "^build",
          // env vars that will impact the hash of "build" task for only "web" app
          "$STRIPE_SECRET_KEY",
          "$NEXT_PUBLIC_STRIPE_PUBLIC_KEY",
          "$NEXT_PUBLIC_ANALYTICS_ID",
      ],
      "outputs": [".next/**"],
    },
    "docs#build": { // override settings for the "build" task for the "docs" app
      "dependsOn": [
        "^build",
          // env vars that will impact the hash of "build" task for only "web" app
          "$STRIPE_SECRET_KEY",
          "$NEXT_PUBLIC_STRIPE_PUBLIC_KEY",
          "$NEXT_PUBLIC_ANALYTICS_ID",
      ],
      "outputs": [".next/**"],
    }
  },
  "globalDependencies": [
    "$GITHUB_TOKEN"// env var that will impact the hashes of all tasks,
    "tsconfig.json" // file contents will impact the hashes of all tasks,
    ".env.*" // glob file contents will impact the hashes of all tasks,
  ]
}

Note: In most monorepos, you don't often use environment variables in shared packages, but mostly in applications. Thus, to get higher cache hit rates, you should only include environment variables in the app-specific tasks where they are used/inlined.

For more information, read the caching and hashing documentation.

Partial Yarn v2/v3 support

In addition to Yarn v1, npm, and pnpm package managers, Turborepo now supports Yarn v2+ with nodeLinker: "node-modules" set in .yarnrc.yml. This key tells Yarn v2+ to mimic Yarn v1's node_modules installation behavior. Yarn v2+ Plug'n'Play (a.k.a. "PnP") is not currently supported.

What's next?

Since our launch, Turborepo has focused on seamless incremental adoption/migration and speeding up CI/CD. We are committed to both of those values, but now we'll also be focusing on improving Turborepo's day-to-day ergonomics for local development and observability. We're really excited about this next chapter and will be sharing more details soon.

We're hiring!

The Turborepo team at Vercel is hiring! We're specifically looking for full time Senior Full Stack Software Engineers and Senior DevOps/Infrastructure Engineers to help us make Turborepo even better.

Last updated on August 12, 2022