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

Emit JavaScript modules for browsers like esm.sh #133

Open
ericlery opened this issue Mar 2, 2024 · 13 comments
Open

Emit JavaScript modules for browsers like esm.sh #133

ericlery opened this issue Mar 2, 2024 · 13 comments
Labels
feature New feature or request

Comments

@ericlery
Copy link

ericlery commented Mar 2, 2024

JSR doesn't have the ability to emit JavaScript from TypeScript sources to serve browsers.

The JavaScript emitted should also be cached.

Example of TypeScript code from JSR https://jsr.io/@kwhinnery/yassify/1.0.0/mod.ts:

export function yassify(str: string): string {
  return `${str} 💅✨👑`;
}

At this moment, this code doesn't work.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JSR in the Browsers</title>
</head>
<body>
  <script type="module">
    import { yassify } from "https:/jsr.io/@kwhinnery/yassify@1.0.0";

    alert(yassify("In the browser!"));
  </script>
</body>
</html>

Although doing similar with esm.sh works:

<script type="module">
  import { yassify } from "https://esm.sh/jsr/@kwhinnery/yassify@1.0.0";

  alert(yassify("In the browser!"));
</script>

The jsr.io website actually displays that

JSR is designed for TypeScript. You publish TypeScript source, and JSR handles generating API docs, .d.ts files, and transpiling your code for cross-runtime compatibility.
JSR packages are distributed as web-standard ECMAScript modules.

JSR should implement emitting and caching for browsers. It would be the ultimate JavaScript registry.

@ericlery ericlery changed the title Emit JavaScript Cached modules like esm.sh Emit JavaScript Cached modules for browsers like esm.sh Mar 2, 2024
@ericlery ericlery changed the title Emit JavaScript Cached modules for browsers like esm.sh Emit JavaScript modules for browsers like esm.sh Mar 2, 2024
@bartlomieju bartlomieju added the feature New feature or request label Mar 2, 2024
@ije
Copy link

ije commented Mar 3, 2024

hi, you can use esm.sh for now, util this feature is added.

- https://esm.sh/jsr/@kwhinnery/yassify@1.0.0
+ https://jsr.io/@kwhinnery/yassify@1.0.0

@lucacasonato lucacasonato added this to JSR Mar 4, 2024
@github-project-automation github-project-automation bot moved this to Needs Plan in JSR Mar 4, 2024
@jespertheend
Copy link

The JSR website says it works with any runtime. Which is a pretty bold claim when it doesn't work in browsers :P

@ericlery
Copy link
Author

ericlery commented Mar 9, 2024

The JSR website says it works with any runtime. Which is a pretty bold claim when it doesn't work in browsers :P

It's actually a bit more complicated than that. It works on projects when your back end process/bundle your front end.

But for me personally, the good ol' browser link is the way for quick and dirty prototyping. For some people, it's even their norm.

@jespertheend
Copy link

For me it's my norm, it's why I exclusively write .js files 😅

Fwiw, jsr's usage policy says:

It is not acceptable to use JSR as a CDN for serving assets directly to web applications in a browser, except for development purposes. JSR is not a general purpose file hosting service.

So I suppose that even if this does get added, it will still be pretty useless.

I think maybe instead we should start bugging jsDelivr. They already support npm, so hopefully they could make use of the npm compatibility layer without too much effort. Their site says:

Custom CDN Hosting

We can work together and set up a custom configuration for your project. This way, you can have full control over your files and the ability to utilize the full power of jsDelivr.

@marvinhagemeister
Copy link
Contributor

FYI esm.sh already added support for JSR.

@jespertheend
Copy link

Ah cool! I wasn't aware.

@ericlery
Copy link
Author

Yes to all of you that re-mention it, esm.sh already added support of JSR, that's the title and the whole point for this issue:

Make it available for JSR too please.

Why should we use something else to get JSR modules?

@mhanuszh
Copy link

mhanuszh commented Jul 9, 2024

I'm not here to annoy anyone subscribed to this issue, but...
Is this feature being even considered by the devs? I haven't found anything about them planning on adding this.

@dbushell
Copy link

dbushell commented Aug 7, 2024

Let us be clear: Deno is not removing HTTP imports.
https://deno.com/blog/http-imports

Deno is supposedly committed to supporting HTTP imports. Or at least not removing them.

With the Deno standard library now published exclusively on JSR — deno.land/std is months out of date, and importing from source is broken — I'd expect JSR to surface some kind of HTTP import URL.

@dirkluijk
Copy link

dirkluijk commented Oct 13, 2024

Surprised that this is not (yet?) supported. I suppose it would be quite easy to serve packages directly to browsers, and seems like a missed opportunity. 😉

@ericlery
Copy link
Author

ericlery commented Jan 6, 2025

Surprised that this is not (yet?) supported. I suppose it would be quite easy to serve packages directly to browsers, and seems like a missed opportunity. 😉

Absolutely. I can't believe I've opened this issue nearly one year ago!

@BlackAsLight
Copy link

If I was to guess, they most likely don't want to support it at least at this time due to the extra hosting cost that would burden JSR with.

@ericlery
Copy link
Author

ericlery commented Jan 6, 2025

If I was to guess, they most likely don't want to support it at least at this time due to the extra hosting cost that would burden JSR with.

Exactly. I hope some Tech Giant will stand up to support JSR. Maybe one that is part of WinterCG like Vercel or even better Cloudflare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: Needs Plan
Development

No branches or pull requests

9 participants