plugin-ruby icon indicating copy to clipboard operation
plugin-ruby copied to clipboard

Bundle everything into the npm module

Open kddnewton opened this issue 1 year ago • 28 comments

See this issue: https://github.com/prettier/plugin-ruby/issues/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.

kddnewton avatar Jul 22 '22 17:07 kddnewton

Is that possible to compile Ruby as WASM?

JounQin avatar Jul 23 '22 01:07 JounQin

Yes it is! But only with Ruby 3.2. So in the future that’ll be a great solution.

On Fri, Jul 22, 2022 at 9:12 PM JounQin @.***> wrote:

Is that possible to compile Ruby as WASM?

— Reply to this email directly, view it on GitHub https://github.com/prettier/plugin-ruby/issues/1260#issuecomment-1193029214, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABG3P3XOVU4TR7GWDE5IYATVVNBGLANCNFSM54MJACEA . You are receiving this because you authored the thread.Message ID: @.***>

kddnewton avatar Jul 23 '22 02:07 kddnewton

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.

JounQin avatar Jul 23 '22 08:07 JounQin

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

kddnewton avatar Jul 26 '22 17:07 kddnewton

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

JounQin avatar Jul 26 '22 22:07 JounQin

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 https://github.com/prettier/prettier/issues/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.

kddnewton avatar Aug 05 '22 15:08 kddnewton

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. 😅

JounQin avatar Aug 05 '22 15:08 JounQin

@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 avatar Aug 05 '22 16:08 kddnewton

@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 https://github.com/un-ts/synckit/issues/94

JounQin avatar Aug 05 '22 16:08 JounQin

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

kddnewton avatar Aug 10 '22 13:08 kddnewton

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

https://github.com/prettier/plugin-ruby/commit/23f2089144e65896e526b517c76406a087327ade#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.

JounQin avatar Aug 10 '22 14:08 JounQin

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

kddnewton avatar Aug 10 '22 14:08 kddnewton

Okay @JounQin we're back to hanging now

kddnewton avatar Aug 10 '22 14:08 kddnewton

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 avatar Aug 10 '22 14:08 JounQin

@kddnewton

https://github.com/prettier/plugin-ruby/commit/f1d1937c5aabee7490ffa77728fa15fdda09616e#diff-a19812fe5175f5ae8fccdf2c9400b66ea4408f519c4208fded5ae4c3365cac4dR1

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

JounQin avatar Aug 10 '22 14:08 JounQin

What command should I run for debugging your issue?

JounQin avatar Aug 10 '22 14:08 JounQin

@JounQin that's starting to work!

kddnewton avatar Aug 10 '22 14:08 kddnewton

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

JounQin avatar Aug 28 '22 02:08 JounQin

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 avatar Sep 19 '22 18:09 kddnewton

Moving this issue over to node-syntax-tree here: https://github.com/ruby-syntax-tree/node-syntax-tree/issues/43.

kddnewton avatar Oct 18 '22 16:10 kddnewton

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

JounQin avatar Nov 20 '23 19:11 JounQin

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.

kddnewton avatar Nov 20 '23 19:11 kddnewton

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

JounQin avatar Nov 20 '23 20:11 JounQin

Done

kddnewton avatar Nov 21 '23 01:11 kddnewton

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

ghost avatar Jan 29 '24 17:01 ghost

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

kddnewton avatar Jan 29 '24 17:01 kddnewton

It was in reference to your recommendation in the comment here: https://github.com/prettier/plugin-ruby/issues/1232#issuecomment-1192799354

ghost avatar Jan 30 '24 00:01 ghost

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.

JounQin avatar Jan 30 '24 01:01 JounQin