diff --git a/package-lock.json b/package-lock.json index f9578a73f..8fb5236c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "morphir-elm", "version": "2.90.1", - "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { "ajv": "^8.10.0", diff --git a/package.json b/package.json index 87177a3f8..1c88d2c4c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Morphir/Elm/Frontend.elm b/src/Morphir/Elm/Frontend.elm index ae9d4ddde..501046ff4 100644 --- a/src/Morphir/Elm/Frontend.elm +++ b/src/Morphir/Elm/Frontend.elm @@ -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) @@ -160,6 +161,7 @@ type Error | MissingTypeSignature SourceLocation | RecordPatternNotSupported SourceLocation | TypeInferenceError SourceLocation Infer.TypeError + | ExposedModuleNotFound Path type alias Imports = @@ -435,6 +437,9 @@ mapSource opts packageInfo dependencies sourceFiles = ("Type inference error: " ++ Encode.encode 0 (encodeTypeError typeError)) sourceLocation [] + + ExposedModuleNotFound _ -> + [] ) |> List.foldl (\( filePath, fileError ) soFar -> @@ -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 ) @@ -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) @@ -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 ->