Publish a library


Hi @ all :wave:

I have created a ReasonML Package for Sha512 / Crypto in general.

How do I publish this / use it in one of my other projects?
I have already tried to install it and add it to my bsconfig.json, but it says:

  31 ┆   };
  32 ┆ 
  33 ┆   let hashedPassword = Sha512.make(password);
  34 ┆   Js.log(hashedPassword);
  35 ┆ };
  The module or file Sha512 can't be found.
  - If it's a third-party dependency:
    - Did you list it in bsconfig.json?
    - Did you run `bsb` instead of `bsb -make-world`
      (latter builds third-parties)?
  - Did you include the file's directory in bsconfig.json?

What am I doing wrong?

Thank you!


I got it working the way I wanted with removing the namespace in bsconfig.json.

Is this something you would advise against or is this okay?


Awesome to see this library! Thanks for working on this.
I’d recommend having a file with the name of the library where you re-expose each module. If you name your library ReCrypt then your file can be named that and so will be the module available to users when they use your library. They will do ReCrypt.Sha256.make to use that functions.


But you would still remove the namespace, right?
Doesnt this still also expose the Sha512 Module? So that I would then expose Sha512 and ReCrypt?

I saw you can also set the Namespace to a string value. So if I set it to „re-crypt“, all modules would be prefixed with ReCrypt, right?


That’s right, they would. For a simple (so far) project like this, a namespace with the right name can work fine. For more complex projects, you may want to try


I rewrote the file structure as you suggested and I really like it.
Thank you for that! :heart:

Now I noticed something though, which seems odd to me.
Aliasing the ReCrypt_Sha512 Module in Reason like this…

module Sha512 = ReCrypt_Sha512;

…produces the following JavaScript Code:

'use strict';

var Sha512 = /* alias */0;

exports.Sha512 = Sha512;
/* No side effect */

Shouldn’t Buckescript export the ReCrypt_Sha512 Module instead of 0 so JS users can import Sha512 from ReCrypt? Now they would have to import the ReCrypt_Sha512 Module directly, right?


Hi Torben, by default BuckleScript does not output JS in a format that can be easily consumed from JS. The output JS is more optimized into a format that BuckleScript can understand. If you want to explicitly re-export the entire Sha512 module you can do something like:

module Sha512 = {
  include ReCrypt_Sha512;


Ah okay. Thank you!

Are there any downsides to your suggested method of including the module?


It may result in a bit bigger bundle size. You can check the output JS while trying out various techniques to see what happens, it’s quite interesting to see how it changes.