-
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
Add support for typescript-formatter #119
Comments
Isn't that incremental up-to-date checking handy though ;-) Even if we batched these calls, you'd still be doing filesystem IO per file. Compare that to the three steps below your custom step Spotless requires each formatter step to be a function that turns a string into a string. This allows Spotless to protect the user from all kinds of misbehaving formatters, and to efficiently compose multiple formatters. Changing this model to support batching would be very difficult, and it couldn't help with the filesystem IO part of your performance problem. The right way to do this would be to create a new |
@nedtwigg Meanwhile I have a solution for batchprocessing typescript files on initial spotless check, while picking results from previously batch-processed typescript files when actual spotless call is performed. I would be willing to give the solution using j2v8 a try on my end. It would probably be best to create a new formatter step for this. correct? In order to be able to use NodeJS embedded in j2v8, I still have to manage a
Suggestions? Ideas? |
A fourth option:
The two main problems with the structure above are:
If something similar to the structure above was working, it would be relatively easy to solve the two performance / resource problems mentioned above. |
That was actually what I meant with my first option ;) - it requires to have a matching npm/node installation on the machine running the formatting. I see a slightly easier way using the gradle wrapper and https://github.com/srs/gradle-node-plugin - this installs a local node/npm on the fly which I can use to create the node_modules without requiring the user to install anything on the system itself. |
Apologies, you stated that very clearly :)
Gradle requires a JDK on the machine. Most folks doing typescript or really any frontend dev are going to have npm on their machine. If you build the typescript thing to say "pass me the npm executable to use", then you have options: pass it explicitly, procure it using gradle-node-plugin, or grab it from the path. I think adding a hard dep on gradle-node-plugin puts you in a corner, especially if you can shrink your surface area pretty easily to just "pass me npm". Spotless has 4 artifacts: |
Yeah, I see where you're going - makes sense to keep the lib/lib-extra with as few dependencies as possible. Let's try it this way and see how it is going. On the progress side: given there is a prepared
Measuring the performance of this proof-of-concept on my macbook pro:
As a result of this measurement, it seems to be absolutely important, that we can keep the J2V8 engine between the formatting of two files (in the same spotless run). That shouldn't be a problem, should it? |
Great! We have a similar problem in that we create a bunch of classloaders that need to be closed: We can change SpotlessCache to be something more generic, maybe Very excited for this improvement - supporting the entire npm ecosystem is a big deal! |
@nedtwigg Update on my status and a few questions: I now have an initial implementation of the two formatter-steps typescript-formatter However, I have a few questions:
Also, feedback on the current (draft) state of code is very welcome :) |
Ruh-roh. I don't know for sure, but sounds like it! I'll take a deeper look this weekend.
I think we can use JUnit categories to mark these. /** Marker class for tests that need a native NPM to work. */
public static interface NeedsNpm {}
@Category(NeedsNpm.class)
public class SomeNewStepTest {} Then we setup
My inclination is to integrate prettier into spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java Lines 421 to 431 in f622379
Then it could be used like this: spotless {
format 'graphQl', {
target 'src/main/resources/**/*. graphql'
prettier()
}
freshmark {
target '*.md'
prettier()
} This also applies to @fvgh's work on integrating Eclipse's WTP formatters. I was thinking the same |
Also, can't wait to review code, won't have time til this weekend. Can you open a PR? I won't merge till we're ready, but I think it's easier to discuss in that format. |
Thanks for your feedback. I just created the PR - will get back to adressing your answers after the weekend. |
This has been resolved since September 2018 :P Closing Feb 2019. Thanks again @simschla, great contribution! |
I'm building a custom spotless rule for formatting typescript files using typescript-formatter. This all works well at the moment, however, my custom rule takes rather long, since I need to spawn a system process (using gradle "exec") for every single file. typescript-formatter, however, would have the ability to format a list of files all at once which would tremendously speed up things. It would be nice to have spotless support to do this "all files at once".
my current spotless format rule:
The text was updated successfully, but these errors were encountered: