Improve how we generate code (especially SDK) during `wasp build`
Update: Read the comment below for the latest info
Original description
Since after restructuring we have the line "wasp": "file:.wasp/out/sdk/wasp", in user's package.json, this meant that we also need to change something about how Wasp project is built.
Why? Because wasp build generates code in .wasp/build, while wasp start generates wasp code in .wasp/out. This was done on purpose, because we didn't want those two to mix, since the generated code can be (and is, although not a lot) different.
So wasp start generates framework code + SDK code in .wasp/out, and that code imports and uses user's code from the root of the project.
wasp build works the same way, but writes generated framework code + SDK code into ./wasp/build.
The problem, as I said above, is that now, with restructuring, this won't work well for code generated with wasp build because user's code, via its package.json, depends on SDK in .wasp/out/sdk, while it should depend on SDK in ./wasp/build/sdk.
We discussed how to best fix this, and what we did for the moment, is had wasp build write its SDK code into ./wasp/out/sdk instead of ./wasp/build/sdk, overwriting ./wasp/out/sdk.
This is a hack, but it is not problematic because currently SDK is exactly the same code be it for wasp start or wasp build -> code is different for generated framework code, but not for SDK.
Also, we did this in a bit hacky fashion in the code: search for ../out/sdk/wasp in the codebase to see what was done.
We should however look into a nicer solution, because this one is, as mentioned, somewhat hacky, and also could be causing some issues if in the future there would appear some differences between the SDK code generated for the wasp start and the one generated for the wasp build.
What seems to be the best idea for the future is to also copy all the user's code into the .wasp/build directory, instead of leaving the user's code as it is. Then, when copying that code, we can rewrite its package.json to have a different path for importing SDK, one that imports the SDK generated by wasp build. One way to do it is to put user's code somewhere next to generated and framework code, update imports of user's code in the generated code as needed, and that should work. Or, another idea is to copy the user's code into .wasp/build, but then not generate the framework and SDK code directly in .wasp/build, but put it two levels lower, potentially in .wasp/build/.wasp/out -> this way we replicate the relative paths among generated code and user's code, and don't have to modify imports of user's code. Maybe there are some better ideas also.
What is important here is copying user's code -> this sounds right. It enables us to do any rewrites if needed. It also means that if user does wasp build and then changes something in their user code, those later changes won't be reflected in the built code, as one would expect -> what one expects from wasp build is that whatever is built there is based on the state of the code as it was at the moment of running wasp build, and is standalone, encapsulated.
TODO: Link to a PR where we made the hacky fix.
Source: wasp-lang/wasp