Skip to content

Commit

Permalink
Revert "Make Wasp TS Config projects work with project references (#2461
Browse files Browse the repository at this point in the history
)"

This reverts commit d91b412.
  • Loading branch information
sodic authored Jan 24, 2025
1 parent d91b412 commit ad5af76
Show file tree
Hide file tree
Showing 26 changed files with 42 additions and 62 deletions.
4 changes: 2 additions & 2 deletions waspc/data/Generator/templates/react-app/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{{={= =}=}}
{
"extends": "@tsconfig/vite-react/tsconfig.json",
"compilerOptions": {
Expand All @@ -15,6 +14,7 @@
"src"
],
"references": [
{ "path": "{= srcTsConfigPath =}" }
// TODO: It would be better to inject this knowledge from Haskell.
{ "path": "../../../tsconfig.json" }
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion waspc/examples/todoApp/main.wasp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app todoApp {
wasp: {
version: "^0.16.0"
version: "^0.15.0"
},
title: "ToDo App",
// head: [],
Expand Down
6 changes: 5 additions & 1 deletion waspc/headless-test/examples/todoApp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
// Source 2: https://github.com/testing-library/jest-dom/issues/546#issuecomment-1889884843
"node_modules/@types"
],
"outDir": ".wasp/out/user"
"outDir": ".wasp/out/user",
"paths" : {
"@util": ["./src/util.js"],
"@components/*": ["./src/components/*"],
}
},
"include": [
"src"
Expand Down
7 changes: 3 additions & 4 deletions waspc/src/Wasp/AppSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
import Data.List (find)
import Data.Maybe (fromMaybe, isJust)
import Data.Text (Text)
import StrongPath (Abs, Dir, File, File', Path', Rel, (</>))
import StrongPath (Abs, Dir, File', Path', Rel, (</>))
import Wasp.AppSpec.Action (Action)
import Wasp.AppSpec.Api (Api)
import Wasp.AppSpec.ApiNamespace (ApiNamespace)
Expand All @@ -49,7 +49,7 @@ import Wasp.AppSpec.Route (Route)
import Wasp.Env (EnvVar)
import Wasp.ExternalConfig.PackageJson (PackageJson)
import Wasp.Node.Version (oldestWaspSupportedNodeVersion)
import Wasp.Project.Common (SrcTsConfigFile, WaspProjectDir)
import Wasp.Project.Common (WaspProjectDir)
import Wasp.Project.Db.Migrations (DbMigrationsDir)
import qualified Wasp.Psl.Ast.Schema as Psl.Schema
import qualified Wasp.SemanticVersion as SV
Expand Down Expand Up @@ -89,8 +89,7 @@ data AppSpec = AppSpec
-- | Connection URL for a database used during development. If provided, generated app will
-- make sure to use it when run in development mode.
devDatabaseUrl :: Maybe String,
customViteConfigPath :: Maybe (Path' (Rel WaspProjectDir) File'),
srcTsConfigPath :: Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
customViteConfigPath :: Maybe (Path' (Rel WaspProjectDir) File')
}

-- TODO: Make this return "Named" declarations?
Expand Down
20 changes: 2 additions & 18 deletions waspc/src/Wasp/Generator/WebAppGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Data.Maybe (fromJust)
import qualified FilePath.Extra as FP.Extra
import StrongPath
( Dir,
File,
File',
Path,
Path',
Expand Down Expand Up @@ -57,7 +56,7 @@ import Wasp.JsImport
makeJsImport,
)
import qualified Wasp.Node.Version as NodeVersion
import Wasp.Project.Common (SrcTsConfigFile, dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir, waspProjectDirFromAppComponentDir)
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, generatedCodeDirInDotWaspDir)
import qualified Wasp.Project.Common as Project
import Wasp.Util ((<++>))

Expand All @@ -66,7 +65,7 @@ genWebApp spec = do
sequence
[ genFileCopy [relfile|README.md|],
genFileCopy [relfile|tsconfig.json|],
genAppTsConfigJson spec,
genFileCopy [relfile|tsconfig.app.json|],
genFileCopy [relfile|tsconfig.node.json|],
genFileCopy [relfile|netlify.toml|],
genPackageJson spec (npmDepsForWasp spec),
Expand All @@ -81,21 +80,6 @@ genWebApp spec = do
where
genFileCopy = return . C.mkTmplFd

genAppTsConfigJson :: AppSpec -> Generator FileDraft
genAppTsConfigJson spec = do
return $
C.mkTmplFdWithDstAndData
(C.asTmplFile [relfile|tsconfig.app.json|])
(C.asWebAppFile [relfile|tsconfig.app.json|])
( Just $
object
[ "srcTsConfigPath" .= SP.fromRelFile srcTsConfigPath
]
)
where
srcTsConfigPath :: Path' (Rel C.WebAppRootDir) (File SrcTsConfigFile) =
waspProjectDirFromAppComponentDir </> AS.srcTsConfigPath spec

genDotEnv :: AppSpec -> Generator [FileDraft]
-- Don't generate .env if we are building for production, since .env is to be used only for
-- development.
Expand Down
4 changes: 1 addition & 3 deletions waspc/src/Wasp/Project/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do
clientEnvVars <- readDotEnvClient waspDir

let packageJsonContent = EC._packageJson externalConfigs
srcTsConfigPath = EC._srcTsConfigPath externalConfigs

let appSpec =
AS.AppSpec
Expand All @@ -103,8 +102,7 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do
AS.userDockerfileContents = maybeUserDockerfileContents,
AS.configFiles = configFiles,
AS.devDatabaseUrl = devDbUrl,
AS.customViteConfigPath = customViteConfigPath,
AS.srcTsConfigPath = srcTsConfigPath
AS.customViteConfigPath = customViteConfigPath
}

return $ runValidation ASV.validateAppSpec appSpec
Expand Down
21 changes: 6 additions & 15 deletions waspc/src/Wasp/Project/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ module Wasp.Project.Common
getSrcTsConfigInWaspProjectDir,
srcTsConfigInWaspLangProject,
srcTsConfigInWaspTsProject,
waspProjectDirFromAppComponentDir,
)
where

import StrongPath (Abs, Dir, File, File', Path', Rel, reldir, relfile, toFilePath, (</>))
import System.Directory (doesFileExist)
import Wasp.AppSpec.ExternalFiles (SourceExternalCodeDir, SourceExternalPublicDir)
import qualified Wasp.Generator.Common as G.Common
import qualified Wasp.Generator.Common

type CompileError = String

Expand Down Expand Up @@ -65,33 +64,25 @@ nodeModulesDirInWaspProjectDir :: Path' (Rel WaspProjectDir) (Dir NodeModulesDir
nodeModulesDirInWaspProjectDir = [reldir|node_modules|]

-- | NOTE: If you change the depth of this path, also update @waspProjectDirFromProjectRootDir@ below.
generatedCodeDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir G.Common.ProjectRootDir)
-- TODO: We sometimes call this directory "ProjectRootDir" and sometimes
-- "GeneratedCodeDir". We should unify the naming (the latter is the beter
-- name).
-- TODO: Hm this has different name than it has in Generator.
generatedCodeDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir Wasp.Generator.Common.ProjectRootDir)
generatedCodeDirInDotWaspDir = [reldir|out|]

-- | NOTE: If you change the depth of this path, also update @waspProjectDirFromProjectRootDir@ below.
buildDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir G.Common.ProjectRootDir)
buildDirInDotWaspDir :: Path' (Rel DotWaspDir) (Dir Wasp.Generator.Common.ProjectRootDir)
buildDirInDotWaspDir = [reldir|build|]

-- TODO: This backwards relative path relies on multiple forward relative path
-- definitions. We should find a better way to express it (e.g., by somehow
-- calculating it from existing definitions)
waspProjectDirFromAppComponentDir :: G.Common.AppComponentRootDir d => Path' (Rel d) (Dir WaspProjectDir)
waspProjectDirFromAppComponentDir = [reldir|../../../|]

-- | NOTE: This path is calculated from the values of @dotWaspDirInWaspProjectDir@,
-- @generatedCodeDirInDotWaspDir@ and @buildDirInDotWaspDir@., which are the three functions just above.
-- Also, it assumes @generatedCodeDirInDotWaspDir@ and @buildDirInDotWaspDir@ have same depth.
-- If any of those change significantly (their depth), this path should be adjusted.
waspProjectDirFromProjectRootDir :: Path' (Rel G.Common.ProjectRootDir) (Dir WaspProjectDir)
waspProjectDirFromProjectRootDir :: Path' (Rel Wasp.Generator.Common.ProjectRootDir) (Dir WaspProjectDir)
waspProjectDirFromProjectRootDir = [reldir|../../|]

dotWaspRootFileInWaspProjectDir :: Path' (Rel WaspProjectDir) File'
dotWaspRootFileInWaspProjectDir = [relfile|.wasproot|]

dotWaspInfoFileInGeneratedCodeDir :: Path' (Rel G.Common.ProjectRootDir) File'
dotWaspInfoFileInGeneratedCodeDir :: Path' (Rel Wasp.Generator.Common.ProjectRootDir) File'
dotWaspInfoFileInGeneratedCodeDir = [relfile|.waspinfo|]

packageJsonInWaspProjectDir :: Path' (Rel WaspProjectDir) (File PackageJsonFile)
Expand Down
10 changes: 4 additions & 6 deletions waspc/src/Wasp/Project/ExternalConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,20 @@ import Wasp.Project.ExternalConfig.TsConfig (analyzeSrcTsConfigFile)

data ExternalConfigs = ExternalConfigs
{ _packageJson :: P.PackageJson,
_tsConfig :: T.TsConfig,
_srcTsConfigPath :: Path' (Rel WaspProjectDir) (File SrcTsConfigFile)
_tsConfig :: T.TsConfig
}
deriving (Show)

analyzeExternalConfigs ::
Path' Abs (Dir WaspProjectDir) ->
Path' (Rel WaspProjectDir) (File SrcTsConfigFile) ->
IO (Either [CompileError] ExternalConfigs)
analyzeExternalConfigs waspDir srcTsConfigPath = runExceptT $ do
analyzeExternalConfigs waspDir srcTsConfigFile = runExceptT $ do
packageJsonContent <- ExceptT $ analyzePackageJsonFile waspDir
tsConfigContent <- ExceptT $ analyzeSrcTsConfigFile waspDir srcTsConfigPath
tsConfigContent <- ExceptT $ analyzeSrcTsConfigFile waspDir srcTsConfigFile

return $
ExternalConfigs
{ _packageJson = packageJsonContent,
_tsConfig = tsConfigContent,
_srcTsConfigPath = srcTsConfigPath
_tsConfig = tsConfigContent
}
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Project/WaspFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ findWaspFile waspDir = do
. (waspDir </>)
<$> find ((suffix `isSuffixOf`) . fromRelFile) files

fileNotFoundMessage = "Couldn't find a *.wasp or a *.wasp.ts file in directory " ++ fromAbsDir waspDir ++ " ."
fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the " ++ fromAbsDir waspDir ++ " directory"
bothFilesFoundMessage =
"Found both *.wasp and *.wasp.ts files in the project directory. "
++ "You must choose how you want to define your app (using Wasp or TypeScript) and only keep one of them."
Expand Down
1 change: 1 addition & 0 deletions waspc/waspc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ library
Wasp.Generator.NpmInstall
Wasp.Generator.NpmInstall.Common
Wasp.Generator.NpmInstall.InstalledNpmDepsLog
Wasp.Generator.ImportPathAlias
Wasp.Generator.SdkGenerator
Wasp.Generator.SdkGenerator.Auth.AuthFormsG
Wasp.Generator.SdkGenerator.Auth.EmailAuthG
Expand Down

0 comments on commit ad5af76

Please sign in to comment.