Turborepo 1.4

Turborepo 1.4

Tuesday, August 9th, 2022
Greg Soltis
Name
Greg Soltis
X
@gsoltis
Nathan Hammond
Name
Nathan Hammond
X
@nathanhammond
Tom Knickman
Name
Tom Knickman
X
@tknickman
Anthony Shew
Name
Anthony Shew
X
@anthonysheww
Jared Palmer
Name
Jared Palmer
X
@jaredpalmer
Mehul Kar
Name
Mehul Kar
X
@mehulkar

Turborepo 1.4 brings:

Update today by running npm install turbo@latest.

Automatic environment variable inclusion

To help ensure correct caching across environments Turborepo will now automatically infer and include public environment variables when calculating cache keys for apps built with Astro, Create React App, Gatsby, Next.js, Nuxt, SvelteKit, Vite, Vue, and more. You can safely remove framework-specific public environment variables from turbo.json if you manually declared them.

{
  "pipeline": {
    "build": {
      "dependsOn": [
        "^build"
-       // Include build time public inlined environment variables that
-       // are different in development and production, so that
-       // Turborepo does not use the same cached build
-       // across environments
-       "$NEXT_PUBLIC_EXAMPLE_ENV_VAR"
      ]
    }
  }
}

Note that this automatic detection and inclusion only works if Turborepo successfully infers the framework your apps are built with. Additionally, the environment variables will only be included in the cache key for tasks in workspaces where that framework is used. In other words, environment variables inferred for Next.js apps, will only be included in the cache key for workspaces detected as Next.js apps. Tasks in other workspaces in the monorepo will not be impacted.

For example, consider a monorepo with three workspaces: a Next.js project, a Create React App project, and a TypeScript package. Each has a build script, and both apps depend on the TypeScript project. Let's say that this Turborepo has a standard turbo.json pipeline that builds them all in order:

{
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],
    },
  },
}

As of 1.4, when you run turbo run build, Turborepo will not consider any build time environment variables relevant when building the TypeScript package. However, when building the Next.js app, Turborepo will infer that environment variables starting with NEXT_PUBLIC_ could alter the output of the .next folder and should thus be included when calculating the hash. Similarly, when calculating the hash of the Create React App's build script, all build time environment variables starting with REACT_APP_PUBLIC_ will be included.

This improvement in hash specificity by framework is a significant step toward optimal, safe, and correct caching.

eslint-config-turbo

We've also created a new ESLint config for further in-editor assistance to help ensure your Turborepo cache can be correctly shared across every environment. While our new hashing algorithm should cover most situations with most frameworks, this ESLint config will provide in-editor feedback for teams using other build time inlined environment variables that are not framework-prefixed but impact build outputs (i.e. caching), and teams using their own in-house frameworks that we cannot detect automatically.

To get started, extend from eslint-config-turbo in your root eslintrc (opens in a new tab) file:

{
  // Automatically flag env vars missing from turbo.json
  "extends": ["next/core-web-vitals", "turbo"],
}

If you prefer more control over the rules - use can install and configure the eslint-plugin-turbo plugin directly by first adding it to plugins and then configuring the desired rules:

{
  "extends": ["next/core-web-vitals"],
  "plugins": ["turbo"],
  "rules": {
    // Automatically flag env vars missing from turbo.json
    "turbo/no-undeclared-env-vars": "error",
  },
}

The plugin will warn you if you are using non-framework-related environment variables in your code that have not been declared in your turbo.json.

As of 1.4.x, we now include eslint-config-turbo in all of our examples and in new projects generated via npx create-turbo.

Learn more about ESLint configs and plugins in the ESLint docs (opens in a new tab).

New framework and library examples

Based on your feedback and suggestions, we've created new examples to integrate Turborepo into your workflow:

Other bug fixes and improvements

Community

Since releasing Turborepo v1.3 in June (opens in a new tab), we've seen incredible adoption and community growth:

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

This release was brought to you by the contributions of: @B2o5T, @chitchu, @elis, @gsoltis, @harshcut, @jaredpalmer, @kocisov, @nathanhammond, @neolivz, @NuroDev, @oneezy, @samouri, @shayc, @StevenMatchett, @tknickman, @trevorr, @zsoldosp, and more!

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