prettier / plugin-ruby

Prettier Ruby Plugin
MIT License
1.45k stars 96 forks source link

Bundle everything into the npm module #1260

Open kddnewton opened 2 years ago

kddnewton commented 2 years ago

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.

JounQin commented 2 years ago

Is that possible to compile Ruby as WASM?

kddnewton commented 2 years ago

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: @.***>

JounQin commented 2 years ago

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 commented 2 years ago

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

JounQin commented 2 years ago

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

kddnewton commented 1 year ago

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.

JounQin commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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

kddnewton commented 1 year ago

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

JounQin commented 1 year ago

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.

kddnewton commented 1 year ago

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

kddnewton commented 1 year ago

Okay @JounQin we're back to hanging now

JounQin commented 1 year ago

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 synckit@0.8.2 which propagates sync errors from worker, it'll handle some unexpected sync errors.

JounQin commented 1 year ago

@kddnewton

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

- const { runAsWorker } = require("synckit/lib/index.cjs");
+ const { runAsWorker } = require("synckit");
JounQin commented 1 year ago

What command should I run for debugging your issue?

kddnewton commented 1 year ago

@JounQin that's starting to work!

JounQin commented 1 year ago

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

kddnewton commented 1 year ago

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 commented 1 year ago

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

JounQin commented 8 months ago

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

kddnewton commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

Done

ghost commented 5 months ago

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

kddnewton commented 5 months ago

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

ghost commented 5 months ago

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

JounQin commented 5 months ago

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.