Shall we narrow the scope of the main index? #155
Replies: 4 comments
-
I'm quite torn on that matter. On one hand, the current approach keeps Langium more in line with other JS libraries that are only imported by their name. On the other hand, this would make imports a bit more structured, like I'm used from other programming languages/runtimes. Either way, if we go trough with this idea, we should use What do other experienced JS devs think? @danieldietrich @brucou |
Beta Was this translation helpful? Give feedback.
-
I don't really have a strong opinion here. What are the advantages of both approaches from an API consumer point of view? Exporting the whole API from one place may be simpler for the consumer of that API. They do not have to remember in which specific package was that specific function that they are using. I always had the issue with RxJS and LoDash, when I had to remember how to import a Subject and how to import a On the other hand, splitting per route, say Also
That matching may also be a coupling of |
Beta Was this translation helpful? Give feedback.
-
Thanks for asking, Mark. Personally, I don't like imports from sub-packages. Here are my thoughts: Importing from sub-modules exposes internal APIAnt Design is a good example for a bad user experience regarding sub-module imports. I would not recommend to do so because there is the risk that users import APIs that are meant to be internal. Especially we might need to export an API in a sub-module because other sub-modules make internally use of it. See also no-submodule-imports as an example that sub-module imports are considered bad practice. Importing from sub-modules is not approachableWith sub-module imports it is hard from the user perspective to find out which types/objects are available for importing. Only documentation helps to get the right pointers on how to do (read: import) things. I would love to use the following API, it would be approachable because we could make use of content assist. import * as langium from 'langium'
const { Foo } = langium.parser;
const { Bar } = langium.grammar; Organizing exportsI suggest to define an To get the status quo, the top-level // same as `export * from './grammar/index.ts'`
export * from './documents';
export * from './generator';
export * from './grammar';
export * from './lsp';
... To change the API in direction of See also TypeScript: Namespaces and Modules. |
Beta Was this translation helpful? Give feedback.
-
If we agree on keeping the single Example: a function name |
Beta Was this translation helpful? Give feedback.
-
Currently we reexport most of Langium's API in the index.ts. As a consequence, we lose the context when users import a symbol from
'langium'
. All symbols are available in this global pool regardless of our internal code structure.A possible alternative would be to reduce the main index to reexport only from sources of the same directory level (
dependency-injection
,default-module
etc.) and addindex.ts
files to all subdirectories. Then you would import everything grammar-related from'langium/lib/grammar'
, everything LSP-related from'langium/lib/lsp'
and so on. This would nicely match the structure of services in ourLangiumServices
type. WDYT?Beta Was this translation helpful? Give feedback.
All reactions