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 3 #2410

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 +19,10 @@ import StrongPath.TH (relfile)
import qualified System.Info
import Wasp.Generator.Common (ProjectRootDir)
import Wasp.Generator.DbGenerator.Common (MigrateArgs (..), dbSchemaFileInProjectRootDir)
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 qualified Wasp.Job as J
import Wasp.Job.Process (runNodeCommandAsJob, runNodeCommandAsJobWithExtraEnv)
import Wasp.Project.Common (WaspProjectDir, waspProjectDirFromProjectRootDir)

migrateDev :: Path' Abs (Dir ProjectRootDir) -> MigrateArgs -> J.Job
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,12 +36,12 @@ import Wasp.Generator.DbGenerator.Common
)
import qualified Wasp.Generator.DbGenerator.Jobs as DbJobs
import Wasp.Generator.FileDraft.WriteableMonad (WriteableMonad (copyDirectoryRecursive, doesDirectoryExist))
import qualified Wasp.Generator.WriteFileDrafts as Generator.WriteFileDrafts
import Wasp.Job.IO
( collectJobTextOutputUntilExitReceived,
printJobMsgsUntilExitReceived,
readJobMessagesAndPrintThemPrefixed,
)
import qualified Wasp.Generator.WriteFileDrafts as Generator.WriteFileDrafts
import Wasp.Project.Db.Migrations (DbMigrationsDir)
import Wasp.Util (checksumFromFilePath, hexToString)
import Wasp.Util.IO (deleteFileIfExists, doesFileExist)
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,15 +16,15 @@ import System.Exit (ExitCode (..))
import UnliftIO (race)
import Wasp.AppSpec (AppSpec (waspProjectDir))
import Wasp.Generator.Common (ProjectRootDir)
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)
import qualified Wasp.Generator.SdkGenerator as SdkGenerator
import qualified Wasp.Generator.ServerGenerator.Setup as ServerSetup
import qualified Wasp.Generator.WebAppGenerator.Setup as WebAppSetup
import Wasp.Job (Job, JobMessage, JobType)
import qualified Wasp.Job as J
import Wasp.Job.IO.PrefixedWriter (PrefixedWriter, printJobMessagePrefixed, runPrefixedWriter)
import Wasp.Project.Common (WaspProjectDir, nodeModulesDirInWaspProjectDir)
import qualified Wasp.Util.IO as IOUitl

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,6 @@ 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.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 All @@ -66,6 +63,9 @@ import Wasp.Generator.WebAppGenerator.Common
reactVersion,
)
import qualified Wasp.Generator.WebAppGenerator.Common as WebApp
import qualified Wasp.Job as J
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Job.Process (runNodeCommandAsJob)
import qualified Wasp.Node.Version as NodeVersion
import Wasp.Project.Common (WaspProjectDir)
import qualified Wasp.Project.Db as Db
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/ServerGenerator/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.ServerGenerator.Common as Common
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
installNpmDependencies projectDir = do
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/ServerGenerator/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.ServerGenerator.Common as Common
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
startServer projectDir = do
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,10 +9,10 @@ import Control.Concurrent.Extra (threadDelay)
import Control.Monad (void)
import StrongPath (Abs, Dir, Path')
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Job as J
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Generator.ServerGenerator.Start (startServer)
import Wasp.Generator.WebAppGenerator.Start (startWebApp)
import qualified Wasp.Job as J
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)

-- | This is a blocking action, that will start the processes that run web app and server.
-- It will run as long as one of those processes does not fail.
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,8 +7,8 @@ import Control.Concurrent (newChan)
import Control.Concurrent.Async (concurrently)
import StrongPath (Abs, Dir, Path')
import System.Exit (ExitCode (..))
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import qualified Wasp.Generator.WebAppGenerator.Test as WebAppTest
import Wasp.Job.IO (readJobMessagesAndPrintThemPrefixed)
import Wasp.Project.Common (WaspProjectDir)

testWebApp :: [String] -> Path' Abs (Dir WaspProjectDir) -> IO (Either String ())
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/WebAppGenerator/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.WebAppGenerator.Common as Common
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
installNpmDependencies projectDir = do
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/WebAppGenerator/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ where

import StrongPath (Abs, Dir, Path', (</>))
import Wasp.Generator.Common (ProjectRootDir)
import qualified Wasp.Generator.WebAppGenerator.Common as Common
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
startWebApp projectDir = do
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/WebAppGenerator/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ where

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

testWebApp :: [String] -> Path' Abs (Dir WaspProjectDir) -> J.Job
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/NodePackageFFI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Wasp.Data (DataDir)
import qualified Wasp.Data as Data
import qualified Wasp.Node.Version as NodeVersion

-- | This are the globally installed packages waspc runs directly from
-- | This are the globally installed packages waspc runs directly from
-- their global installation path.
data RunnablePackage
= DeployPackage
Expand Down
22 changes: 21 additions & 1 deletion waspc/src/Wasp/Project/WaspFile/TypeScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Wasp.Project.Common
WaspTsFile,
dotWaspDirInWaspProjectDir,
)
import qualified Wasp.Psl.Ast.Model as Psl.Schema.Model
import qualified Wasp.Psl.Ast.Schema as Psl.Schema
import Wasp.Util (orElse)
import Wasp.Util.Aeson (encodeToString)
Expand Down Expand Up @@ -70,9 +71,26 @@ compileWaspTsFile waspProjectDir tsconfigNodeFileInWaspProjectDir waspFilePath =
( runNodeCommandAsJob
waspProjectDir
"npx"
-- We're using tsc to compile the *.wasp.ts file into a JS file.
--
-- The tsconfig.wasp.json is configured to give our users with the
-- best possible IDE support while coding the *.wasp.ts file.
--
-- When we actually want to compile the *.wasp.ts file, we must
-- override some of those rules.
--
-- Tehnically, some overrides could have been specified
-- in the tsconfig.wasp.json file, but we decided to keep them here
-- because it helps users avoid accidentally breaking things.
[ "tsc",
"-p",
fromAbsFile (waspProjectDir </> tsconfigNodeFileInWaspProjectDir),
-- The tsconfig.wasp.json file has the noEmit flag on.
-- The file only exists IDE support, and we don't want users to
-- accidentally chage the outDir.
--
-- Here, to actually generate the JS file in the desired location,
-- we must turn off the noEmit flag and specify the outDir.
"--noEmit",
"false",
"--outDir",
Expand All @@ -86,6 +104,8 @@ compileWaspTsFile waspProjectDir tsconfigNodeFileInWaspProjectDir waspFilePath =
ExitSuccess -> Right absCompiledWaspJsFile
where
outDir = waspProjectDir </> dotWaspDirInWaspProjectDir
-- We know this will be the output JS file's location because it's how TSC
-- works (assuming we've specified the outDir, which we did).
absCompiledWaspJsFile = outDir </> compiledWaspJsFileInDotWaspDir
compiledWaspJsFileInDotWaspDir =
castFile $
Expand Down Expand Up @@ -126,7 +146,7 @@ executeMainWaspJsFileAndGetDeclsFile waspProjectDir prismaSchemaAst absCompiledM
ExitSuccess -> return $ Right absDeclsOutputFile
where
absDeclsOutputFile = waspProjectDir </> dotWaspDirInWaspProjectDir </> [relfile|decls.json|]
allowedEntityNames = Psl.Schema.getModelNames prismaSchemaAst
allowedEntityNames = Psl.Schema.Model.getName <$> Psl.Schema.getModels prismaSchemaAst

readDecls :: Psl.Schema.Schema -> Path' Abs (File AppSpecDeclsJsonFile) -> IO (Either [CompileError] [AS.Decl])
readDecls prismaSchemaAst declsJsonFile = runExceptT $ do
Expand Down
5 changes: 0 additions & 5 deletions waspc/src/Wasp/Psl/Ast/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ module Wasp.Psl.Ast.Schema
getEnums,
getDatasources,
getGenerators,
getModelNames,
)
where

import Wasp.Psl.Ast.ConfigBlock (ConfigBlock)
import qualified Wasp.Psl.Ast.ConfigBlock as Psl.ConfigBlock
import Wasp.Psl.Ast.Enum (Enum)
import Wasp.Psl.Ast.Model (Model)
import qualified Wasp.Psl.Ast.Model as Model
import Wasp.Psl.Ast.Type (Type)
import Wasp.Psl.Ast.View (View)
import Prelude hiding (Enum)
Expand Down Expand Up @@ -51,6 +49,3 @@ getGenerators schema = [generator | generator@((Psl.ConfigBlock.ConfigBlock Psl.

getConfigBlocks :: Schema -> [ConfigBlock]
getConfigBlocks (Schema blocks) = [configBlock | ConfigBlock configBlock <- blocks]

getModelNames :: Schema -> [String]
getModelNames schema = map Model.getName $ getModels schema
Comment on lines -55 to -56
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed here: #2276 (comment)

5 changes: 3 additions & 2 deletions waspc/waspls/src/Wasp/LSP/Prisma/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Wasp.LSP.ServerMonads (ServerM, modify)
import qualified Wasp.LSP.ServerState as State
import Wasp.Project (WaspProjectDir)
import Wasp.Project.Analyze (analyzePrismaSchema)
import Wasp.Psl.Ast.Schema (getModelNames)
import qualified Wasp.Psl.Ast.Model as Model
import Wasp.Psl.Ast.Schema (getModels)

analyzeAndSetPrismaSchema :: Path' Abs (Dir WaspProjectDir) -> ServerM ()
analyzeAndSetPrismaSchema waspDir = do
Expand All @@ -18,7 +19,7 @@ analyzeAndSetPrismaSchema waspDir = do
logOutput "warnings" $ show warnings
(Right prismaSchemaAst, warnings) -> do
logOutput "warnings" $ show warnings
logOutput "models" $ show $ getModelNames prismaSchemaAst
logOutput "models" $ show $ Model.getName <$> getModels prismaSchemaAst
modify (State.prismaSchemaAst .~ prismaSchemaAst)
where
logOutput :: String -> String -> ServerM ()
Expand Down
Loading