{"action":"created","issue":{"url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2688","repository_url":"https://api.github.com/repos/BuckleScript/bucklescript","labels_url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2688/labels{/name}","comments_url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2688/comments","events_url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2688/events","html_url":"https://github.com/BuckleScript/bucklescript/issues/2688","id":309625551,"number":2688,"title":"Namespace discussion","user":{"login":"chenglou","id":1909539,"avatar_url":"https://avatars2.githubusercontent.com/u/1909539?v=4","gravatar_id":"","url":"https://api.github.com/users/chenglou","html_url":"https://github.com/chenglou","followers_url":"https://api.github.com/users/chenglou/followers","following_url":"https://api.github.com/users/chenglou/following{/other_user}","gists_url":"https://api.github.com/users/chenglou/gists{/gist_id}","starred_url":"https://api.github.com/users/chenglou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenglou/subscriptions","organizations_url":"https://api.github.com/users/chenglou/orgs","repos_url":"https://api.github.com/users/chenglou/repos","events_url":"https://api.github.com/users/chenglou/events{/privacy}","received_events_url":"https://api.github.com/users/chenglou/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-29T05:35:23Z","updated_at":"2018-03-30T13:33:37Z","closed_at":null,"author_association":"OWNER","body":"I've collected some feedbacks and thoughts regarding our namespace solution so far:\r\n\r\n- Despite the fact that the namespace option has been turned on by default in the bsb templates, it seems that every few weeks there's a new blog post coming out that warns of global file clashes and/or say that we don't have a namespacing system. It's a somewhat recurrent topic in Discord as well.\r\n- We don't seem to have a plan to transition to `\"namespace\": true` by default in bsb in the medium term.\r\n- There's also the issue that folks really want to put bindings into the top-level module, e.g. `MyLibrary.foo`, but our current namespace system doesn't allow it.\r\n- The lack of the latter feature also means that folks can't transition toward using the namespace feature in in bsconfig.json as easily. This is a feature in rather high demand (cc @rickyvetter, @jaredly)\r\n- Even though it's well-documented, it seems that folks also get confused that namespacing is for third-party consumption and doesn't affect the current library.\r\n- There are some small hard-to-repro bugs regarding namespace staleness.\r\n- Confusions around the name of the module vs package.json name vs bsconfig.json name vs npm scoped name.\r\n\r\nI'm creating this issue because I feel that we should have a cleaner experience regarding namespacing. As an alternative, bsconfig also happens to have the feature [`sources.public`](https://bucklescript.github.io/bucklescript/docson/#build-schema.json). I'm wondering if we can tweak that as an alternative to namespace. Usage:\r\n\r\n```json\r\n{\r\n  \"name\": \"my-app\",\r\n  \"sources\": {\r\n    \"dir\" : \"src\",\r\n    \"public\": [\"MyApp\"]\r\n  }\r\n}\r\n```\r\n\r\nIn `src/MyApp.re`:\r\n\r\n```reason\r\nlet a = 1;\r\nmodule Utils = Utils;\r\n```\r\n\r\nUsage in another project:\r\n\r\n```json\r\n{\r\n  \"name\": \"your-app\",\r\n  \"bs-dependencies\": [\"my-app\"]\r\n}\r\n```\r\n\r\n```reason\r\nlet myValue = MyApp.a; /* 1 */\r\nlet log = MyApp.Utils.log;\r\n```\r\n\r\nThis currently fails to compile because `Utils` from my-app project is hidden, although it's aliased from `MyApp.re`.\r\n\r\nThis is apparently not trivial to implement. The benefits is that you get top-level bindings for free, and you get to expose more than one thing. Additionally, this by itself solves all of the above pitfalls of our current solution."},"comment":{"url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/comments/377525014","html_url":"https://github.com/BuckleScript/bucklescript/issues/2688#issuecomment-377525014","issue_url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2688","id":377525014,"user":{"login":"stroiman","id":237227,"avatar_url":"https://avatars0.githubusercontent.com/u/237227?v=4","gravatar_id":"","url":"https://api.github.com/users/stroiman","html_url":"https://github.com/stroiman","followers_url":"https://api.github.com/users/stroiman/followers","following_url":"https://api.github.com/users/stroiman/following{/other_user}","gists_url":"https://api.github.com/users/stroiman/gists{/gist_id}","starred_url":"https://api.github.com/users/stroiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stroiman/subscriptions","organizations_url":"https://api.github.com/users/stroiman/orgs","repos_url":"https://api.github.com/users/stroiman/repos","events_url":"https://api.github.com/users/stroiman/events{/privacy}","received_events_url":"https://api.github.com/users/stroiman/received_events","type":"User","site_admin":false},"created_at":"2018-03-30T13:33:37Z","updated_at":"2018-03-30T13:33:37Z","author_association":"NONE","body":"I've experienced two issues with the namespacing.\r\n\r\n * Scoped packages gets awkward package names.\r\n * If same package is implicitly imported multiple times, the versions must be compatible.\r\n\r\n**Scoped package names**\r\n\r\nPackage `@ScopeName/PackageName` is imported as `ScopeNamePackageName`, which becomes quite awkward. More natural package names would be:\r\n\r\n * `PackageName` IMHO most natural, but at risk of namespace collisions with other packages.\r\n * `ScopeName.Package.Name`\r\n\r\nThis awkward namespace name is also the reason I didn't enable namespaces for my published scoped packages.\r\n\r\n**Multiple imports of same package**\r\n\r\nI have package `@stroiman/respect` which depends on package `@stroiman/async` for helping managing async code. This is purely an implementation detail - there is nothing in the public interface of `respect` that refers to `async`.\r\n\r\nIf I use `respect` from my application, and my application also depends on `async`, but in an incompatible version - I am unable to compile.\r\n\r\nIn pure node.js, this sort of dependency would not be a problem, as NPM itself happily installs both versions:\r\n\r\n```\r\nmyapp/node_modules/@stroiman/async\r\nmyapp/node_modules/@stroiman/respect/node_modules/@stroiman/async\r\n```\r\n\r\n**Suggestion**\r\n\r\nIf you could overwrite the root namespace on import, I think that could solve both issues (namespace collision of similarly named packages, and having multiple incompatible versions)\r\n\r\nThe package name of the imported package would merely be a _default_ namespace, but could be overwritten in the `bs-dependencies`/`bs-dev-dependencies` section.\r\n\r\n```\r\n\"name\": \"@stroiman/respect\",\r\n\"namespace\": true,\r\n\"bs-dependencies\": [\r\n  { \"name\": \"@stroiman/async\",\r\n    \"root-namespace\": \"Imports.Async\" \r\n    // The root-namespace should be prefixed with this package's name, to\r\n    // respect any overwrites by the importing package.\r\n  }\r\n```\r\n\r\nThis way, the two versions of `async`, located in two different folders on disc,\r\nare compiled into two separate root namespaces.\r\n"}}
{"actor":{"display_login":"stroiman"}}