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 2 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
19 changes: 18 additions & 1 deletion waspc/src/Wasp/Project/WaspFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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 @@ -117,9 +118,23 @@ compileWaspTsFile waspProjectDir tsconfigNodeFileInWaspProjectDir waspFilePath =
( runNodeCommandAsJob
waspProjectDir
"npx"
-- We're using tsc to compile the *.wasp.ts file into a JS file.
--
-- The compilation rules mostly come from tsconfig.wasp.json but also
-- include several overrides:
-- - We don't keep all the rules in tsconfig.wasp.json because it
-- would give users a way to break things.
-- - We don't keep all the rules here (inline) because users would
-- suffer bad DX (no IDE support in *.wasp.ts file).
Martinsos marked this conversation as resolved.
Show resolved Hide resolved
[ "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.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Original discussion: #2276 (comment)

"--noEmit",
"false",
"--outDir",
Expand All @@ -133,6 +148,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 @@ -170,7 +187,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