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

EsModules #880

Merged
merged 10 commits into from
Jul 9, 2024
Merged

EsModules #880

merged 10 commits into from
Jul 9, 2024

Conversation

Quafadas
Copy link
Contributor

@Quafadas Quafadas commented Jul 5, 2024

First step to closing #638 .

A publish local off this branch actually seems to work.

  • Unbreak broken tests
  • Add new tests
  • Get CI green

@Quafadas
Copy link
Contributor Author

Quafadas commented Jul 5, 2024

I can't understand the failing test on windows :-(.

@Quafadas
Copy link
Contributor Author

Quafadas commented Jul 7, 2024

This seems to be easier than expected. I think this PR would actually be viable which was a surprise for me.

If it were to get merged and it maintainers agreed, I'd try and follow it up with two more PRs

  • enabling SmallModulesFor
  • an EsImportMap rewrite-esmodule-imports-at-link-time functionality...

@Quafadas Quafadas changed the title WIP: Make Es modules work Make Es modules work Jul 7, 2024
@Quafadas Quafadas changed the title Make Es modules work EsModules Jul 7, 2024
@nguyenyou
Copy link

Thank you very much for working on this 🤩

@Quafadas
Copy link
Contributor Author

Quafadas commented Jul 9, 2024

@tgodzik Hi Tomasz, I think this would be ready for a discussion ... it takes the first step toward making scalaJS EsModules powerful in mdoc.

This PR modifies only Mdocs CLI. As far as I can tell, this PR works in the sense that it emits ESModules, and those modules work with docs own static server in watch mode. If you agree with the direction of travel, I'd attempt to follow it up with two more PRs

  • enabling SmallModulesFor
  • EsImportMap rewrite-esmodule-imports-at-link-time functionality...

I think that would enable mdoc to provide documentation for a broad array of scala JS projects.

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.

Just one minor comment from, otherwise looks good. I don't have a lot of background in JS, but I don't see anything problematic in merging this if it's useful for you.

But, out of curiosity, why is it beneficial over using normal scripts, especially in case of mdoc?

.println(s"""<script type="module" src="$relmdoc"></script>""")
.toString
case NoModule =>
new CodeBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we deduplicate this with the first case since it's the same?

Copy link
Contributor Author

@Quafadas Quafadas Jul 9, 2024

Choose a reason for hiding this comment

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

Yes. I wasn't sure if it was more readable to split the cases into the three cases, or whether it would be better to have an if... I can change it to deduplicate

Copy link
Contributor

Choose a reason for hiding this comment

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

We could even just do case CommonJSModule | NoModule => which would be simplest

@Quafadas
Copy link
Contributor Author

Quafadas commented Jul 9, 2024

But, out of curiosity, why is it beneficial over using normal scripts, especially in case of mdoc?

Well, the use case isn't 100% proven, but basically; EsModules allow importing other EsModules.

To take an example - the excellent laminar shoelace library, its documentation is (as far s I can tell) a full-blown-full-stack sbt+vite+fly.io app. As things stand, I think it has to be that, because you gotta resolve the npm shoelace dependancy then build and bundle.
https://github.com/raquo/laminar-full-stack-demo/blob/acc41bd63745de786d20715934169abe147853a7/client/package.json#L28

The barrier to entry there, is actually pretty high - full stack scala plus a bundler (vite => entire nom ecosystem) plus setup cloud infrastructure.

EsModules allow importing other EsModules.

Party trick - in browser referencing a CDN.
https://github.com/Quafadas/ShoelaceSansBundler/blob/3bd156fd55884f71aeb00cb967b308e9ecf99772/importmap.json#L3

In isolation, I agree this PR is not that useful :-) ...

My hope, if you were comfortable with the direction of travel, is that I would then follow up this PR with something like this;
VirtusLab/scala-cli#2737

for mdoc.

The hypothesis is then, that something like laminar-shoelace or my own (lower profile :-) ) experiments, can be easily documented (via markdown - mdoc) and published in a static site (e.g. on GitHub pages - the browser just needs to hit up the CDN) - and they can depend on an arbitrary EsModule dependancy - without needing the bundler.

The remaining problems, are already quite well solved...

... and without a bundler or backend! Said differently, I believe this could (no guarantees) ultimately crush the barrier to entry of documenting scala-js libs.

@tgodzik
Copy link
Contributor

tgodzik commented Jul 9, 2024

That sounds awesome! It would be cool if you could later add a bit of documentation to mdoc if it pans out.

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.

Thanks!

@tgodzik tgodzik merged commit 87ca141 into scalameta:main Jul 9, 2024
14 checks passed
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.

3 participants