on master help sign in
Allow generation when listed application files have no main
d42572aEvan Czaplicki
builder/src/Generate/Output.hs+23−18
@@ -63,25 +63,30 @@ generate options summary graph@(Crawl.Graph args _ _ _ _) =
63
63
64generateMonolith :: Options -> Summary.Summary -> Crawl.Result -> [Module.Raw] -> Task.Task ()
64generateMonolith :: Options -> Summary.Summary -> Crawl.Result -> [Module.Raw] -> Task.Task ()
65generateMonolith (Options debug target output_) summary@(Summary.Summary _ project _ ifaces _) graph names =
65generateMonolith (Options debug target output_) summary@(Summary.Summary _ project _ ifaces _) graph names =
66− do
67− objectGraph <- organize summary graph
68− let pkg = Project.getName project
66+ do let pkg = Project.getName project
69 let roots = map (Module.Canonical pkg) names
67 let roots = map (Module.Canonical pkg) names
68+ objectGraph <- organize summary graph
70− let (Right builder) = Obj.generate debug target ifaces objectGraph roots
69+ case Obj.generate debug target ifaces objectGraph roots of
70+ Nothing ->
71+ return ()
72+
73+ Just builder ->
74+ let
71− let monolith =
75+ monolith =
76+ "(function(scope){\n'use strict';"
72− "(function(scope){\n'use strict';" <> Functions.functions <> builder <> "}(this));"
77+ <> Functions.functions <> builder <> "}(this));"
73−
78+ in
74− liftIO $
79+ liftIO $
75− case output_ of
80+ case output_ of
76− Nothing ->
81+ Nothing ->
77− IO.writeBuilder "elm.js" monolith
82+ IO.writeBuilder "elm.js" monolith
78−
83+
79− Just None ->
84+ Just None ->
80− return ()
85+ return ()
81−
86+
82− Just (Custom maybeDir fileName) ->
87+ Just (Custom maybeDir fileName) ->
83− do path <- safeCustomPath maybeDir fileName
88+ do path <- safeCustomPath maybeDir fileName
84− IO.writeBuilder path monolith
89+ IO.writeBuilder path monolith
85
90
86
91
87
92
compiler/src/Generate/JavaScript.hs+5−7
@@ -39,22 +39,20 @@ import qualified Reporting.Helpers as H
39data Mode = Debug | Prod
39data Mode = Debug | Prod
40
40
41
41
42−generate :: Mode -> Name.Target -> I.Interfaces -> Opt.Graph -> [ModuleName.Canonical] -> Either [ModuleName.Canonical] B.Builder
42+generate :: Mode -> Name.Target -> I.Interfaces -> Opt.Graph -> [ModuleName.Canonical] -> Maybe B.Builder
43generate mode target interfaces (Opt.Graph mains graph fields) roots =
43generate mode target interfaces (Opt.Graph mains graph fields) roots =
44 let
44 let
45 rootSet = Set.fromList roots
45 rootSet = Set.fromList roots
46 rootMap = Map.restrictKeys mains rootSet
46 rootMap = Map.restrictKeys mains rootSet
47 in
47 in
48− if Map.size rootMap == Set.size rootSet then
48+ if Map.null rootMap then
49+ Nothing
50+ else
49 let
51 let
50 realMode = toRealMode mode target fields
52 realMode = toRealMode mode target fields
51 state = Map.foldrWithKey (addMain realMode graph) emptyState rootMap
53 state = Map.foldrWithKey (addMain realMode graph) emptyState rootMap
52 in
54 in
53− Right $ stateToBuilder state <> toMainExports realMode interfaces rootMap
55+ Just $ stateToBuilder state <> toMainExports realMode interfaces rootMap
54−
55− else
56− Left $ Set.toList $
57− Set.intersection rootSet (Map.keysSet mains)
58
56
59
57
60addMain :: Name.Mode -> Graph -> ModuleName.Canonical -> main -> State -> State
58addMain :: Name.Mode -> Graph -> ModuleName.Canonical -> main -> State -> State