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

Restructuring prototype RFC #1584

Merged
merged 25 commits into from
Jan 29, 2024
Merged

Conversation

sodic
Copy link
Contributor

@sodic sodic commented Nov 23, 2023

Fixes: #1426

Instructions for looking at the RFC

This PR includes (almost**) all necessary changes to run a project that follows the new structure. It also includes an example of one such project (the prototype).

Here's how I recommend you approach the RFC:

  1. Read the PR's description (this text)
  2. Go through the files, look at the changes, and read/reply to the comments.

** Details why almost are explained in the comments.

A reminder on the new structure

How does the new structure look like?

Wasp users write User code.

Wasp generates Generated Code. The Generated Code is split into:

  1. SDK Code - This covers all the functionalities Wasp users import and use in User code (either directly or indirectly).
  2. Framework Code - This covers the "shell" code. It's the code that imports and executes User code, indirectly importing and using SDK Code.
    image

Here's an illustration of how the new structure looks like in the file system.

.
├── main.wasp
├── node_modules
│   ├── <other_modules>
│   └── <wasp_sdk_code>         # packages in the @wasp directory
├── .wasp/
│   └── <wasp_framework_code>
├── src
├────<user_code>
├── package.json
├── .eslintrc.json
└── tsconfig.json

Running the prototype

The prototype is a Wasp application that's organized according to the new structure and can run using an adopted version of waspc (the one in this branch).

Here's how to run it:

  1. Checkout the branch.
  2. Position yourself in waspc/examples/todo-typescript.
  3. Run cabal run wasp-cli clean && cabal run wasp-cli start and wait for the app to start (i.e., stops outputting new text). You'll see a white screen in the browser (this is normal).
  4. Ctrl+C the start command.
  5. Run ./migrate from the project root directory.
  6. Run cabal run wasp-cli start again
  7. Open your browser and you should have a working prototype!

Changes in this PR

These are the changes that were necessary to get the prototype working.

  1. A large chunk of the code has been moved from the .wasp/out/{server,client} (framework code) to various packages in the scope node_modules/@wasp/. Each package also includes whatever was necessary to make it work with Wasp.
  2. As a result of the first change, most @wasp user imports now look a little different (the final form of SDK imports is still open to discussion).
  3. A large chunk of the code now residing in node_modules/@wasp has been edited (i.e., not only copy-pasted) to allow for a more ergonomic organization and cleaner imports. You don't need to be aware of these changes, they'll become obvious during the implementation. Still, I commented on some of the changes for discussion purposes.
  4. The compiler went through various small changes to make it all work.
  5. Wasp no longer copies the user's code into .wasp/out/{server,client}. Instead, the framework code (i.e., code inside .wasp/out/{server,client}) now imports the user code directly. It does this using relative imports.
  6. The waspc/examples directory now contains an extra app which acts as a prototype (waspc/examples/todo-typescript).

PR comments explore each change and decision in more detail, so let's discuss them there. If I missed something, feel free to start a new thread on the appropriate code segment.

@sodic sodic force-pushed the filip-restructuring-prototype branch from 8298f5f to 3da3f52 Compare November 24, 2023 13:13
@sodic sodic changed the title Filip restructuring prototype Restructuring prototype RFC Nov 24, 2023
waspc/cli/src/Wasp/Cli/Common.hs Show resolved Hide resolved
waspc/data/Generator/templates/react-app/src/index.tsx Outdated Show resolved Hide resolved
waspc/data/Cli/templates/basic/src/client/vite-env.d.ts Outdated Show resolved Hide resolved
waspc/data/Generator/templates/react-app/src/router.tsx Outdated Show resolved Hide resolved
Comment on lines 17 to 19
optimizeDeps: {
exclude: ['@wasp']
},
Copy link
Contributor Author

@sodic sodic Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vite's dependency optimization was causing weird bugs.

Todo: describe

@infomiho knows what's up. @Martinsos take my word for it for now, I'll update the comment in a bit.

waspc/examples/todo-typescript/tsconfig.json Outdated Show resolved Hide resolved
waspc/src/Wasp/Generator/JsImport.hs Show resolved Hide resolved
waspc/src/Wasp/JsImport.hs Show resolved Hide resolved
@@ -0,0 +1,20 @@
{
"name": "core",
"type": "module",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will make an md file documenting the new structure.

@sodic sodic force-pushed the filip-restructuring-prototype branch from 4e7be10 to a5a7382 Compare January 8, 2024 13:42
@infomiho infomiho force-pushed the filip-restructuring-prototype branch from f967599 to a5a7382 Compare January 19, 2024 15:25
@sodic sodic changed the base branch from main to filip-restructuring January 29, 2024 12:22
@sodic sodic marked this pull request as ready for review January 29, 2024 12:49
@sodic sodic merged commit 6f0714a into filip-restructuring Jan 29, 2024
2 of 8 checks passed
@sodic sodic deleted the filip-restructuring-prototype branch January 29, 2024 13:00
@sodic sodic restored the filip-restructuring-prototype branch January 29, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a restructuring prototype
3 participants