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 10 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
2 changes: 1 addition & 1 deletion waspc/data/Generator/templates/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{=& devDepsChunk =},
"scripts": {
"start": "vite",
"build": "tsc && vite build"
"build": "tsc --build && vite build"
},
"engineStrict": true,
"engines": {
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
1 change: 1 addition & 0 deletions waspc/data/Generator/templates/react-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { defaultExclude } from "vitest/config"

{=# customViteConfig.isDefined =}
// Ignoring the TS error because we are importing a file outside of TS root dir.
// @ts-ignore
{=& customViteConfig.importStatement =}
const _waspUserProvidedConfig = {=& customViteConfig.importIdentifier =}
{=/ customViteConfig.isDefined =}
Expand Down
5 changes: 4 additions & 1 deletion waspc/data/Generator/templates/sdk/wasp/server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ const serverEnvSchema = z.discriminatedUnion('NODE_ENV', [
])

// PUBLIC API
export const env = ensureEnvSchema(process.env, serverEnvSchema)
export const env = ensureEnvSchema(
{ NODE_ENV: serverDevSchema.shape.NODE_ENV.value, ...process.env },
serverEnvSchema,
)

function getRequiredEnvVarErrorMessage(featureName: string, envVarName: string) {
return `${envVarName} is required when using ${featureName}`
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 =}" }
]
}
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This got moved from SdkGenerator.Server.Operations, nothing new here.

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
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