Applies a codemod to all source files
org.openrewrite.codemods.ApplyCodemod
Applies a codemod represented by an NPM package to all source files.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is available under the Moderne Source Available License.
Options
Type | Name | Description | Example |
---|---|---|---|
String | transform | Transform to be applied using the executable. | -t path/to/transform/optimus-prime |
String | executable | Optional. Path to the codemod executable relative to the NPM directory. Defaults to jscodeshift/bin/jscodeshift.js . | @next/codemod/bin/next-codemod.js |
String | fileFilter | Optional glob pattern to filter files to apply the codemod to. Defaults to all files. Note: not all codemods support file glob filtering. | `**/*.(j |
List | codemodArgs | Optional. Arguments which get passed to the codemod command. | --force --jscodeshift='--parser=${parser}' |
Used by
This recipe is used as part of the following composite recipes:
- Add React imports
- Adds
DefaultTheme
module augmentation to typescript projects. - Combination of all deprecations
- Convert
var
tolet
- Converts ExpansionPanel to use ExpansionPanel component
- Converts GridList to use Grid component
- Converts JSS styles to styled-components
- Converts JSS to TypeScript in React components
- Converts
rootRef
toref
- Converts
sx
prop tosx
style prop - Converts all
@mui/material
submodule imports to the root module - Converts base imports to use React hooks
- Converts components to use the v4 adapter module
- Ensures presets are safe to use
- Generate named exports from CommonJS modules
- Migrate
ImageResponse
imports - Migrate to the New Image Component
- Moves date pickers to
@mui/x-date-picker
- Moves lab modules to
@mui/material
- Moves tree view to
@mui/x-tree-view
- Optimizes imports
- Prepends emotion cache
- Remove "use strict" directives
- Remove
<a>
Tags From Link Components - Remove system props and add them to the
sx
prop - Removes
Unstyled
suffix from base components - Removes
component
prop from base components - Removes
imgProps
prop from Avatar component - Rename Next Image Imports
- Rename Next Image Imports
- Renames CSS properties for Box component
- Renames CSS variables
- Renames
Mui
classname prefix - Renames
TextField
toInput
- Renames
alpha
prop toopacity
- Renames
closeIcon
prop tocloseButtonIcon
- Renames
collapsedHeight
prop totransitionCollapsedHeight
- Renames
color
prop tocolorOverride
- Renames
component
prop toas
- Renames
gap
prop tospacing
- Renames
option
prop togetOptionLabel
- Renames
row
prop toflexDirection="row"
- Renames base components to slots
- Renames components to slots
- Replace all function expressions with only
return
statement with simple arrow - Replace lodash and underscore array functions with native JavaScript
- Replace lodash and underscore function functions with native JavaScript
- Replace lodash and underscore object functions with native JavaScript
- Replace lodash and underscore utility functions with native JavaScript
- Replaces
@mui
imports with@mui/material
- Transform AMD style
define()
calls to ES6import
statements - Transform AMP HOC into page config
- Transform Anonymous Components into Named Components
- Transform CommonJS style
require()
calls to ES6import
statements - Update the theme creation from
@mui/system@v5
to be compatible with@pigment-css/react
- Update the usage of the
sx
prop to be compatible with@pigment-css/react
- Updates
borderRadius
prop values - Updates
circle
prop tovariant="circular"
- Updates
circular
prop tovariant="circular"
- Updates
down
prop for Hidden component - Updates
justify
prop tojustifyContent
for Grid component - Updates
minRows
andmaxRows
props for TextareaAutosize component - Updates
overlap
prop tovariant="dot"
- Updates
round
values for theme typography - Updates
size
prop for IconButton component - Updates
variant
prop for Chip component - Updates
variant
prop for CircularProgress component - Updates
variant
prop for Fab component - Updates
variant
prop for Skeleton component - Updates
variant
prop usage - Updates
width
values for theme breakpoints - Updates base imports to use named exports
- Updates createMuiTheme usage
- Updates import paths for core styles
- Updates link underline on hover
- Updates props for Dialog component
- Updates props for DialogTitle component
- Updates props for Modal component
- Updates props for Table component
- Updates scroll buttons for Tabs component
- Updates the usage of
styled
from@mui/system@v5
to be compatible with@pigment-css/react
- Updates the usage of the
@mui/material/Grid2
,@mui/system/Grid
, and@mui/joy/Grid
components to their updated APIs. - Updates theme breakpoints
- Updates theme options
- Updates theme palette mode
- Updates theme spacing API
- Updates theme spacing
- Updates usage of ThemeProvider
- Updates usage of
@mui/styles
- Updates usage of
@mui/types
- Updates usage of styled engine provider
- Updates usage of transitions
- Updates usage of useAutocomplete
- Updates usage of useTransitionProps
- Updates withMobileDialog higher-order component
- Updates withWidth higher-order component
- Use Built-in Font
- Use
viewport
export - Use
withRouter
Usage
This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly (unless you are running them via the Moderne CLI). To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml
create a new recipe with a unique name. For example: com.yourorg.ApplyCodemodExample
.
Here's how you can define and customize such a recipe within your rewrite.yml:
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ApplyCodemodExample
displayName: Applies a codemod to all source files example
recipeList:
- org.openrewrite.codemods.ApplyCodemod:
transform: '-t path/to/transform/optimus-prime'
executable: '@next/codemod/bin/next-codemod.js'
fileFilter: '**/*.(j|t)sx'
codemodArgs: --force --jscodeshift='--parser=${parser}'
Now that com.yourorg.ApplyCodemodExample
has been defined, activate it and take a dependency on org.openrewrite.recipe:rewrite-codemods:0.16.1
in your build file:
- Gradle
- Maven
- Moderne CLI
- Add the following to your
build.gradle
file:
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("com.yourorg.ApplyCodemodExample")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-codemods:0.16.1")
}
- Run
gradle rewriteRun
to run the recipe.
- Add the following to your
pom.xml
file:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.15.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>com.yourorg.ApplyCodemodExample</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-codemods</artifactId>
<version>0.16.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:run
to run the recipe.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe ApplyCodemod --recipe-option "transform='-t path/to/transform/optimus-prime'" --recipe-option "executable='@next/codemod/bin/next-codemod.js'" --recipe-option "fileFilter='**/*.(j|t)sx'" --recipe-option "codemodArgs=--force --jscodeshift='--parser=${parser}'"
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite.recipe:rewrite-codemods:0.16.1
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
- SourcesFileResults
- SourcesFileErrors
- RecipeRunStats
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
Column Name | Description |
---|---|
Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
Recipe that made changes | The specific recipe that made a change. |
Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
Cycle | The recipe cycle in which the change was made. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
Column Name | Description |
---|---|
Source path | The file that failed to parse. |
Recipe that made changes | The specific recipe that made a change. |
Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
Column Name | Description |
---|---|
The recipe | The recipe whose stats are being measured both individually and cumulatively. |
Source file count | The number of source files the recipe ran over. |
Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
99th percentile scanning time (ns) | 99 out of 100 scans completed in this amount of time. |
Max scanning time (ns) | The max time scanning any one source file. |
Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
99th percentile edit time (ns) | 99 out of 100 edits completed in this amount of time. |
Max edit time (ns) | The max time editing any one source file. |