Skip to content

Commit

Permalink
Update FromJSON instance for TsConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
infomiho committed Sep 25, 2024
1 parent 6789b0e commit f16ee59
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions waspc/src/Wasp/ExternalConfig/TsConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ module Wasp.ExternalConfig.TsConfig
where

import Control.Monad.Except
import Data.Aeson (FromJSON, parseJSON, withObject, (.:?))
import Data.Aeson
( FromJSON,
genericParseJSON,
parseJSON,
)
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy.UTF8 as BS
import Data.Either.Extra (maybeToEither)
import GHC.Generics (Generic)
Expand Down Expand Up @@ -41,22 +46,16 @@ data CompilerOptions = CompilerOptions
typeRoots :: !(Maybe [String]),
outDir :: !(Maybe String)
}
deriving (Show)
deriving (Show, Generic)

instance FromJSON CompilerOptions where
parseJSON = withObject "CompilerOptions" $ \v ->
CompilerOptions
-- We couldn't use the Generic deriving for this because of the _ prefix in the "module" field name.
<$> v .:? "module"
<*> v .:? "target"
<*> v .:? "moduleResolution"
<*> v .:? "jsx"
<*> v .:? "strict"
<*> v .:? "esModuleInterop"
<*> v .:? "lib"
<*> v .:? "allowJs"
<*> v .:? "typeRoots"
<*> v .:? "outDir"
parseJSON =
genericParseJSON $
Aeson.defaultOptions {Aeson.fieldLabelModifier = modifyFieldLabel}
where
-- "module" is a reserved keyword in Haskell, so we use "_module" instead.
modifyFieldLabel "_module" = "module"
modifyFieldLabel other = other

analyzeTsConfigContent :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] TsConfig)
analyzeTsConfigContent waspDir = runExceptT $ do
Expand Down

0 comments on commit f16ee59

Please sign in to comment.