Skip to content

Commit

Permalink
Report invalid exposed modules. finos#1172
Browse files Browse the repository at this point in the history
  • Loading branch information
AttilaMihaly committed Nov 13, 2024
1 parent 4b36eb7 commit 55054c9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"main": "lib/dist/main.js",
"module": "es6",
"scripts": {
"prepare": "npm run setup-elm-tooling",
"clean": "gulp clean",
"test": "gulp test",
"test-morphir-ir-typescript": "gulp testMorphirIRTypeScript",
Expand Down
55 changes: 48 additions & 7 deletions src/Morphir/Elm/Frontend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import Json.Encode as Encode
import Morphir.Compiler as Compiler
import Morphir.Elm.Frontend.Resolve as Resolve exposing (ModuleResolver)
import Morphir.Elm.IncrementalFrontend as IncrementalFrontend
import Morphir.Elm.ModuleName as ModuleName
import Morphir.Elm.WellKnownOperators as WellKnownOperators
import Morphir.Graph
import Morphir.IR.AccessControlled exposing (AccessControlled, private, public)
Expand Down Expand Up @@ -160,6 +161,7 @@ type Error
| MissingTypeSignature SourceLocation
| RecordPatternNotSupported SourceLocation
| TypeInferenceError SourceLocation Infer.TypeError
| ExposedModuleNotFound Path


type alias Imports =
Expand Down Expand Up @@ -435,6 +437,9 @@ mapSource opts packageInfo dependencies sourceFiles =
("Type inference error: " ++ Encode.encode 0 (encodeTypeError typeError))
sourceLocation
[]

ExposedModuleNotFound _ ->
[]
)
|> List.foldl
(\( filePath, fileError ) soFar ->
Expand Down Expand Up @@ -474,6 +479,18 @@ mapSource opts packageInfo dependencies sourceFiles =
}
)

ExposedModuleNotFound modulePath ->
Just
(Compiler.ErrorAcrossSourceFiles
{ errorMessage =
String.concat
[ "Exposed module name not found: "
, Path.toString Name.toTitleCase "." modulePath
]
, files = []
}
)

_ ->
Nothing
)
Expand Down Expand Up @@ -557,9 +574,28 @@ packageDefinitionFromSource opts packageInfo dependencies sourceFiles =
case packageInfo.exposedModules of
Just exposedModules ->
let
exposedModuleNames : Set ModuleName
exposedModuleNames =
exposedModules
validateExposedModules : Set Path -> List ModuleName -> Result Errors (Set Path)
validateExposedModules userSpecifiedExposedModules availableModules =
let
missingModuleNames : Set Path
missingModuleNames =
availableModules
|> List.map (List.map Name.fromString)
|> Set.fromList
|> Set.diff userSpecifiedExposedModules
in
if Set.isEmpty missingModuleNames then
Ok userSpecifiedExposedModules

else
missingModuleNames
|> Set.toList
|> List.map ExposedModuleNotFound
|> Err

exposedModuleNames : Set Path -> Set ModuleName
exposedModuleNames validExposedModules =
validExposedModules
|> Set.map
(\modulePath ->
(packageInfo.name |> Path.toList)
Expand All @@ -574,14 +610,19 @@ packageDefinitionFromSource opts packageInfo dependencies sourceFiles =
--_ =
-- Debug.log "Parsed sources" (parsedFiles |> List.length)
--
parsedFilesByModuleName : Dict ModuleName ParsedFile
parsedFilesByModuleName =
parsedFiles
|> Dict.fromList
in
parsedFiles
|> treeShakeModules exposedModuleNames
|> sortModules
|> Result.andThen (mapParsedFiles opts dependencies packageInfo.name parsedFilesByModuleName)
validateExposedModules exposedModules (Dict.keys parsedFilesByModuleName)
|> Result.andThen
(\validExposedModules ->
parsedFiles
|> treeShakeModules (exposedModuleNames validExposedModules)
|> sortModules
|> Result.andThen (mapParsedFiles opts dependencies packageInfo.name parsedFilesByModuleName)
)
)
|> Result.map
(\moduleDefs ->
Expand Down

0 comments on commit 55054c9

Please sign in to comment.