Top level property sort not working
- 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. :(
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.
is this enough?
Can't do much with a screenshot...
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.
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.
with the provided steps you can reproduce it.
https://stackblitz.com/edit/stackblitz-starters-ipdxxz
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.
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.