-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Plugin autoload doesn't work for packages installed from GitHub and for Yarn PnP #8474
Comments
Relabeling with "area:api" as this isn't specific to the CLI. |
How do we fix it? I was thinking check the dirname is |
Checking |
The old logic didn't require it to be listed in |
What do you think, use The only thing will break is we can't test plugin by adding const packageRoot = packageDir(__dirname);
const autoLoadDir = thirdParty.findParentDir(
path.join(packageRoot, ".."),
"node_modules"
); |
Such a package must follow the plugin naming scheme too.
Does the bug that we discuss here affect global installation? |
I don't think so, if this package has lots plugins in dependencies, we will load.
Hmm, not sure. |
I didn't understand what you mean then. I thought you were talking about something like "plugin packs" - packages that aren't plugins by themselves but install multiple other plugins. Apparently, you meant something else. Please explain. BTW, did you get my email? Can you open DMs on Twitter? |
That's what I mean, "plugin packs" don't need named
|
So far Prettier didn't promise to support such plugin packs. They might get installed in such a way that there will be an inner |
I think we have a wrong logic here right now https://github.com/prettier/prettier/blob/master/src/common/load-plugins.js. Plugin(s) should be added to Eslint looking at a configuration to find out which plugins are installed. But we 0CJS, so some plugins can't be listed in the configuration. My vision:
Pros:
Cons:
These are my thoughts on this issue, I would like to hear other opinions. Maybe we should take a look at Eslint logic. It is pretty well designed. |
We have it. https://prettier.io/docs/en/plugins.html#using-plugins |
@thorn0 Strange, I see it for the first time 😄 But I think it should support |
@evilebottnawi It supports that. It accepts what |
I like the idea to check listed plugins in If I want I prefer auto load
|
Side suggestion: adding Happy to create a new issue / PR if there are no major flaws in the concept. |
I like We havn't support esm plugin, but we will face it. |
ESLint folks are simplifying their config via eslint/eslint#13481 and they have some nice thoughts in https://github.com/eslint/rfcs/tree/master/designs/2019-config-simplification. Essentially, they no longer have paths in their config and the Wondering if we could do something similar in Prettier. Is it necessary that the resulting Prettier config is serializable? Even if not, a Yarn-2-compatible config would need to be in |
Personally I use |
It’s already possible to declare |
Doing it this way, the glob pattern resolving stuff will not detect file extensions declared by the plugins. This is because the context object (which resolves the glob into filepaths) is loaded before the .prettierrc file (see #13276). As a result the plugins get loaded due to the configuration in the prettierrc but the files they're supposed to format won't get detected. This makes it so that there is no option but to pass the plugins using the
It's important that the plugin loading step is done in |
Should this issue title + description also mention pnpm? Just wondering because some other issues about autoloading Prettier plugins failing in pnpm have been marked as duplicates of this issue. |
@karlhorky I think the issue is caused because prettier is not handling PnP correctly but i've only tested it on yarn so I dont know if pnpm has the same problem. If you've got the same sort of problem in pnpm have a look at the fix I suggested in my last comment. If you look at the issue i've linked in that comment you'll see the steps i used and a more thorough explanation of the cause of the problem. Try following the same steps using pnpm instead of yarn2. If the problem gets fixed for you then we can be sure its caused because of the way prettier handles pnp and it's not an issue specific to yarn or any other package manager. |
Check out #11008 - other users have reported similar issues with pnpm, and they have been redirected here as a duplicate. That's why I wrote above that the title + description should maybe include pnpm as well, to make it easier to search for / read through. |
Ok so if I'm understanding correctly, the next major version of Prettier (3.0.0) will have the plugin autoload / automatic search feature removed, so that they will need to be specified always. |
One of the problems mentioned above is that specifying plugins in the .prettierrc file would load the plugin but it would fail to load / detect the file extensions that that plugin formats. Thus a command like |
@Waghabond have you tried |
Environments:
Steps to reproduce:
yarn add prettier/prettier @prettier/plugin-pug
Expected behavior:
Can format pug file with
npx prettier test.pug
Actual behavior:
The CLI can't load
pug
plugin automaticallyProblem should be here, when install from github,
./node_modules/prettier
maybe has ownnode_modules
dir, so theautoLoadDir
will be./node_modules/prettier
, not expected./
, so we are looking for./node_modules/prettier/node_modules/@prettier/plugin-*
not./node_modules/@prettier/plugin-*
(where the@prettier/plugin-pug
is installed).The text was updated successfully, but these errors were encountered: