Skip to content
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

How to use prettier's plugins option? #112

Open
srid opened this issue Aug 15, 2023 · 5 comments
Open

How to use prettier's plugins option? #112

srid opened this issue Aug 15, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@srid
Copy link
Contributor

srid commented Aug 15, 2023

Follow-up to #103

When using the prettier formatter, how do we actually use the plugins option?

With

programs.prettier.settings = {
  plugins = [ "prettier-plugin-tailwindcss" ];
};

(To use https://tailwindcss.com/blog/automatic-class-sorting-with-prettier)

I get:

[INFO]: Error using formatter #prettier:
• [STDOUT]:

• [STDERR]:
[error] Cannot find package 'prettier-plugin-tailwindcss' imported from /Users/srid/code/nix-browser/noop.js
@srid srid added the enhancement New feature or request label Aug 15, 2023
@gkze
Copy link
Contributor

gkze commented Aug 15, 2023

You'd need to install the NPM module yourself. Right now accessing/managing NPM modules from Nix/Nixpkgs isn't straightforward

@Mic92
Copy link
Member

Mic92 commented Aug 24, 2023

Does pluginSearchDirs has any effect at all? I couldn't find it in the upstream documentations. I packaged the plugin with npm2nix but it's not found by prettier:

    treefmt.programs.prettier.settings.plugins = [ "prettier-plugin-tailwindcss" ];
    treefmt.programs.prettier.settings.pluginSearchDirs = [
      "${self'.packages.prettier-plugin-tailwindcss}/lib"
    ];

@Mic92
Copy link
Member

Mic92 commented Aug 24, 2023

I got it working by specifying an absolute plugin path: https://git.clan.lol/clan/clan-core/src/commit/dbc0ae08c09a20b3921c663bee3356ff9d5ad7eb/formatter.nix#L15

@gkze
Copy link
Contributor

gkze commented Sep 13, 2023

Yeah it' not pretty (no pun intended lol) but that works... hopefully once NPM <=> Nix improves it will be more straightforward

@multivac61
Copy link

@Mic92 Is this still the recommended way? Looks like the absolutely plugin path hack has been removed from HEAD: https://git.clan.lol/clan/clan-core/src/branch/main/formatter.nix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants