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

Top level property sort not working #24

Open
rotkiw opened this issue Feb 8, 2024 · 8 comments
Open

Top level property sort not working #24

rotkiw opened this issue Feb 8, 2024 · 8 comments

Comments

@rotkiw
Copy link

rotkiw commented Feb 8, 2024

  • Prettier Version: 3.2.5
  • Operating System (or Browser): Windows 11 Pro 23H2 (22631.3085)
  • Node Version: 18.19.0
  • prettier-plugin-package Version: 1.4.0

How Do We Reproduce?

1, install the latest prettier and prettier-plugin-package modules.

npm i --save-dev prettier prettier-plugin-package

2, create a prettier config file and set prettier-plugin-package as a plugin. without this the plugin will not recognized.

// prettier.config.js
module.exports = {
  plugins: ['prettier-plugin-package'],
}

3, shuffle the package.json content.

4, try to format.

prettier --write package.json

Expected Behavior

top-level keys are sorted.

Actual Behavior

guess what: not so much. :(

@shellscape
Copy link
Owner

I use this daily (have since I published it) and don't have that issue. I'm afraid to be of any help you'll need to demonstrate this in a reproduction using stackblitz or a repo, and provide details on what you think isn't working.

@rotkiw
Copy link
Author

rotkiw commented Feb 8, 2024

Képernyőkép 2024-02-08 210324

is this enough?

@shellscape
Copy link
Owner

Can't do much with a screenshot...

@rotkiw
Copy link
Author

rotkiw commented Feb 8, 2024

as you can see in the picture after formating the top level properties are not in order.

i expect this order:

// meta
'name',
'version',
'flat',
'private',
'publishConfig',
'description',
'license',
'repository',
'author',
'homepage',
'bugs',

// entry
'main',
'bin',
'module',
'type',
'exports',

// constraints
'engines',
'cpu',
'os',

// content and util
'scripts',
'files',
'keywords',

// dependencies
'bundledDependencies',
'optionalDependencies',
'peerDependencies',
'peerDependenciesMeta',
'dependencies',
'devDependencies',
'resolutions',

// types
'types',
'typings'

how about you go to stackblitz and repeat the steps i wrote. 3 of them copyable. maybe not the end of the world. or just close this issue, because you clearly don't care.

@shellscape
Copy link
Owner

a reproduction means to supply code in a way that others can collaborate on it to see the same result as you. if this isn't something that you're willing to put together or provide, please feel free to close this issue and use another package.

@rotkiw
Copy link
Author

rotkiw commented Feb 8, 2024

with the provided steps you can reproduce it.

https://stackblitz.com/edit/stackblitz-starters-ipdxxz

@shellscape
Copy link
Owner

Thanks. Yeah prettier weird that doesn't work. All of the tests pass in the repo, and I modified your stackblitz with a known good configuration that I'm using in several repos (which I verified working) and it's not even working on Stackblitz. Not sure what the cause is.

@shellscape
Copy link
Owner

Alright figured out what the deal is. Doesn't look like #23 actually got Prettier v3 compatibility solved (@viceice worth taking another look at if you have the time). This repro https://stackblitz.com/edit/stackblitz-starters-8zhnz2?file=package-lock.json,package.json,test%2Fpackage.json,.prettierrc.js with v2.8.8 is working fine. You can run npm run test and observe test/package.json changed. Update prettier to any newer v3.* version and it stops working. So something in the plugin architecture probably changed.

Pretty much everything I work on is still pinned to 2.8.8 so the likelihood of me getting around to this is pretty low for the near future. Totally welcome community contributions though.

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

No branches or pull requests

2 participants