Skip to content

Commit

Permalink
Rename tsconfig constants and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sodic committed Oct 9, 2024
1 parent 8ab0b3f commit d90b235
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Control.Concurrent (newChan)
import Control.Concurrent.Async (concurrently)
import Control.Monad.Except (ExceptT (..), liftEither, runExceptT)
import qualified Data.Aeson as Aeson
import Data.Conduit.Process.Typed (ExitCode (..))
import Data.List (find, isSuffixOf)
import StrongPath
( Abs,
Expand All @@ -29,6 +28,7 @@ import StrongPath
relfile,
(</>),
)
import System.Exit (ExitCode (..))
import qualified Wasp.Analyzer as Analyzer
import Wasp.Analyzer.AnalyzeError (getErrorMessageAndCtx)
import Wasp.Analyzer.Parser.Ctx (Ctx)
Expand Down
15 changes: 8 additions & 7 deletions waspc/src/Wasp/Project/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module Wasp.Project.Common
extPublicDirInWaspProjectDir,
prismaSchemaFileInWaspProjectDir,
getSrcTsConfigInWaspProjectDir,
tsConfigInWaspLangProject,
srcTsConfigInWaspLangProject,
srcTsConfigInWaspTsProject,
)
where

Expand Down Expand Up @@ -90,14 +91,14 @@ packageJsonInWaspProjectDir = [relfile|package.json|]
-- TODO: The entire tsconfig story is very fragile
getSrcTsConfigInWaspProjectDir :: WaspFilePath -> Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
getSrcTsConfigInWaspProjectDir = \case
WaspTs _ -> tsConfigInWaspTsProject
WaspLang _ -> tsConfigInWaspLangProject
WaspTs _ -> srcTsConfigInWaspTsProject
WaspLang _ -> srcTsConfigInWaspLangProject

tsConfigInWaspLangProject :: Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
tsConfigInWaspLangProject = [relfile|tsconfig.json|]
srcTsConfigInWaspLangProject :: Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
srcTsConfigInWaspLangProject = [relfile|tsconfig.json|]

tsConfigInWaspTsProject :: Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
tsConfigInWaspTsProject = [relfile|tsconfig.src.json|]
srcTsConfigInWaspTsProject :: Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
srcTsConfigInWaspTsProject = [relfile|tsconfig.src.json|]

packageLockJsonInWaspProjectDir :: Path' (Rel WaspProjectDir) File'
packageLockJsonInWaspProjectDir = [relfile|package-lock.json|]
Expand Down
14 changes: 6 additions & 8 deletions waspc/src/Wasp/Project/ExternalConfig/TsConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Wasp.Project.ExternalConfig.TsConfig
)
where

import Control.Arrow (left)
import Control.Monad.Except (ExceptT (ExceptT), runExceptT, throwError)
import qualified Data.ByteString.Lazy.UTF8 as BS
import Data.Either.Extra (maybeToEither)
Expand All @@ -23,20 +24,17 @@ analyzeSrcTsConfigFile ::
IO (Either [String] T.TsConfig)
analyzeSrcTsConfigFile waspDir srcTsConfigFile = runExceptT $ do
tsConfigFileContents <- ExceptT findTsConfigOrError
srcTsConfigContents <- ExceptT $ readSrcTsConfigFile tsConfigFileContents
srcTsConfigContents <- ExceptT $ left (: []) <$> readTsConfigFile tsConfigFileContents
case validateSrcTsConfig srcTsConfigContents of
[] -> return srcTsConfigContents
errors -> throwError errors
where
findTsConfigOrError = maybeToEither [fileNotFoundMessage] <$> findFileInWaspProjectDir waspDir srcTsConfigFile
fileNotFoundMessage = "Couldn't find the tsconfig.json file in the " ++ toFilePath waspDir ++ " directory"

readSrcTsConfigFile :: Path' Abs (File SrcTsConfigFile) -> IO (Either [String] T.TsConfig)
readSrcTsConfigFile tsConfigFile = do
-- TODO: Reduce polymorphism, should only work with TsConfig files
readTsConfigFile :: Path' Abs (File f) -> IO (Either String T.TsConfig)
readTsConfigFile tsConfigFile = do
tsConfigContent <- IOUtil.readFileBytes tsConfigFile

parseResult <- parseJsonWithComments . BS.toString $ tsConfigContent

case parseResult of
Right tsConfig -> return $ Right tsConfig
Left err -> return $ Left ["Failed to parse tsconfig.json file: " ++ err]
return $ left ("Failed to parse tsconfig file" ++) parseResult
4 changes: 2 additions & 2 deletions waspc/waspls/src/Wasp/LSP/ExtImport/ExportsCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Wasp.LSP.ExtImport.Path (WaspStyleExtFilePath, absPathToCachePath, cacheP
import Wasp.LSP.ExtImport.Syntax (ExtImportNode (einName, einPath), getAllExtImports)
import Wasp.LSP.ServerMonads (HandlerM, ServerM, getProjectRootDir, handler, modify)
import qualified Wasp.LSP.ServerState as State
import Wasp.Project.Common (tsConfigInWaspLangProject)
import Wasp.Project.Common (srcTsConfigInWaspLangProject)
import qualified Wasp.TypeScript.Inspect.Exports as TS

-- | Based on the files imported in the external imports of the current concrete
Expand Down Expand Up @@ -63,7 +63,7 @@ refreshExportsOfFiles files = do
getExportRequestForFile projectRootDir file =
TS.TsExportsRequest
{ TS.filepaths = [SP.fromAbsFile file],
TS.tsconfig = Just $ SP.fromAbsFile $ projectRootDir </> tsConfigInWaspLangProject
TS.tsconfig = Just $ SP.fromAbsFile $ projectRootDir </> srcTsConfigInWaspLangProject
}

-- Replaces entries in the exports cache with the exports lists in the
Expand Down

0 comments on commit d90b235

Please sign in to comment.