@@ -19,6 +19,7 @@ import Compiler.Backend
1919import Compiler.PackageName as PackageName exposing (PackageName)
2020import Compiler.Paths
2121import Compiler.Outline as Outline exposing (Outline)
22+ import Compiler.ModuleName as ModuleName exposing (ModuleName)
2223import Git
2324import Init
2425import Stream
@@ -465,6 +466,7 @@ parseUserArgs model compilerPath =
465466
466467 CliParser.Make flags ->
467468 resolveProject model
469+ |> Task.andThen (verifyMakeFlags model.fsPermission flags.entryPoints flags.output)
468470 |> Task.map
469471 (\resolved ->
470472 Compiler.Backend.run
@@ -821,3 +823,103 @@ resolveProject model =
821823 projectOutline
822824 |> Task.mapError Terminal.PackageInstall.prettifyError
823825 )
826+
827+
828+ verifyMakeFlags : FileSystem.Permission -> Array ModuleName -> Maybe Compiler.Backend.MakeOutput -> Terminal.PackageInstall.PackageResolution -> Task PP.Document Terminal.PackageInstall.PackageResolution
829+ verifyMakeFlags fsPermission entryPoints maybeOutput resolution =
830+ let
831+ maybeOutputPath =
832+ when maybeOutput is
833+ Nothing ->
834+ Nothing
835+
836+ Just Compiler.Backend.StdOut ->
837+ Nothing
838+
839+ Just Compiler.Backend.DevNull ->
840+ Nothing
841+
842+ Just (Compiler.Backend.Html strPath) ->
843+ Just strPath
844+
845+ Just (Compiler.Backend.Js strPath) ->
846+ Just strPath
847+
848+ Just (Compiler.Backend.Exe strPath) ->
849+ Just strPath
850+
851+ compatibleOutputCheck =
852+ when maybeOutputPath is
853+ Nothing ->
854+ Task.succeed {}
855+
856+ Just strPath ->
857+ Node.getPlatform
858+ |> Task.map
859+ (\platform ->
860+ when platform is
861+ Node.Win32 ->
862+ Path.fromWin32String strPath
863+
864+ _ ->
865+ Path.fromPosixString strPath
866+ )
867+ |> Task.andThen
868+ (\path ->
869+ FileSystem.metadata fsPermission { resolveLink = False } path
870+ |> Task.mapError
871+ (\fsError ->
872+ Terminal.Help.report
873+ "CANNOT ACCESS OUTPUT PATH"
874+ (Just path)
875+ (PP.verticalBlock
876+ [ PP.words
877+ ( "You have told me to compile this project to "
878+ ++ Path.toPosixString path
879+ ++ ", but I cannot access this path for some reason!"
880+ )
881+ ]
882+ )
883+ )
884+ |> Task.andThen
885+ (\metadata ->
886+ if metadata.entityType == FileSystem.Directory then
887+ Task.fail <|
888+ Terminal.Help.report
889+ "OUTPUT PATH IS A DIRECTORY"
890+ (Just path)
891+ (PP.verticalBlock
892+ [ PP.words
893+ ( "You have told me to compile this project to "
894+ ++ Path.toPosixString path
895+ ++ ", but this is a directory!"
896+ )
897+ ]
898+ )
899+
900+ else
901+ Task.succeed {}
902+ )
903+ )
904+ in
905+ compatibleOutputCheck
906+ |> Task.andThen
907+ (\{} ->
908+ when Array.findFirst (\moduleName -> not <| Dict.member (ModuleName.toString moduleName) resolution.rootSources) entryPoints is
909+ Nothing ->
910+ Task.succeed resolution
911+
912+ Just { value = moduleName } ->
913+ Task.fail <|
914+ Terminal.Help.report
915+ "MODULE DOES NOT EXIST"
916+ Nothing
917+ (PP.verticalBlock
918+ [ PP.words
919+ ( "You have told me to compile "
920+ ++ ModuleName.toString moduleName
921+ ++ ", but this module isn't defined in this project!"
922+ )
923+ ]
924+ )
925+ )
0 commit comments