Skip to content

watch task #575

Closed

Description

@jamiebuilds

It would nice to be able to use this as just:

yarn add --dev prettier
yarn prettier -- --write src/**/*.js --watch/-w

And only update the files that are changed as they are changed.

Activity

  1. vjeux commented on Feb 2, 2017

    @vjeux
    Contributor

    I wish there was a unix utility for that instead of each project having to reimplement it in a crappy way :(

  2. xtuc commented on Feb 2, 2017

    @xtuc

    @vjeux there is actually unix inotify but you will still need some sort of Node binding.

  3. vjeux commented on Feb 2, 2017

    @vjeux
    Contributor

    @xtuc I was more thinking about

    watch src/**/*.js | xargs prettier -- --write
  4. jamiebuilds commented on Feb 2, 2017

    @jamiebuilds
    Author

    I am using https://github.com/mikeal/watch to do effectively that:

    watch 'prettier --write src/**/*.js' src
    

    The problem is that it will just spawn up a new prettier process and go through every single file again

  5. xtuc commented on Feb 2, 2017

    @xtuc

    Yeah that would be awesome.

  6. lydell commented on Feb 2, 2017

    @lydell
    Member

    There's also cli-watch and chokidar-cli. Example:

    chokidar 'src/**/*.js' -c "test '{event}' = 'change' && prettier --write '{path}'"
    
  7. jlongster commented on Feb 2, 2017

    @jlongster
    Member

    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)

  8. jamiebuilds commented on Feb 2, 2017

    @jamiebuilds
    Author

    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

  9. jlongster commented on Feb 2, 2017

    @jlongster
    Member

    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?

  10. jamiebuilds commented on Feb 2, 2017

    @jamiebuilds
    Author

    Because I want it to run out of the box for everyone working on the project

  11. xtuc commented on Feb 2, 2017

    @xtuc

    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.

  12. jlongster commented on Feb 3, 2017

    @jlongster
    Member

    @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.

  13. baransu commented on Feb 14, 2017

    @baransu

    If you want quick unix tool without implementing it into package I recommend entr.

  14. olpeh commented on Mar 10, 2017

    @olpeh

    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.

  15. vjeux commented on Mar 10, 2017

    @vjeux
    Contributor

    @olpeh: could you create a test plan that reproduces the issue? This way we can look into it.

  16. olpeh commented on Mar 10, 2017

    @olpeh

    @vjeux Sure. Should I create a new issue of that or add it here?
    Is there a template I should follow?

  17. vjeux commented on Mar 10, 2017

    @vjeux
    Contributor

    A new issue would be great. No template, just make sure there's enough information so that we can investigate :)

  18. added a commit that references this issue on Apr 18, 2017
  19. vjeux commented on May 21, 2017

    @vjeux
    Contributor

    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.

  20. eedrah commented on Oct 31, 2017

    @eedrah
    Contributor

    @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:

    npx onchange '**/*.js' -- npx prettier --write {{changed}}
    
  21. added
    locked-due-to-inactivity
    on Jul 6, 2018
  22. locked as resolved and limited conversation to collaborators on Jul 6, 2018
  23. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivity

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions