-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix plugin search on pnpm
#9167
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add simple tests?
To setup this test, I need install Seems not worth to do that. |
@fisker we can recreate the structure to make sure it works, in the future we can better automate testing, fixes without tests is bad idea |
How do we put prettier self into |
@fisker we can mock |
Thanks for this @fisker! |
Would be great to have this merged, I switched to npm for my app template because of that. |
@wighawag I'm using pnpm with prettier. There's an easy workaround, use the |
@aparajita I can make it work from the command line, |
/cc @fisker What do you think? |
FWIW, |
@thorn0 I tried that but without success, there seems to be other problem with the vscode plugin |
@wighawag Are you running a global installed Prettier? |
No I use locally installed in the root of the mono repo. |
@wighawag You should file an issue with the eslint plugin maintainer. |
@aparajita you mean the prettier plugin I suppose |
Oops, yes. |
const autoLoadDir = | ||
findParentDir(__dirname, "node_modules/.pnpm") || | ||
findParentDir(__dirname, "node_modules"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this will work.node_modules/.pnpm
is the default pnpm virtual store directory, but can be overridden by the virtual-store-dir
setting in .npmrc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the information, any suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. It seems the default path (or whatever is specified in pluginSearchDirs
) is being resolved relative to process.cwd()
which sits inside the pnpm virtual store. Packages in the virtual store aren't stored hierarchically so the concept of findParentDir
does not really work. With pnpm, the package hierarchy is captured in the symlink structure, so the plugin searching will need to use the symlink (not the target) somehow. The only way I have gotten plugins to load is by specifying them in .prettierrc
using a relative path, e.g. "plugins": ["./node_modules/prettier-plugin-packagejson"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also use eslint
plugins which seem to work fine with pnpm
... Looking at the eslint docs/internals it seems they resolve plugins as if you were to require
them from the config file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you accept this simple change as is and defer fine-tuned configuration? Prettier doesn't work with PNPM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prettier does work with pnpm, it just won’t auto load plugins. You can load them manually in the .prettierrc, for example: "plugins": ["./node_modules/prettier-plugin-packagejson"]
For anyone following this thread, I've created a PR that hopefully addresses this issue. |
I am switching from PNPM to NPM :( |
Rename // .prettierrc.js
module.exports = {
plugins: [
require.resolve('prettier-plugin-packagejson'),
// ...
]
} |
this doesn't work for me |
any updates on this? it's been open for over 2 years now |
Currently the vscode prettier plugin supports resolve pnpm symlinks. So you don't need // .prettierrc
{
"plugins": ["some-plugin"]
} |
@fz6m really? for me it doesn't detect pnpm packages either |
This was broken for me and I had to migrate from pnpm to npm (loading plugins explicitly didn't work) |
Local tested, it not easy to test, because this logic need plugin installed in same location with
prettier
.Fixes #8056
docs/
directory)changelog_unreleased/*/pr-XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨