-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into miho-react-router-dom-6
- Loading branch information
Showing
25 changed files
with
407 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
|
||
module Wasp.ExternalConfig.TsConfig | ||
( TsConfig (..), | ||
CompilerOptions (..), | ||
) | ||
where | ||
|
||
import Data.Aeson | ||
( FromJSON, | ||
genericParseJSON, | ||
parseJSON, | ||
) | ||
import qualified Data.Aeson as Aeson | ||
import GHC.Generics (Generic) | ||
|
||
data TsConfig = TsConfig | ||
{ compilerOptions :: !CompilerOptions | ||
} | ||
deriving (Show, Generic, FromJSON) | ||
|
||
data CompilerOptions = CompilerOptions | ||
{ _module :: !(Maybe String), | ||
target :: !(Maybe String), | ||
moduleResolution :: !(Maybe String), | ||
jsx :: !(Maybe String), | ||
strict :: !(Maybe Bool), | ||
esModuleInterop :: !(Maybe Bool), | ||
lib :: !(Maybe [String]), | ||
allowJs :: !(Maybe Bool), | ||
typeRoots :: !(Maybe [String]), | ||
outDir :: !(Maybe String) | ||
} | ||
deriving (Show, Generic) | ||
|
||
instance FromJSON CompilerOptions where | ||
parseJSON = | ||
genericParseJSON $ | ||
Aeson.defaultOptions {Aeson.fieldLabelModifier = modifyFieldLabel} | ||
where | ||
-- "module" is a reserved keyword in Haskell, so we use "_module" instead. | ||
modifyFieldLabel "_module" = "module" | ||
modifyFieldLabel other = other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Wasp.Generator.ExternalConfig.Common (ErrorMsg) where | ||
|
||
type ErrorMsg = String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Wasp.Generator.ExternalConfig.PackageJson | ||
( validatePackageJson, | ||
) | ||
where | ||
|
||
import qualified Data.Map as M | ||
import qualified Wasp.ExternalConfig.PackageJson as P | ||
import Wasp.Generator.Common (prismaVersion) | ||
import Wasp.Generator.ExternalConfig.Common (ErrorMsg) | ||
import Wasp.Generator.WebAppGenerator.Common (reactRouterVersion) | ||
|
||
validatePackageJson :: P.PackageJson -> [ErrorMsg] | ||
validatePackageJson packageJson = | ||
concat | ||
[ validate ("wasp", "file:.wasp/out/sdk/wasp") IsListedWithExactVersion, | ||
validate ("prisma", show prismaVersion) IsListedAsDevWithExactVersion, | ||
-- Installing the wrong version of "react-router-dom" can make users believe that they | ||
-- can use features that are not available in the version that Wasp supports. | ||
validate ("react-router-dom", show reactRouterVersion) HasExactVersionIfListed | ||
] | ||
where | ||
validate = validateDep packageJson | ||
|
||
data PackageValidationType = IsListedWithExactVersion | IsListedAsDevWithExactVersion | HasExactVersionIfListed | ||
|
||
validateDep :: P.PackageJson -> (P.PackageName, P.PackageVersion) -> PackageValidationType -> [String] | ||
validateDep packageJson (packageName, expectedPackageVersion) = \case | ||
IsListedWithExactVersion -> checkDeps [P.dependencies packageJson] [requiredPackageMessage "dependencies"] | ||
IsListedAsDevWithExactVersion -> checkDeps [P.devDependencies packageJson] [requiredPackageMessage "devDependencies"] | ||
HasExactVersionIfListed -> checkDeps [P.dependencies packageJson, P.devDependencies packageJson] [] | ||
where | ||
checkDeps depsToCheck errorMessagesIfPackageNotListed = case map (M.lookup packageName) depsToCheck of | ||
(Just actualPackageVersion : _) -> | ||
if actualPackageVersion == expectedPackageVersion | ||
then [] | ||
else [incorrectVersionMessage] | ||
_notListed -> errorMessagesIfPackageNotListed | ||
|
||
incorrectVersionMessage :: String | ||
incorrectVersionMessage = | ||
unwords | ||
["Wasp requires package", show packageName, "to be version", show expectedPackageVersion, "in package.json."] | ||
|
||
requiredPackageMessage :: String -> String | ||
requiredPackageMessage packageJsonLocation = | ||
unwords | ||
[ "Wasp requires package", | ||
show packageName, | ||
"with version", | ||
show expectedPackageVersion, | ||
"in", | ||
show packageJsonLocation, | ||
"in package.json." | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{-# LANGUAGE FlexibleInstances #-} | ||
|
||
module Wasp.Generator.ExternalConfig.TsConfig | ||
( validateTsConfig, | ||
) | ||
where | ||
|
||
import qualified Wasp.ExternalConfig.TsConfig as T | ||
import Wasp.Generator.ExternalConfig.Common (ErrorMsg) | ||
|
||
class IsJavascriptValue a where | ||
showAsJsValue :: a -> String | ||
|
||
instance IsJavascriptValue String where | ||
showAsJsValue = show | ||
|
||
instance IsJavascriptValue [String] where | ||
showAsJsValue = show | ||
|
||
instance IsJavascriptValue Bool where | ||
showAsJsValue True = "true" | ||
showAsJsValue False = "false" | ||
|
||
type FieldName = String | ||
|
||
validateTsConfig :: T.TsConfig -> [ErrorMsg] | ||
validateTsConfig tsConfig = | ||
concat | ||
[ validateRequiredFieldInCompilerOptions "module" "esnext" T._module, | ||
validateRequiredFieldInCompilerOptions "target" "esnext" T.target, | ||
validateRequiredFieldInCompilerOptions "moduleResolution" "bundler" T.moduleResolution, | ||
validateRequiredFieldInCompilerOptions "jsx" "preserve" T.jsx, | ||
validateRequiredFieldInCompilerOptions "strict" True T.strict, | ||
validateRequiredFieldInCompilerOptions "esModuleInterop" True T.esModuleInterop, | ||
validateRequiredFieldInCompilerOptions "lib" ["dom", "dom.iterable", "esnext"] T.lib, | ||
validateRequiredFieldInCompilerOptions "allowJs" True T.allowJs, | ||
validateRequiredFieldInCompilerOptions "typeRoots" ["node_modules/@testing-library", "node_modules/@types"] T.typeRoots, | ||
validateRequiredFieldInCompilerOptions "outDir" ".wasp/phantom" T.outDir | ||
] | ||
where | ||
validateRequiredFieldInCompilerOptions fieldName expectedValue getFieldValue = case getFieldValue compilerOptionsFields of | ||
Just actualValue -> validateFieldValue ("compilerOptions." ++ fieldName) expectedValue actualValue | ||
Nothing -> [missingFieldErrorMessage] | ||
where | ||
missingFieldErrorMessage = | ||
unwords | ||
[ "The", | ||
show fieldName, | ||
"field is missing in tsconfig.json. Expected value:", | ||
showAsJsValue expectedValue ++ "." | ||
] | ||
|
||
compilerOptionsFields = T.compilerOptions tsConfig | ||
|
||
validateFieldValue :: (Eq value, IsJavascriptValue value) => FieldName -> value -> value -> [String] | ||
validateFieldValue fieldName expectedValue actualValue = | ||
if actualValue == expectedValue | ||
then [] | ||
else [invalidValueErrorMessage] | ||
where | ||
invalidValueErrorMessage = | ||
unwords | ||
[ "Invalid value for the", | ||
show fieldName, | ||
"field in tsconfig.json file, expected value:", | ||
showAsJsValue expectedValue ++ "." | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.