apps/docs/content/docs/reference/turbo-codemod.mdx
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 manage repetitive changes.
First, ensure that you've run your package manager's install command.
npx @turbo/codemod [transform] [path] [--dry] [--print]
transform - name of transform, see available transforms below.path - files or directory to transform--dry - Do a dry-run (Code will not be edited)--print - Prints the changed output for comparisonIn most cases, you can run:
npx @turbo/codemod migrate
All the codemods you need to upgrade will be run for you.
The codemods below are used for migration paths in the second major version of Turborepo.
<Accordions> <Accordion title="update-versioned-schema-json (2.7.5)" id="update-versioned-schema-json">Updates the $schema URL in turbo.json files to use the versioned subdomain format. This applies to both root and workspace turbo.json files.
npx @turbo/codemod update-versioned-schema-json
Example
{
- "$schema": "https://turborepo.dev/schema.json",
+ "$schema": "https://v2-7-5.turborepo.dev/schema.json",
}
Updates a versioned schema.json URL to v2.
npx @turbo/codemod update-schema-json-url
Example
{
- "$schema": "https://turborepo.dev/schema.v1.json",
+ "$schema": "https://turborepo.dev/schema.v2.json",
}
Adds a name to package.json in any packages that don't have one.
npx @turbo/codemod add-package-names
Example
{
+ "name": "@repo/ui",
}
Fix glob patterns that are invalid due to changes in processing of globs in turbo.
npx @turbo/codemod clean-globs
Example
{
"tasks": {
"build": {
"outputs": [
// Collapse back-to-back doublestars
- "**/**.ext", // [!code highlight]
+ "**.ext" // [!code highlight]
// Ensure a file extension does not have a double-star
- "**.ext", // [!code highlight]
+ "**/*.ext" // [!code highlight]
// Proper expansion of directory names
- "prefix**/", // [!code highlight]
+ "prefix*/**" // [!code highlight]
]
}
}
}
Move .env files from the removed dotEnv key to inputs.
npx @turbo/codemod migrate-dot-env
Example
{
"tasks": {
"build": {
- "dotEnv": [".env"], // [!code highlight]
"inputs": [
"dist/**",
+ ".env" // [!code highlight]
],
}
}
}
Rename the outputMode key to outputLogs.
npx @turbo/codemod rename-output-mode
Example
{
"tasks": {
"build": {
- "outputMode": "errors-only" // [!code highlight]
+ "outputLogs": "errors-only" // [!code highlight]
}
}
}
Rename the pipeline key to tasks.
npx @turbo/codemod rename-pipeline
Example
{
- "pipeline": {
+ "tasks": {
"build": {
...
},
"dev": {
...
},
"lint": {
...
}
}
}
Renames the experimentalUI key in turbo.json to ui.
npx @turbo/codemod stabilize-ui
Example
{
- "experimentalUI": true
+ "ui": true
}
The codemods below are used for migration paths in the first major version of Turborepo.
<Accordions> <Accordion title="stabilize-env-mode (1.10.0)" id="stabilize-env-mode">Migrates turbo.json's experimentalGlobalPassThroughEnv to globalPassThroughEnv and experimentalPassThroughEnv to passThroughEnv.
npx @turbo/codemod stabilize-env-mode
Example
{
"$schema": "https://turborepo.dev/schema.json",
- "experimentalGlobalPassThroughEnv": ["CC"],
+ "globalPassThroughEnv": ["CC"],
"pipeline": {
"build": {
- "experimentalPassThroughEnv": ["GOROOT"],
+ "passThroughEnv": ["GOROOT"],
}
}
}
Updates any existing environment variable fields whose contents would be ambiguous to the new wildcard syntax.
npx @turbo/codemod transform-env-literals-to-wildcards
Example
{
"$schema": "https://turborepo.dev/schema.json",
- "globalEnv": ["THIS_*_IS_LITERAL"],
- "globalPassThroughEnv": ["!LITERAL_LEADING_EXCLAMATION"],
+ "globalEnv": ["THIS_\\*_IS_LITERAL"],
+ "globalPassThroughEnv": ["\\!LITERAL_LEADING_EXCLAMATION"],
"pipeline": {
"build": {
- "env": ["50_PERCENT_OFF*_HAS_SMALL_PRINT"],
- "passThroughEnv": ["**BOLDED**"],
+ "env": ["50_PERCENT_OFF\\*_HAS_SMALL_PRINT"],
+ "passThroughEnv": ["\\*\\*BOLDED\\*\\*"],
}
}
}
Migrates turbo.json outputs to include the previously inferred dist/** and build/**.
npx @turbo/codemod set-default-outputs
Example
{
"$schema": "https://turborepo.dev/schema.json",
"globalDependencies": [".env"],
"globalEnv": ["CI_ENV"],
"pipeline": {
"build": {
"dependsOn": ["^build"],
"env": ["API_BASE"],
"outputs": [".next/**", "!.next/cache/**", "!.next/dev/**"]
},
- "lint": {
- "outputs": []
- },
+ "lint": {},
"dev": {
"cache": false,
"persistent": true,
+ "outputs": ["dist/**", "build/**"]
}
}
}
Migrates all environment variable dependencies in turbo.json from dependsOn and globalDependencies to env and globalEnv respectively.
npx @turbo/codemod migrate-env-var-dependencies
Example
// After, turbo.json
{
"$schema": "https://turborepo.dev/schema.json",
- "globalDependencies": [".env", "$CI_ENV"],
+ "globalDependencies": [".env"],
+ "globalEnv": ["CI_ENV"],
"pipeline": {
"build": {
- "dependsOn": ["^build", "$API_BASE"],
+ "dependsOn": ["^build"],
+ "env": ["API_BASE"],
"outputs": [".next/**", "!.next/cache/**", "!.next/dev/**"],
},
"lint": {},
"dev": {
"cache": false,
"persistent": true
}
}
}
npx @turbo/codemod add-package-manager
Example
{
"name": "turborepo-basic",
"version": "0.0.0",
"private": true,
+ "packageManager": "[email protected]",
"workspaces": [
"apps/*",
"packages/*"
]
}
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.
npx @turbo/codemod create-turbo-config
Example
<Tabs items={["package.json", "turbo.json"]}> <Tab value="package.json">
// After, package.json
{
"name": "@acme/workspace",
"private": true,
- "turbo": {
- "pipeline": {
- ...
- }
- },
}