Skip to content

Commit

Permalink
Add extra context to Analyze.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
sodic committed Sep 11, 2024
1 parent 0c7b901 commit b7c4800
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ readDeclsJsonFile declsJsonFile = do

analyzeWaspTsFile :: Path' Abs (Dir WaspProjectDir) -> Psl.Schema.Schema -> Path' Abs (File WaspTsFile) -> IO (Either [CompileError] [AS.Decl])
analyzeWaspTsFile waspDir _prismaSchemaAst _waspFilePath = runExceptT $ do
-- TODO: The function currently doesn't require the path to main.wasp.ts
-- because it reads it from the tsconfig
-- Should we ensure that the tsconfig indeed points to the name we expect? Probably.
compiledWaspJsFile <- ExceptT $ compileWaspTsFile waspDir
specJsonFile <- ExceptT $ executeMainWaspJsFile waspDir compiledWaspJsFile
contents <- ExceptT $ readDeclsJsonFile specJsonFile
Expand Down Expand Up @@ -141,6 +144,7 @@ compileWaspTsFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError]
compileWaspTsFile waspDir = do
-- TODO: The function should also receive the tsconfig.node.json file (not the main.wasp.ts file),
-- because the source of truth (the name of the file, where it's compiled) comes from the typescript config.
-- However, we might want to keep this information in haskell and then verify that the tsconfig is correct.
chan <- newChan
(_, tscExitCode) <-
concurrently
Expand All @@ -150,7 +154,7 @@ compileWaspTsFile waspDir = do
"npx"
[ "tsc",
"-p",
"tsconfig.node.json",
toFilePath tsconfigNodeFile,
"--noEmit",
"false",
"--outDir",
Expand All @@ -164,7 +168,9 @@ compileWaspTsFile waspDir = do
-- TODO: I shoulde be getting the compiled file path from the tsconfig.node.file
ExitSuccess -> return $ Right compiledWaspJsFile
where
-- TODO: Potentially extract somewhere if it ends up being used in multiple places.
compiledWaspJsFile = waspDir </> dotWaspDirInWaspProjectDir </> [relfile|config/main.wasp.mjs|]
tsconfigNodeFile = waspDir </> [relfile|tsconfig.node.json|]

analyzeWaspLangFile :: Psl.Schema.Schema -> Path' Abs (File WaspLangFile) -> IO (Either [CompileError] [AS.Decl])
analyzeWaspLangFile prismaSchemaAst waspFilePath = do
Expand Down
5 changes: 3 additions & 2 deletions waspc/src/Wasp/Project/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Wasp.Project.Common
where

import StrongPath (Abs, Dir, File', Path', Rel, reldir, relfile, toFilePath, (</>))
import StrongPath.Types (File)
import System.Directory (doesFileExist)
import Wasp.AppSpec.ExternalFiles (SourceExternalCodeDir, SourceExternalPublicDir)
import qualified Wasp.Generator.Common
Expand Down Expand Up @@ -86,8 +87,8 @@ tsconfigInWaspProjectDir = [relfile|tsconfig.json|]

findFileInWaspProjectDir ::
Path' Abs (Dir WaspProjectDir) ->
Path' (Rel WaspProjectDir) File' ->
IO (Maybe (Path' Abs File'))
Path' (Rel WaspProjectDir) (File f) ->
IO (Maybe (Path' Abs (File f)))
findFileInWaspProjectDir waspDir file = do
let fileAbsFp = waspDir </> file
fileExists <- doesFileExist $ toFilePath fileAbsFp
Expand Down

0 comments on commit b7c4800

Please sign in to comment.