-
Notifications
You must be signed in to change notification settings - Fork 460
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
Prettier dies when directory is removed before spotlessApply
#863
Comments
TL;DR this is hard to fix. Implementing #675 would make it easier. One hacky workaround would be to make it possible for If your build looks like this: spotless {
typescript {
prettier()
... Then your task dependency tree looks likes this:
The work happens in spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java Line 83 in 397e36f
Both I think the problem is that the npm step makes a package.json in spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java Lines 543 to 553 in 397e36f
spotless/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java Lines 56 to 64 in 397e36f
This already happens lazily as part of the up-to-date check. spotless/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java Lines 55 to 57 in 397e36f
Fixing this would require moving the file creation out of the up-to-date check, which would remove checking |
I'm definitely willing to help, but my knowledge of Gradle internals (or Spotless internals, for that matter) is not that deep, so I'd need help ;) One dumb question, though: Is it important that the |
If you change prettier from I just thought of another totally hairbrained workaround. Around this part: spotless/lib/src/main/java/com/diffplug/spotless/npm/NpmFormatterStepStateBase.java Lines 88 to 93 in 397e36f
you could just check to see if the file is missing, and if it is, run |
Ah, I wasn't aware that it takes the prettier version from Your idea sounds wild, but it also sounds like it should still work - then the version check is fine, and the actual formatting, too. Is there a drawback I can't see? |
Main drawback is speed and ugly. Tiny chance that the deps resolve differently between runs due to a new transitive dep being published, but I think you can safely ignore that. |
Sounds quite good to me. Do you want me to try and implement it? |
Yes, if the feature is worth it to you. Spotless does (and has done) everything I need for a very long time. I don't care what gets added, as long as it doesn't break something for somebody else. |
As you can see, I opened a PR :) |
Fixed in |
I'm using Spotless with Prettier in a Gradle submodule. (Another submodule also uses Spotless, but with Kotlin.)
My
build
task will clean the/build
directory before starting, as the compiled Javascript resources will end up in there. However, it seems that Spotless first creates a directoryspotless-node-modules-prettier-format
in/build
, which will then get cleaned by thebuild
task, and then the actualspotlessCheck
fails quite ugly:It seems that this only happens when I run
build
in more than this submodule.Can Spotless be made to create that directory not in the configuration phase, but only when it actually runs?
Gradle: 7.0, but also observed with earlier versions
Spotless version: 5.12.4
OS: Latest Manjaro
The text was updated successfully, but these errors were encountered: