On each wasp build you have to wait for node_modules to get reinstalled, completely from scratch, which is a PITA.
Here is the "offending" line: https://github.com/wasp-lang/wasp/blob/main/waspc/cli/src/Wasp/Cli/Command/Build.hs#L47 -> we delete the whole .wasp/build dir when creating new build. The idea behind this is to make sure we have clean start, that nothing from the previous build is by accident left over.
But this cleans up node_modules, so they have to be installed from scratch every time!
Potential solution is to remove everything but node_modules. But what if some redundant stuff is left in them from before? Well I think it doesn't matter, they are anyway not getting deployed, it is instead expected that when you deploy you do npm build (it is what we do in our Docker container for deploying server).
There is another thing I wonder here though -> why do we even need node_modules for wasp build? We are just producing code that is to be deployed -> Docker container is anyway building node_modules on its own from what I see, and doing prisma generation and stuff. I think we let wasp build install node_modules because we normally do that after generating code and we just reused logic for that, but it might actually be redundant in this case, and we could possibly just remove it!
We also run migration checks here, which are not really needed? Check the related issue linked in the next comment.
Proposal:
try skipping the installation of node_modules in the case when doing wasp build.
Place to do this is in Wasp.Generator.writeWebAppCode -> we call runSetup there after code generation. Well, we should not call it when doing wasp build! What is the purpose of runSetup anyway, what is it setting up? We should also note that writeWebbAppCode doesn't mention in its name or its header comment that it will do any setup, which is misleading. So I think we should figure out exactly what this setup is, maybe it is dev setup really, rename runSetup function accordingly, and then also make sure we have two versions of writeWebAppCode function -> one that doesn't call setup, and one that calls setup (but then the name should reflect it). Or, we have just one that doesn't call setup, and then the caller of it will call the setup after it if it wants.
If it turns out that we do need setup for wasp build, well then we can just try to not delete the node_modules/ directory when clearing up the .wasp/build/ dir, that will already make re-builds much faster.
Inspired by this thread: https://discord.com/channels/686873244791210014/1098143517936734319/1098143517936734319 .
On each
wasp build
you have to wait for node_modules to get reinstalled, completely from scratch, which is a PITA. Here is the "offending" line: https://github.com/wasp-lang/wasp/blob/main/waspc/cli/src/Wasp/Cli/Command/Build.hs#L47 -> we delete the whole .wasp/build dir when creating new build. The idea behind this is to make sure we have clean start, that nothing from the previous build is by accident left over.But this cleans up node_modules, so they have to be installed from scratch every time!
Potential solution is to remove everything but node_modules. But what if some redundant stuff is left in them from before? Well I think it doesn't matter, they are anyway not getting deployed, it is instead expected that when you deploy you do npm build (it is what we do in our Docker container for deploying server).
There is another thing I wonder here though -> why do we even need node_modules for
wasp build
? We are just producing code that is to be deployed -> Docker container is anyway building node_modules on its own from what I see, and doing prisma generation and stuff. I think we letwasp build
install node_modules because we normally do that after generating code and we just reused logic for that, but it might actually be redundant in this case, and we could possibly just remove it!We also run migration checks here, which are not really needed? Check the related issue linked in the next comment.
Proposal:
wasp build
. Place to do this is inWasp.Generator.writeWebAppCode
-> we callrunSetup
there after code generation. Well, we should not call it when doingwasp build
! What is the purpose ofrunSetup
anyway, what is it setting up? We should also note thatwriteWebbAppCode
doesn't mention in its name or its header comment that it will do any setup, which is misleading. So I think we should figure out exactly what this setup is, maybe it is dev setup really, renamerunSetup
function accordingly, and then also make sure we have two versions ofwriteWebAppCode
function -> one that doesn't call setup, and one that calls setup (but then the name should reflect it). Or, we have just one that doesn't call setup, and then the caller of it will call the setup after it if it wants.wasp build
, well then we can just try to not delete the node_modules/ directory when clearing up the .wasp/build/ dir, that will already make re-builds much faster.