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

Rescript and Deno #4965

Closed
Zizico2 opened this issue Feb 21, 2021 · 21 comments
Closed

Rescript and Deno #4965

Zizico2 opened this issue Feb 21, 2021 · 21 comments
Labels
stale Old issues that went stale

Comments

@Zizico2
Copy link

Zizico2 commented Feb 21, 2021

Are there any plans to support Deno? The Deno ecosystem is growing rapidly and we are stuck with JavaScript and TypeScript since bs-platform is only packaged as an npm package.

@bobzhang
Copy link
Member

I did not try deno, but I suppose it should work without much hassle, do you have any particular issue? You can just download the npm package and check if it works

@Zizico2
Copy link
Author

Zizico2 commented Feb 23, 2021

@bobzhang I opened an issue requesting ReScript support for Alephjs. One of their goals is to stay away from npm.
alephjs/aleph.js#159

@shadowtime2000
Copy link

shadowtime2000 commented Feb 23, 2021

I did not try deno, but I suppose it should work without much hassle, do you have any particular issue? You can just download the npm package and check if it works

@bobzhang Deno is not a Node thing, it is a whole another server side runtime. That would not work because while Node uses CJS we use native ES modules.

@bobzhang
Copy link
Member

Note we support es6 modules, you can configure it like

"package-specs" : "es6" // "es6-global" for precise path

You don't need use npm, you can just use a http client to download bs-platform, I am not sure how deno support packages

@bobzhang
Copy link
Member

bobzhang commented Feb 26, 2021

I made a repo to show how to use ReScript with Deno, you don't need do anything special with Deno since we support the ESModule standard https://github.com/bobzhang/rescript-deno

@shadowtime2000
Copy link

@bobzhang Yes that could work, but it is inconvenient when trying to use ReScript with frameworks like Aleph as many developers who use Deno try to limit the dependency on Node and NPM as much as possible.

@bobzhang
Copy link
Member

@shadowtime2000 There is only one dependency: bs-platform, the package has no dependencies, you can just download the package by hand. Did I miss anything?

@shadowtime2000
Copy link

@bobzhang Yes, that most Deno developers wouldn't want to have to use Node alongside with Deno, but just Deno.

@bobzhang
Copy link
Member

where is node used?

@shadowtime2000
Copy link

@bobzhang Well, you have to use NPM to install the bs-platform package which Deno devs wouldn't like, and then the running of that build system requires Node.

@shadowtime2000
Copy link

What I am talking about is a bs-platform package that uses Deno APIs to do the building.

@shadowtime2000
Copy link

@bobzhang Maybe I didn't clearly explain myself. I am talking about having support for the ReScript compiler itself inside Deno, and not having to use Node because it's kind of dumb to have to rely on Node to use Deno. I have no idea how ReScript compiler works but it seems like majority of it is native code so you could just write bindings to it using Deno's APIs.

@seanstrom
Copy link

seanstrom commented Apr 6, 2021

Hey 👋
I too would be interested in knowing if it’s possible to publish the Rescript packages as Deno packages.

From what I was reading, Deno doesn’t seem to have a default package manager or registry. So that may mean that Rescript may need to compile to JS that uses import statements with remote paths like:
import * as Array from 'https://unpkg.com/[email protected]/lib/es6/array.js'

We could also use something like Trex (unofficial package manager) to provide Import Maps for something like:
import * as Array from 'bs-platform/array'

Another piece would be to provide Deno alternatives for scripts like bsb, bsc, and any other Node based executables. The APIs are different enough that this could require some extra Deno knowledge about how to install and use executables with Deno.

I would be happy to help experiment with some of this and see if we can put something together. I really think that Rescript could benefit from the Deno community, and that the Deno community would appreciate Rescript since they like TypeScript (officially supported by Deno) but at times would prefer an alternative type system and/or language 😊

cc @bobzhang

@bobzhang bobzhang reopened this Apr 6, 2021
@bobzhang
Copy link
Member

bobzhang commented Apr 7, 2021

@seanstrom Hi, we are open contributions to make deno use experience better.
Note only bsb is relevant, it is a small file that should be easy to adapt to deno

@shadowtime2000
Copy link

So I assume bsb is just some glue code to use child_process to load the actual native compiler and use it. That should be relatively simple to recreate in Deno as it already has support for that with Deno.run.

@bobzhang
Copy link
Member

bobzhang commented Apr 7, 2021

yes, if you don't use watch mode, bsb is basically the same as bsb.exe sitting in darwin/linux/win32

@seanstrom
Copy link

@seanstrom Hi, we are open contributions to make deno use experience better.

Great to hear 😊

Note only bsb is relevant, it is a small file that should be easy to adapt to deno

I have a question about the bsc script, why it is not relevant? It seems like it also uses child_process.

I also have some notes and questions around supporting Deno. Some of these comments are based on this Rescipt + Deno demo and the Rescript compiler internals.

Notes:

What are your thoughts on this? How should we add Deno support for the runtime modules from bs-platform?

cc @bobzhang

@bobzhang
Copy link
Member

bobzhang commented Apr 7, 2021

I have a question about the bsc script, why it is not relevant?

Only the build system bsb is client facing, it internally called bsc.exe directly. The cli of bsc is unstable and subject to change.

rename bs-platform to bs_platform

We are going to publish it as rescript on npm, so it should not be an issue.

wants avoid using directories like node_modules.

You can try to use the module format es6-global. There may be some other issues

@seanstrom
Copy link

I created a fork of the Rescript + Deno experiment and added a Deno import map, along with the external-stdlib setting in the bsconfig.json. The use of a import map makes it pretty easy to use Deno to download the Rescript standard library 😃

Here's the experiment with Rescript + Deno with import map file
https://github.com/seanstrom/rescript-deno/tree/deno-import-map

@bobzhang
Copy link
Member

Indeed import map is quite nice, I also made use of it here https://github.com/bobzhang/rescript-react-demo
@seanstrom feel free to send a PR to if any changes are needed to make the experience better

@stale
Copy link

stale bot commented Apr 25, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Old issues that went stale label Apr 25, 2023
@stale stale bot closed this as completed May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Old issues that went stale
Projects
None yet
Development

No branches or pull requests

4 participants