-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Figure out Wasp's node_modules
story
#1429
Comments
node_modules
storynode_modules
story
One thing to consider are It enables you to specify the SDK packages in the project's {
"name": "my-project",
"devDependencies": {
"@wasp/auth": "file:./sdk/@wasp/auth"
},
} |
Relevant comment: #1584 (comment). We are going with a single package for now. Reasons can be found in the linked discussion. We'll be installing our sdk package using a local package installation from somewhere inside the |
Background
Wasp users write User code.
Wasp generates Generated Code. We want to split the Generated Code into:
Here's how the new structure looks in the file system:
Questions
The plan is to ensure that Wasp's SDK inside the
node_modules
folder includes everything Wasp users might want to import (e.g.,useQuery
,entities
, etc.).We must decide on how to use, organize, package, and build the SDK.
1 Organization
There are several possible ways to organize the SDK Code.
Having only a single
package.json
file might make more semantic sense. After all, it is a single package (Wasp SDK) and all the code should probably follow the same rules.Having one
package.json
file per module might make less semantic sense, but also makes things more flexible for the future (and maybe even now). For example, having different packages for the client and the server would split the constraints for packaging and building the SDK (assuming we want to keep the same compiler output, a server project and a client project).With that in mind, here are the options:
A single package
Requires a single
package.json
file for N modules.Packages:
node_modules/wasp
.Imported as:
wasp/auth/useAuth
,wasp/queries/getSomething
Multiple packages
Requires N
package.json
files for N modules.Packages:
node_modules/wasp-queries
,node_modules/wasp-auth
, ...Imported as:
wasp-rpc/useAuth
,wasp-auth/getSomething
Multiple scoped packages:
Requires N
package.json
files for N modules.Packages:
node_modules/@wasp/auth
,node_modules/@wasp/queries
, ...Imported as:
@wasp/auth/useAuth
,@wasp/queries/getSomething
Organization: Decision
Still under consideration, but we are currently going with scoped packages. See #1584 (comment)
2 Usage
The IDE always tells Wasp users that their code imports and uses the SDK code from the
node_modules
directory. However, we must choose what happens during runtime. I see two options:Option 1. intuitively makes much more sense and is the one we'd prefer to go with. However, Option 2. might be easier to get working (in case we encounter more unanticipated problems).
Usage: Decision
Option 1 was possible and simple enough to get working, so we went with option 1 (i.e., SDKs are proper NPM packages).
3 Building and Packaging
This section talks about the SDK's creation process.
3.1 Packaging
Packaging refers to how we "present" the SDK, we can:
Packaging: Decision
The prototype proved that we can package our SDK code as ES Module (i.e.,
type: module
in package.json) packages without issues (Vite handles it properly, and our server code uses ES Modules).What we know:
import
/export
syntax) requires apackage.json
file for specifyingtype: module
. [TESTED]package.json
file. It just works. [TESTED]node_module
folders, using the first (nearest) package definition it finds. This means that the code insideproject_root/.wasp
will automatically look for packages inside/project_root/node_modules
[TESTED]3.2 Building
Building refers to the steps Wasp executes to produce the SDK after detecting user changes that require updating it:
*.js
) and type declaration files (*.d.ts
) on each user change. This will definitely work but will probably be slow.node_modules
as-is, without a special build step and leave the compilation to the user (not sure if this could work).Building: Decision
We must build the TypeScript code, as some users will want to use JavaScript. Still, we can get away without building anything for the time being, as Wasp currently always requires TypeScript (regardless of what the user uses).
The text was updated successfully, but these errors were encountered: