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

Make Standard Library browser compatible #641

Open
oscarotero opened this issue Dec 6, 2020 · 3 comments
Open

Make Standard Library browser compatible #641

oscarotero opened this issue Dec 6, 2020 · 3 comments

Comments

@oscarotero
Copy link

Hi!
Now that you are working on review and stabilizing the Deno Standard Library here https://github.com/denoland/deno/issues/8405, I like to make a suggestion.

One of the greatest point of Deno is the compatibility with the standards. If it works on the browser, it should work on Deno, I guess this is the reason why you're implementing web APIs like window, location, alert or fetch. The standard library of Deno is a great addition, but to me it has a problem: it's written in Typescript. I know that Typescript is a big bet for Deno and I think it's great that it can be supported by default, without need to install any additional tool to transpile. But browsers do not support Typescript, so there's no way to import and use any deno std module directly in the browser.

Perhaps this was been discussed before, but I'd like to propose that these components would have a ES6 javascript version, that could be imported and used in the browser. I'm not suggesting to remove Typescript, but providing an additional *.js endpoint so in a browser I could import and execute:

import { basename } from "https://deno.land/std@0.79.0/path/mod.js"

basename("/foo/bar.txt");

Doing so, the std library would be not only great for Deno but for the whole javascript ecosystem.

Some of the std modules require the Deno.* runtime API (fs, for example). But others don't. I propose to provide a *.js version only for those modules using standard web apis.

What do you think?

@nayeemrmn
Copy link
Contributor

providing an additional *.js endpoint so in a browser I could import and execute

The browser-compatible modules have at the top:

// This module is browser-compatible.

The idea is that these modules can run in browsers already if bundled into JS with deno bundle. I don't think it's a goal to go beyond that.

However, the idea of the registry (deno.land/x/ or deno.land/std/) being generically able to serve pre-compiled JavaScript with ?js at the end of the URL was thrown around in the past. I can't see an open issue if you want to open one there instead: https://github.com/denoland/deno_registry2/issues.

@kitsonk
Copy link
Contributor

kitsonk commented Dec 6, 2020

There is also this, which we were going to put into std but decided against: https://github.com/denoify/denofill. I need to refresh it and update it, but the is the more logical way to ensure that things in std can easily work in browsers, versus constraining the std library in some way.

@oscarotero
Copy link
Author

@nayeemrmn thanks for your quick answer. deno bundle outputs a single javascript file with all dependencies, so it's not exactly what I'm suggesting. Perhaps, something like Deno.transpileOnly is more accurate. The idea is having modern and well tested javascript modules that you can import anywhere (deno, browsers...) and they just work.

I'm also mean to do it only to std modules, instead all packages in the deno.land/x/ registry, that would be much more harder. So I'm not sure if this should be done in the deno_registry2 repository or is something more related with the standard modules (that, as I can see, it's suggested to be moved to a separate repo)

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

No branches or pull requests

3 participants