-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Improve plugin resolution (fixes pnpm compatibility) #11248
Conversation
Thanks for working on this.
|
This will break monorepo. |
I've come up with a solution that fixes compatibility with pnpm and shouldn't (hopefully) break any project setups (monorepo, global install, etc). It also doesn't care about what the virtual store is called or where it is. I added tests and updated the plugins documentation page as well. I'm not very familiar with jest so I'd appreciate if someone could check those over. There are comments in the code that hopefully make it clear, but I'll somewhat briefly explain here: Essentially, instead of trying to find pnpm's All packages in the virtual store have a directory structure that looks like this:
All packages in the virtual store are appended with Additionally, you can now pass
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
What's stopping you? |
But it's something that should work out of box instead of manual configuring. Not to mention those who prefer to use JSON as the configuration format (like me). |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@fisker Was hoping you could take a look at this again. I fixed the merge conflicts and all tests pass. |
Added proper tests to make codecov happy. Are there any issues that are preventing this from being merged? @fisker |
Sorry for the delay, I haven't take a deep look. But the plugin search related part already changed in |
@fisker I closed this by mistake. Are you able to reopen it and change the base to I updated my changes/tests to work with |
I can't, the button is disabled. |
Ah weird. New PR is here: #13583 |
Description
Fixes #8056
== See this reply for an explanation of the updated fix: #11248 (comment) ==
Previously, plugins were loaded from thenode_modules
directory that was parent to the current running instance of Prettier. Loading relative to the cwd ensures that the rightnode_modules
is used (for example, when using Prettier with pnpm).I added pkg-dir to handle finding the project directory. I initially wrote my own way to find it, but I figured using this package is probably better and safer than anything I could come up with. This package simply starts from the cwd and traverses up until it finds a path wherepackage.json
exists. Hopefully this wouldn't break plugin loading for anyone. I can't think of any project setups where this would.I've tested this with my own projects that use pnpm and Prettier loads all my plugins without issue.Checklist
I could be completely wrong, but I don't think additional tests need to be written for this change. All current tests pass.
cwd
will always be a path in the actual project that is being formatted, so the rightnode_modules
will be found.docs/
directory).I can update the docs if needed, but it seems like the way
plugins.md
is currently worded still makes sense.The default directory is still the
node_modules
above theprettier
binary, we're just getting there a different way.changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨