---
title: Turborepo Codemods
description: To make upgrading easier, Turborepo includes codemods and migration scripts.
---

# 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

```sh
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](https://nodejs.org/dist/latest-v17.x/docs/api/packages.html#packagemanager) and is used by Turborepo for faster package manager detection (vs. inferring from just the filesystem alone).

For example, for Yarn v1:

```json
// Before
{
  "name": "turborepo-basic",
  "version": "0.0.0",
  "private": true,
  "workspaces": [
    "apps/*",
    "packages/*"
  ],
  ...
}
```

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

#### Usage

Go to your project:

```sh
cd path-to-your-turborepo/
```

Run the codemod:

```sh
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:

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

```json
// 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:

```sh
cd path-to-your-turborepo/
```

Run the codemod:

```sh
npx @turbo/codemod create-turbo-config
```
