From 6526b495a6c14355c02a9422b4dd99aa9661e512 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Sat, 14 Dec 2024 13:00:23 -0300 Subject: [PATCH 01/13] Ensure users don't create a .wasp file --- waspc/src/Wasp/Project/Analyze.hs | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/waspc/src/Wasp/Project/Analyze.hs b/waspc/src/Wasp/Project/Analyze.hs index 4f5e065198..8e6889570c 100644 --- a/waspc/src/Wasp/Project/Analyze.hs +++ b/waspc/src/Wasp/Project/Analyze.hs @@ -12,7 +12,13 @@ import StrongPath File', Path', fromAbsDir, + fromAbsFile, + fromRelFile, + reldir, + relfile, + (), ) +import qualified System.FilePath as FP import qualified Wasp.AppSpec as AS import Wasp.AppSpec.Core.Decl.JSON () import qualified Wasp.AppSpec.Valid as ASV @@ -63,7 +69,10 @@ analyzeWaspProject waspDir options = do Right declarations -> EC.analyzeExternalConfigs waspDir (getSrcTsConfigInWaspProjectDir waspFilePath) >>= \case Left errors -> return (Left errors, []) - Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations + Right declarations -> + EC.analyzeExternalConfigs waspDir (getSrcTsConfigInWaspProjectDir waspFilePath) >>= \case + Left errors -> return (Left errors, []) + Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations constructAppSpec :: Path' Abs (Dir WaspProjectDir) -> @@ -109,6 +118,31 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do return $ runValidation ASV.validateAppSpec appSpec +waspDirExists :: Path' Abs (Dir WaspProjectDir) -> IO (Either String (Path' Abs (Dir WaspProjectDir))) +waspDirExists waspDir = do + let waspDotWaspPath = waspDir [relfile|.wasp|] + isFile <- IOUtil.doesFileExist waspDotWaspPath + if isFile + then return $ Left "The path to the Wasp project is a file, but it should be a directory." + else return $ Right waspDir + +findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath) +findWaspFile waspDir = do + files <- fst <$> IOUtil.listDirectory waspDir + return $ case (findWaspTsFile files, findWaspLangFile files) of + (Just _, Just _) -> Left bothFilesFoundMessage + (Nothing, Nothing) -> Left fileNotFoundMessage + (Just waspTsFile, Nothing) -> Right waspTsFile + (Nothing, Just waspLangFile) -> Right waspLangFile + where + findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files + findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files + findFileThatEndsWith suffix files = castFile . (waspDir ) <$> find ((suffix `isSuffixOf`) . fromRelFile) files + 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." + analyzePrismaSchema :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] Psl.Schema.Schema, [CompileWarning]) analyzePrismaSchema waspProjectDir = do findPrismaSchemaFile waspProjectDir >>= \case From 23baafdfddf4747614d2d7bdc0148eecd392fe8f Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Sat, 14 Dec 2024 13:23:00 -0300 Subject: [PATCH 02/13] Updated changelog --- waspc/ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/waspc/ChangeLog.md b/waspc/ChangeLog.md index 509e1da374..b638eb004a 100644 --- a/waspc/ChangeLog.md +++ b/waspc/ChangeLog.md @@ -91,6 +91,8 @@ Read more about breaking changes in the migration guide: https://wasp-lang.dev/d Big thanks to our community members who contributed to this release! @Bojun-Feng @dabrorius @komyg @NathanaelA @vblazenka @genyus +- Improved the error message when the user has a top level *.wasp* file. + ## 0.15.2 ### 🐞 Bug fixes From cfeb8b5f441df454c5be1b4a5304cc4d5ac08dd2 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 23 Dec 2024 10:48:57 -0300 Subject: [PATCH 03/13] Move file check logic to findWaspFile --- waspc/src/Wasp/Project/Analyze.hs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/waspc/src/Wasp/Project/Analyze.hs b/waspc/src/Wasp/Project/Analyze.hs index 8e6889570c..2cbd57baf5 100644 --- a/waspc/src/Wasp/Project/Analyze.hs +++ b/waspc/src/Wasp/Project/Analyze.hs @@ -69,10 +69,7 @@ analyzeWaspProject waspDir options = do Right declarations -> EC.analyzeExternalConfigs waspDir (getSrcTsConfigInWaspProjectDir waspFilePath) >>= \case Left errors -> return (Left errors, []) - Right declarations -> - EC.analyzeExternalConfigs waspDir (getSrcTsConfigInWaspProjectDir waspFilePath) >>= \case - Left errors -> return (Left errors, []) - Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations + Right externalConfigs -> constructAppSpec waspDir options externalConfigs prismaSchemaAst declarations constructAppSpec :: Path' Abs (Dir WaspProjectDir) -> @@ -118,22 +115,19 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do return $ runValidation ASV.validateAppSpec appSpec -waspDirExists :: Path' Abs (Dir WaspProjectDir) -> IO (Either String (Path' Abs (Dir WaspProjectDir))) -waspDirExists waspDir = do - let waspDotWaspPath = waspDir [relfile|.wasp|] - isFile <- IOUtil.doesFileExist waspDotWaspPath - if isFile - then return $ Left "The path to the Wasp project is a file, but it should be a directory." - else return $ Right waspDir - findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath) findWaspFile waspDir = do - files <- fst <$> IOUtil.listDirectory waspDir - return $ case (findWaspTsFile files, findWaspLangFile files) of - (Just _, Just _) -> Left bothFilesFoundMessage - (Nothing, Nothing) -> Left fileNotFoundMessage - (Just waspTsFile, Nothing) -> Right waspTsFile - (Nothing, Just waspLangFile) -> Right waspLangFile + let dotWaspPath = waspDir [relfile|.wasp|] + isFile <- IOUtil.doesFileExist dotWaspPath + if isFile + then return $ Left "Invalid file name for the .wasp file. Please rename it to [something].wasp." + else do + files <- fst <$> IOUtil.listDirectory waspDir + return $ case (findWaspTsFile files, findWaspLangFile files) of + (Just _, Just _) -> Left bothFilesFoundMessage + (Nothing, Nothing) -> Left fileNotFoundMessage + (Just waspTsFile, Nothing) -> Right waspTsFile + (Nothing, Just waspLangFile) -> Right waspLangFile where findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files From 70ab224f56fd415527e021db03ce05bc314d26ce Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 27 Dec 2024 09:48:28 -0300 Subject: [PATCH 04/13] Enforce only one .wasp file --- waspc/src/Wasp/Project/Analyze.hs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/waspc/src/Wasp/Project/Analyze.hs b/waspc/src/Wasp/Project/Analyze.hs index 2cbd57baf5..32749fd5ab 100644 --- a/waspc/src/Wasp/Project/Analyze.hs +++ b/waspc/src/Wasp/Project/Analyze.hs @@ -6,6 +6,11 @@ module Wasp.Project.Analyze where import Control.Arrow (ArrowChoice (left)) +import Control.Concurrent (newChan) +import Control.Concurrent.Async (concurrently) +import Control.Monad.Except (ExceptT (..), liftEither, runExceptT) +import qualified Data.Aeson as Aeson +import Data.List (any, find, isSuffixOf) import StrongPath ( Abs, Dir, @@ -124,18 +129,22 @@ findWaspFile waspDir = do else do files <- fst <$> IOUtil.listDirectory waspDir return $ case (findWaspTsFile files, findWaspLangFile files) of - (Just _, Just _) -> Left bothFilesFoundMessage - (Nothing, Nothing) -> Left fileNotFoundMessage - (Just waspTsFile, Nothing) -> Right waspTsFile - (Nothing, Just waspLangFile) -> Right waspLangFile + (tsFiles, langFiles) + | not (null tsFiles) && not (null langFiles) -> Left bothFilesFoundMessage + | null tsFiles && null langFiles -> Left fileNotFoundMessage + | [waspTsFile] <- tsFiles, null langFiles -> Right waspTsFile + | null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile + | otherwise -> Left multipleFilesFoundMessage where - findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files - findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files - findFileThatEndsWith suffix files = castFile . (waspDir ) <$> find ((suffix `isSuffixOf`) . fromRelFile) files + findWaspTsFile files = map (WaspTs) (findFileThatEndsWith ".wasp.ts" files) + findWaspLangFile files = map (WaspLang) (findFileThatEndsWith ".wasp" files) + findFileThatEndsWith suffix files = map (castFile . (waspDir )) (findFilesThatEndWith suffix files) + findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf`) . fromRelFile) files 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." + multipleFilesFoundMessage = "Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one." analyzePrismaSchema :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] Psl.Schema.Schema, [CompileWarning]) analyzePrismaSchema waspProjectDir = do From 94a3bf3bd0b3db854d31c75fcb6429078b6fe2a7 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 27 Dec 2024 09:52:41 -0300 Subject: [PATCH 05/13] Replaced map with <$> --- waspc/src/Wasp/Project/Analyze.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/waspc/src/Wasp/Project/Analyze.hs b/waspc/src/Wasp/Project/Analyze.hs index 32749fd5ab..8c0ba3e4bf 100644 --- a/waspc/src/Wasp/Project/Analyze.hs +++ b/waspc/src/Wasp/Project/Analyze.hs @@ -136,9 +136,9 @@ findWaspFile waspDir = do | null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile | otherwise -> Left multipleFilesFoundMessage where - findWaspTsFile files = map (WaspTs) (findFileThatEndsWith ".wasp.ts" files) - findWaspLangFile files = map (WaspLang) (findFileThatEndsWith ".wasp" files) - findFileThatEndsWith suffix files = map (castFile . (waspDir )) (findFilesThatEndWith suffix files) + findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files + findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files + findFileThatEndsWith suffix files = castFile . (waspDir ) <$> findFilesThatEndWith suffix files findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf`) . fromRelFile) files fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the " ++ fromAbsDir waspDir ++ " directory" bothFilesFoundMessage = From bb47f0f06abb73d78e6ae1c8102114e58ba3296d Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 6 Jan 2025 19:14:09 -0300 Subject: [PATCH 06/13] Updated findWaspFile in new location --- waspc/src/Wasp/Project/Analyze.hs | 26 -------------------------- waspc/src/Wasp/Project/WaspFile.hs | 30 ++++++++++++++++++------------ 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/waspc/src/Wasp/Project/Analyze.hs b/waspc/src/Wasp/Project/Analyze.hs index 8c0ba3e4bf..50eba51bc5 100644 --- a/waspc/src/Wasp/Project/Analyze.hs +++ b/waspc/src/Wasp/Project/Analyze.hs @@ -120,32 +120,6 @@ constructAppSpec waspDir options externalConfigs parsedPrismaSchema decls = do return $ runValidation ASV.validateAppSpec appSpec -findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath) -findWaspFile waspDir = do - let dotWaspPath = waspDir [relfile|.wasp|] - isFile <- IOUtil.doesFileExist dotWaspPath - if isFile - then return $ Left "Invalid file name for the .wasp file. Please rename it to [something].wasp." - else do - files <- fst <$> IOUtil.listDirectory waspDir - return $ case (findWaspTsFile files, findWaspLangFile files) of - (tsFiles, langFiles) - | not (null tsFiles) && not (null langFiles) -> Left bothFilesFoundMessage - | null tsFiles && null langFiles -> Left fileNotFoundMessage - | [waspTsFile] <- tsFiles, null langFiles -> Right waspTsFile - | null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile - | otherwise -> Left multipleFilesFoundMessage - where - findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files - findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files - findFileThatEndsWith suffix files = castFile . (waspDir ) <$> findFilesThatEndWith suffix files - findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf`) . fromRelFile) files - 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." - multipleFilesFoundMessage = "Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one." - analyzePrismaSchema :: Path' Abs (Dir WaspProjectDir) -> IO (Either [CompileError] Psl.Schema.Schema, [CompileWarning]) analyzePrismaSchema waspProjectDir = do findPrismaSchemaFile waspProjectDir >>= \case diff --git a/waspc/src/Wasp/Project/WaspFile.hs b/waspc/src/Wasp/Project/WaspFile.hs index 62a9acf2fc..fcc1ecf00d 100644 --- a/waspc/src/Wasp/Project/WaspFile.hs +++ b/waspc/src/Wasp/Project/WaspFile.hs @@ -12,6 +12,7 @@ import StrongPath castFile, fromAbsDir, fromRelFile, + relfile, (), ) import qualified Wasp.AppSpec as AS @@ -28,24 +29,29 @@ import qualified Wasp.Util.IO as IOUtil findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath) findWaspFile waspDir = do - files <- fst <$> IOUtil.listDirectory waspDir - return $ case (findWaspTsFile files, findWaspLangFile files) of - (Just _, Just _) -> Left bothFilesFoundMessage - (Nothing, Nothing) -> Left fileNotFoundMessage - (Just waspTsFile, Nothing) -> Right waspTsFile - (Nothing, Just waspLangFile) -> Right waspLangFile + let dotWaspPath = waspDir [relfile|.wasp|] + isFile <- IOUtil.doesFileExist dotWaspPath + if isFile + then return $ Left "Invalid file name for the .wasp file. Please rename it to [something].wasp." + else do + files <- fst <$> IOUtil.listDirectory waspDir + return $ case (findWaspTsFile files, findWaspLangFile files) of + (tsFiles, langFiles) + | not (null tsFiles) && not (null langFiles) -> Left bothFilesFoundMessage + | null tsFiles && null langFiles -> Left fileNotFoundMessage + | [waspTsFile] <- tsFiles, null langFiles -> Right waspTsFile + | null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile + | otherwise -> Left multipleFilesFoundMessage where findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files - findFileThatEndsWith suffix files = - castFile - . (waspDir ) - <$> find ((suffix `isSuffixOf`) . fromRelFile) files - - fileNotFoundMessage = "Couldn't find a *.wasp or a *.wasp.ts file in directory " ++ fromAbsDir waspDir ++ " ." + findFileThatEndsWith suffix files = castFile . (waspDir ) <$> findFilesThatEndWith suffix files + findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf`) . fromRelFile) files + 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." + multipleFilesFoundMessage = "Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one." analyzeWaspFile :: Path' Abs (Dir WaspProjectDir) -> From 7b0ee3a7b6d5679dd0a3e00bb9ba6231da743020 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 6 Jan 2025 19:15:39 -0300 Subject: [PATCH 07/13] Removed unused imports --- waspc/src/Wasp/Project/Analyze.hs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/waspc/src/Wasp/Project/Analyze.hs b/waspc/src/Wasp/Project/Analyze.hs index 50eba51bc5..4f5e065198 100644 --- a/waspc/src/Wasp/Project/Analyze.hs +++ b/waspc/src/Wasp/Project/Analyze.hs @@ -6,24 +6,13 @@ module Wasp.Project.Analyze where import Control.Arrow (ArrowChoice (left)) -import Control.Concurrent (newChan) -import Control.Concurrent.Async (concurrently) -import Control.Monad.Except (ExceptT (..), liftEither, runExceptT) -import qualified Data.Aeson as Aeson -import Data.List (any, find, isSuffixOf) import StrongPath ( Abs, Dir, File', Path', fromAbsDir, - fromAbsFile, - fromRelFile, - reldir, - relfile, - (), ) -import qualified System.FilePath as FP import qualified Wasp.AppSpec as AS import Wasp.AppSpec.Core.Decl.JSON () import qualified Wasp.AppSpec.Valid as ASV From 51cfaf88c615da0743784869d5651ab945ae2357 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 10 Feb 2025 19:00:22 -0300 Subject: [PATCH 08/13] Updated text --- waspc/src/Wasp/Project/WaspFile.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waspc/src/Wasp/Project/WaspFile.hs b/waspc/src/Wasp/Project/WaspFile.hs index fcc1ecf00d..e85eb1ca5c 100644 --- a/waspc/src/Wasp/Project/WaspFile.hs +++ b/waspc/src/Wasp/Project/WaspFile.hs @@ -32,7 +32,7 @@ findWaspFile waspDir = do let dotWaspPath = waspDir [relfile|.wasp|] isFile <- IOUtil.doesFileExist dotWaspPath if isFile - then return $ Left "Invalid file name for the .wasp file. Please rename it to [something].wasp." + then return $ Left "Your Wasp file can't be called just '.wasp'. Please rename it to [something].wasp." else do files <- fst <$> IOUtil.listDirectory waspDir return $ case (findWaspTsFile files, findWaspLangFile files) of From bd6aeb82d0f727afe368af4ed48983df84192146 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Tue, 11 Feb 2025 08:27:01 -0300 Subject: [PATCH 09/13] Review changes --- waspc/src/Wasp/Project/WaspFile.hs | 41 ++++++++++++++++-------------- waspc/src/Wasp/Util/StrongPath.hs | 5 ++++ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/waspc/src/Wasp/Project/WaspFile.hs b/waspc/src/Wasp/Project/WaspFile.hs index e85eb1ca5c..195555a337 100644 --- a/waspc/src/Wasp/Project/WaspFile.hs +++ b/waspc/src/Wasp/Project/WaspFile.hs @@ -26,32 +26,35 @@ import Wasp.Project.WaspFile.TypeScript (analyzeWaspTsFile) import Wasp.Project.WaspFile.WaspLang (analyzeWaspLangFile) import qualified Wasp.Psl.Ast.Schema as Psl.Schema import qualified Wasp.Util.IO as IOUtil +import Wasp.Util.StrongPath (findAllFilesWithSuffix) findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath) -findWaspFile waspDir = do - let dotWaspPath = waspDir [relfile|.wasp|] - isFile <- IOUtil.doesFileExist dotWaspPath - if isFile - then return $ Left "Your Wasp file can't be called just '.wasp'. Please rename it to [something].wasp." - else do - files <- fst <$> IOUtil.listDirectory waspDir - return $ case (findWaspTsFile files, findWaspLangFile files) of - (tsFiles, langFiles) - | not (null tsFiles) && not (null langFiles) -> Left bothFilesFoundMessage - | null tsFiles && null langFiles -> Left fileNotFoundMessage - | [waspTsFile] <- tsFiles, null langFiles -> Right waspTsFile - | null tsFiles, [waspLangFile] <- langFiles -> Right waspLangFile - | otherwise -> Left multipleFilesFoundMessage +findWaspFile projectDir = do + filesInProjectDir <- fst <$> IOUtil.listDirectory projectDir + let filesEndingWithWasp = findAllFilesWithSuffix ".wasp" filesInProjectDir + filesEndingWithWaspTs = findAllFilesWithSuffix ".wasp.ts" filesInProjectDir + return $ case (filesEndingWithWasp, filesEndingWithWaspTs) of + ([], []) -> Left fileNotFoundMessage + (_ : _, _ : _) -> Left bothFilesFoundMessage + ([], waspTsFiles) -> case waspTsFiles of + [singleWaspTsFile] -> + if fromRelFile singleWaspTsFile == ".wasp.ts" + then Left (invalidFileNameMessage ".wasp.ts") + else Right . WaspTs $ castFile (projectDir singleWaspTsFile) + multipleWaspTsFiles -> Left multipleFilesFoundMessage + (waspLangFiles, []) -> case waspLangFiles of + [singleWaspLangFile] -> + if fromRelFile singleWaspLangFile == ".wasp" + then Left (invalidFileNameMessage ".wasp") + else Right . WaspLang $ castFile (projectDir singleWaspLangFile) + multipleWaspTsFiles -> Left multipleFilesFoundMessage where - findWaspTsFile files = WaspTs <$> findFileThatEndsWith ".wasp.ts" files - findWaspLangFile files = WaspLang <$> findFileThatEndsWith ".wasp" files - findFileThatEndsWith suffix files = castFile . (waspDir ) <$> findFilesThatEndWith suffix files - findFilesThatEndWith suffix files = filter ((suffix `isSuffixOf`) . fromRelFile) files - fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the " ++ fromAbsDir waspDir ++ " directory" + fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the project 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." multipleFilesFoundMessage = "Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one." + invalidFileNameMessage fileExtension = "Your Wasp file can't be called '" ++ fileExtension ++ "'. Please rename it to something like [name]" ++ fileExtension ++ "." analyzeWaspFile :: Path' Abs (Dir WaspProjectDir) -> diff --git a/waspc/src/Wasp/Util/StrongPath.hs b/waspc/src/Wasp/Util/StrongPath.hs index bc66b967f5..55ea8bafb3 100644 --- a/waspc/src/Wasp/Util/StrongPath.hs +++ b/waspc/src/Wasp/Util/StrongPath.hs @@ -4,11 +4,13 @@ module Wasp.Util.StrongPath stripProperPrefix, splitAbsExtension, splitRelExtension, + findAllFilesWithSuffix, ) where import Control.Arrow (first) import Control.Monad.Catch (MonadThrow) +import Data.List (isSuffixOf) import qualified Path as P import qualified StrongPath as SP import qualified StrongPath.Path as SP @@ -33,3 +35,6 @@ splitAbsExtension path = splitRelExtension :: MonadThrow m => SP.Path' (SP.Rel b) (SP.File a) -> m (SP.Path' (SP.Rel b) (SP.File c), String) splitRelExtension path = first SP.fromPathRelFile <$> P.splitExtension (SP.toPathRelFile path) + +findAllFilesWithSuffix :: String -> [SP.Path p r (SP.File f)] -> [SP.Path p r (SP.File f)] +findAllFilesWithSuffix extension = filter ((extension `isSuffixOf`) . SP.toFilePath) \ No newline at end of file From 4f87c06845e64385c4a8eb4c4cc5e3bd2099a4cf Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Tue, 11 Feb 2025 08:30:10 -0300 Subject: [PATCH 10/13] Fix formatting --- waspc/src/Wasp/Util/StrongPath.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waspc/src/Wasp/Util/StrongPath.hs b/waspc/src/Wasp/Util/StrongPath.hs index 55ea8bafb3..5a55755205 100644 --- a/waspc/src/Wasp/Util/StrongPath.hs +++ b/waspc/src/Wasp/Util/StrongPath.hs @@ -37,4 +37,4 @@ splitRelExtension path = first SP.fromPathRelFile <$> P.splitExtension (SP.toPathRelFile path) findAllFilesWithSuffix :: String -> [SP.Path p r (SP.File f)] -> [SP.Path p r (SP.File f)] -findAllFilesWithSuffix extension = filter ((extension `isSuffixOf`) . SP.toFilePath) \ No newline at end of file +findAllFilesWithSuffix extension = filter ((extension `isSuffixOf`) . SP.toFilePath) From 5297fac67fd4c09e2287b0d4fbf768eb171bb35b Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 12 Feb 2025 08:45:30 -0300 Subject: [PATCH 11/13] Review changes --- waspc/src/Wasp/Project/WaspFile.hs | 17 +++++++---------- waspc/src/Wasp/Util/StrongPath.hs | 5 +++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/waspc/src/Wasp/Project/WaspFile.hs b/waspc/src/Wasp/Project/WaspFile.hs index 195555a337..3f962a7c55 100644 --- a/waspc/src/Wasp/Project/WaspFile.hs +++ b/waspc/src/Wasp/Project/WaspFile.hs @@ -4,15 +4,12 @@ module Wasp.Project.WaspFile ) where -import Data.List (find, isSuffixOf) import StrongPath ( Abs, Dir, Path', castFile, - fromAbsDir, fromRelFile, - relfile, (), ) import qualified Wasp.AppSpec as AS @@ -26,7 +23,7 @@ import Wasp.Project.WaspFile.TypeScript (analyzeWaspTsFile) import Wasp.Project.WaspFile.WaspLang (analyzeWaspLangFile) import qualified Wasp.Psl.Ast.Schema as Psl.Schema import qualified Wasp.Util.IO as IOUtil -import Wasp.Util.StrongPath (findAllFilesWithSuffix) +import Wasp.Util.StrongPath (findAllFilesWithSuffix, getFilename) findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath) findWaspFile projectDir = do @@ -39,22 +36,22 @@ findWaspFile projectDir = do ([], waspTsFiles) -> case waspTsFiles of [singleWaspTsFile] -> if fromRelFile singleWaspTsFile == ".wasp.ts" - then Left (invalidFileNameMessage ".wasp.ts") + then Left (makeInvalidFileNameMessage ".wasp.ts") else Right . WaspTs $ castFile (projectDir singleWaspTsFile) - multipleWaspTsFiles -> Left multipleFilesFoundMessage + multipleWaspTsFiles -> Left (makeMultipleFilesMessage "*.wasp.ts" (map getFilename multipleWaspTsFiles)) (waspLangFiles, []) -> case waspLangFiles of [singleWaspLangFile] -> if fromRelFile singleWaspLangFile == ".wasp" - then Left (invalidFileNameMessage ".wasp") + then Left (makeInvalidFileNameMessage ".wasp") else Right . WaspLang $ castFile (projectDir singleWaspLangFile) - multipleWaspTsFiles -> Left multipleFilesFoundMessage + multipleWaspFiles -> Left (makeMultipleFilesMessage "*.wasp" (map getFilename multipleWaspFiles)) where fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the project 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." - multipleFilesFoundMessage = "Found multiple *.wasp or *.wasp.ts files in the project directory. Please keep only one." - invalidFileNameMessage fileExtension = "Your Wasp file can't be called '" ++ fileExtension ++ "'. Please rename it to something like [name]" ++ fileExtension ++ "." + makeMultipleFilesMessage suffix files = "Found multiple " ++ suffix ++ " files in the project directory: " ++ show files ++ ". Please keep only one." + makeInvalidFileNameMessage suffix = "Your Wasp file can't be called '" ++ suffix ++ "'. Please rename it to something like [name]" ++ suffix ++ "." analyzeWaspFile :: Path' Abs (Dir WaspProjectDir) -> diff --git a/waspc/src/Wasp/Util/StrongPath.hs b/waspc/src/Wasp/Util/StrongPath.hs index 5a55755205..3e8faa9641 100644 --- a/waspc/src/Wasp/Util/StrongPath.hs +++ b/waspc/src/Wasp/Util/StrongPath.hs @@ -5,6 +5,7 @@ module Wasp.Util.StrongPath splitAbsExtension, splitRelExtension, findAllFilesWithSuffix, + getFilename, ) where @@ -14,6 +15,7 @@ import Data.List (isSuffixOf) import qualified Path as P import qualified StrongPath as SP import qualified StrongPath.Path as SP +import System.FilePath (takeFileName) stripProperPrefix :: SP.Path' SP.Abs (SP.Dir a) -> SP.Path' SP.Abs (SP.File b) -> Maybe (SP.Path' (SP.Rel a) (SP.File b)) stripProperPrefix base file = @@ -38,3 +40,6 @@ splitRelExtension path = findAllFilesWithSuffix :: String -> [SP.Path p r (SP.File f)] -> [SP.Path p r (SP.File f)] findAllFilesWithSuffix extension = filter ((extension `isSuffixOf`) . SP.toFilePath) + +getFilename :: SP.Path' (SP.Rel b) (SP.File a) -> String +getFilename = takeFileName . SP.toFilePath From c77c0cbdfd24d5ad432d48f499b5f7babffc06e5 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 12 Feb 2025 08:51:37 -0300 Subject: [PATCH 12/13] Added pattern matching --- waspc/src/Wasp/Project/WaspFile.hs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/waspc/src/Wasp/Project/WaspFile.hs b/waspc/src/Wasp/Project/WaspFile.hs index 3f962a7c55..ed1879c632 100644 --- a/waspc/src/Wasp/Project/WaspFile.hs +++ b/waspc/src/Wasp/Project/WaspFile.hs @@ -9,7 +9,6 @@ import StrongPath Dir, Path', castFile, - fromRelFile, (), ) import qualified Wasp.AppSpec as AS @@ -34,16 +33,14 @@ findWaspFile projectDir = do ([], []) -> Left fileNotFoundMessage (_ : _, _ : _) -> Left bothFilesFoundMessage ([], waspTsFiles) -> case waspTsFiles of - [singleWaspTsFile] -> - if fromRelFile singleWaspTsFile == ".wasp.ts" - then Left (makeInvalidFileNameMessage ".wasp.ts") - else Right . WaspTs $ castFile (projectDir singleWaspTsFile) + [singleWaspTsFile] + | getFilename singleWaspTsFile == ".wasp.ts" -> Left (makeInvalidFileNameMessage ".wasp.ts") + | otherwise -> Right . WaspTs $ castFile (projectDir singleWaspTsFile) multipleWaspTsFiles -> Left (makeMultipleFilesMessage "*.wasp.ts" (map getFilename multipleWaspTsFiles)) (waspLangFiles, []) -> case waspLangFiles of - [singleWaspLangFile] -> - if fromRelFile singleWaspLangFile == ".wasp" - then Left (makeInvalidFileNameMessage ".wasp") - else Right . WaspLang $ castFile (projectDir singleWaspLangFile) + [singleWaspLangFile] + | getFilename singleWaspLangFile == ".wasp" -> Left (makeInvalidFileNameMessage ".wasp") + | otherwise -> Right . WaspLang $ castFile (projectDir singleWaspLangFile) multipleWaspFiles -> Left (makeMultipleFilesMessage "*.wasp" (map getFilename multipleWaspFiles)) where fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the project directory." From 44da7bbb4706c2619ba27443f90641bbeb065164 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 12 Feb 2025 09:44:02 -0300 Subject: [PATCH 13/13] Removed unused function --- waspc/src/Wasp/Project/WaspFile.hs | 11 ++++++----- waspc/src/Wasp/Util/StrongPath.hs | 5 ----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/waspc/src/Wasp/Project/WaspFile.hs b/waspc/src/Wasp/Project/WaspFile.hs index ed1879c632..f64e76ac7c 100644 --- a/waspc/src/Wasp/Project/WaspFile.hs +++ b/waspc/src/Wasp/Project/WaspFile.hs @@ -9,6 +9,7 @@ import StrongPath Dir, Path', castFile, + fromRelFile, (), ) import qualified Wasp.AppSpec as AS @@ -22,7 +23,7 @@ import Wasp.Project.WaspFile.TypeScript (analyzeWaspTsFile) import Wasp.Project.WaspFile.WaspLang (analyzeWaspLangFile) import qualified Wasp.Psl.Ast.Schema as Psl.Schema import qualified Wasp.Util.IO as IOUtil -import Wasp.Util.StrongPath (findAllFilesWithSuffix, getFilename) +import Wasp.Util.StrongPath (findAllFilesWithSuffix) findWaspFile :: Path' Abs (Dir WaspProjectDir) -> IO (Either String WaspFilePath) findWaspFile projectDir = do @@ -34,14 +35,14 @@ findWaspFile projectDir = do (_ : _, _ : _) -> Left bothFilesFoundMessage ([], waspTsFiles) -> case waspTsFiles of [singleWaspTsFile] - | getFilename singleWaspTsFile == ".wasp.ts" -> Left (makeInvalidFileNameMessage ".wasp.ts") + | fromRelFile singleWaspTsFile == ".wasp.ts" -> Left (makeInvalidFileNameMessage ".wasp.ts") | otherwise -> Right . WaspTs $ castFile (projectDir singleWaspTsFile) - multipleWaspTsFiles -> Left (makeMultipleFilesMessage "*.wasp.ts" (map getFilename multipleWaspTsFiles)) + multipleWaspTsFiles -> Left (makeMultipleFilesMessage "*.wasp.ts" (map fromRelFile multipleWaspTsFiles)) (waspLangFiles, []) -> case waspLangFiles of [singleWaspLangFile] - | getFilename singleWaspLangFile == ".wasp" -> Left (makeInvalidFileNameMessage ".wasp") + | fromRelFile singleWaspLangFile == ".wasp" -> Left (makeInvalidFileNameMessage ".wasp") | otherwise -> Right . WaspLang $ castFile (projectDir singleWaspLangFile) - multipleWaspFiles -> Left (makeMultipleFilesMessage "*.wasp" (map getFilename multipleWaspFiles)) + multipleWaspFiles -> Left (makeMultipleFilesMessage "*.wasp" (map fromRelFile multipleWaspFiles)) where fileNotFoundMessage = "Couldn't find the *.wasp or a *.wasp.ts file in the project directory." bothFilesFoundMessage = diff --git a/waspc/src/Wasp/Util/StrongPath.hs b/waspc/src/Wasp/Util/StrongPath.hs index 3e8faa9641..5a55755205 100644 --- a/waspc/src/Wasp/Util/StrongPath.hs +++ b/waspc/src/Wasp/Util/StrongPath.hs @@ -5,7 +5,6 @@ module Wasp.Util.StrongPath splitAbsExtension, splitRelExtension, findAllFilesWithSuffix, - getFilename, ) where @@ -15,7 +14,6 @@ import Data.List (isSuffixOf) import qualified Path as P import qualified StrongPath as SP import qualified StrongPath.Path as SP -import System.FilePath (takeFileName) stripProperPrefix :: SP.Path' SP.Abs (SP.Dir a) -> SP.Path' SP.Abs (SP.File b) -> Maybe (SP.Path' (SP.Rel a) (SP.File b)) stripProperPrefix base file = @@ -40,6 +38,3 @@ splitRelExtension path = findAllFilesWithSuffix :: String -> [SP.Path p r (SP.File f)] -> [SP.Path p r (SP.File f)] findAllFilesWithSuffix extension = filter ((extension `isSuffixOf`) . SP.toFilePath) - -getFilename :: SP.Path' (SP.Rel b) (SP.File a) -> String -getFilename = takeFileName . SP.toFilePath