Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions builder/src/Reporting/Exit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ data Outline
| OutlineNoAppCore
| OutlineNoAppJson
| OutlineLamderaMissingDeps
| OutlineLamderaMissingCodecs
| OutlineLamderaReplacementPackageVersionTooLow Pkg.Name V.Version V.Version
| OutlineLamderaReplacementPackageVersionTooHigh Pkg.Name V.Version V.Version

Expand Down Expand Up @@ -1064,6 +1065,13 @@ toOutlineReport problem =
, D.reflow "Note: if you're trying to run a normal Elm app, use the elm binary instead."
]

OutlineLamderaMissingCodecs ->
Help.report "MISSING DEPENDENCY" (Just "elm.json")
"A Lamdera application must have \"lamdera/codecs\" as a dependency."
[ D.reflow "Wire code generation relies on this package. You can install it with:"
, D.indent 4 $ D.green $ "lamdera install lamdera/codecs"
]

OutlineLamderaReplacementPackageVersionTooLow name replacedVersion elmJsonVersion ->
Help.report "UNSUPPORTED VERSION" (Just "elm.json")
("This version of the Lamdera compiler supports the following range for \"" <> Pkg.toChars name <> "\":")
Expand Down
15 changes: 12 additions & 3 deletions compiler/src/Generate/JavaScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Prelude hiding (cycle, print)
import qualified Data.ByteString.Builder as B
import Data.Monoid ((<>))
import qualified Data.List as List
import Data.Map ((!))
import qualified Data.Map as Map
import qualified Data.Name as Name
import qualified Data.Set as Set
Expand All @@ -23,6 +22,7 @@ import qualified AST.Optimized as Opt
import qualified Data.Index as Index
import qualified Elm.Kernel as K
import qualified Elm.ModuleName as ModuleName
import qualified Elm.Package as Pkg
import qualified Generate.JavaScript.Builder as JS
import qualified Generate.JavaScript.Expression as Expr
import qualified Generate.JavaScript.Functions as Functions
Expand Down Expand Up @@ -194,10 +194,10 @@ addGlobalHelp mode graph global state =
let
addDeps deps someState =
Set.foldl' (addGlobal mode graph) someState deps

argLookup = makeArgLookup graph
in
case graph ! global of
case Map.findWithDefault (error $ globalNotFound global) global graph of
-- @LAMDERA
Opt.Define (Opt.Function args body) deps
| length args > 1 ->
Expand Down Expand Up @@ -716,3 +716,12 @@ toMainEsmExports mode mains =
in
"export const Elm = " <> exports <> ";"


globalNotFound :: Opt.Global -> String
globalNotFound (Opt.Global (ModuleName.Canonical pkg modul) name) =
"Global not found in dependency graph: "
++ Pkg.toChars pkg ++ ":" ++ Name.toChars modul ++ "." ++ Name.toChars name
++ "\n This likely means a required package is missing from elm.json."
++ "\n If you are using the Lamdera compiler, make sure lamdera/codecs is installed:"
++ "\n lamdera install lamdera/codecs"

10 changes: 7 additions & 3 deletions extra/Lamdera/Checks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ runChecks root shouldCheckLamdera direct indirect default_ = do
return $ Left err

Right () ->
let allDeps = Map.union direct indirect in
if Map.member Pkg.lamderaCore direct
then do
onlyWhen shouldCheckLamdera (Lamdera.Checks.runChecks_ root)
default_
then
if not (Map.member Pkg.lamderaCodecs allDeps)
Comment thread
miniBill marked this conversation as resolved.
Outdated
then return $ Left Exit.OutlineLamderaMissingCodecs
else do
onlyWhen shouldCheckLamdera (Lamdera.Checks.runChecks_ root)
default_
else
if shouldCheckLamdera
then return $ Left Exit.OutlineLamderaMissingDeps
Expand Down