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

Post 0.16.0 cleanup #2490

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions waspc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ module-graph.png

# macOS related
.DS_Store

# apps for testing
examples/ignored
Comment on lines +20 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sneaked this in because I like to have experimental apps in the scope of cabal run wasp-cli but I don't like them polluting my commit history.

3 changes: 3 additions & 0 deletions waspc/data/Cli/templates/skeleton/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
// Source 2: https://github.com/testing-library/jest-dom/issues/546#issuecomment-1889884843
"node_modules/@types"
],
// Wasp internally uses TypeScript's project references to compile the
// code. Referenced projects may not disable emit, so we must specify an
// outDir.
"outDir": ".wasp/out/user"
},
"include": [
Expand Down
3 changes: 3 additions & 0 deletions waspc/data/Generator/templates/react-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
// Wasp's TS config arrangement is based on Vite's tsconfig arrangement We
// have an extra top-level file because the two projects are independent. The
// empty files array is necessary to allow `noEmit` in referenced projects.
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
Expand Down
6 changes: 5 additions & 1 deletion waspc/data/Generator/templates/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// make project references work for the TS config), then I believe the
// correct configuration is "rootDir": "." (the project reference should
// take care of the user code), but we should double-check.
//
// Before changing this property, ensure you're aware of the implications:
// - https://github.com/wasp-lang/wasp/pull/1584#discussion_r1404019301
// - https://github.com/wasp-lang/wasp/pull/1713/files#diff-58191eecd9cc55f71c73de89420df8b1866dce38ad35f4ef0f6f8874616eda77R32
"rootDir": ".",
// Overriding this because we want to use top-level await
"module": "esnext",
Expand All @@ -30,6 +34,6 @@
"src"
],
"references": [
{ "path": "../../../tsconfig.json" }
{ "path": "{= srcTsConfigPath =}" }
]
}
6 changes: 3 additions & 3 deletions waspc/src/Wasp/Generator/ExternalConfig/TsConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ validateFieldValue fullyQualifiedFieldName expectedValue actualValue =
unwords
[ "Invalid value for the",
"\"" ++ show fullyQualifiedFieldName ++ "\"",
"field in tsconfig.json, you must set it to:",
"field in TS config, you must set it to:",
showAsJsValue expected ++ "."
]

fieldMustBeUnsetErrorMessage =
unwords
[ "The",
"\"" ++ show fullyQualifiedFieldName ++ "\"",
"field in tsconfig.json must be unset."
"field in TS Config must be left unspecified."
]

makeMissingFieldErrorMessage expected =
unwords
[ "The",
"\"" ++ show fullyQualifiedFieldName ++ "\"",
"field is missing in tsconfig.json, you must set it to:",
"field is missing in TS config, you must set it to:",
showAsJsValue expected ++ "."
]
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/SdkGenerator/CrudG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Wasp.Generator.FileDraft (FileDraft)
import qualified Wasp.Generator.JsImport as GJI
import Wasp.Generator.Monad (Generator)
import qualified Wasp.Generator.SdkGenerator.Common as C
import Wasp.Generator.SdkGenerator.Server.OperationsGenerator (extImportToJsImport)
import Wasp.Generator.SdkGenerator.JsImport (extImportToJsImport)

genCrud :: AppSpec -> Generator [FileDraft]
genCrud spec =
Expand Down
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/SdkGenerator/EnvValidation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Wasp.Generator.FileDraft (FileDraft)
import qualified Wasp.Generator.JsImport as GJI
import Wasp.Generator.Monad (Generator)
import qualified Wasp.Generator.SdkGenerator.Common as C
import Wasp.Generator.SdkGenerator.Server.OperationsGenerator (extImportToJsImport)
import Wasp.Generator.SdkGenerator.JsImport (extImportToJsImport)
import qualified Wasp.Generator.ServerGenerator.Common as Server
import qualified Wasp.Generator.WebAppGenerator.Common as WebApp
import qualified Wasp.Project.Db as Db
Expand Down
38 changes: 38 additions & 0 deletions waspc/src/Wasp/Generator/SdkGenerator/JsImport.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Wasp.Generator.SdkGenerator.JsImport
( extImportToJsImport,
extOperationImportToImportJson,
)
where

import qualified Data.Aeson as Aeson
import Data.Maybe (fromJust)
import StrongPath ((</>))
import qualified StrongPath as SP
import qualified Wasp.AppSpec.ExtImport as EI
import Wasp.Generator.Common (dropExtensionFromImportPath)
import qualified Wasp.Generator.JsImport as GJI
import qualified Wasp.Generator.SdkGenerator.Common as C
import Wasp.JsImport (JsImport (..), JsImportPath (..))
import qualified Wasp.JsImport as JI

extImportToJsImport :: EI.ExtImport -> JsImport
extImportToJsImport extImport@(EI.ExtImport extImportName extImportPath) =
JsImport
{ _path = ModuleImportPath importPath,
_name = importName,
_importAlias = Just $ EI.importIdentifier extImport ++ "_ext"
}
where
importPath = C.makeSdkImportPath $ dropExtensionFromImportPath $ extCodeDirP </> SP.castRel extImportPath
extCodeDirP = fromJust $ SP.relDirToPosix C.extSrcDirInSdkRootDir
importName = GJI.extImportNameToJsImportName extImportName

extOperationImportToImportJson :: EI.ExtImport -> Aeson.Value
extOperationImportToImportJson =
GJI.jsImportToImportJson
. Just
. applyExtImportAlias
. extImportToJsImport
where
applyExtImportAlias jsImport =
jsImport {_importAlias = Just $ JI.getImportIdentifier jsImport ++ "_ext"}
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
{-# LANGUAGE TypeApplications #-}

module Wasp.Generator.SdkGenerator.Server.OperationsGenerator
( extImportToJsImport,
serverOperationsDirInSdkRootDir,
( serverOperationsDirInSdkRootDir,
genOperations,
)
where

import Data.Aeson (object, (.=))
import qualified Data.Aeson as Aeson
import Data.List (nub)
import Data.Maybe (fromJust, fromMaybe)
import Data.Maybe (fromMaybe)
import StrongPath (Dir, Dir', File', Path', Rel, reldir, relfile, (</>))
import qualified StrongPath as SP
import Wasp.AppSpec (AppSpec)
import qualified Wasp.AppSpec as AS
import qualified Wasp.AppSpec.Action as AS.Action
import qualified Wasp.AppSpec.ExtImport as EI
import Wasp.AppSpec.Operation (getName)
import qualified Wasp.AppSpec.Operation as AS.Operation
import qualified Wasp.AppSpec.Query as AS.Query
import Wasp.AppSpec.Valid (isAuthEnabled)
import Wasp.Generator.Common (dropExtensionFromImportPath, makeJsonWithEntityData)
import Wasp.Generator.Common (makeJsonWithEntityData)
import Wasp.Generator.FileDraft (FileDraft)
import qualified Wasp.Generator.JsImport as GJI
import Wasp.Generator.Monad (Generator)
import Wasp.Generator.SdkGenerator.Common (SdkTemplatesDir, getOperationTypeName, mkTmplFdWithData, serverTemplatesDirInSdkTemplatesDir)
import qualified Wasp.Generator.SdkGenerator.Common as C
import Wasp.JsImport (JsImport (..), JsImportPath (..))
import qualified Wasp.JsImport as JI
import Wasp.Generator.SdkGenerator.JsImport (extOperationImportToImportJson)
import Wasp.Util (toUpperFirst)

data ServerOpsTemplatesDir
Expand Down Expand Up @@ -153,26 +149,3 @@ getOperationTmplData isAuthEnabledGlobally operation =
.= maybe [] (map (makeJsonWithEntityData . AS.refName)) (AS.Operation.getEntities operation),
"usesAuth" .= fromMaybe isAuthEnabledGlobally (AS.Operation.getAuth operation)
]

extOperationImportToImportJson :: EI.ExtImport -> Aeson.Value
extOperationImportToImportJson =
GJI.jsImportToImportJson
. Just
. applyExtImportAlias
. extImportToJsImport

applyExtImportAlias :: JsImport -> JsImport
applyExtImportAlias jsImport =
jsImport {_importAlias = Just $ JI.getImportIdentifier jsImport ++ "_ext"}

extImportToJsImport :: EI.ExtImport -> JsImport
extImportToJsImport extImport@(EI.ExtImport extImportName extImportPath) =
JsImport
{ _path = ModuleImportPath importPath,
_name = importName,
_importAlias = Just $ EI.importIdentifier extImport ++ "_ext"
}
where
importPath = C.makeSdkImportPath $ dropExtensionFromImportPath $ extCodeDirP </> SP.castRel extImportPath
extCodeDirP = fromJust $ SP.relDirToPosix C.extSrcDirInSdkRootDir
importName = GJI.extImportNameToJsImportName extImportName
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Wasp.Generator.FileDraft (FileDraft)
import qualified Wasp.Generator.JsImport as GJI
import Wasp.Generator.Monad (Generator)
import qualified Wasp.Generator.SdkGenerator.Common as C
import Wasp.Generator.SdkGenerator.Server.OperationsGenerator (extImportToJsImport)
import Wasp.Generator.SdkGenerator.JsImport (extImportToJsImport)
import qualified Wasp.Generator.WebSocket as AS.WS

genWebSockets :: AppSpec -> Generator [FileDraft]
Expand Down
15 changes: 11 additions & 4 deletions waspc/src/Wasp/Generator/ServerGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Data.Maybe
)
import StrongPath
( Dir,
File,
File',
Path,
Path',
Expand All @@ -28,6 +29,7 @@ import StrongPath
relfile,
(</>),
)
import qualified StrongPath as SP
import Wasp.AppSpec (AppSpec)
import qualified Wasp.AppSpec as AS
import qualified Wasp.AppSpec.App as AS.App
Expand Down Expand Up @@ -57,6 +59,7 @@ import Wasp.Generator.ServerGenerator.OperationsG (genOperations)
import Wasp.Generator.ServerGenerator.OperationsRoutesG (genOperationsRoutes)
import Wasp.Generator.ServerGenerator.WebSocketG (depsRequiredByWebSockets, genWebSockets, mkWebSocketFnImport)
import qualified Wasp.Node.Version as NodeVersion
import Wasp.Project.Common (SrcTsConfigFile, waspProjectDirFromAppComponentDir)
import Wasp.Project.Db (databaseUrlEnvVarName)
import qualified Wasp.SemanticVersion as SV
import Wasp.Util ((<++>))
Expand All @@ -67,7 +70,7 @@ genServer spec =
[ genFileCopy [relfile|README.md|],
genFileCopy [relfile|nodemon.json|],
genRollupConfigJs spec,
genTsConfigJson,
genTsConfigJson spec,
genPackageJson spec (npmDepsForWasp spec),
genNpmrc,
genGitignore
Expand Down Expand Up @@ -101,17 +104,21 @@ genDotEnv spec =
dotEnvInServerRootDir :: Path' (Rel ServerRootDir) File'
dotEnvInServerRootDir = [relfile|.env|]

genTsConfigJson :: Generator FileDraft
genTsConfigJson = do
genTsConfigJson :: AppSpec -> Generator FileDraft
genTsConfigJson spec = do
return $
C.mkTmplFdWithDstAndData
(C.asTmplFile [relfile|tsconfig.json|])
(C.asServerFile [relfile|tsconfig.json|])
( Just $
object
[ "majorNodeVersion" .= show (SV.major NodeVersion.oldestWaspSupportedNodeVersion)
[ "majorNodeVersion" .= show (SV.major NodeVersion.oldestWaspSupportedNodeVersion),
"srcTsConfigPath" .= SP.fromRelFile srcTsConfigPath
]
)
where
srcTsConfigPath :: Path' (Rel C.ServerRootDir) (File SrcTsConfigFile) =
waspProjectDirFromAppComponentDir </> AS.srcTsConfigPath spec

genPackageJson :: AppSpec -> N.NpmDepsForWasp -> Generator FileDraft
genPackageJson spec waspDependencies = do
Expand Down
8 changes: 6 additions & 2 deletions waspc/src/Wasp/Project/ExternalConfig/TsConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ 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)
import StrongPath (Abs, Dir, File, Path', Rel, toFilePath)
import StrongPath (Abs, Dir, File, Path', Rel, basename, fromRelFile, toFilePath)
import qualified Wasp.ExternalConfig.TsConfig as T
import Wasp.Generator.ExternalConfig.TsConfig (validateSrcTsConfig)
import Wasp.Project.Common
( SrcTsConfigFile,
WaspProjectDir,
findFileInWaspProjectDir,
)
import Wasp.Util (indent)
import qualified Wasp.Util.IO as IOUtil
import Wasp.Util.Json (parseJsonWithComments)

Expand All @@ -37,4 +38,7 @@ readTsConfigFile :: Path' Abs (File f) -> IO (Either String T.TsConfig)
readTsConfigFile tsConfigFile = do
tsConfigContent <- IOUtil.readFileBytes tsConfigFile
parseResult <- parseJsonWithComments . BS.toString $ tsConfigContent
return $ left ("Failed to parse tsconfig file: " ++) parseResult
return $ left ((errorMessagePrefix ++) . indent 2) parseResult
where
errorMessagePrefix = "Failed to parse '" ++ baseTsConfigFilePath ++ "':\n"
baseTsConfigFilePath = fromRelFile (basename tsConfigFile)
Comment on lines +41 to +44
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the indent and the new line, the message looks like this:

❌ --- [Error] Analyzing wasp project failed: -------------------------------------

1 errors found:
- Failed to parse 'tsconfig.json':
  [eval]:15
      "composite": true,
      ^^^^^^^^^^^

  SyntaxError: Unexpected string
      at makeContextifyScript (node:internal/vm:122:14)
      at node:internal/process/execution:89:22
      at [eval]-wrapper:6:24
      at runScript (node:internal/process/execution:83:62)
      at evalScript (node:internal/process/execution:114:10)
      at node:internal/main/eval_string:30:3

  Node.js v18.20.4

Without them, it looks broken:

❌ --- [Error] Analyzing wasp project failed: -------------------------------------

1 errors found:
- Failed to parse 'tsconfig.json': [eval]:15
    "composite": true,
    ^^^^^^^^^^^

SyntaxError: Unexpected string
    at makeContextifyScript (node:internal/vm:122:14)
    at node:internal/process/execution:89:22
    at [eval]-wrapper:6:24
    at runScript (node:internal/process/execution:83:62)
    at evalScript (node:internal/process/execution:114:10)
    at node:internal/main/eval_string:30:3

Node.js v18.20.4

8 changes: 4 additions & 4 deletions waspc/src/Wasp/Util/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Data.Text (Text)
import qualified Data.Text.IO as T.IO
import qualified Data.Text.IO as Text.IO
import qualified Path.IO as PathIO
import StrongPath (Abs, Dir, Dir', File, Path', Rel, basename, parseRelDir, parseRelFile, toFilePath, (</>))
import StrongPath (Abs, Dir, File, Path', Rel, basename, parseRelDir, parseRelFile, toFilePath, (</>))
import qualified StrongPath as SP
import qualified StrongPath.Path as SP.Path
import qualified System.Directory as SD
Expand Down Expand Up @@ -66,7 +66,7 @@ listDirectoryDeep absDirPath = do
-- TODO: write tests.

-- | Lists files and directories at top lvl of the directory.
listDirectory :: forall d f. Path' Abs (Dir d) -> IO ([Path' (Rel d) (File f)], [Path' (Rel d) Dir'])
listDirectory :: forall r d f. Path' Abs (Dir r) -> IO ([Path' (Rel r) (File f)], [Path' (Rel r) (Dir d)])
listDirectory absDirPath = do
fpRelItemPaths <- SD.listDirectory fpAbsDirPath
relFilePaths <- filterFiles fpAbsDirPath fpRelItemPaths
Expand All @@ -76,12 +76,12 @@ listDirectory absDirPath = do
fpAbsDirPath :: FilePath
fpAbsDirPath = toFilePath absDirPath

filterFiles :: FilePath -> [FilePath] -> IO [Path' (Rel d) (File f)]
filterFiles :: FilePath -> [FilePath] -> IO [Path' (Rel r) (File f)]
filterFiles absDir relItems =
filterM (SD.doesFileExist . (absDir FilePath.</>)) relItems
>>= mapM parseRelFile

filterDirs :: FilePath -> [FilePath] -> IO [Path' (Rel d) Dir']
filterDirs :: FilePath -> [FilePath] -> IO [Path' (Rel r) (Dir d)]
filterDirs absDir relItems =
filterM (SD.doesDirectoryExist . (absDir FilePath.</>)) relItems
>>= mapM parseRelDir
Expand Down
4 changes: 3 additions & 1 deletion waspc/test/AppSpec/ValidTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import qualified Data.Map as M
import Data.Maybe (fromJust)
import Fixtures (systemSPRoot)
import NeatInterpolation (trimming)
import StrongPath (relfile)
import qualified StrongPath as SP
import Test.Tasty.Hspec
import qualified Util.Prisma as Util
Expand Down Expand Up @@ -489,7 +490,8 @@ spec_AppSpecValid = do
AS.userDockerfileContents = Nothing,
AS.configFiles = [],
AS.devDatabaseUrl = Nothing,
AS.customViteConfigPath = Nothing
AS.customViteConfigPath = Nothing,
AS.srcTsConfigPath = [relfile|tsconfig.json|]
}

getPrismaSchemaWithConfig restOfPrismaSource =
Expand Down
4 changes: 3 additions & 1 deletion waspc/test/Generator/WebAppGeneratorTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Generator.WebAppGeneratorTest where

import qualified Data.Map as M
import Fixtures
import StrongPath (relfile)
import qualified StrongPath as SP
import System.FilePath ((</>))
import Test.Tasty.Hspec
Expand Down Expand Up @@ -64,7 +65,8 @@ spec_WebAppGenerator = do
AS.userDockerfileContents = Nothing,
AS.configFiles = [],
AS.devDatabaseUrl = Nothing,
AS.customViteConfigPath = Nothing
AS.customViteConfigPath = Nothing,
AS.srcTsConfigPath = [relfile|tsconfig.json|]
}

describe "genWebApp" $ do
Expand Down
1 change: 1 addition & 0 deletions waspc/waspc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ library
Wasp.Generator.SdkGenerator.CrudG
Wasp.Generator.SdkGenerator.EmailSender.Providers
Wasp.Generator.SdkGenerator.EnvValidation
Wasp.Generator.SdkGenerator.JsImport
Wasp.Generator.SdkGenerator.Server.AuthG
Wasp.Generator.SdkGenerator.Server.OAuthG
Wasp.Generator.SdkGenerator.Server.CrudG
Expand Down
Loading