How to build rescript package

Hello,

I have a React/Rescript software that is a general purpose library. I do not want yet to publish it on the web.
But the only way I could use it was to create symbolic links. All proposed solutions I found on the
web resulted in a duplicate react problem.

What is the correct Rescript equivalent of opam pin add . or dune install for an OCaml package ?

You need to use npm, as for any other js library.

If you don’t want to publish it yet, you could use npm link / yarn link / etc. to symlink your lib.

1 Like

By the way, there is a bit of a working example of developing a lib, and consuming it from another project using npm link method in this forum post.

1 Like

I finally found a way, but there is still a strange thing:

  1. in package.json, I add a dependency like: "rescript-mylib": "file:path_to_package"
  2. I add the dependency in bsconfig.json
  3. I do an open RescriptMylib in the .res file using it.

Remain a question: When I use rescript-future, I do not need the last step (open RescriptFuture). Why?

Step 3) was hard to guess, because there is a name transformation rescript-mylib => RescriptMylib.
Where is this documented ? I do not see any difference between rescript-mylib and rescript-future except the local installation?

You can use all Modules of a library directly. So you don’t have to open RescriptFuture for accessing e.g. the Future module.

There is a namespace property in the bsconfig which will wrap all modules of a project into a single root module. This is documented here: Build System Configuration | ReScript Language Manual

In the side note is also a description about the “name transformation” :wink:

Many thanks, indeed, “namespace”: true was the reason I needed the open.
There is still a duplicate warning issue:
Duplicated package: @rescript/react

Which I do not know if I should worry?

You shouldn’t worry about it