C

msw/2/request-changes

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

Following the original msw upgrade guide, the signature of the request handler have changed. Some of the parameters have changed their type, some widely used objects are available directly on the callback argument object for convenience. Following changes are applied by this codemod:

  • req.url is now obtained as new URL(request.url), request being a new object available for destructure from the single callback argument
  • req.params are now exposed in the same callback argument
  • req.cookies are now exposed in the same callback argument
  • req.body is now removed instead of being deprecated. New response object now has a .json() method that should be the preferred way.

This codemod does not update the mentioned signatures of callback methods due to the fact that there are more changes in other codemods included in the upgrade-recipe that rely on the old signature. To apply the 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

Ready to contribute?

Build your own codemod and share it with the community.