-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
watch task #575
Comments
I wish there was a unix utility for that instead of each project having to reimplement it in a crappy way :( |
@vjeux there is actually unix |
@xtuc I was more thinking about watch src/**/*.js | xargs prettier -- --write |
I am using https://github.com/mikeal/watch to do effectively that:
The problem is that it will just spawn up a new prettier process and go through every single file again |
Yeah that would be awesome. |
There's also cli-watch and chokidar-cli. Example:
|
Do you have your editor instantly show changes from the filesystem? If not, how would save a file a file twice, since the second time there will have been changes to the file and you'll overwrite them? (My editor warns me about this and asks to confirm) |
My editor automatically shows changes. It's fast enough that it doesn't cause me any issues for now. If the watch task only rebuilds the file I'm working on it should stay that way |
Interesting, that's the opposite workflow from usual, where we have editor plugins that will automatically reformat on save. The editor invokes prettier before saving, formats it, and then it's saved. My experience with watchers has always been painful trying to get them working across operating systems. Is there any reason you don't want to have the editor invoke prettier, @thejameskyle ? Which editor are you using? |
Because I want it to run out of the box for everyone working on the project |
With Vim, i'm not notified that the file has changed unless I try to save. If I really save I will just override my version with the formated one. Prettify before save is actually a better solution in my case. I know many other editors will just load the new version of the file you're currently on. |
@thejameskyle fwiw, many of the editor integrations also invoke the script from scratch. I think atom is the only one that doesn't because it's written in JS and already supports JS APIs first-class. A more generic solution might be to introduce a "server" mode that just spawns it in the background and anything can run the CLI as many times as it wants. This would benefit all editors as well as your watch mode. Not sure how much more complex that would be, or if there's already a node module to help with that though. |
You might find this useful: http://langserver.org/ |
If you want quick unix tool without implementing it into package I recommend entr. |
FYI: It tried using prettier together with npm-watch but it wrote the files as empty. Tried using https://github.com/mikeal/watch instead as @thejameskyle suggested and it seems to work. This is good enough at least for me. |
@olpeh: could you create a test plan that reproduces the issue? This way we can look into it. |
@vjeux Sure. Should I create a new issue of that or add it here? |
A new issue would be great. No template, just make sure there's enough information so that we can investigate :) |
`prettier_d` is like [eslint_d], but it runs `prettier` instead of `eslint`. This eliminates the Node.js startup delay from all but the first run of `prettier_d`, making it a snappier experience. [eslint_d]: https://github.com/mantoni/eslint_d.js Related discussion: * prettier#575 (comment) * prettier#918 (comment) * prettier#753 (comment)
`prettier_d` is like [eslint_d], but it runs `prettier` instead of `eslint`. This eliminates the Node.js startup delay from all but the first run of `prettier_d`, making it a snappier experience. [eslint_d]: https://github.com/mantoni/eslint_d.js Related discussion: * #575 (comment) * #918 (comment) * #753 (comment)
I'm doing a spring cleaning of the issues and we're unlikely going to implement it, so closing. If someone is interested in building this, there is no opposition. |
@vjeux - I thought perhaps it might be nice to put in the README how to use this with an [external] watcher - that way it hopefully will please everyone wanting a watcher, without having requests to reimplement this functionality in the code of Prettier. Thoughts? I made pull request #3126 if you want it. For those who are coming here from Google wanting this functionality, the short version is:
|
It would nice to be able to use this as just:
And only update the files that are changed as they are changed.
The text was updated successfully, but these errors were encountered: