-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Proposal: add JavaScript support via OXC #106
Comments
I think if it comes into ash-project org and collaborate, would be good; or even on igniter as core optional installing |
Agreed :) Still in the early stages of discovery. |
I'm happy to work on a Rustler integration if needed. |
There is some discussion in the igniter discord channel on the rustler side of things. Would be a wonderful to have more eyes and hands on it |
@jimsynz : Currently I am expanding on ideas on the best way forward to integrate js parser and ast manipulator from elixir. Here is one approach I have decided to take (unless there are unknown unknowns): I imagine writing one JS AST manipulator in elixir would be possible, but keeping it upto date would be a hassle. So, the plan is to have ast in rust. Reference that AST struct from elixir. manipulate that ast in js using This is the 4 step plan (rough direction) as suggested by @zachdaniel
|
Here is what I found about integration rust Struct and elixir
|
same pattern found here as well:
|
Here are more code references:
|
What is the general solution to #4 above? If we're going to invest a lot of time and energy into this via rustler, we need to have confidence that we can ship this to effectively any platform someone is developing on. The nice thing about pure elixir solutions is that we know they have elixir installed at a minimum 🤣 |
This seems to be the easier part. With RustlerPrecompiled library, this is breeze. Code change: https://github.com/TwistingTwists/crucible/blob/d686d940aa71c7213dd0ef2ec1b5af0da126988b/lib/native.ex#L6-L11 So, this is already done!! See assets which are precompiled binaries: https://github.com/TwistingTwists/crucible/actions/runs/11458278738 |
haven't added support for windows yet. or musl binaries. But this can be done. This is just the barebones apple and linux_x86 support for precompiled binaries. |
Windows support will be a hard requirement FWIW |
If we want igniter to be truly ubiquitous across the ecosystem, it has to run everywhere elixir runs. |
There is a good news. Can compile for windows, apple and linux (x86 and arm!) woot! 🥳 Here: https://github.com/TwistingTwists/crucible/releases/tag/v0.1.1 |
I've had a long holiday in context of diwali in India. Back now. First update: Since AST is in Rust, and the AST manipulation is also available via rust methods, my idea is to keep all the AST and AST manipulation in Rust-land. Here is an API to begin with.
Let's see how this goes. |
Hi @TwistingTwists |
The methods for manipulating ast will be present in Rust (oxc_semantic) already does a lot of ast manipulation. the library will call those methods from elixir (via rustler) Proposed API on elixir side would be (roughly): For Handling Hooks in app.js
|
Hello Dear @zachdaniel, Thank you! |
It depends on what you mean by priority :) I will not be personally working on it any time soon, but will happily support it and may eventually work on it myself if nothing ends up getting over the line :) |
Greetings, friends. Over the past two weeks, I’ve been learning how to test libraries in Rust to seamlessly integrate them with Igniter and cover all file modification requirements. Before I explain: All of this is based on my limited knowledge of Rust, so there might be better solutions. Two approaches came to mind for working with the OXC library:
Unfortunately, based on this discussion(oxc-project/oxc#7801), deserialization isn’t supported yet and won’t be available anytime soon. This makes this approach completely infeasible. Having this capability would have greatly helped in achieving full access.
In this case, the AST doesn’t get imported into Elixir. Instead, specific requirements are met by writing tailored functions for each need. I’ve already explained about OXC above. I hope you can give me some advice. Right now, I can fulfill the needs of my own library, but my goal is to establish a more foundational approach and also integrate it with Igniter. I’d really appreciate hearing your thoughts. The OXC library is actually inspired by another project called BiomeJS (https://github.com/biomejs/biome/tree/main/crates), but it has taken a completely different direction. The BiomeJS project is very active, and it seems to support deserialization. However, working with it would require at least two weeks of effort before making a decision. You can check the link above to see its submodules. I’ve worked a bit with this library, but its documentation didn’t meet my requirements, so I couldn’t make much progress. It seems like it would take around one to two weeks to properly evaluate it. What are your thoughts and suggestions?
Limited functions like theseRefs:
UpdateFor Biome |
I think we really only have two options based on all of this:
Obviously #2 is a huge undertaking. So we probably start with #1 and then maybe someday tackle #2. I would like to make |
Hi @zachdaniel , I hope you're doing well. The approach you mentioned for porting tools to Rust seems logical and reasonable. However, my primary concern revolves around using Let me clarify with an example: imagine building an AST in Rust for JavaScript. Each part of a node, such as a function or a variable, has a specific type (like a struct) that allows for seamless operations within Rust. Now, let’s assume we want to use this in Elixir. The first issue is that we’d need to rewrite all the types in Elixir. This essentially means recreating the entire JavaScript parser from scratch, defeating the purpose of using Rust. If we convert it to JSON, it can be easily consumed in Elixir. However, the problem arises when we want to modify that JSON in Elixir and send it back to Rust to be converted into an AST with its original types. This is the core issue: in Elixir, we can’t make AST-like modifications as we would with macros. So, what are the potential solutions?
This issue is particularly evident with parsers because they essentially create constructs that don’t natively exist in Rust. They involve analyzing and managing numerous types, lifetimes, and mechanisms to prevent panics—all of which don’t align well with Elixir. If we were to adapt it for Elixir’s format, we’d also need to create a reverse transformation format to convert data from Elixir back into Rust. For example, I haven’t found a way to handle This is the problem I was trying to highlight. I don’t have opinions on other features; my focus has been specifically on parsers. My observations are based on examining these two projects and discussing them with their maintainers. That said, your suggestions make perfect sense. It’s entirely feasible to use tools that don’t have the same challenges as parsers. For instance, tools for CLI utilities could be adapted from Rust’s ecosystem to Elixir without major issues. Regarding writing a full
Best, |
I'm following the issue, and what it seems like is that it's going to be massive amounts of work no matter how we cut it to have js patching in Elixir in any kind of fluid way. So I think we just make very specific utilities, like you mentioned, and just leave all the rest for later for now. We can tell people "the way we patch js is by writing rust, sorry 🤷". Later on down the road we can figure out ways to make it nicer. Rust isn't all that bad 😋 |
We can provide a basic utility to say something like "patch this text" which passes text to a rust script which passes us the new text back, so that it still sits nicely in the igniter framework. |
@zachdaniel For example:
For now, these examples are sufficient for my own library for example. The user can write their JavaScript in a separate file and make changes there, rather than directly modifying |
Yep, basic fit-for-purpose tools sounds perfect to me as a start, and we can continue to explore the space as necessary <3 |
Requirement
One feature that could significantly enhance Igniter's support for all basic requirements in Phoenix is a robust JavaScript parser or manipulator.
Developing this from scratch would be a
large-scale
project, requiring considerable time and effort.Therefore, I suggest considering the Oxc project, which is implemented in Rust, as a potential solution.
Where we can use it:
Imagine you want to create a
Phoenix
component that requires aphx-hook
. You would need to modify theapp.js
file to inject the entire JavaScript file into theHook
object, or alternatively, create a separate JavaScript file, import it intoapp.js
, and then inject it into the hook.Currently, all of this is done manually in Elixir projects, which involves a lot of documentation and a complex process. This approach is not ideal and can discourage users from using it.
For example, take a look at this object that I injected using the JavaScript spread operator.
No I want to add
GetUserText
object.Thank you in advance
Refs
The text was updated successfully, but these errors were encountered: