Rescript-compiler: Support vendoring packages with a namespace

Created on 23 Nov 2020  路  7Comments  路  Source: rescript-lang/rescript-compiler

It would be good to allow projects to vendor a dependency with a namespace.
Currently vendoring a project with multiple modules (in its root) pollutes consumer's namespace.
Let's say i'm working on project alpha and I want to vendor a project named beta with two modules A, B.

   vendor/
      beta/
         A.res
         B.res
    src/
    .
    .
    .

Now i have A and B in alpha's global namespace which is not desirable. I have to rename each module with Beta_ prefiex and create aliases in another module (Beta.res).
It would be better if there was a cleaner way to do that.

Solution I can think if is support namespaces in sources, ie:

```json
{
"sources": {
"dir": "beta",
"namespace": "Beta",
}
}
````

Most helpful comment

Even without vendoring, this would be extremely helpful to be able to structure one's project into multiple namespaces.

E.g. I created an Api "namespace" in a project by having modules Api_Xxx.res and aliasing those in Api.res:

module Common = Api_Common;
module Error = Api_Error;
module Interceptors = Api_Interceptors;
module Requests = Api_Requests;
module Types = Api_Types;
module LongPolling = Api_LongPolling;
// etc.

It would be much nicer to just have Common.res, Api.res etc. in a subfolder api that is configured to use the namespace Api.

All 7 comments

Even without vendoring, this would be extremely helpful to be able to structure one's project into multiple namespaces.

E.g. I created an Api "namespace" in a project by having modules Api_Xxx.res and aliasing those in Api.res:

module Common = Api_Common;
module Error = Api_Error;
module Interceptors = Api_Interceptors;
module Requests = Api_Requests;
module Types = Api_Types;
module LongPolling = Api_LongPolling;
// etc.

It would be much nicer to just have Common.res, Api.res etc. in a subfolder api that is configured to use the namespace Api.

Pinned packages should solve this? You can then use namespace: true in the package's bsconfig.json. They're a brand new concept, not documented but available to try in version 8.4.0-dev.4

Maybe, I didn't try them but I think the solution should be simpler. (without using workspaces and multiple bsconfigs).

@bobzhang What do you think about this?
better name for this issue would be suport namespaced source code dirs

Every solid project has lots of files, and of course some of them have the same name. Imagine some React project: lots of Button components: Footer/Button.jsx, Header/Button.jsx, Notifications/Button.jsx etc. Should I invent unique name for every file?

That's not related to this issue. This issue relates to vendoring ReScript projects within other ReScript projects.

If you have a problem with the fundamentals of ReScript development, please take it to the forum.

Well, it was just the start, but later discussion moved to "namespaced source code dirs" direction. I believe possibility to namespace modules by folder name can help to ease unique names problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexfedoseev picture alexfedoseev  路  5Comments

bobzhang picture bobzhang  路  3Comments

TheSpyder picture TheSpyder  路  5Comments

chenglou picture chenglou  路  4Comments

bobzhang picture bobzhang  路  4Comments