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

Make Prettier and Biome optional peer dependencies #19

Closed
silvenon opened this issue Aug 16, 2024 · 7 comments · Fixed by #27
Closed

Make Prettier and Biome optional peer dependencies #19

silvenon opened this issue Aug 16, 2024 · 7 comments · Fixed by #27

Comments

@silvenon
Copy link

silvenon commented Aug 16, 2024

What do you think of making Prettier and Biome optional dependencies, and conditionally importing whichever one is selected as the formatter? That way people get to install Prettier or Biome version they want, or none.

I've never done this before, but it seems like marking them as optional peer dependencies would be the way to go in that scenario using peerDependenciesMeta. ChatGPT says that npm v7+ supports this, and that only Yarn v1 would print out warnings for unmet peerDependencies, which seems like a small price to pay.

@sairus2k
Copy link

sairus2k commented Jan 3, 2025

I like the idea of not installing Biome packages if I don't use them, but there are a few things to consider:

  1. Biome dependencies: If we make Biome optional, users would need to install two more packages (@biomejs/js-api and @biomejs/wasm-nodejs in addition to @biomejs/biome) to use it as a formatter. This might not be as convenient as the current setup.

  2. How Prettier is used now: It's important to note that Prettier is not truly optional in the current implementation. It's used to format SVG files even when Biome is set as the formatter (since Biome doesn't support SVG), and it formats everything when no formatter is selected. This behavior doesn't align with the documentation stating there's no default formatter.

  3. Another way to implement Biome: One option is to use the exec() function to run Biome using the command exec(biome format <filename.ts>). This would remove the need for Biome as a dependency for users who don't use it and remove the requirement for the Biome JS API packages for those who do use Biome as a formatter.

Given these points, we should consider the following steps:

  1. We need to clarify the current behavior in the documentation regarding Prettier's usage.
  2. We need to investigate the possibility of making Prettier truly optional, especially when no formatter is selected.
  3. We need to explore the exec-based approach for Biome to simplify dependencies.
  4. Once these issues are addressed, we could revisit the idea of making both formatters optional dependencies.

This approach would improve the current situation and set the groundwork for potentially making the formatters optional in the future. What do you think about tackling these points first, @AlemTuzlak?

@silvenon
Copy link
Author

silvenon commented Jan 3, 2025

Thanks for the elaboration. Sounds to me like there isn't much leeway here, I was hoping that making them optional would be straightforward. What about moving towards formatting them only if there is a formatter installed? So that by default there's indeed no formatting, and Prettier truly can truly become optional.

Otherwise I don't see much point in these optimizations if only Biome can be extracted out, doesn't feel like much of a gain.

Provided that the maintainers are interested in optimizing their package size.

@AlemTuzlak
Copy link
Contributor

@sairus2k thank you for the detailed write-up, to answer your points:

  1. the reason prettier is used to format the svg file is indeed because biome doesn't support it yet, I guess the docs are a bit miseading in this case
  2. If there was a lightweight lib that just formatted simple files that would be great but I'm guessing there isn't, I think that vast majority of projects use a formatter of some kind so I wouldn't worry much about people who don't care as whatever the output is... they don't care. Making one or the other required would be pretty dope but not as straightforward as I'd like
  3. I think this could work, although this would require biome to be globally available, or we would need to point to the exact path in the node_modules which is tricky as different package managers construct different paths
  4. agreed

I fully agree, another option would be to completely remove formatting, maybe it should be left to the project owners themselves to lint the files, also what's important to note is that this is a devDep and none of these deps end up in your prod bundle so it's not as big of an impact on your app. What do you guys think?

@silvenon
Copy link
Author

silvenon commented Jan 9, 2025

this is a devDep and none of these deps end up in your prod bundle so it's not as big of an impact on your app

Nevertheless it's still something that CI has to install, and you'll likely end up with two different versions of Prettier.

One easy solution that comes to mind is setting Prettier dependency to ^3.0.0 (or something low like that) rather than ^3.3.3, that way if someone's using ^3.3.2 in their project deduping will still be possible.

What do you think?

@achou11
Copy link

achou11 commented Jan 9, 2025

If there was a lightweight lib that just formatted simple files that would be great but I'm guessing there isn't

Although this is very new, it may be what you're looking for 😄

https://github.com/JoshuaKGoldberg/formatly

@AlemTuzlak
Copy link
Contributor

@achou11 wow this is exatly what I'm looking for lol

@achou11
Copy link

achou11 commented Jan 9, 2025

I fully agree, another option would be to completely remove formatting, maybe it should be left to the project owners themselves to lint the files

Personally, I don't have much of a problem with removing formatting functionality if that's something you decide to pursue 👍

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

Successfully merging a pull request may close this issue.

4 participants