Skip to content

Commit fd59ca3

Browse files
committed
Use aeson-1.*
1 parent b934f20 commit fd59ca3

9 files changed

Lines changed: 39 additions & 69 deletions

File tree

src/Stack/Types/BuildPlan.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Control.Arrow ((&&&))
3737
import Control.DeepSeq (NFData)
3838
import Control.Exception (Exception)
3939
import Control.Monad.Catch (MonadThrow, throwM)
40-
import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, withText, (.!=), (.:), (.:?), (.=))
40+
import Data.Aeson (FromJSON (..), FromJSONKey(..), ToJSON (..), ToJSONKey (..), object, withObject, withText, (.!=), (.:), (.:?), (.=))
4141
import Data.ByteString (ByteString)
4242
import qualified Data.ByteString as BS
4343
import Data.Data
@@ -281,9 +281,7 @@ newtype Maintainer = Maintainer { unMaintainer :: Text }
281281

282282
-- | Name of an executable.
283283
newtype ExeName = ExeName { unExeName :: Text }
284-
deriving (Show, Eq, Ord, Hashable, IsString, Generic, Store, NFData, Data, Typeable)
285-
instance ToJSON ExeName where
286-
toJSON = toJSON . unExeName
284+
deriving (Show, Eq, Ord, Hashable, IsString, Generic, Store, NFData, Data, Typeable, ToJSON, ToJSONKey, FromJSONKey)
287285
instance FromJSON ExeName where
288286
parseJSON = withText "ExeName" $ return . ExeName
289287

@@ -420,11 +418,6 @@ instance FromJSON Snapshots where
420418
Right (LTS x y) -> return $ IntMap.singleton x y
421419
Right (Nightly _) -> fail "Unexpected nightly value"
422420

423-
instance ToJSON a => ToJSON (Map ExeName a) where
424-
toJSON = toJSON . Map.mapKeysWith const unExeName
425-
instance FromJSON a => FromJSON (Map ExeName a) where
426-
parseJSON = fmap (Map.mapKeysWith const ExeName) . parseJSON
427-
428421
-- | A simplified version of the 'BuildPlan' + cabal file.
429422
data MiniBuildPlan = MiniBuildPlan
430423
{ mbpCompilerVersion :: !CompilerVersion

src/Stack/Types/Compiler.hs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ module Stack.Types.Compiler where
88
import Control.DeepSeq
99
import Data.Aeson
1010
import Data.Data
11-
import Data.Map (Map)
12-
import qualified Data.Map as Map
1311
import Data.Monoid ((<>))
1412
import Data.Store (Store)
1513
import qualified Data.Text as T
@@ -43,20 +41,11 @@ instance ToJSON CompilerVersion where
4341
instance FromJSON CompilerVersion where
4442
parseJSON (String t) = maybe (fail "Failed to parse compiler version") return (parseCompilerVersion t)
4543
parseJSON _ = fail "Invalid CompilerVersion, must be String"
46-
instance FromJSON a => FromJSON (Map CompilerVersion a) where
47-
-- TODO: Dedupe with similar code in Stack.Types.Version?
48-
--
49-
-- Maybe this ought to be abstracted into a 'JSONKey' class, so that a
50-
-- fully generic definition for Map can be provided.
51-
parseJSON val = do
52-
m <- parseJSON val
53-
fmap Map.fromList $ mapM go $ Map.toList m
54-
where
55-
go (k, v) = do
56-
let mparsed = parseCompilerVersion (T.pack k)
57-
case mparsed of
58-
Nothing -> fail $ "Failed to parse CompilerVersion " ++ k
59-
Just parsed -> return (parsed, v)
44+
instance FromJSONKey CompilerVersion where
45+
fromJSONKey = FromJSONKeyTextParser $ \k ->
46+
case parseCompilerVersion k of
47+
Nothing -> fail $ "Failed to parse CompilerVersion " ++ T.unpack k
48+
Just parsed -> return parsed
6049

6150
parseCompilerVersion :: T.Text -> Maybe CompilerVersion
6251
parseCompilerVersion t

src/Stack/Types/FlagName.hs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import Data.Attoparsec.Text
3030
import Data.Char (isLetter, isDigit, toLower)
3131
import Data.Data
3232
import Data.Hashable
33-
import Data.Map (Map)
34-
import qualified Data.Map as Map
3533
import Data.Store (Store)
3634
import Data.Text (Text)
3735
import qualified Data.Text as T
@@ -52,7 +50,7 @@ instance Show FlagNameParseFail where
5250
-- | A flag name.
5351
newtype FlagName =
5452
FlagName Text
55-
deriving (Typeable,Data,Generic,Hashable,Store,NFData)
53+
deriving (Typeable,Data,Generic,Hashable,Store,NFData,ToJSONKey)
5654
instance Eq FlagName where
5755
x == y = compare x y == EQ
5856
instance Ord FlagName where
@@ -75,6 +73,10 @@ instance FromJSON FlagName where
7573
fail ("Couldn't parse flag name: " ++ s)
7674
Just ver -> return ver
7775

76+
instance FromJSONKey FlagName where
77+
fromJSONKey = FromJSONKeyTextParser $ \k ->
78+
either (fail . show) return $ parseFlagName k
79+
7880
-- | Attoparsec parser for a flag name
7981
flagNameParser :: Parser FlagName
8082
flagNameParser =
@@ -125,12 +127,3 @@ toCabalFlagName :: FlagName -> Cabal.FlagName
125127
toCabalFlagName (FlagName name) =
126128
let !x = T.unpack name
127129
in Cabal.FlagName x
128-
129-
instance ToJSON a => ToJSON (Map FlagName a) where
130-
toJSON = toJSON . Map.mapKeysWith const flagNameText
131-
instance FromJSON a => FromJSON (Map FlagName a) where
132-
parseJSON val = do
133-
m <- parseJSON val
134-
fmap Map.fromList $ mapM go $ Map.toList m
135-
where
136-
go (k, v) = fmap (, v) $ either (fail . show) return $ parseFlagNameFromString k

src/Stack/Types/PackageName.hs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import Data.Attoparsec.Text
3333
import Data.Data
3434
import Data.Hashable
3535
import Data.List (intercalate)
36-
import Data.Map (Map)
37-
import qualified Data.Map as Map
3836
import Data.Store (Store)
3937
import Data.Text (Text)
4038
import qualified Data.Text as T
@@ -61,7 +59,7 @@ instance Show PackageNameParseFail where
6159
-- | A package name.
6260
newtype PackageName =
6361
PackageName Text
64-
deriving (Eq,Ord,Typeable,Data,Generic,Hashable,NFData,Store)
62+
deriving (Eq,Ord,Typeable,Data,Generic,Hashable,NFData,Store,ToJSON,ToJSONKey)
6563

6664
instance Lift PackageName where
6765
lift (PackageName n) =
@@ -71,8 +69,6 @@ instance Lift PackageName where
7169
instance Show PackageName where
7270
show (PackageName n) = T.unpack n
7371

74-
instance ToJSON PackageName where
75-
toJSON = toJSON . packageNameText
7672
instance FromJSON PackageName where
7773
parseJSON j =
7874
do s <- parseJSON j
@@ -81,6 +77,10 @@ instance FromJSON PackageName where
8177
fail ("Couldn't parse package name: " ++ s)
8278
Just ver -> return ver
8379

80+
instance FromJSONKey PackageName where
81+
fromJSONKey = FromJSONKeyTextParser $ \k ->
82+
either (fail . show) return $ parsePackageName k
83+
8484
-- | Attoparsec parser for a package name
8585
packageNameParser :: Parser PackageName
8686
packageNameParser =
@@ -141,15 +141,6 @@ parsePackageNameFromFilePath fp = do
141141
strip ('l':'a':'b':'a':'c':'.':xs) = return xs
142142
strip _ = throwM (CabalFileNameParseFail (toFilePath fp))
143143

144-
instance ToJSON a => ToJSON (Map PackageName a) where
145-
toJSON = toJSON . Map.mapKeysWith const packageNameText
146-
instance FromJSON a => FromJSON (Map PackageName a) where
147-
parseJSON val = do
148-
m <- parseJSON val
149-
fmap Map.fromList $ mapM go $ Map.toList m
150-
where
151-
go (k, v) = fmap (, v) $ either (fail . show) return $ parsePackageNameFromString k
152-
153144
-- | An argument which accepts a template name of the format
154145
-- @foo.hsfiles@.
155146
packageNameArgument :: O.Mod O.ArgumentFields PackageName

src/Stack/Types/Version.hs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import Data.Attoparsec.Text
3838
import Data.Data
3939
import Data.Hashable
4040
import Data.List
41-
import Data.Map (Map)
42-
import qualified Data.Map as Map
4341
import Data.Maybe (listToMaybe)
4442
import Data.Monoid
4543
import Data.Set (Set)
@@ -95,14 +93,9 @@ instance FromJSON Version where
9593
Nothing ->
9694
fail ("Couldn't parse package version: " ++ s)
9795
Just ver -> return ver
98-
instance FromJSON a => FromJSON (Map Version a) where
99-
parseJSON val = do
100-
m <- parseJSON val
101-
fmap Map.fromList $ mapM go $ Map.toList m
102-
where
103-
go (k, v) = do
104-
k' <- either (fail . show) return $ parseVersionFromString k
105-
return (k', v)
96+
instance FromJSONKey Version where
97+
fromJSONKey = FromJSONKeyTextParser $ \k ->
98+
either (fail . show) return $ parseVersion k
10699

107100
newtype IntersectingVersionRange =
108101
IntersectingVersionRange { getIntersectingVersionRange :: Cabal.VersionRange }

stack-7.8.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@ extra-deps:
2323
- http-client-0.5.3.3
2424
- http-conduit-2.2.3
2525
- ignore-0.1.1.0
26-
- binary-tagged-0.1.3.1
26+
- binary-tagged-0.1.4.1
2727
- fsnotify-0.2.1
2828
- ansi-terminal-0.6.2.3
2929
# For deepseq-1.4
3030
- deepseq-1.4.1.2
31-
- aeson-0.11.2.0
3231
- bytestring-0.10.6.0
3332
- Cabal-1.18.1.6
3433
- containers-0.5.6.3
3534
- hpc-0.6.0.2
3635
- process-1.2.1.0
3736
- time-1.5.0.1
38-
- base-compat-0.9.0
39-
- hpack-0.14.0
37+
- base-compat-0.9.1
38+
- hpack-0.15.0
4039
- microlens-0.4.1.0
4140
- open-browser-0.2.1.0
4241
- tls-1.3.8
@@ -55,11 +54,11 @@ extra-deps:
5554
- attoparsec-0.13.0.2
5655
- fail-4.9.0.0
5756
- tagged-0.8.4
58-
- persistent-template-2.1.8.1
59-
- aeson-compat-0.3.3.0
57+
- persistent-template-2.5.1.6
58+
- aeson-compat-0.3.6
6059
- http-api-data-0.2.2
6160
- time-locale-compat-0.1.1.1
62-
- persistent-2.5
61+
- persistent-2.6
6362
- store-0.3
6463
- store-core-0.3
6564
- th-reify-many-0.1.6
@@ -81,6 +80,12 @@ extra-deps:
8180
- conduit-extra-1.1.15
8281
- streaming-commons-0.1.16
8382
- safe-exceptions-0.1.4.0
83+
- aeson-1.0.2.1
84+
- scientific-0.3.4.9
85+
- semigroups-0.18.2
86+
- void-0.7.1
8487
flags:
8588
time-locale-compat:
8689
old-locale: false
90+
semigroups:
91+
bytestring-builder: false

stack-8.0.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ extra-deps:
1616
- pid1-0.1.0.0
1717
- store-0.3
1818
- store-core-0.3
19+
- hpack-0.15.0
20+
- aeson-1.0.2.1

stack.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ library
177177
System.Process.Read
178178
System.Process.Run
179179
build-depends: Cabal >= 1.18.1.5 && < 1.25
180-
, aeson (>= 0.8.0.2 && < 0.10) || (>= 0.11 && < 0.12)
180+
, aeson (>= 1.0 && < 1.1)
181181
, ansi-terminal >= 0.6.2.3
182182
, async >= 2.0.2 && < 2.2
183183
, attoparsec >= 0.12.1.5 && < 0.14

stack.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ extra-deps:
2222
- optparse-applicative-0.13.0.0
2323
- text-metrics-0.1.0
2424
- pid1-0.1.0.0
25+
- aeson-1.0.2.1
26+
- hpack-0.15.0
27+
- persistent-2.6
28+
- persistent-template-2.5.1.6
2529
flags:
2630
stack:
2731
hide-dependency-versions: true

0 commit comments

Comments
 (0)