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

Bundle everything into the npm module #1260

Open
kddnewton opened this issue Jul 22, 2022 · 28 comments
Open

Bundle everything into the npm module #1260

kddnewton opened this issue Jul 22, 2022 · 28 comments
Assignees

Comments

@kddnewton
Copy link
Member

See this issue: #1232 for details.

I'm not entirely sure how to solve this, but I know it will involve adding a prepublishOnly step to the package.json that's going to use bundler to dump all of the necessary files into the package somehow.

@JounQin
Copy link
Member

JounQin commented Jul 23, 2022

Is that possible to compile Ruby as WASM?

@kddnewton
Copy link
Member Author

kddnewton commented Jul 23, 2022 via email

@JounQin
Copy link
Member

JounQin commented Jul 23, 2022

Why not try it out right now?

https://www.ruby-lang.org/en/news/2022/04/03/ruby-3-2-0-preview1-released/

Is there anything preventing us?

When it's already compiled into WASM, no ruby runtime is required.

@kddnewton
Copy link
Member Author

Right... I don't know what I was talking about. I will try this!

@JounQin
Copy link
Member

JounQin commented Jul 26, 2022

Besides, in case of handling asynchronous due to WASM, you can try https://github.com/un-ts/synckit to turn it synchronously again!

@kddnewton
Copy link
Member Author

So this now works in https://github.com/ruby-syntax-tree/node-syntax-tree. Except that it doesn't support RBS yet, because it's very difficult to compile non-bundled native extensions: https://twitter.com/kateinoigakukun/status/1555202638064799750?s=20&t=9wXaP7QoPngehSIujvUGFw.

The other difficulty is that loading WASM requires an async call, so we still are blocked on that. Fortunately that's changing in v3 of prettier prettier/prettier#13142.

I think the answer for now is going to be waiting for prettier v3 and waiting on/working on support for non-bundled native extensions for WASI.

@JounQin
Copy link
Member

JounQin commented Aug 5, 2022

Besides, in case of handling asynchronous due to WASM, you can try https://github.com/un-ts/synckit to turn it synchronously again!

@kddnewton Did you tried this one? Of course waiting for prettier@v3 is another solution. 😅

@kddnewton
Copy link
Member Author

@JounQin I did! I couldn't get it to work. To be honest I'm not sure what I was doing wrong, but it would just hang no matter what I tried.

@JounQin
Copy link
Member

JounQin commented Aug 5, 2022

@JounQin I did! I couldn't get it to work. To be honest I'm not sure what I was doing wrong, but it would just hang no matter what I tried.

@kddnewton Can you provide a branch so I can offer some help?

At least you can try SYNCKIT_TIMEOUT env to see what's wrong.

And the problem may be fixed by un-ts/synckit#94

@kddnewton
Copy link
Member Author

@JounQin sure! The branch is here: https://github.com/prettier/plugin-ruby/tree/synckit.

@JounQin
Copy link
Member

JounQin commented Aug 10, 2022

I haven't looked into details yet, but the root issue could be

23f2089#diff-598b75d6dc772eb13aa7141f35bb93046ae26c58a97e8647ecf7f74aec8ae93fR2

It does not need/should be called immediately

- const parseSync = createSyncFn(require.resolve("./worker"))();
+ const parseSync = createSyncFn(require.resolve("./worker"));

I'll clone and check quickly.

@kddnewton
Copy link
Member Author

Nice, now I'm just getting some cloning errors.

@kddnewton
Copy link
Member Author

Okay @JounQin we're back to hanging now

@JounQin
Copy link
Member

JounQin commented Aug 10, 2022

Nice, now I'm just getting some cloning errors.

See

You must make sure, the result is serializable by Structured Clone Algorithm


Besides, you'd better upgrade to [email protected] which propagates sync errors from worker, it'll handle some unexpected sync errors.

@JounQin
Copy link
Member

JounQin commented Aug 10, 2022

@kddnewton

f1d1937#diff-a19812fe5175f5ae8fccdf2c9400b66ea4408f519c4208fded5ae4c3365cac4dR1

- const { runAsWorker } = require("synckit/lib/index.cjs");
+ const { runAsWorker } = require("synckit");

@JounQin
Copy link
Member

JounQin commented Aug 10, 2022

What command should I run for debugging your issue?

@kddnewton
Copy link
Member Author

@JounQin that's starting to work!

@JounQin
Copy link
Member

JounQin commented Aug 28, 2022

@kddnewton Any progress or how could I help to achieve this?

@kddnewton
Copy link
Member Author

Yes please! If you could help me get https://github.com/ruby-syntax-tree/node-syntax-tree to compile the RBS plugin as well - which is the only blocker, then I could ship this using the WASM code and it would be totally good to go.

@kddnewton
Copy link
Member Author

Moving this issue over to node-syntax-tree here: ruby-syntax-tree/node-syntax-tree#43.

@JounQin
Copy link
Member

JounQin commented Nov 20, 2023

I saw ruby-syntax-tree/node-syntax-tree#43 is marked as completed, but https://github.com/ruby-syntax-tree/node-syntax-tree itself is archived, is this supported already? @kddnewton

@kddnewton
Copy link
Member Author

Not really - I'm just giving up on that possibility to be honest. The issue is RBS compilation into WASM. If someone figures that out, we can make it happen. But at the same time I'm working on replacing the backend of syntax tree to use prism, so we'll be using a different form of compilation for that.

@JounQin
Copy link
Member

JounQin commented Nov 20, 2023

I'd like to give it a try when I'm free. Can you assign this issue to me and reopen it?

Reference https://ruby.github.io/ruby.wasm

@kddnewton kddnewton reopened this Nov 21, 2023
@kddnewton kddnewton assigned kddnewton and JounQin and unassigned kddnewton Nov 21, 2023
@kddnewton
Copy link
Member Author

Done

@ghost
Copy link

ghost commented Jan 29, 2024

Is the current opinion that we should stop using this plugin?

@kddnewton
Copy link
Member Author

@alan-pie I'm not sure what you mean. This is an enhancement, the plugin itself functions just fine.

@ghost
Copy link

ghost commented Jan 30, 2024

It was in reference to your recommendation in the comment here:
#1232 (comment)

@JounQin
Copy link
Member

JounQin commented Jan 30, 2024

There're 3 options, dropping is the worst, I'm going to add this feature while I'm focusing on other projects these days.

Plaese be patient, or even better, join to help.

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

2 participants