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

JS snippets for nodejs target #1525

Open
ibaryshnikov opened this issue May 11, 2019 · 7 comments
Open

JS snippets for nodejs target #1525

ibaryshnikov opened this issue May 11, 2019 · 7 comments

Comments

@ibaryshnikov
Copy link
Member

Initially nodejs target was not supported when js snippets were implemented. Is it the time to add support for nodejs?

There is already code like this in js-sys tests:

#[wasm_bindgen(module = "tests/wasm/Iterator.js")]

https://github.com/rustwasm/wasm-bindgen/blob/master/crates/js-sys/tests/wasm/Iterator.rs#L5

And it somehow works. But when I tried to compile my own module, it compiled and failed in runtime because the .js file was not copied to the pkg folder. How did you make the tests work?

@fitzgen
Copy link
Member

fitzgen commented May 13, 2019

IIRC, because node only has experimental support for modules that you have to enable with a special flag at startup, we don't support modules + js snippets on node unless you set the WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE env var, which is just for our own internal testing really.

To properly support js snippets on node, we want to rewrite the exports to common js.

@ibaryshnikov
Copy link
Member Author

@fitzgen nice, thank you for the response! so it's already on your roadmap?

@fitzgen
Copy link
Member

fitzgen commented May 13, 2019

I would say we know what needs to be done, but have not prioritized it or come up with any target release dates or anything like that. If you want to talk about it next WG meeting, feel free to add to the schedule!

@kellytk
Copy link

kellytk commented Aug 13, 2019

What would help move this issue forward, at least for the no-modules target?

@alexcrichton
Copy link
Contributor

The original RFC has a bit more information, but there's not much more other than "this needs implementing" for the node/no-modules targets. The "this" in terms of what needs to happen is specified in the RFC.

@kellytk
Copy link

kellytk commented Aug 23, 2019

I made https://github.com/yewstack/yew-wasm-pack-minimal and used Rollup with the intention of removing it when wasm-pack can be used exclusively. If it could be modified in any way to assist with implementation please feel welcome to open an issue.

@PhilippGackstatter
Copy link

Is there an update on snippets for nodejs?

Does this require "only" implementation and if so, is there a plan for how to do so? Specifically, it seems like there hasn't been a decision on which JS parser to use. I could imagine implementing this, but it depends on how much time it would take.

We currently want to use websocket support from rust-libp2p that imports a JS snippet to implement it. It seems to be fixed by removing the export keyword from the websocket_transport function and adding the line

exports.websocket_transport = websocket_transport;

I assume, however, that a more universal solution would not be as straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants