on master help sign in
Add dependencies field to Deps
8a46eadEvan Czaplicki
Elm.cabal+4−2
@@ -110,7 +110,8 @@ Library
110 text,
110 text,
111 transformers >= 0.2,
111 transformers >= 0.2,
112 union-find,
112 union-find,
113− uniplate
113+ uniplate,
114+ unordered-containers
114
115
115Executable elm
116Executable elm
116 Main-is: Compiler.hs
117 Main-is: Compiler.hs
@@ -189,7 +190,8 @@ Executable elm
189 text,
190 text,
190 transformers >= 0.2,
191 transformers >= 0.2,
191 union-find,
192 union-find,
192− uniplate
193+ uniplate,
194+ unordered-containers
193
195
194Executable elm-doc
196Executable elm-doc
195 Main-is: Docs.hs
197 Main-is: Docs.hs
compiler/Elm/Internal/Dependencies.hs+29−13
@@ -7,7 +7,7 @@ import qualified Control.Exception as E
7import Data.Aeson
7import Data.Aeson
8import qualified Data.List as List
8import qualified Data.List as List
9import qualified Data.ByteString.Lazy as BS
9import qualified Data.ByteString.Lazy as BS
10−import qualified Data.Map as Map
10+import qualified Data.HashMap.Strict as Map
11import qualified Elm.Internal.Name as N
11import qualified Elm.Internal.Name as N
12import qualified Elm.Internal.Version as V
12import qualified Elm.Internal.Version as V
13
13
@@ -20,35 +20,54 @@ data Deps = Deps
20 , repo :: String
20 , repo :: String
21 , exposed :: [String]
21 , exposed :: [String]
22 , elmVersion :: V.Version
22 , elmVersion :: V.Version
23+ , dependencies :: [(N.Name,V.Version)]
23 } deriving Show
24 } deriving Show
24
25
25instance FromJSON Deps where
26instance FromJSON Deps where
26 parseJSON (Object obj) =
27 parseJSON (Object obj) =
27− do version <- obj .: "version"
28+ do version <- get obj "version" "your projects version number"
28
29
29− summary <- obj .: "summary"
30+ summary <- get obj "summary" "a short summary of your project"
30 when (length summary >= 80) $
31 when (length summary >= 80) $
31 fail "'summary' must be less than 80 characters"
32 fail "'summary' must be less than 80 characters"
32
33
33− desc <- obj .: "description"
34+ desc <- get obj "description" "an extended description of your project \
35+ \and how to get started with it."
34− license <- obj .: "license"
36+ license <- get obj "license" "license information (BSD3 is recommended)"
35
37
36− repo <- obj .: "repository"
38+ repo <- get obj "repository" "a link to the project's GitHub repo"
37 name <- case repoToName repo of
39 name <- case repoToName repo of
38 Left err -> fail err
40 Left err -> fail err
39 Right nm -> return nm
41 Right nm -> return nm
40
42
41− exposed <- obj .: "exposed-modules"
43+ exposed <- get obj "exposed-modules" "a list of modules exposed to users"
42 when (null exposed) $
44 when (null exposed) $
43 fail "there are no 'exposed-modules'.\n\
45 fail "there are no 'exposed-modules'.\n\
44− \At least one module must be exposed for anyone to use this library!"
46+ \At least one module must be exposed \
47+ \for anyone to use this library!"
45
48
46− elmVersion <- obj .: "elm-version"
49+ elmVersion <- get obj "elm-version" "the version of the Elm compiler you are using"
47
50
51+ deps <- toDeps =<< get obj "dependencies"
52+ "a listing of your project's dependencies"
53+
48− return $ Deps name version summary desc license repo exposed elmVersion
54+ return $ Deps name version summary desc license repo exposed elmVersion deps
49
55
50 parseJSON _ = mzero
56 parseJSON _ = mzero
51
57
58+toDeps deps =
59+ forM (Map.toList deps) $ \(f,v) ->
60+ case (N.fromString f, V.fromString v) of
61+ (Just name, Just version) -> return (name,version)
62+ (Nothing, _) -> fail $ N.errorMsg f
63+ (_, Nothing) -> fail $ "invalid version number " ++ v
64+
65+get obj field desc =
66+ do maybe <- obj .:? field
67+ case maybe of
68+ Nothing -> fail $ "Missing field " ++ show field ++ ", " ++ desc
69+ Just value -> return value
70+
52repoToName :: String -> Either String N.Name
71repoToName :: String -> Either String N.Name
53repoToName repo
72repoToName repo
54 | not (end `List.isSuffixOf` repo) = Left msg
73 | not (end `List.isSuffixOf` repo) = Left msg
@@ -86,8 +105,5 @@ withDeps handle path =
86 "could not find file " ++ path ++
105 "could not find file " ++ path ++
87 "\n You may need to create a dependency file for your project."
106 "\n You may need to create a dependency file for your project."
88
107
89−dependencies :: FilePath -> ErrorT String IO (Map.Map String String)
90−dependencies _ = return Map.empty -- withDeps deps
91−
92depsAt :: FilePath -> ErrorT String IO Deps
108depsAt :: FilePath -> ErrorT String IO Deps
93depsAt = withDeps id
109depsAt = withDeps id