Close module or re-open an "original" (eg: Js)

Quick question for a given use case:

I use “rescript-js” using bsc-flags

  "bsc-flags": [
    "-open Belt",
    "-open ReScriptJs"
  ],

This is totally fine for me until I started to use rescript-relay which need at some point Js.Exn (currently missing from rescript-js).

So I was wondering: can I keep this global open ReScriptJs and “close” it somehow in a given file?
Or reopen the “original Js” module ?

Thanks for your tips, have a nice day :slight_smile:

3 Likes

I think you you can override ReScriptJs module to work it around. Put somewhere in your codebase file ReScriptJs.res

module Js = {
   include  ReScriptJs__Js
   module Exn = Js_exn
}
2 Likes

Thanks for the trick !

Main idea here is that since Js module is shadowed there is no way to get access to original Js module. But you can get submodules like Js_exn and use it one way or another.

This is working well but has a limitation: in case of ReScriptJs, Promise has been overwritten by @ryyppy/rescript-promise and this is causing trouble as generated code by rescript-relay is looking for the original one.
I have to not open ReScriptJs via bcc-flags and keep local open :frowning:

How about doing something like this?

module Js = {
   include  ReScriptJs__Js
   module Exn = Js_exn
   module Promise = Js_promise
   module Promise2 = ReScriptJs.Js.Promise
}

I never use -open, I made my own mini stdlib file that I manually open at the top of every file. This “mini stdlib” uses a combination of module X = Belt.X and include to bring together everything I use regularly.

When done this way, the original Js reference can be stored before open ReScriptJs.