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

Ability to remap @JSImports at linking time #4837

Open
armanbilge opened this issue Mar 24, 2023 · 4 comments
Open

Ability to remap @JSImports at linking time #4837

armanbilge opened this issue Mar 24, 2023 · 4 comments
Labels
enhancement Feature request (that does not concern language semantics, see "language") separate repo Addressing this issue should be done in a separate repository. Closed here.

Comments

@armanbilge
Copy link
Member

An interesting alternative to bundling is loading dependencies from a CDN. esm.run for example serves dependencies as minified, bundled ESM modules.

The catch is that import statements need refer to the CDN urls. If you control all the @JSImports used by your application this is fine, but in general libraries will not want to hard-code a particular CDN into their imports. So ideally there would be a way to remap the imports at application linking time.

Many browsers offer an "importmap" feature to achieve this kind of remapping. Still, I think this is an interesting feature for Scala.js itself, because it allows to deploy "self-contained" JS files that would work in any browser that supports ESM as well as Node.js (or Deno), without requiring additional configuration to remap imports.

@sjrd
Copy link
Member

sjrd commented Mar 24, 2023

That sounds like something that could be done outside the core, by preprocessing the IRFiles consumed by the linker. They can be customized with the Compile/scalaJSIR task, which is a Seq[IRFile]. Each IRFile can be mapped to an adapter IRFile that applies the preprocessing in its tree method.

@armanbilge
Copy link
Member Author

Thank you for the pointers, that was quite straightforward actually :)

I do still think this is a compelling, works-out-of-the-box alternative to dealing with JS bundlers and personally I'd love to see this graduate to a core feature.

  1. Implementing outside of core relies on unstable APIs.
  2. It's harder to get traction with non-userland-extensible tooling such as scala-cli.
  3. IDK what I'm doing when it comes to compilery stuff 😆

@sjrd
Copy link
Member

sjrd commented Mar 25, 2023

The good thing about something separate, though, is that it can iterate until the best design is found. It could be an external sbt plugin. If and when the design stabilizes and the feature gets traction, we can consider whether it's worth putting in the core.

If we want to put it in the core straight away, we have to spend upfront time discussing the perfect design, because it can never change afterward.

(unstable APIs can break now and then, but they usually last for several release cycles)

@sjrd sjrd added enhancement Feature request (that does not concern language semantics, see "language") separate repo Addressing this issue should be done in a separate repository. Closed here. labels Apr 7, 2023
@gzm0
Copy link
Contributor

gzm0 commented Apr 9, 2023

Is this a candidate for a linker plugin? (for context: we've been toying with this idea for years, but never had use cases to design an API / interface against).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request (that does not concern language semantics, see "language") separate repo Addressing this issue should be done in a separate repository. Closed here.
Projects
None yet
Development

No branches or pull requests

3 participants