prettier/prettier-vscode

Prettier plugin being ignored if installed via another package.

Levdbas opened this issue ยท 4 comments

Summary

When a prettier plugin is being included by another package, it doesn't get loaded by prettier-vscode.

Steps To Reproduce:

  1. Make/create a NPM package with for example the PHP plugin as dependency.
  2. Include the newly created npm package in your project.
  3. Open a PHP file, run prettier on it.
  4. Prettier vscode gives a warning that the plugin could not format this document.
  5. Now add @prettier/plugin-php to the package.json of the project, yarn install, restart vscode
  6. Open PHP file again, and run prettier. Now it runs.

Expected result

Prettier plugins included by dependency packages should be included as well.

Actual result

Prettier plugins included by dependency packages are not being loaded. Only if added to the package.js file of the actual project.

Additional information

I have a personal package that include all my build tools, including code formatting. We use this package around the company to all have the same build tools for every project we do. This way we can update our dev dependencies at once for all projects.

VS Code Version: 2.2.2

Prettier & Prettier Plugin Version:
PHP: 0.11.2
Prettier: 1.18.2

OS and version:
Windows 10

This isn't something I plan on fixing, the way we load prettier reads the package.json. If we were to do this, we would have to read the node_modules folder and that would cause other issues like refreshing the module when version changes. The recommendation is to just install prettier as a top level dependency along with plugins.

@ntotten please reconsider the decision โ€“ this is a valid use case. There should be no difference in how Prettier discovers its plugins in CLI and how this happens in VSCode. Otherwise, DX will be inconsistent and people will be opening issues here time and again.

Atom package has managed to autoload plugins and it works great. All you need is to launch Prettier with the correct cwd and it will do the discovery. No need for scanning node_modules.

At our company, we have a package called @acme/prettier-config, which in turn depends on prettier-plugin-packagejson. Developers just do yarn add -D prettier @acme/prettier-config in a new repo, then put "@acme/prettier-config" into project's .prettierrc and they are ready to go. No need to even know that there's a plugin involved in the setup โ€“ that's an implementation detail.

So I just spent some time testing this out. The VS Code prettier extension actually uses prettier to resolve the plugins. There are two cases here that I think will result in a plugin not working, but in both cases, in my tests, the extension behaves the same as prettier.

  1. If you only install a plugin, i.e. npm i @prettier/prettier-php and try to run the extension or prettier CLI. In both cases, nothing will work because no instance of prettier can be found.

  2. If you run npm i prettier @acme/prettier-config. In this case, the plugins are not detected because they are located in @acme/prettier-config/node_modules. This behavior is the same in the CLI and the extension. Note that if you use yarn instead of NPM this actually isn't an issue because yarn flattens out the node_module folder.

I am inclined to close this as by design, but if you can provide an example repo that clearly shows where the extension behaves different from the CLI, I am happy to investigate more.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.