Customizable source directories for gleam build
#1845
Replies: 4 comments
-
If we support multiple directories we would need to enforce module uniqueness. We already do this between different packages, so it should come for free. We would need to test this though. We would need to ensure that src paths do not nest, if they do return an error. I think we would also want to disallow absolute paths and paths outside the directory that An import path and the file path both directly map onto the module name so we would not be able to use the system that typescript does. Would it be possible to achieve the goal with a single customisable source path? Adding support for multiple will be a much larger change than a single one, and it'll be one more thing to handle for every future compiler change. I am not convinced that it's worthwhile to support one JS deployment platform. |
Beta Was this translation helpful? Give feedback.
-
I like the idea of configurable source directory but would be worried about the impacts of the shared-root idea. If gleam ever allows for local dependencies, does the need for shared-root style setups disappear? If the application has a |
Beta Was this translation helpful? Give feedback.
-
Yes, but I just keep thinking about what you said here :\ Multiple directories would ultimately just be a "nice to have". Super helpful, but not strictly necessary. A single customizable source directory would be enough to at least finish out a prototype. |
Beta Was this translation helpful? Give feedback.
-
This is a really good observation. I think it might, yes.
We would collect all the srcs into one tree and error if there are any duplicates from the different roots. Once that is done there can only every be 1 or 0 entrypoint modules. |
Beta Was this translation helpful? Give feedback.
-
Based on a conversation in Discord
./src/ is a great default, but occasionally you run into constraints that require something a bit more customizable.
In gleam.toml, we could potentially let you specify something like...
We might even want to let you specify multiple source directories...
...which would unfortunately be a bit ambiguous. Should
import a/b
resolve to ./api/a/b.gleam or ./lib/a/b.gleam if there's a conflict? Maybe we just throw an error if it could be resolved more than one way?Another solution could be a "shared root" similar to what TypeScript does
...which in Gleam could then allow you to...
...where the prefix makes imports unambiguous.
Beta Was this translation helpful? Give feedback.
All reactions