Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS config cleanup - Part 2 #2407

Merged
merged 10 commits into from
Jan 2, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import StrongPath (Abs, Dir, File, Path')
import Wasp.Cli.Command.CreateNewProject.Common (defaultWaspVersionBounds)
import Wasp.Cli.Command.CreateNewProject.ProjectDescription (NewProjectAppName, NewProjectName)
import Wasp.NodePackageFFI (InstallablePackage (WaspConfigPackage), getPackageInstallationPath)
import Wasp.Project.Analyze (WaspFilePath (..), findWaspFile)
import Wasp.Project.Analyze (WaspFilePath (..))
import Wasp.Project.Common (WaspProjectDir)
import Wasp.Project.ExternalConfig.PackageJson (findPackageJsonFile)
import Wasp.Project.WaspFile (findWaspFile)
import qualified Wasp.Util.IO as IOUtil

replaceTemplatePlaceholdersInTemplateFiles :: NewProjectAppName -> NewProjectName -> Path' Abs (Dir WaspProjectDir) -> IO ()
Expand Down
2 changes: 1 addition & 1 deletion waspc/cli/src/Wasp/Cli/Command/Db/Studio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Wasp.Cli.Command (Command)
import Wasp.Cli.Command.Message (cliSendMessageC)
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
import Wasp.Generator.DbGenerator.Jobs (runStudio)
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import qualified Wasp.Message as Msg
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)

Expand Down
6 changes: 3 additions & 3 deletions waspc/cli/src/Wasp/Cli/Command/TsConfigSetup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import StrongPath (Abs, Dir, Path')
import System.Exit (ExitCode (..))
import Wasp.Cli.Command (Command, CommandError (..), require)
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject))
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Job as J
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Job.Process (runNodeCommandAsJob)
import Wasp.NodePackageFFI (InstallablePackage (WaspConfigPackage), getPackageInstallationPath)

-- | Prepares the project for using Wasp's TypeScript SDK.
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/AI/GenerateNewProject/WaspFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import qualified Wasp.AI.GenerateNewProject.Common.Prompts as Prompts
import Wasp.AI.GenerateNewProject.Plan (Plan)
import Wasp.AI.OpenAI.ChatGPT (ChatMessage (..), ChatRole (..))
import Wasp.Analyzer.Parser.Ctx (Ctx (..))
import Wasp.Project.Analyze (analyzeWaspFileContent)
import Wasp.Project.WaspFile (analyzeWaspFileContent)
import qualified Wasp.Psl.Ast.Schema as Psl.Schema
import qualified Wasp.Util.Aeson as Utils.Aeson

Expand Down
10 changes: 10 additions & 0 deletions waspc/src/Wasp/Analyzer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ analyze prismaSchemaAst =
>=> (wrapAnalyzerError TypeError . typeCheck stdTypes)
>=> (wrapAnalyzerError EvaluationError . evaluate stdTypes)

-- | When writing main.wasp.ts, TypeScript should know about all the available
-- entities.
-- Since Wasp's AST includes entity declarations, the easiest way to get a list
-- of all entities defined in the Prisma Schema is by:
-- 1. Creating an AST with (and only with) the declarations for the Prisma
-- schema Entities.
-- 2. Type-checking that AST and returning the result.
-- This gives us a list of entity declarations we can then forward to
-- TypeScript (which then validates the user config only uses existing
-- entities).
Martinsos marked this conversation as resolved.
Show resolved Hide resolved
getEntityDecls :: Psl.Schema.Schema -> Either [AnalyzeError] [Decl]
getEntityDecls schema =
wrapAnalyzerError TypeError (typeCheck stdTypes astWithEntitiesOnly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ tuple4 eval1 eval2 eval3 eval4 = evaluation $ \(typeDefs, bindings) -> withCtx $
extImport :: TypedExprEvaluation AppSpec.ExtImport.ExtImport
extImport = evaluation' . withCtx $ \ctx -> \case
TypedAST.ExtImport name extImportPath ->
-- NOTE(martin): This parsing here could instead be done in Parser.
-- NOTE(martin): This parsing here could instead be done in Parser.
-- I don't have a very good reason for doing it here instead of Parser, except
-- for being somewhat simpler to implement.
Expand Down
4 changes: 1 addition & 3 deletions waspc/src/Wasp/AppSpec/ExtImport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ instance FromJSON ExtImport where
nameStr <- o .: "name"
pathStr <- o .: "path"
extImportName <- parseExtImportName kindStr nameStr
extImportPath <- case parseExtImportPath pathStr of
Right path' -> pure path'
Left err -> fail err
extImportPath <- either fail pure $ parseExtImportPath pathStr
return $ ExtImport extImportName extImportPath
where
parseExtImportName kindStr nameStr = case kindStr of
Expand Down
3 changes: 2 additions & 1 deletion waspc/src/Wasp/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import StrongPath.Types (File)
import Wasp.Analyzer.Parser.Ctx (Ctx, getCtxRgn)
import Wasp.Analyzer.Parser.SourcePosition (SourcePosition (..))
import Wasp.Analyzer.Parser.SourceRegion (SourceRegion (..))
import Wasp.Project.Common (WaspLangFile)
import Wasp.Util (indent, insertAt, leftPad)
import qualified Wasp.Util.Terminal as T

-- | Transforms compiler error (error with parse context) into an informative, pretty String that
-- can be printed directly into the terminal. It uses terminal features like escape codes
-- (colors, styling, ...).
showCompilerErrorForTerminal :: (Path' Abs (File f), String) -> (String, Ctx) -> String
showCompilerErrorForTerminal :: (Path' Abs (File WaspLangFile), String) -> (String, Ctx) -> String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

showCompilerErrorForTerminal (waspFilePath, waspFileContent) (errMsg, errCtx) =
let srcRegion = getCtxRgn errCtx
in intercalate
Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/DbGenerator/Jobs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import StrongPath.TH (relfile)
import qualified System.Info
import Wasp.Generator.Common (ProjectRootDir)
import Wasp.Generator.DbGenerator.Common (MigrateArgs (..), dbSchemaFileInProjectRootDir)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Process (runNodeCommandAsJob, runNodeCommandAsJobWithExtraEnv)
import qualified Wasp.Job as J
import Wasp.Job.Process (runNodeCommandAsJob, runNodeCommandAsJobWithExtraEnv)
import Wasp.Generator.ServerGenerator.Common (serverRootDirInProjectRootDir)
import Wasp.Generator.ServerGenerator.Db.Seed (dbSeedNameEnvVarName)
import Wasp.Project.Common (WaspProjectDir, waspProjectDirFromProjectRootDir)
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/DbGenerator/Operations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Wasp.Generator.DbGenerator.Common
)
import qualified Wasp.Generator.DbGenerator.Jobs as DbJobs
import Wasp.Generator.FileDraft.WriteableMonad (WriteableMonad (copyDirectoryRecursive, doesDirectoryExist))
import Wasp.Generator.Job.IO
import Wasp.Job.IO
( collectJobTextOutputUntilExitReceived,
printJobMsgsUntilExitReceived,
readJobMessagesAndPrintThemPrefixed,
Expand Down
6 changes: 3 additions & 3 deletions waspc/src/Wasp/Generator/NpmInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import System.Exit (ExitCode (..))
import UnliftIO (race)
import Wasp.AppSpec (AppSpec (waspProjectDir))
import Wasp.Generator.Common (ProjectRootDir)
import Wasp.Generator.Job (Job, JobMessage, JobType)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO.PrefixedWriter (PrefixedWriter, printJobMessagePrefixed, runPrefixedWriter)
import Wasp.Job (Job, JobMessage, JobType)
import qualified Wasp.Job as J
import Wasp.Job.IO.PrefixedWriter (PrefixedWriter, printJobMessagePrefixed, runPrefixedWriter)
import Wasp.Generator.Monad (GeneratorError (..))
import Wasp.Generator.NpmInstall.Common (AllNpmDeps (..), getAllNpmDeps)
import Wasp.Generator.NpmInstall.InstalledNpmDepsLog (forgetInstalledNpmDepsLog, loadInstalledNpmDepsLog, saveInstalledNpmDepsLog)
Expand Down
6 changes: 3 additions & 3 deletions waspc/src/Wasp/Generator/SdkGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import Wasp.Generator.DbGenerator (getEntitiesForPrismaSchema)
import qualified Wasp.Generator.DbGenerator.Auth as DbAuth
import Wasp.Generator.FileDraft (FileDraft)
import qualified Wasp.Generator.FileDraft as FD
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Job as J
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Job.Process (runNodeCommandAsJob)
import Wasp.Generator.Monad (Generator)
import qualified Wasp.Generator.NpmDependencies as N
import Wasp.Generator.SdkGenerator.AuthG (genAuth)
Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/ServerGenerator/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Job as J
import Wasp.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Generator.ServerGenerator.Common as Common

installNpmDependencies :: Path' Abs (Dir ProjectRootDir) -> J.Job
Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/ServerGenerator/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Job as J
import Wasp.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Generator.ServerGenerator.Common as Common

startServer :: Path' Abs (Dir ProjectRootDir) -> J.Job
Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Control.Concurrent.Extra (threadDelay)
import Control.Monad (void)
import StrongPath (Abs, Dir, Path')
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import qualified Wasp.Job as J
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Generator.ServerGenerator.Start (startServer)
import Wasp.Generator.WebAppGenerator.Start (startWebApp)

Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Control.Concurrent (newChan)
import Control.Concurrent.Async (concurrently)
import StrongPath (Abs, Dir, Path')
import System.Exit (ExitCode (..))
import Wasp.Generator.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import qualified Wasp.Generator.WebAppGenerator.Test as WebAppTest
import Wasp.Project.Common (WaspProjectDir)

Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/WebAppGenerator/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Job as J
import Wasp.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Generator.WebAppGenerator.Common as Common

installNpmDependencies :: Path' Abs (Dir ProjectRootDir) -> J.Job
Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/WebAppGenerator/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Job as J
import Wasp.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Generator.WebAppGenerator.Common as Common

startWebApp :: Path' Abs (Dir ProjectRootDir) -> J.Job
Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/WebAppGenerator/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ where

import StrongPath (Abs, Dir, Path', relfile, (</>))
import qualified StrongPath as SP
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Job as J
import Wasp.Job.Process (runNodeCommandAsJob)
import Wasp.Generator.WebAppGenerator.Common (webAppRootDirInProjectRootDir)
import Wasp.Project.Common (WaspProjectDir, dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)

Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/Job.hs → waspc/src/Wasp/Job.hs
Martinsos marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Wasp.Generator.Job
module Wasp.Job
( Job,
JobMessage (..),
JobMessageData (..),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Wasp.Generator.Job.Common
module Wasp.Job.Common
( getJobMessageOutHandle,
getJobMessageContent,
)
Expand All @@ -7,7 +7,7 @@ where
import qualified Data.Text as T
import System.Exit (ExitCode (..))
import System.IO (Handle, stderr, stdout)
import qualified Wasp.Generator.Job as J
import qualified Wasp.Job as J

getJobMessageOutHandle :: J.JobMessage -> Handle
getJobMessageOutHandle jobMsg = case J._data jobMsg of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Wasp.Generator.Job.IO
module Wasp.Job.IO
( readJobMessagesAndPrintThemPrefixed,
printJobMessage,
printJobMsgsUntilExitReceived,
Expand All @@ -11,9 +11,9 @@ import Control.Monad.IO.Class (liftIO)
import Data.Text (Text)
import qualified Data.Text.IO as T.IO
import System.IO (hFlush)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Common (getJobMessageContent, getJobMessageOutHandle)
import Wasp.Generator.Job.IO.PrefixedWriter (printJobMessagePrefixed, runPrefixedWriter)
import qualified Wasp.Job as J
import Wasp.Job.Common (getJobMessageContent, getJobMessageOutHandle)
import Wasp.Job.IO.PrefixedWriter (printJobMessagePrefixed, runPrefixedWriter)

printJobMsgsUntilExitReceived :: Chan J.JobMessage -> IO ()
printJobMsgsUntilExitReceived chan = do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TupleSections #-}

module Wasp.Generator.Job.IO.PrefixedWriter
module Wasp.Job.IO.PrefixedWriter
( printJobMessagePrefixed,
runPrefixedWriter,
PrefixedWriter,
Expand All @@ -17,9 +17,9 @@ import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.IO as T.IO
import System.IO (hFlush, stderr)
import Wasp.Generator.Job (JobType)
import qualified Wasp.Generator.Job as J
import Wasp.Generator.Job.Common (getJobMessageContent, getJobMessageOutHandle)
import Wasp.Job (JobType)
import qualified Wasp.Job as J
import Wasp.Job.Common (getJobMessageContent, getJobMessageOutHandle)
import qualified Wasp.Util.Terminal as Term

-- |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Wasp.Generator.Job.Process
module Wasp.Job.Process
( runProcessAsJob,
runNodeCommandAsJob,
runNodeCommandAsJobWithExtraEnv,
Expand All @@ -21,7 +21,7 @@ import System.Exit (ExitCode (..))
import qualified System.Info
import qualified System.Process as P
import UnliftIO.Exception (bracket)
import qualified Wasp.Generator.Job as J
import qualified Wasp.Job as J
import qualified Wasp.Node.Version as NodeVersion

-- TODO:
Expand Down
Loading
Loading