Skip to content
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

Remap ESModule imports at link time in mdoc #883

Merged
merged 96 commits into from
Sep 17, 2024
Merged

Conversation

Quafadas
Copy link
Contributor

See #882 , I had to start over and try a different paradigm.

This PR does a lot more than I would have wanted. Explanation to follow, if CI goes green.

@Quafadas Quafadas changed the title Remap2 Remap ESModule imports at link time in mdoc Jul 11, 2024
@Quafadas
Copy link
Contributor Author

Quafadas commented Jul 11, 2024

@tgodzik

Apologies for all the spam today. This is my best shot. I have tests passing on 2.13 and 2.12, but I can't get the 3 series working. I think this means that I don't understand something fundamental about the interaction between 2 & 3 artefacts. Could it be that I would need to ask Arman to publish his library for scala 3?

I had believed, that this would work.
https://github.com/Quafadas/mdoc/blob/1b1f096694b814a19758cd95c4e313926c41d782/mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala#L160-L161

But it leaves apparently some mismatch with

==> X tests.js.JsCliSuite.basic  0.435s java.lang.NoSuchMethodError: 'byte[] org.scalajs.ir.Names$.org$scalajs$ir$Names$$validateSimpleEncodedName(byte[])'

@tgodzik
Copy link
Contributor

tgodzik commented Jul 12, 2024

Could it be that I would need to ask Arman to publish his library for scala 3?

That might be the issue or the classpath for Scala 3 is broken still. I can try take a look next week if you're still having difficulties

@Quafadas
Copy link
Contributor Author

Aha! I have it! Write up in bound!

@Quafadas
Copy link
Contributor Author

Yes!
image

@Quafadas
Copy link
Contributor Author

Quafadas commented Jul 12, 2024

Finally! Having gotten the class paths right, I was then struck by a bad case of windows-in-CI.

@tgodzik - I'm sorry for all the spam. Here's the writeup - it may be that I need to start over and do this incrementally as this is a bit messy as a big lump change. I do think it's quite cool though so I'm happy I reached the end.

struggled with the class path. In order to figure out the solution, I needed to be able get to a state where the existing JsCliSuite test succeeded, next to mz Remap ESModule test failing. This was problematic because mdoc implicitly assumes that it would find mdoc.properties on the class path.

This means that, to have a new test that configures the CLI differently, I would

  1. need a new class path (entire new copy paste SBT unitJS project, how to manage different mdoc.properties generation?, rejected).
  2. need a novel testing strategy (definitely last resort)
  3. make mdoc.properties explicit and configurable. This is arguably a useful feature in it's own right.

Most of the change in the PR end up being to make option 3 viable.

Most changes are then forced because mdoc main branch parses the CLI args after (!) it reads the mdoc.properties file that mdoc assumes it finds on the class path. In particular, much of the test setup is based around that assumption.

To make this work, I had to change that order. i.e. parse the CLI args first. Then go search for a configurably named (default = mdoc.properties) file.

This meant making "mdoc.properties" explicit in a few places in the codebase (tests in particular). That may make this change controversial. Also : required adding braces in many places, which then required reformatting lots of files. Yey?

At this point, I could then generate a new es.properties next to the default mdoc.properties in the plugin. Both properties files are then concurrently on the class path, but selected by the CLI.

This allowed for more than one test in the suite. After that the scientific method bailed me out of needing to actually understand class paths :-), and the PR (finally) went green with two new integration tests for ESModules.

It's a lot more than I intended. I'm not sure how to best get it comfortable to merge. I also need to write some docs. Happy to add to this PR... or a separate follow up.

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

The PR doesn't look to crazy and I think the situation with mdoc.properties file could be improved. I think this looks ok

cli/src/main/scala/mdoc/internal/cli/Settings.scala Outdated Show resolved Hide resolved
mdoc-js-worker/src/main/scala/ScalaJSWorker.scala Outdated Show resolved Hide resolved
mdoc-js/src/main/scala/mdoc/modifiers/JsModifier.scala Outdated Show resolved Hide resolved
mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala Outdated Show resolved Hide resolved
mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala Show resolved Hide resolved
tests/unit-js/src/test/scala/tests/js/JsCliSuite.scala Outdated Show resolved Hide resolved
tests/unit/src/test/scala/tests/cli/CliArgsSuite.scala Outdated Show resolved Hide resolved
@Quafadas
Copy link
Contributor Author

Okay - thank you - that is encouraging! I've rebased - hopefully correctly.

I'm not trying to pressure you either - perhaps we leave it open for another couple of weeks, and if it doesn't attract more feedback one way or another, then call pulling the trigger or close it? Mostly I would wish to avoid having it hanging around as summer ends.

@tgodzik
Copy link
Contributor

tgodzik commented Sep 10, 2024

I'll wait until the next week then.

tgodzik pushed a commit to tgodzik/mdoc that referenced this pull request Sep 16, 2024
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

Any chance you could reopen this PR with only the needed changes? It's seems the commit history is too long and there unrelated changes showing up in the PR.

.DS_Store Outdated Show resolved Hide resolved
docs/js.md Outdated Show resolved Hide resolved
docs/js.md Outdated Show resolved Hide resolved
@Quafadas
Copy link
Contributor Author

Quafadas commented Sep 16, 2024

Any chance you could reopen this PR with only the needed changes? It's seems the commit history is too long and there unrelated changes showing up in the PR.

I guess I need to. This PR starts from the end and worked back to the start point. I think what I should do, is open a series of PRs which start at the main branch, and work forward towards this. I think they are;

  1. make mdoc.properties configurable, so that we can have more than one classpath arrangement in the test suite
  2. Introduce the changes which make mdocJs consume ESModules
  3. Introduce the remapping function

Unfortunately, it's going to take more time - I have more flexibility over summer than now... but it's on my list. Thankyou again for looking.

@tgodzik
Copy link
Contributor

tgodzik commented Sep 16, 2024

It's fine for me to just tidy up the PR, I can do it otherwise.

@Quafadas
Copy link
Contributor Author

I think that's everything? I've done all that I could see.

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

Let's merge it! Thanks for working on it!

@tgodzik tgodzik merged commit de1f63f into scalameta:main Sep 17, 2024
14 checks passed
@Quafadas
Copy link
Contributor Author

@tgodzik Thankyou 🙏 !

@Quafadas
Copy link
Contributor Author

I've tested this PR as much as I can. As far as I can tell, it works, it's just astonishingly tricky to configure correctly.

Here's a repo that loads shoelace as an ESModule inside a laminar app, and loads icons on request.
image

This repository leaves some breadcrumbs, if anyone was interested.
https://github.com/Quafadas/mdoc_test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants