Skip to content

How to migrate my plugin to support Prettier v3?

fisker Cheung edited this page Jul 11, 2023 · 5 revisions

Prettier v3 will change the plugin's interface. So this document describes how to migrate to v3 for plugin developers.

1. Remove use of prettier.doc.build.concat(), use array literal instead.

Notes:

  • Don't forget to update logic if your plugin traverse docs.

Changelog

2. Remove 2nd parameter in parse() function.

If you need core plugins check how to get the core plugins from the changelog.

Notes:

  • parse() can be async function.

Changelog

3. Update embed() function.

Check this link to see how the new embed works.

Notes:

  • If your plugin doesn't support embed() print, make sure you remove it (Empty function will cause print process slower).
  • If your plugin supports embed() print and you already have visitorKeys for your AST, please add getVisitorKeys() function, it will improve embed() print.
  • If your plugin supports embed() print and your AST have cycles, make sure exclude them in getVisitorKeys() function, otherwise your plugin won't work.

4. await your Prettier API calls.

If you are calling Prettier APIs inside your plugin or tests, make sure they are awaited.

Changelog

5. (optional) You can migrate your plugin to ES Module if you like.

Changelog