Skip to content

Workaround for errors sent improperly to stdout by prettier_d#39

Closed
matthugs wants to merge 1 commit into
prettier:masterfrom
matthugs:prettier_d-support
Closed

Workaround for errors sent improperly to stdout by prettier_d#39
matthugs wants to merge 1 commit into
prettier:masterfrom
matthugs:prettier_d-support

Conversation

@matthugs
Copy link
Copy Markdown

From this it should be simple to use prettier_d as a drop-in
replacement by customizing the prettier-js-command custom variable.

fixes #34

From this it should be simple to use `prettier_d` as a drop-in
replacement by customizing the `prettier-js-command` custom variable.

fixes prettier#34
@matthugs matthugs force-pushed the prettier_d-support branch from 8c78d43 to 0f67890 Compare June 19, 2024 20:39
@jacksonrayhamilton
Copy link
Copy Markdown
Collaborator

Thanks for submitting this back when you did! Unfortunately I feel like this contribution has gone stale.

prettier_d is no longer maintained as of several years ago: https://github.com/josephfrazier/prettier_d

I tried the changes suggested in this PR with the alternative package: https://github.com/mikew/prettier_d_slim

Indeed, these changes did un-swallow errors from pretter_d_slim. Unfortunately, when I tried it, I only saw errors, and my code didn't get formatted.

With globally-installed prettier

prettier errors:
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

With prettier installed in node_modules

prettier errors:
TypeError: prettier.resolveConfigFile.sync is not a function

My sense is that more work may be needed on the side of prettier-js or on prettier_d_slim to make this integration work - and prettier_d_slim does not appear to be keeping pace with Prettier development either.

@jacksonrayhamilton
Copy link
Copy Markdown
Collaborator

If folks are unsatisfied with the performance of running the prettier executable on each file save, I feel those people may be better served by https://github.com/jscheid/prettier.el, which is designed to mitigate the overhead of prettier.

Personally, I do not find the overhead of calling prettier has a material impact on my workflow. My prediction is that Prettier packages which maintain a background process could end up costing me more time than the penalties I pay on file save, if there were ever issues with those packages' background processes that I needed to diagnose.

@jacksonrayhamilton
Copy link
Copy Markdown
Collaborator

I experimented with prettierd (no _) as well, another daemon implementation: https://github.com/fsouza/prettierd

This daemon doesn't throw errors, so it's usable. It also writes its errors to stdout, so the suggested change could be useful if people wanted to use it.

However, when experimenting with this implementation, right away I found myself fussing with manual process management, confirming my fears about bad DX associated with daemon usage.

I find that this daemon implementation requires a manual restart via the terminal when it gets into an error state (e.g. malformed config). Also, when you run prettierd status, it doesn't report the status of all currently-running daemons, only the status of a daemon associated with exactly the current directory (not subdirectories either); this makes it even harder to figure out if you have a running daemon that needs a restart.

That said, I don't want to deny people the opportunity to use and customize this package how they like, especially considering this is a minor change. I'll recreate this PR with support for prettierd and just add a note about the caveats I observed.

@jacksonrayhamilton jacksonrayhamilton mentioned this pull request Jul 3, 2025
@jacksonrayhamilton
Copy link
Copy Markdown
Collaborator

Recreated here: #91

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 this pull request may close these issues.

Support other prettier bin commands

2 participants