Docs
/
API Reference
/
Codemods

Turborepo Codemods

Turborepo provides Codemod transformations and automatic migration scripts to help upgrade your Turborepo codebase when a feature is deprecated.

Codemods are transformations that run on your codebase programmatically. This allows for a large amount of changes to be applied without having to manually go through every file.

Usage

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

Turborepo 1.x

add-package-manager

Transforms the root package.json so that packageManager key as the detected package manager (yarn, npm, pnpm) and version (e.g. yarn@1.22.17). This key is now supported by Node.js and is used by Turborepo for faster package manager detection (vs. inferring from just the filesystem alone).

For example, for Yarn v1:

// Before
{
  "name": "turborepo-basic",
  "version": "0.0.0",
  "private": true,
  "workspaces": [
    "apps/*",
    "packages/*"
  ],
  ...
}
// After
{
  "name": "turborepo-basic",
  "version": "0.0.0",
  "private": true,
  "packageManager": "yarn@1.22.17",
  "workspaces": [
    "apps/*",
    "packages/*"
  ],
  ...
}

Usage

Go to your project:

cd path-to-your-turborepo/

Run the codemod:

npx @turbo/codemod add-package-manager

create-turbo-config

Creates the turbo.json file at the root of your project based on the "turbo" key in package.json. The "turbo" key is subsequently deleted from package.json.

For example:

// Before, package.json
{
  "name": "Monorepo root",
  "private": true,
  "turbo": {
    "baseBranch": "origin/main",
    "pipeline": {
      ...
    }
  },
  ...
}
// After, package.json
{
  "name": "Monorepo root",
  "private": true,
  ...
}

// After, turbo.json
{
  "$schema": "https://turborepo.org/schema.json",
  "baseBranch": "origin/main",
  "pipeline": {
    ...
  }
}

Usage

Go to your project:

cd path-to-your-turborepo/

Run the codemod:

npx @turbo/codemod create-turbo-config
Last updated on February 11, 2022