elm-in-elm / compiler / Elm.Data.FilePath

File path of an Elm (or other) file.


type alias FilePath =
String

Just a String alias, instead of a type wrapper. We generally use records with explanatory field names where two Strings would be next to each other, to protect against swapping them accidentally.

expectedFilePath : { sourceDirectory : FilePath, moduleName : Elm.Data.ModuleName.ModuleName } -> FilePath

Converts from module name to its expected file path. Additionally needs the source directory from elm.json.

The source directory can be passed both with and without the trailing slash.

expectedFilePath { sourceDirectory = "src", moduleName = "Foo" }
--> "src/Foo.elm"

expectedFilePath { sourceDirectory = "src/", filePath = "Foo" }
--> "src/Foo.elm"

removeTrailingSlash : FilePath -> FilePath

Normalize the file path.

removeTrailingSlash "src/foo/"
--> "src/foo"

removeTrailingSlash "src/foo"
--> "src/foo"

removeTrailingSlash "src/foo/Main.elm"
--> "src/foo/Main.elm"