Feature preview: the name of namespace can be customized


#1

Namespace is allowed to be customized in next release, try it npm i -g bs-platform@next.

Changes to build system are error-prone, test and early feedback are appreciated.

bsconfig.json

"namespace" : "your-valid-name"

#2

For us newbies, could you give an example where this might be useful?


#3

Hey there, BuckleScript’s namespace feature lets you wrap up your project’s modules inside a top-level parent module so that they don’t clash with any other modules that they might be used with: https://bucklescript.github.io/docs/en/build-configuration#name-namespace

Previously, BuckleScript automatically used the same name as the npm package scope, as the namespace. So e.g. for a package @your/package, the module structure would look like: YourPackage.Foo, YourPackage.Bar, etc. This could not be customized.

Now, you can customize the namespace module’s name to whatever you like. It doesn’t have to come from the npm package scope name.


#4

Thanks! I didn’t really know about this namespacing feature before – should my binding https://github.com/benadamstyles/bs-fluture have "namespace": true? Currently, if you install it, it’s available under BsFluture, I guess because the filename is BsFluture.re. That seems correct to me, but am I missing anything?


#5

That’s fine if you’re OK with exposing BsFluture as your toplevel module. An alternative (which is encouraged nowadays) would be to scope it with a namespace, so e.g. it would be BenadamStylesBsFluture (or customized). Personally, I prefer my toplevel modules to be more like Yawaramin_MyProject, and I like documenting that toplevel module as well. So I personally don’t use the namespace feature, and instead do a little extra work to arrange things the way I like. I wrote about that here: https://dev.to/yawaramin/a-modular-ocaml-project-structure-1ikd