C

msw/2/response-usages

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

To send a response from MSW handler, one would previously use something like res(ctx.text("Hello world")). In msw v2, this is achieved by returning a native WebAPI Response object. msw v2 conveniently exposes a HttpResponse function that has useful methods for creating just that object with a desired body. This codemod replaces the old res calls with the new HttpResponse function calls and a bunch of ctx utilities that usually go with it. See examples below.

This codemod does not remove unused properties on the callback signature due to the fact that there are more changes in other codemods included in the upgrade-recipe that rely on it. To apply these changes, you will have to run the recipe or run a callback-signature codemod that will do only that and replace all the references of old signature arguments.

Before

ts

After

ts

Before

ts

After

ts

Before

ts

After

ts

Before

ts

After

ts

Before

ts

After

ts

Ready to contribute?

Build your own codemod and share it with the community.