Speeding up Prettier locally and on your CI with dprint
david.deno.dev
david.deno.dev
Edit: I'm especially impressed with its dependency management. Import maps are a breeze and a welcome change to... whatever is going on in Nodeland. Like, I don't have to set up my imports both in tsconfig.json and package.json and walk this delicate tightrope to make sure that things don't just start breaking. With Deno's import maps it kind of just... works. I also love that I don't have to deal with a `node_modules` folder, and I can choose to vendor my dependencies if I'd like. It reminds me of the Go approach, which I really enjoy.
There's other things I like but these are the big ones. The more I can get switched over to Deno the better.
I do not believe there is willpower for institutional changes to the javascript ecosystem that exists on timelines of less then 5 years.
Basically I've been dealing with the ESM changes. Add in the TypeScript complexity and all of the sudden I've now spent hours debugging some obscure issue rather than being productive... I've debated moving away from Node.js altogether because of it but there's no real realistic alternatives right now (for frontend development/bundling using React/Remix).
I probably can't do any better, but the whole ESM migration has been completely mishandled. Even more infuriating is the response that things are working _as expected_... Hopefully Deno gains some traction and we can put this all behind us.
Vite Vue + Typescript template run fine in dev mode but could not be built for production, thanks to a combination of an Vue issue and a tsconfig flag.
Node polyfills work on `yarn dev`, but throw "kn.nextTick is not a function" for production build. Apparently I have to use package `rollup-plugin-polyfill-node` instead of `rollup-plugin-node-polyfills`.
Now with all the setting up out of the way, it does feels good to have a dev server starting almost instantly, hot reload and full page reload stay constantly fast. Sometime though hot reload just fails and I had to manually reload the page, or manually remount the component I'm working on (by navigating back and forth) to see the changes.
It also feels like I'm not even using typescript but plain javascript. Vite would happily serve broken code and some errors will only be shown on `yarn build`. I lost a watch compiler essentially.
Deno does use some other Rust-based dprint plugins for deno fmt though and dprint-plugin-prettier uses an embedded Deno runtime with Prettier snapshotted in it. Also, Deno now has a similar built-in incremental formatting and linting as of 1.21 last week, so those subcommands finish almost immediately after the first run... though they were already very fast https://deno.com/blog/v1.21#incremental-formatting-and-linti...
Big number of people pointing out the quirks about a language and its ecosystem does not mean that they are not good in terms of productivity, it just means that they are just used a lot.
"There are only two kinds of languages: the ones people complain about and the ones nobody uses" — Bjarne Stroustrup
The complaining actually helps, such as the example you can see in the node.js ecosystem, better and better tools are being built every day, and also "better" alternatives like Deno (in quotes because IMHO it still needs to prove itself).
When Python also got big because of the ML uprising, there was a time that we saw a post complaining about it every day. Same was true for PHP like 10-15 years ago.
So don't feel the need to explain why you chose your stack unless you really want to. Languages don't have feelings, you can leave them and learn a new one if it helps you accomplish things.
Say prettier also added a cache to save the state of previous files, it would also be only 1s.
Also, dprint uses very fast globbing with two threads working together in order to collect files. I would guess Prettier would still be slower if it did this because it's programmed in JS (though not by much), but it doesn't do it.
I'm much more impressed by "dprint is 3* faster than Prettier for the same task" than "dprint is 40* faster than Prettier because dprint caches results and Prettier doesn't". That makes me want to look at dprint. The "40* faster" figure makes it look like the benchmark is wrong.
To add another advantage of using dprint not mentioned, is that since it's pluggable you can use Prettier and other formatters all from the same formatting CLI. The main dprint repo does this in its dprint.json (https://github.com/dprint/dprint/blob/3d822a48133358ec4e2d5b...)
David, I already owe you guys more beer than I can buy for all the great work on the Deno toolchain, but if we could get this issue[1] with HTML template tags going, it would be easier for me to convince the Lit crowd to chip in. Tanks again for the great work!
[1] https://github.com/dprint/dprint-plugin-typescript/issues/9
Also makes much more sense for local scripting. Give it a try even if in doubt for production.
It is not cosmically faster than tsserver, but some — including myself — do prefer it. I wouldn't recommend to change anything if you are busy — but maybe take a glance when in the mood for checking out new things.
https://github.com/denoland/deno/pull/14319
Here's the issue: https://github.com/denoland/deno/issues/10157
I get Prettier's whole shtick about not being configurable so that your team can't fight over a style guide, but as a team that already had an internal style guide that predates Prettier, I just want a tool that can match what we have already decided on, which is where dprint has fit in nicely.
It's the Unix mentality of chaining things rather than building it in to the package.
Now you could query the CI from the CI but that seems to be a dubious dependency to me, and user would need to set up an access token.
A lot of steps in CI aren't there to do something, they're merely there for analysis reasons and conditionally marking builds as failed
> I've seen many devs work with broken environments and just ignore the problems because it doesn't actually stop them, or because they don't realise it's broken.
That sounds like an educational issue. I work in a small team in a small organization.
Reading your comment I assume you want the repo server to reject incorrectly formatted code at push time. Rejecting commits/pushes has the disadvantage that you cannot share your code/branch with others (or yourself on other devices), and cannot back up your code to the repo server.
You could argue formatting doesn’t take long. I’d argue, the repo server shouldn’t keep me from publishing code to a dev branch.