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

Adapt the wasp clean command and fix dep installation #1603

Merged
merged 74 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
da8b259
Early prototype
sodic Nov 4, 2023
0d7087f
Add prototype migration script and fix some issues
sodic Nov 15, 2023
e3fdecc
Merge branch 'main' into filip-restructuring-prototype
sodic Nov 15, 2023
6789cd5
Update the todo-ts prototype version to match main
sodic Nov 16, 2023
eb338c6
Switch user files to the new (vertical) structure in prototype
sodic Nov 17, 2023
35c9efa
Prototype with direct imports works in development
sodic Nov 21, 2023
d51e64b
Fix typo in package.json
sodic Nov 21, 2023
22c7706
Revert cosmetic updates to todo-typescript example apps
sodic Nov 23, 2023
02bdcbe
Remove old queries files
sodic Nov 24, 2023
1002c4b
Remove extra dependencies from auth package
sodic Nov 24, 2023
8d39046
Remove completed todo
sodic Nov 24, 2023
3fd2f16
Remove redundant server types
sodic Nov 24, 2023
20b5ef7
Remove redundant exports from operations
sodic Nov 24, 2023
577c6cf
Remove redundant dependencies and package lock
sodic Nov 24, 2023
3da3f52
Remove npm install skip
sodic Nov 24, 2023
3ceb92d
Fix formatting
sodic Nov 24, 2023
1c6a12f
Make migrate script more portable
sodic Nov 24, 2023
d22922d
Turn scoped package into a single package
sodic Nov 30, 2023
49c85e0
Generate SDK from templates in prototype
sodic Dec 8, 2023
a02e047
Add project and sdk depdency installation
sodic Dec 11, 2023
fbbda45
Remove redundant npm install message
sodic Dec 11, 2023
3606f45
Add package.json to AppSpec
sodic Dec 14, 2023
6ece919
Handle dependencies through package.json
sodic Dec 15, 2023
6ad7c54
Implement wasp reset
sodic Dec 15, 2023
fba7e16
Remove redundant import
sodic Dec 15, 2023
df7d9e1
Merge branch 'filip-project-install-step' into filip-wasp-reset
sodic Dec 15, 2023
d8f9ee2
Fix double installation of dependencies
sodic Dec 18, 2023
52c547b
Move prisma client to top-level node_modules
sodic Dec 18, 2023
a1dfcdd
Rename args to cmdArgs
sodic Dec 19, 2023
a985446
Fix formatting
sodic Dec 19, 2023
53ac450
Fix formatting
sodic Dec 19, 2023
ea5a4c1
Remove @prisma/client from project deps
sodic Dec 19, 2023
b4f813e
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
sodic Dec 19, 2023
45a827f
Merge branch 'filip-project-install-step' into filip-wasp-reset
sodic Dec 19, 2023
afdb509
Merge branch 'main' into filip-restructuring-prototype
sodic Jan 4, 2024
a5a7382
Make prototype work with inject auth changes
sodic Jan 8, 2024
3de8205
Merge branch 'filip-restructuring-prototype' into filip-project-insta…
sodic Jan 8, 2024
2459306
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
sodic Jan 9, 2024
06fc466
Merge branch 'filip-project-install-step' into filip-wasp-reset
sodic Jan 9, 2024
1999b21
Add fix and cleanstart scripts
sodic Jan 10, 2024
60ae566
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
sodic Jan 10, 2024
b43e704
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
sodic Jan 10, 2024
d17fbe9
Fix deps duplication in restructuring
sodic Jan 17, 2024
ba1c358
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
sodic Jan 17, 2024
aa0d496
Dedups probably fixes duplicate React
infomiho Jan 17, 2024
79bf3cd
Change React plugin
infomiho Jan 18, 2024
754fb29
fix
Martinsos Jan 18, 2024
2749b95
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
Martinsos Jan 18, 2024
24c8d78
fix
Martinsos Jan 18, 2024
0894f5f
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
Martinsos Jan 19, 2024
c13216d
fix
Martinsos Jan 19, 2024
667a31b
Merge branch 'main' into filip-restructuring-prototype
infomiho Jan 19, 2024
2d44d9c
Reverted stdout prefix to similar how Filip improved it.
Martinsos Jan 19, 2024
36f73c9
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
Martinsos Jan 19, 2024
a1ac860
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
Martinsos Jan 19, 2024
1146237
Updated docs regarding dependencies.
Martinsos Jan 19, 2024
6061e8f
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
Martinsos Jan 19, 2024
23f2e85
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
Martinsos Jan 19, 2024
a35040e
Apply latest auth changes to the prototype (#1646)
infomiho Jan 19, 2024
662219c
Merge branch 'filip-restructuring-prototype' into filip-project-insta…
sodic Jan 21, 2024
453986c
Fix types after merge
sodic Jan 21, 2024
38ffdd3
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
sodic Jan 21, 2024
66682ff
Fixes HttpError and AuthError instanceof bug (#1648)
infomiho Jan 21, 2024
24b2540
Fix problems after merge
sodic Jan 21, 2024
66a68c9
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
sodic Jan 21, 2024
7e8ae2c
Removed redundant TODOs
Martinsos Jan 21, 2024
79526b2
Fix npm installation in restructuring (#1652)
Martinsos Jan 25, 2024
8588660
Merge branch 'main' into filip-restructuring-prototype
sodic Jan 29, 2024
f85daea
Merge branch 'filip-restructuring-prototype' into filip-project-insta…
sodic Jan 29, 2024
ca188eb
Merge branch 'filip-project-install-step' into filip-restructuring-pr…
sodic Jan 29, 2024
6c26c91
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
sodic Jan 29, 2024
a3951a2
Merge branch 'filip-restructuring' into filip-restructuring-prisma
sodic Jan 29, 2024
009ceb8
Merge branch 'filip-restructuring-prisma' into filip-wasp-reset
sodic Jan 29, 2024
b71d7ea
Merge branch 'filip-restructuring' into filip-wasp-reset
sodic Jan 29, 2024
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
4 changes: 1 addition & 3 deletions waspc/cli/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Wasp.Cli.Command.CreateNewProject (createNewProject)
import qualified Wasp.Cli.Command.CreateNewProject.AI as Command.CreateNewProject.AI
import Wasp.Cli.Command.Db (runDbCommand)
import qualified Wasp.Cli.Command.Db.Migrate as Command.Db.Migrate
import qualified Wasp.Cli.Command.Db.Reset as Command.Db.Reset
import qualified Wasp.Cli.Command.Db.Seed as Command.Db.Seed
import qualified Wasp.Cli.Command.Db.Studio as Command.Db.Studio
import Wasp.Cli.Command.Deploy (deploy)
Expand Down Expand Up @@ -158,7 +157,7 @@ printUsage =
cmd " start Runs Wasp app in development mode, watching for file changes.",
cmd " start db Starts managed development database for you.",
cmd " db <db-cmd> [args] Executes a database command. Run 'wasp db' for more info.",
cmd " clean Deletes all generated code and other cached artifacts.",
cmd " clean Deletes all generated code, all cached artifacts, and the node_modules dir.",
" Wasp equivalent of 'have you tried closing and opening it again?'.",
cmd " build Generates full web app code, ready for deployment. Use when deploying or ejecting.",
cmd " deploy Deploys your Wasp app to cloud hosting providers.",
Expand Down Expand Up @@ -200,7 +199,6 @@ dbCli :: [String] -> IO ()
dbCli args = case args of
["start"] -> runCommand Command.Start.Db.start
"migrate-dev" : optionalMigrateArgs -> runDbCommand $ Command.Db.Migrate.migrateDev optionalMigrateArgs
["reset"] -> runDbCommand Command.Db.Reset.reset
["seed"] -> runDbCommand $ Command.Db.Seed.seed Nothing
["seed", seedName] -> runDbCommand $ Command.Db.Seed.seed $ Just seedName
["studio"] -> runDbCommand Command.Db.Studio.studio
Expand Down
21 changes: 20 additions & 1 deletion waspc/cli/src/Wasp/Cli/Command/BashCompletion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ bashCompletion = do
["db", cmdPrefix] -> listMatchingCommands cmdPrefix dbSubCommands
_ -> liftIO . putStrLn $ ""
where
commands = ["new", "version", "waspls", "start", "db", "clean", "uninstall", "build", "telemetry", "deps", "info", "completion", "completion:generate"]
commands =
[ "new",
"new:ai",
"version",
"waspls",
"completion",
"completion:generate",
"uninstall",
"start",
"db",
"clean",
"build",
"deploy",
"telemetry",
"deps",
"dockerfile",
"info",
"test",
"studio"
]
dbSubCommands = ["migrate-dev", "studio"]
listMatchingCommands :: String -> [String] -> Command ()
listMatchingCommands cmdPrefix cmdList = listCommands $ filter (cmdPrefix `isPrefixOf`) cmdList
Expand Down
24 changes: 8 additions & 16 deletions waspc/cli/src/Wasp/Cli/Command/Clean.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ module Wasp.Cli.Command.Clean
)
where

import Control.Monad.IO.Class (liftIO)
import qualified StrongPath as SP
import System.Directory
( doesDirectoryExist,
removeDirectoryRecursive,
)
import Wasp.Cli.Command (Command)
import Wasp.Cli.Command.Message (cliSendMessageC)
import Wasp.Cli.Command.Common (deleteDirectoryIfExistsVerbosely)
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
import qualified Wasp.Message as Msg
import Wasp.Project.Common (dotWaspDirInWaspProjectDir)
import Wasp.Project.Common (dotWaspDirInWaspProjectDir, nodeModulesDirInWaspProjectDir)

clean :: Command ()
clean = do
InWaspProject waspProjectDir <- require
let dotWaspDirFp = SP.toFilePath $ waspProjectDir SP.</> dotWaspDirInWaspProjectDir
cliSendMessageC $ Msg.Start "Deleting .wasp/ directory..."
doesDotWaspDirExist <- liftIO $ doesDirectoryExist dotWaspDirFp
if doesDotWaspDirExist
then do
liftIO $ removeDirectoryRecursive dotWaspDirFp
cliSendMessageC $ Msg.Success "Deleted .wasp/ directory."
else cliSendMessageC $ Msg.Success "Nothing to delete: .wasp directory does not exist."

let dotWaspDir = waspProjectDir SP.</> dotWaspDirInWaspProjectDir
let nodeModulesDir = waspProjectDir SP.</> nodeModulesDirInWaspProjectDir

deleteDirectoryIfExistsVerbosely dotWaspDir
deleteDirectoryIfExistsVerbosely nodeModulesDir
21 changes: 20 additions & 1 deletion waspc/cli/src/Wasp/Cli/Command/Common.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
module Wasp.Cli.Command.Common
( readWaspCompileInfo,
throwIfExeIsNotAvailable,
deleteDirectoryIfExistsVerbosely,
)
where

import Control.Monad.Except
import qualified Control.Monad.Except as E
import StrongPath (Abs, Dir, Path')
import qualified StrongPath as SP
import StrongPath.Operations
import System.Directory (findExecutable)
import System.Directory
( findExecutable,
)
import Wasp.Cli.Command (Command, CommandError (..))
import Wasp.Cli.Command.Message (cliSendMessageC)
import qualified Wasp.Message as Msg
import Wasp.Project (WaspProjectDir)
import qualified Wasp.Project.Common as Project.Common
import Wasp.Util (ifM)
Expand All @@ -34,3 +40,16 @@ throwIfExeIsNotAvailable exeName explanationMsg = do
Nothing ->
E.throwError $
CommandError ("Couldn't find `" <> exeName <> "` executable") explanationMsg

deleteDirectoryIfExistsVerbosely :: Path' Abs (Dir d) -> Command ()
deleteDirectoryIfExistsVerbosely dir = do
cliSendMessageC $ Msg.Start $ "Deleting the " ++ dirName ++ " directory..."
dirExist <- liftIO $ IOUtil.doesDirectoryExist dir
if dirExist
then do
liftIO $ IOUtil.removeDirectory dir
cliSendMessageC $ Msg.Success $ "Deleted the " ++ dirName ++ " directory."
else do
cliSendMessageC $ Msg.Success $ "Nothing to delete: The " ++ dirName ++ " directory does not exist."
where
dirName = SP.toFilePath $ basename dir
64 changes: 41 additions & 23 deletions waspc/cli/src/Wasp/Cli/Command/Watch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,50 @@ import Wasp.Cli.Message (cliSendMessage)
import qualified Wasp.Generator.Common as Wasp.Generator
import qualified Wasp.Message as Msg
import Wasp.Project (CompileError, CompileWarning, WaspProjectDir)
import Wasp.Project.Common (extClientCodeDirInWaspProjectDir, extServerCodeDirInWaspProjectDir, extSharedCodeDirInWaspProjectDir)
import Wasp.Project.Common (srcDirInWaspProjectDir)

-- TODO: Idea: Read .gitignore file, and ignore everything from it. This will then also cover the
-- .wasp dir, and users can easily add any custom stuff they want ignored. But, we also have to
-- be ready for the case when there is no .gitignore, that could be possible.

-- | Forever listens for any file changes in waspProjectDir, and if there is a change,
-- compiles Wasp source files in waspProjectDir and regenerates files in outDir.
-- It will defer recompilation until no new change was detected in the last second.
-- It also takes 'ongoingCompilationResultMVar' MVar, into which it stores the result
-- (warnings, errors) of the latest (re)compile whenever it happens. If there is already
-- something in the MVar, it will get overwritten.
-- | Forever listens for any file changes at the very top level of @waspProjectDir@, and also for
-- any changes at any depth in the @waspProjectDir@/src/ dir. If there is a change, compiles Wasp
-- source files in @waspProjectDir@ and regenerates files in @outDir@. It will defer recompilation
-- until no new change was detected in the last second. It also takes 'ongoingCompilationResultMVar'
-- MVar, into which it stores the result (warnings, errors) of the latest (re)compile whenever it
-- happens. If there is already something in the MVar, it will get overwritten.
watch ::
Path' Abs (Dir WaspProjectDir) ->
Path' Abs (Dir Wasp.Generator.ProjectRootDir) ->
MVar ([CompileWarning], [CompileError]) ->
IO ()
watch waspProjectDir outDir ongoingCompilationResultMVar = FSN.withManager $ \mgr -> do
currentTime <- getCurrentTime
chan <- newChan
_ <- FSN.watchDirChan mgr (SP.fromAbsDir waspProjectDir) eventFilter chan
let watchProjectSubdirTree path = FSN.watchTreeChan mgr (SP.fromAbsDir $ waspProjectDir </> path) eventFilter chan
_ <- watchProjectSubdirTree extClientCodeDirInWaspProjectDir
_ <- watchProjectSubdirTree extServerCodeDirInWaspProjectDir
_ <- watchProjectSubdirTree extSharedCodeDirInWaspProjectDir
listenForEvents chan currentTime
_ <- watchFilesAtTopLevelOfWaspProjectDir mgr chan
_ <- watchFilesAtAllLevelsOfSrcDirInWaspProjectDir mgr chan
listenForEvents chan =<< getCurrentTime
where
watchFilesAtTopLevelOfWaspProjectDir mgr chan =
FSN.watchDirChan mgr (SP.fromAbsDir waspProjectDir) eventFilter chan
where
eventFilter :: FSN.Event -> Bool
eventFilter event =
-- TODO: Might be valuable to also filter out files from .gitignore.
not (isEditorTmpFile filename)
&& filename /= "package-lock.json"
where
filename = FP.takeFileName $ FSN.eventPath event

watchFilesAtAllLevelsOfSrcDirInWaspProjectDir mgr chan =
FSN.watchTreeChan mgr (SP.fromAbsDir $ waspProjectDir </> srcDirInWaspProjectDir) eventFilter chan
where
eventFilter :: FSN.Event -> Bool
eventFilter event =
-- TODO: Might be valuable to also filter out files from .gitignore.
not (isEditorTmpFile filename)
where
filename = FP.takeFileName $ FSN.eventPath event

listenForEvents :: Chan FSN.Event -> UTCTime -> IO ()
listenForEvents chan lastCompileTime = do
event <- readChan chan
Expand Down Expand Up @@ -114,12 +131,13 @@ watch waspProjectDir outDir ongoingCompilationResultMVar = FSN.withManager $ \mg
-- create next to the source code. Bad thing here is that users can't modify this,
-- so better approach would be probably to use information from .gitignore instead, or
-- maybe combining the two somehow.
eventFilter :: FSN.Event -> Bool
eventFilter event =
let filename = FP.takeFileName $ FSN.eventPath event
in not (null filename)
&& take 2 filename /= ".#" -- Ignore emacs lock files.
&& not (head filename == '#' && last filename == '#') -- Ignore emacs auto-save files.
&& last filename /= '~' -- Ignore emacs and vim backup files.
&& not (head filename == '.' && ".swp" `isSuffixOf` filename) -- Ignore vim swp files.
&& not (head filename == '.' && ".un~" `isSuffixOf` filename) -- Ignore vim undo files.
isEditorTmpFile :: String -> Bool
isEditorTmpFile "" = False
isEditorTmpFile filename =
or
[ take 2 filename == ".#", -- Emacs lock files.
head filename == '#' && last filename == '#', -- Emacs auto-save files.
last filename == '~', -- Emacs and vim backup files.
head filename == '.' && ".swp" `isSuffixOf` filename, -- Vim swp files.
head filename == '.' && ".un~" `isSuffixOf` filename -- Vim undo files.
]
35 changes: 22 additions & 13 deletions waspc/src/Wasp/Generator/NpmDependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ module Wasp.Generator.NpmDependencies
( DependencyConflictError (..),
getDependenciesPackageJsonEntry,
getDevDependenciesPackageJsonEntry,
getUserNpmDepsForPackage,
combineNpmDepsForPackage,
NpmDepsForPackage (..),
NpmDepsForPackageError (..),
conflictErrorToMessage,
genNpmDepsForPackage,
NpmDepsForFullStack,
NpmDepsForFramework,
NpmDepsForWasp (..),
NpmDepsForUser (..),
buildNpmDepsForFullStack,
buildWaspFrameworkNpmDeps,
)
where

Expand All @@ -27,23 +28,26 @@ import qualified Wasp.AppSpec.App.Dependency as D
import qualified Wasp.AppSpec.PackageJson as AS.PackageJson
import Wasp.Generator.Monad (Generator, GeneratorError (..), logAndThrowGeneratorError)

data NpmDepsForFullStack = NpmDepsForFullStack
data NpmDepsForFramework = NpmDepsForFramework
{ npmDepsForServer :: NpmDepsForPackage,
npmDepsForWebApp :: NpmDepsForPackage
}
deriving (Show, Eq, Generic)

instance ToJSON NpmDepsForFullStack where
toEncoding = genericToEncoding defaultOptions
instance ToJSON NpmDepsForFramework

instance FromJSON NpmDepsForFullStack
instance FromJSON NpmDepsForFramework

data NpmDepsForPackage = NpmDepsForPackage
{ dependencies :: [D.Dependency],
devDependencies :: [D.Dependency]
}
deriving (Show, Generic)

instance ToJSON NpmDepsForPackage

instance FromJSON NpmDepsForPackage

data NpmDepsForWasp = NpmDepsForWasp
{ waspDependencies :: [D.Dependency],
waspDevDependencies :: [D.Dependency]
Expand All @@ -54,12 +58,11 @@ data NpmDepsForUser = NpmDepsForUser
{ userDependencies :: [D.Dependency],
userDevDependencies :: [D.Dependency]
}
deriving (Show)
deriving (Show, Eq, Generic)

instance ToJSON NpmDepsForPackage where
toEncoding = genericToEncoding defaultOptions
instance ToJSON NpmDepsForUser

instance FromJSON NpmDepsForPackage
instance FromJSON NpmDepsForUser

data NpmDepsForPackageError = NpmDepsForPackageError
{ dependenciesConflictErrors :: [DependencyConflictError],
Expand Down Expand Up @@ -89,12 +92,12 @@ genNpmDepsForPackage spec npmDepsForWasp =
++ devDependenciesConflictErrors conflictErrorDeps
)

buildNpmDepsForFullStack :: AppSpec -> NpmDepsForWasp -> NpmDepsForWasp -> Either String NpmDepsForFullStack
buildNpmDepsForFullStack spec forServer forWebApp =
buildWaspFrameworkNpmDeps :: AppSpec -> NpmDepsForWasp -> NpmDepsForWasp -> Either String NpmDepsForFramework
buildWaspFrameworkNpmDeps spec forServer forWebApp =
case (combinedServerDeps, combinedWebAppDeps) of
(Right a, Right b) ->
Right
NpmDepsForFullStack
NpmDepsForFramework
{ npmDepsForServer = a,
npmDepsForWebApp = b
}
Expand Down Expand Up @@ -135,6 +138,12 @@ sortedDependencies a = (sort $ dependencies a, sort $ devDependencies a)
-- to combine them together, returning (Right) a new NpmDepsForPackage
-- that combines them, and on error (Left), returns a NpmDepsForPackageError
-- which describes which dependencies are in conflict.
-- TODO: The comment above and function name are not exactly correct any more,
-- as user deps don't get combined with the wasp deps any more, instead user deps
-- are just checked against wasp deps to see if there are any conflicts, and then
-- wasp deps are more or less returned as they are (maybe with some changes? But certainly no user deps added).
-- This function deserves rewriting / rethinking. This should be addressed while solving
-- GH issue https://github.com/wasp-lang/wasp/issues/1644 .
combineNpmDepsForPackage :: NpmDepsForWasp -> NpmDepsForUser -> Either NpmDepsForPackageError NpmDepsForPackage
combineNpmDepsForPackage npmDepsForWasp npmDepsForUser =
if null conflictErrors && null devConflictErrors
Expand Down
Loading
Loading