A starter repository for learning how to create OpenRewrite recipes for JavaScript and TypeScript. This repo includes example recipes with comprehensive tests, demonstrating the full project setup you need to author and test your own recipes.
New to OpenRewrite JavaScript recipe development? Start by checking out the OpenRewrite documentation and our JavaScript LST examples doc.
Clone this repository and install dependencies:
git clone git@github.com:moderneinc/javascript-recipe-starter.git
cd javascript-recipe-starter
npm installRun the tests:
npm testThis repository includes example recipes that demonstrate different authoring approaches and OpenRewrite capabilities:
-
MigrateUtilFunctions - Replaces deprecated Node.js
utiltype checking methods (likeutil.isArray()) with native JavaScript equivalents (likeArray.isArray()). Demonstrates pattern-based, declarative recipe authoring usingpatternandrewrite()rules with type context. -
SayHelloRecipe - Adds a
hello()method to JavaScript/TypeScript classes that don't already have one. Demonstrates visitor-based recipe authoring with manual LST manipulation and the template API. -
SemanticForwardRefMigration - Wraps React
forwardRef()calls withmemo()for better performance. Demonstrates semantic type matching that works across different import styles (named, namespace, default, and aliased imports). Shows how one pattern with type context can match syntactically different but semantically equivalent code.
- FindMethodCalls - Finds and records all calls to a specified method name in a data table. Demonstrates search recipes that collect findings without modifying code, useful for impact analysis before migrations. Shows the
@Optiondecorator for configurable recipes and@Columnfor data table structure. Results can be exported to CSV.
javascript-recipe-starter/
├── src/
│ ├── migrate-util-functions.ts
│ ├── say-hello-recipe.ts
│ ├── semantic-matching.ts
│ ├── find-method-calls.ts
│ └── index.ts
├── test/
│ ├── migrate-util-functions.test.ts
│ ├── say-hello-recipe.test.ts
│ ├── semantic-matching.test.ts
│ └── find-method-calls.test.ts
├── package.json
├── tsconfig.json
└── jest.config.js
To run these recipes against your own JavaScript/TypeScript codebase, you'll need to use the Moderne CLI and configure it to use JavaScript LSTs:
mod run . --recipe=MigrateUtilFunctionsSee LICENSE file for details.