From f16ee595e4dd493a583a09374e9cf32485e46ab8 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Wed, 25 Sep 2024 19:31:30 +0200 Subject: [PATCH] Update FromJSON instance for TsConfig --- waspc/src/Wasp/ExternalConfig/TsConfig.hs | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/waspc/src/Wasp/ExternalConfig/TsConfig.hs b/waspc/src/Wasp/ExternalConfig/TsConfig.hs index 83874dd02e..2297a7f5c0 100644 --- a/waspc/src/Wasp/ExternalConfig/TsConfig.hs +++ b/waspc/src/Wasp/ExternalConfig/TsConfig.hs @@ -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) @@ -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