GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tsfmt maven plugin by source-knights · Pull Request #553 · diffplug/spotless

Conversation

@source-knights

@source-knights source-knights commented Mar 29, 2020

Copy link
Copy Markdown
Contributor

As discussed in #552 creating a new PR for this

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
source-knights and others added 12 commits March 26, 2020 13:49
@source-knights
Add Typescript Tsfmt to Maven Plugin
ed9612b
@source-knights
Update README.md
0e429a5
@source-knights
Update README to include tsfmt maven plugin
bb72ebd
@source-knights
Update CHANGES.md
ae05010
@source-knights
Update CHANGES.md
588990a
@source-knights
Fix unit test, correct xml end tag
e973a2e
@source-knights
Spotless apply
2ebe163
@source-knights
Merge branch 'master' of https://github.com/source-knights/spotless
6a71794
@source-knights
Spotless apply
588aa43
@nedtwigg
Merge branch 'master' into master
528e708
@nedtwigg
Make the Typescript defaults a little less expensive to compute, and …
811c661
…closer to the other defaults.
@nedtwigg
Condense the typescript docs for plugin-maven.
90a1870
@source-knights source-knights mentioned this pull request Mar 29, 2020
Add tsfmt support for maven #552
Closed
nedtwigg added 3 commits March 29, 2020 09:45
@nedtwigg
DRY on test files - reveals that tsfmtInline and tsconfig are both no…
97beb15
…t working as expected.
@nedtwigg
Make it easier to run single maven-plugin tests from the IDE.
8c10f56
@nedtwigg
Fix warning about -color
7bd2220
@nedtwigg

nedtwigg commented Mar 29, 2020

Copy link
Copy Markdown
Member

I fixed the warning about -color, no change in behavior. The tsconfig.json is still failing with No inputs were found . I think it's fine to just remove tsconfig.json support from the maven plugin, although I would like to get to the bottom of it because I suspect we'll learn something important.

Another important point is that the inline configuration does not appear to be working. It is indenting with 4 spaces rather than 1, whereas we are getting the correct result when reading the same config directly from tsfmt.json. I wonder if there's a datatype issue in the XML parsing (e.g. boolean vs int vs string).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nedtwigg
Fix types in the inline config.
e9da142
@nedtwigg

nedtwigg commented Mar 29, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Yep, the inline config was broken due to datatypes problem, as the previous commit shows. But now it's fixed, so we're almost done!

The tsconfig test is still broken. I don't want to advertise in the docs that it works, when the tests show that it doesn't. Here's the two things I need from you before I can merge and release:

  • figure out why tsconfig is broken and fix OR remove tsconfig from maven docs and impl
  • fix the buildDir default (the annotation must do what it says, but I don't care what it says)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nedtwigg
nedtwigg reviewed Mar 29, 2020
View reviewed changes
Comment thread plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java Outdated
@Parameter
private Map<String, Object> config;

@Parameter(defaultValue = "${project.build.directory}", required = true, readonly = true)

@nedtwigg nedtwigg Mar 29, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I mean by "buildDir" default. It appears to not actually be readonly, and it also appears that the default does not work. One solution is for the "buildDir" to be just a regular nullable parameter, since it seems that's how you're actually using it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@source-knights source-knights Mar 29, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was put in due to the tsftmt step formatter wants to have the build dir. In the Gradle impl that seems to be easier, but here in the Maven this seems to be the way. At least that Parameter(defaultValue = "${project.build.directory}" is used somewhere else (and seems to work with all the tests, except maybe the tsconfig test).

I still think the error message with tsconfig is missleading, cause when I looked at it, it was actually mentioning the found file name of the test.ts, so it does not really seem to be an error with missing inputs.

No time to look at this right now, maybe tomorrow. Thx @nedtwigg

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nedtwigg nedtwigg Mar 29, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. My assertion is that defaultValue has no effect, because later on you say "if buildDir is null then set it to some default value". That logic, of setting a default value if it is null, is fine. My objection, perhaps mistaken, is that the parameter annotation is claiming to magically set a default value, but it isn't working. So if it isn't working, it shouldn't be there.

If there are other instances like this in the codebase, then I think they are broken too.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nedtwigg nedtwigg Mar 29, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm skeptical that new File(".") will work well as a default value for multiproject setups, but I'm willing to merge and ship this and wait for someone to have a problem and then we can worry about fixing it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@source-knights source-knights Mar 29, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will get null if you start this without a maven/gradle setup (e.g. in a unit test straight in IDE). Therefore I set the ".". But might be wrong

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nedtwigg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@nedtwigg nedtwigg Mar 29, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried deleting it, and I saw failures in the maven integration tests, which run using "real maven".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@source-knights
Fix buildDir going into Tsfmt
2641254
This does not work in the Tsfmt class but in the AbstractSpotlessMojo
class:
@parameter(defaultValue = "${project.build.directory}"

So the change is to set it in the Mojo class to the FileLocator and get
it from there if required
@source-knights

source-knights commented Mar 30, 2020

Copy link
Copy Markdown
Contributor Author

Just fixed the buildDir, it is now getting the correct dir when I debugged through it. Seems that the ${project.build.directory} is only evaluated or returning correct value in that Mojo class.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@source-knights
Fix tsconfig file
9ac7a49
When I use "files" with a direct link to "src/main/typescript/test.ts"
it works. If I leave "files" out (and just use
"include": [
	 "src/main/typescript/*.ts"
	 	]
) it does fail with

C:\Users\xyz\AppData\Local\Temp\junit3377288995823290344\target\spotless-node-modules-tsfmt-format\node_modules\typescript-formatter\lib\utils.js:64:
Error: No inputs were found in config file 'tsconfig.json'. Specified
'include' paths were '["src/main/typescript/*.ts"]' and 'exclude' paths
were '["nothing.xml"]'. -> [Help 1]
@source-knights

source-knights commented Mar 30, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@nedtwigg Tsconfig test is working now, but only when I use "files" with a direct link to "src/main/typescript/test.ts" in the tsconfig file.

If I leave "files" out and just use

"include": [
	 "src/main/typescript/*.ts"
	 	]

it does fail with

C:\Users\xyz\AppData\Local\Temp\junit3377288995823290344\target\spotless-node-modules-tsfmt-format\node_modules\typescript-formatter\lib\utils.js:64:
Error: No inputs were found in config file 'tsconfig.json'. Specified
'include' paths were '["src/main/typescript/*.ts"]' and 'exclude' paths
were '["nothing.xml"]'. -> [Help 1]

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

source-knights added 2 commits March 30, 2020 10:59
@source-knights
spotless apply
33b13f6
@source-knights
Fix issue with FileLocator and tsconfig file
80cc770
@source-knights

source-knights commented Mar 30, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I found the real problem. The fact that the FileLocator class copies the settings/config files in the target directory under a temporary name leads to this problem with tsconfig file. Seems the tsfmt implementation then looks in the wrong paths when using "include"/"exclude" while using the correct one with "files" in the json config. Instead of using that FileLocator impl switching to a straight file location works (which is actually what the gradle impl does too, comparing the actually used paths during debugging).

@nedtwigg this is solved now as far as I can see

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

source-knights added 3 commits March 30, 2020 19:02
@source-knights
spotless apply
daff537
@source-knights
spotless apply
839bcbd
@source-knights
add tsconfig test to plugin gradle
56ddfcb
nedtwigg added 4 commits March 30, 2020 20:39
@nedtwigg
Make the buildDir a non-optional part of FileLocator.
5593769
@nedtwigg
Give FileLocator an in-place locator capability.
5f4bbfa
@nedtwigg
Make the gradle tests use the same test files as the maven and lib te…
6d21884
…sts.
@nedtwigg
Remove @nullable from the maven plugin.
9567b07
@nedtwigg

nedtwigg commented Mar 31, 2020

Copy link
Copy Markdown
Member

Thanks very much for getting to the bottom of this! I now understand your fix better, and understand why my commits broke it, but I'm too sleepy to finish this right now.

I did not realize until now that every config file was being copied to a temp location. I tried to rip that out, but it fails because we need maven's resource manager to resolve the "${basedir}" stuff, and the API maven gives us to parse those refuses to say where the files actually are on disk.

Since we understand the limitation, my plan for tomorrow is to

  1. remove tsconfig support
  2. merge and release this PR in a new version
  3. make a new issue which says "Why does the maven plugin copy every config file to a random temp location? It is breaking the typescript usecase".

Is this okay with you? If a maven wizard comes along with a fix, then we get a perf improvement for the whole plugin, and we get an elegant implementation for the tsconfig.json case that we've struggled with. And if we don't get a wizard, we've documented this problem for others which will have it, rather than sweeping it under the rug into a weird one-off implementation for this one step.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@source-knights

source-knights commented Mar 31, 2020

Copy link
Copy Markdown
Contributor Author

@nedtwigg Not sure if you need to change anything after my last commit for the tsconfig. The FileLocator puts stuff in target/build folder and creates a temporary name instead of the e.g. "tsconfig.json". As I am skipping this now the ${project.basedir} in the maven xml is still used, the file is just not copied as a temp filename then. Work fine for me.

So in short, the new solution will still replace the base ${project.basedir} property.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@source-knights

source-knights commented Mar 31, 2020

Copy link
Copy Markdown
Contributor Author

It's just that ${project.basedir}/tsconfig.json will not be processed to c:\Users\xyz\AppData\Local\Temp\junit12342425646563626/target/spotless_temp_8475628489474754.json but stay c:\Users\xyz\AppData\Local\Temp\junit12342425646563626/tsconfig.json

To proof that the property is replaced and not just uses current dir, you can even put something like "TEST/${project.basedir}/tsconfig.json" in the maven xml and it will be replaced to "TEST/c:\Users\xyz\AppData\Local\Temp\junit12342425646563626/tsconfig.json" and not found then of course.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nedtwigg

nedtwigg commented Apr 2, 2020

Copy link
Copy Markdown
Member

A-haaaaaa. So the ${basedir} is just string replacement that happens in the XML to POJO mapping, it's not our responsibility to do it. Well then what the heck is our resource manager for!? Lol. That's a question for another PR. Thanks very much. Sorry for slow response.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nedtwigg added 5 commits April 1, 2020 23:42
@nedtwigg
Revert all ned's commits since the last good commit by @source-knights
2f77a77
@nedtwigg
Put the baseDir into FileLocator, and ensure that names match their "…
3d791da
…maven canonical" names (e.g. erroneously calling buildDir "target").
@nedtwigg
Make the gradle tests use the same test files as the maven and lib te…
f5d9e07
…sts.
@nedtwigg
Extracted Tsfmt.locateFile into Tsfmt.locateLocal.
7d21bf4
@nedtwigg
Remove maven-plugin info from the lib changelog.
1bb33d6
@nedtwigg
nedtwigg merged commit 7ba6d1a into diffplug:master Apr 2, 2020
@nedtwigg nedtwigg mentioned this pull request Apr 2, 2020
Tsfmt Maven Plugin for Spotless #548
Merged
2 of 3 tasks
@nedtwigg

nedtwigg commented Apr 2, 2020

Copy link
Copy Markdown
Member

Released in 1.29.0

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nedtwigg nedtwigg mentioned this pull request May 4, 2020
Resource leak when using Maven plugin #559
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nedtwigg nedtwigg nedtwigg left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@source-knights @nedtwigg
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.