Skip to content

Customizable source directories for gleam build #1556

@aslilac

Description

@aslilac

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...

source = "./api/"

We might even want to let you specify multiple source directories...

source = ["./api/", "./lib/"]

...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

# Must be a parent of all modules
sourceRoot = "./" 
# These would probably be "Gleam paths" and not fs paths.
# They would be resolved relative to `sourceRoot`
modules = ["api", "lib"] 

...which in Gleam could then allow you to...

import lib/some/shared/logic.{Whatever}

// ...

...where the prefix makes imports unambiguous.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionThe approach has not yet been decided

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions