Playground: Bring back load_modules API #4393
   Merged  
   Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.    
 
This patch is the result of an exploration to bring back the
load_modulesAPI, which was recently disabled.The proposed approach is to double down on the usage of js_of_ocaml pseudo file system to load these modules. As can be seen, the implementation of
load_modulesAPI for the playground is really simple, just a couple of calls toJs.create_fileto load both cmi and cmj files into jsoo pseudo file system.Advantages of using pseudo file system
Env.Persistent_signature.loadorJs_cmj_load.load_unit, it's just files all the way down.Converting from traditional cmi/cmj files to browser-ready files
To complete the process of being able to compile code that references 3rd party BuckleScript libs on the browser, the plan is to have another small program that allows to create "browser-ready cmijs" from
node_modulesfolder, a proof of concept of what this package could look like can be seen in https://github.com/jchavarri/bs-playground-bundler.The generation of resulting scripts relies on js_of_ocaml pseudo file system to convert the binary representation of cmis into the utf-16 strings that will be loaded from the browser.
Remaining work
If this PR gets approved and merged, I will proceed then with other tasks to clean up / update other points:
-playgroundflag incmij_mainjsoo_refmt_main