-
Notifications
You must be signed in to change notification settings - Fork 189
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
Mapping ocaml unix APIs to nodejs calls #1115
Conversation
If I'm looking at this correctly, it seems the only way to write tests that run in nodejs is to include them inside the |
@hhugo if you have some time to look over this, I'm hoping to get this over the finish line within the next week-or-so! |
Yes, this is correct. I’m not sure if any of the runtime js files are linked by default though, you may need to make changes in Util |
Hmm, I'm not sure what you mean |
I'm not sure what else to do here without guidance (specifically "you may need to make changes in Util") so I'm marking this ready-for-review to hopefully get some attention |
That mean I don't think you need to worry about this as unix.js is already part of the default runtime. |
This is not the only way. Look at tests in lib/test (e.g. https://github.com/ocsigen/js_of_ocaml/blob/master/lib/tests/test_nodejs_filesystem_errors.ml). Theses tests run in node only, the dune file says |
I though more about this. I would prefer to integrate with the "js_of_ocaml filesystem proxy" with something similar to what we have with function unix_stat(n){
var root = resolve_fs_device(n);
if(!root.device.stat)
caml_failwith("unix_stat: no implemented");
root.device.stat(root.rest);
} You would then have update |
Improves #483 |
Excellent! Happy to do this. You are okay with JS built for the browser failing with |
That or we implement some dummy stat. |
One thing I considered for Grain was embedding the file stats of the built JS file for anything in memory, since any embedded files would be a snapshot at that timestamp. Is this a good idea? If so, any thoughts on how I'd implement that? |
Can you describe the grain use case a bit more ? |
Currently, Grain compiles the compiler (written in Reason) to JS using JSOO and then includes it into a nodejs runtime called However, I also did some research into a browser bundle to add a playground on our website—this should be a natural workflow, as we can compile to WebAssembly in the browser, and then directly run it in a WebAssembly context. Unfortunately, we'd need the unix methods supported in the browser because our compiler compares timestamps of files for caching and recompilation. I was planning to add this feature in the future when work began on our in-browser editor. |
The current implementation of fs_fake.js is a bit naive currently. With some work you should be able to add additional information like stat. |
I don't have more to say right now, but I'm happy to answer any question if you spend some time working on it. |
Thanks! For this first draft, I'll not handle the browser APIs, but I will plan to revisit in the future. |
e9f645a
to
a1dfd07
Compare
@hhugo this should be ready for review! I added some tests that I could think of for the Unix calls that were implemented. Let me know if you think there should be more tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while get the full picture of changes. Some comments probably reflect that.
The one thing I don't like about it is the raise-catch-raise business. see my comment about adding an extra argument.
@hhugo Thanks for the feedback! I've updated the MlNodeDevice methods to take the There are a couple decisions to be made still (unresolved comments) but I'm happy to get those fixed up in the morning. |
fad3108
to
82dd36e
Compare
Done! |
82dd36e
to
6fe714c
Compare
I few more tests and we should be ready to merge |
I'll try to get to that this afternoon. Have a couple of job interviews, but hope to have time outside of them. |
I added the tests in the same way you added Unix.mkdir and Unix.rmdir tests, but I added the Failure messages to the expected output. If there is a better way to handle these, please let me know 🙏 |
Thanks a lot for the hard work, I will merge once the CI is happy. |
This is just a draft right now because I need a lot of advice on TODOs and testing (sorry, first time contributing here).
@hhugo saw my work on these utilities in the Grain repository and said I should look into upstreaming them. So here is my first pass.
I tried changing some of our assumptions to allow for non-nodejs usage, but I don't know what the functions should do if not inside nodejs.
Please help guide me into taking this over the finish line! 🍻