diff --git a/elm2nix.cabal b/elm2nix.cabal index 25242c4..14f2634 100644 --- a/elm2nix.cabal +++ b/elm2nix.cabal @@ -45,6 +45,7 @@ library , text , transformers , unordered-containers + , vector exposed-modules: Elm2Nix Elm2Nix.FixedOutput diff --git a/scripts/tests.sh b/scripts/tests.sh index 6e3c35e..0a08016 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -34,5 +34,5 @@ pushd test/lib elm2nix convert > elm-srcs.nix elm2nix snapshot > versions.dat nix-build - checkfile ./result/Main.html + checkfile ./result/share/doc/Main.json popd diff --git a/src/Elm2Nix.hs b/src/Elm2Nix.hs index f151747..f026ea2 100644 --- a/src/Elm2Nix.hs +++ b/src/Elm2Nix.hs @@ -24,6 +24,8 @@ import qualified Data.HashMap.Strict as HM import qualified Data.ByteString.Lazy as LBS import qualified Data.Aeson as Json import qualified Data.Text as Text +import qualified Data.Vector as Vector +import qualified Data.Either as Either import Elm2Nix.FixedOutput (FixedDerivation(..), prefetch) import Elm2Nix.PackagesSnapshot (snapshot) @@ -51,16 +53,21 @@ parseElmJsonDeps obj = case obj of Object hm -> do deps <- tryLookup hm "dependencies" - case deps of - Object dhm -> do - direct <- tryLookup dhm "direct" - indirect <- tryLookup dhm "indirect" - liftM2 (++) (parseDeps direct) (parseDeps indirect) - v -> Left (UnexpectedValue v) + + let libstyleDeps = parseDeps deps + if Either.isRight libstyleDeps then + libstyleDeps + else + case deps of + Object dhm -> do + direct <- tryLookup dhm "direct" + indirect <- tryLookup dhm "indirect" + liftM2 (++) (parseDeps direct) (parseDeps indirect) + v -> Left (UnexpectedValue v) v -> Left (UnexpectedValue v) where parseDep :: Text -> Value -> Either Elm2NixError Dep - parseDep name (String ver) = Right (Text.unpack name, Text.unpack ver) + parseDep name (String ver) = Right (Text.unpack name, sanitizeVersion (Text.unpack ver)) parseDep _ v = Left (UnexpectedValue v) parseDeps :: Value -> Either Elm2NixError [Dep] @@ -71,6 +78,10 @@ parseElmJsonDeps obj = maybeToRight _ (Just x) = Right x maybeToRight y Nothing = Left y + sanitizeVersion :: String -> String + sanitizeVersion = + takeWhile (\c -> c /= ' ') -- converts "1.0.0 <= v < 2.0.0" to "1.0.0" + tryLookup :: HashMap Text Value -> Text -> Either Elm2NixError Value tryLookup hm key = maybeToRight (KeyNotFound key) (HM.lookup key hm) diff --git a/test/lib/elm.json b/test/lib/elm.json index a157bcb..4cae4e9 100644 --- a/test/lib/elm.json +++ b/test/lib/elm.json @@ -4,10 +4,10 @@ "summary": "test elm2nix", "license": "BSD-3-Clause", "version": "1.0.0", - "exposed-module": ["Main"], + "exposed-modules": ["Main"], "elm-version": "0.19.0 <= v < 0.20.0", "dependencies": { - "elm/core": "1.0.2", + "elm/core": "1.0.2 <= v < 2.0.0" }, "test-dependencies": {} } diff --git a/test/lib/src/Main.elm b/test/lib/src/Main.elm index 1c71b31..5122685 100644 --- a/test/lib/src/Main.elm +++ b/test/lib/src/Main.elm @@ -1,4 +1,7 @@ module Main exposing (f) +{-| @docs f -} + +{-| Anwer to universe life and everything -} f : () -> Int f () = 42