Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Prettier v3 #156

Merged
merged 2 commits into from
Aug 25, 2023
Merged

Migrate to Prettier v3 #156

merged 2 commits into from
Aug 25, 2023

Conversation

Gudahtt
Copy link
Owner

@Gudahtt Gudahtt commented Jul 11, 2023

Prettier has been updated to v3. We now use types from Prettier directly, so the types package has been dropped as well.

This plugin was affected by three changes mentioned in the changelog 1:

  • parse now has one less parameter. The parsers parameter (which wasn't being used by this plugin) was removed.
  • The Babel parser is now located at prettier/plugins/babel.
  • Prettier now expects parsers to be async

A change was also required due to a seemingly-undocumented change to the output of the Prettier JSON parser. The AST is now returned wrapped in a JsonRoot node, which was not the case in v2.

eslint-plugin-prettier has been updated to v5, which is compatible with Prettier v3.

Fixes #119

src/index.ts Outdated Show resolved Hide resolved
@Gudahtt
Copy link
Owner Author

Gudahtt commented Jul 11, 2023

This is still in draft because I am seeing this error when attempting to run Jest:

Error: You need to run with a version of node that supports ES Modules in the VM API.

There may still be an incompatibility between Jest and Prettier v3. I saw a few tracking issues for this, though this error wasn't referenced in those discussions as far as I could tell.

@fisker
Copy link

fisker commented Jul 11, 2023

Prettier uses jest-light-runner, you may want try.

@bmichotte

This comment was marked as off-topic.

@pstachula-dev

This comment was marked as off-topic.

@Gudahtt Gudahtt force-pushed the prettier-v3 branch 6 times, most recently from 7d4b7e0 to 6785aef Compare August 25, 2023 02:03
@Gudahtt Gudahtt marked this pull request as ready for review August 25, 2023 02:05
@Gudahtt
Copy link
Owner Author

Gudahtt commented Aug 25, 2023

This is probably in good shape now! I'd like to do more testing before merging.

For anyone following this PR, if you were looking for a way to help, testing would be appreciated! You can test this by:

  • Checking out this branch
  • Installing dependencies (nvm use && yarn)
  • Building the plugin (yarn build)

Then in your project (which should be using Prettier v3 and prettier-plugin-sort-json), overwrite node_modules/prettier-plugin-sort-json/dist/index.js with the dist/index.js from the build on this branch. That should do it.

@Gudahtt Gudahtt force-pushed the prettier-v3 branch 2 times, most recently from 4443d56 to 75f37d9 Compare August 25, 2023 02:19
Prettier has been updated to v3. We now use types from Prettier
directly, so the types package has been dropped as well.

This plugin was affected by three changes mentioned in the changelog [1]:

* `parse` now has one less parameter. The `parsers` parameter (which
wasn't being used by this plugin) was removed.
* The Babel parser is now located at `prettier/plugins/babel`.
* Prettier now expects parsers to be async

A change was also required due to a seemingly-undocumented change to
the output of the Prettier JSON parser. The AST is now returned wrapped
in a `JsonRoot` node, which was not the case in v2.

`eslint-plugin-prettier` has been updated to v5, which is compatible
with Prettier v3.

fixes #119

[1]: https://prettier.io/blog/2023/07/05/3.0.0.html
@bmichotte
Copy link

bmichotte commented Aug 25, 2023

For anyone following this PR, if you were looking for a way to help, testing would be appreciated! You can test this by:

Hello @Gudahtt,

I just tested on one of my project with the following config

/** @type {import("prettier").Config} */
module.exports = {
    plugins: [
           require.resolve('prettier-plugin-tailwindcss'), 
           require.resolve('prettier-plugin-sort-json')
    ],
    trailingComma: 'all',
    tabWidth: 4,
    printWidth: 120,
    semi: false,
    singleQuote: true,
    bracketSameLine: true,
    arrowParens: 'avoid',
    jsonRecursiveSort: true,
}

with those versions :

prettier 3.0.2
prettier-plugin-sort-json 2.0.0 # overwrote with this PR version
prettier-plugin-tailwindcss 0.5.3

And everything went well, the tested json files where correctly reformatted 👍

@vlapo
Copy link

vlapo commented Aug 25, 2023

Tested on our projects and looks good. Nice work 🚀

@Gudahtt
Copy link
Owner Author

Gudahtt commented Aug 25, 2023

Thanks for the help @bmichotte and @vlapo ! I've tested this myself as well, and it seems to work. I'll prepare a v3 release now.

@Gudahtt Gudahtt merged commit d199617 into main Aug 25, 2023
15 checks passed
@Gudahtt Gudahtt deleted the prettier-v3 branch August 25, 2023 12:41
@Gudahtt
Copy link
Owner Author

Gudahtt commented Aug 25, 2023

This has been published as v3: https://github.com/Gudahtt/prettier-plugin-sort-json/releases/tag/v3.0.0

@bmichotte
Copy link

Thank you @Gudahtt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Prettier v3
5 participants