Skip to content

Commit 07db54c

Browse files
authored
Support WebAssembly modules (#8031)
1 parent 0c0374c commit 07db54c

31 files changed

+764
-241
lines changed

.changeset/wild-schools-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": minor
3+
---
4+
5+
Add support for Wasm (WebAssembly) modules.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
# Keep environment variables out of version control
3+
.env
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, test } from "vitest";
2+
import { getJsonResponse } from "../../__test-utils__";
3+
4+
// Need to remove the `.wrangler` directory and run the following commands before the tests.
5+
// I'm not sure how to do this with our testing setup so have skipped the test for now.
6+
// const commands = [
7+
// `pnpm wrangler d1 migrations apply prisma-demo-db --local`,
8+
// `pnpm wrangler d1 execute prisma-demo-db --command "INSERT INTO \"User\" (\"email\", \"name\") VALUES ('[email protected]', 'Jane Doe (Local)');" --local`,
9+
// ];
10+
11+
test.skip("runs D1 query using Prisma", async () => {
12+
const result = await getJsonResponse();
13+
expect(result).toEqual([
14+
{ id: 1, email: "[email protected]", name: "Jane Doe (Local)" },
15+
]);
16+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- CreateTable
2+
CREATE TABLE "User" (
3+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
4+
"email" TEXT NOT NULL,
5+
"name" TEXT
6+
);
7+
8+
-- CreateIndex
9+
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@playground/prisma",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"prebuild": "pnpm generate",
7+
"build": "vite build --app",
8+
"check:types": "tsc --build",
9+
"predev": "pnpm generate",
10+
"dev": "vite dev",
11+
"generate": "pnpm prisma generate",
12+
"migrate-db": "pnpm wrangler d1 migrations apply prisma-demo-db --local",
13+
"preview": "vite preview",
14+
"seed-db": "pnpm wrangler d1 execute prisma-demo-db --command \"INSERT INTO \"User\" (\"email\", \"name\") VALUES ('[email protected]', 'Jane Doe (Local)');\" --local"
15+
},
16+
"devDependencies": {
17+
"@cloudflare/vite-plugin": "workspace:*",
18+
"@cloudflare/workers-tsconfig": "workspace:*",
19+
"@cloudflare/workers-types": "^4.20250121.0",
20+
"@prisma/adapter-d1": "^6.3.0",
21+
"@prisma/client": "^6.3.0",
22+
"prisma": "^6.3.0",
23+
"typescript": "catalog:default",
24+
"vite": "catalog:vite-plugin",
25+
"wrangler": "catalog:vite-plugin"
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
generator client {
5+
provider = "prisma-client-js"
6+
previewFeatures = ["driverAdapters"]
7+
// Default output directory does not work with Vite. See https://github.com/vitejs/vite/issues/19036#issuecomment-2558791944
8+
output = "../node_modules/@prisma/client-generated"
9+
}
10+
11+
datasource db {
12+
provider = "sqlite"
13+
url = env("DATABASE_URL")
14+
}
15+
16+
model User {
17+
id Int @id @default(autoincrement())
18+
email String @unique
19+
name String?
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { PrismaD1 } from "@prisma/adapter-d1";
2+
import { PrismaClient } from "@prisma/client-generated";
3+
4+
interface Env {
5+
DB: D1Database;
6+
}
7+
8+
export default {
9+
async fetch(request, env) {
10+
const adapter = new PrismaD1(env.DB);
11+
const prisma = new PrismaClient({ adapter });
12+
const users = await prisma.user.findMany();
13+
14+
return Response.json(users);
15+
},
16+
} satisfies ExportedHandler<Env>;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{ "path": "./tsconfig.node.json" },
5+
{ "path": "./tsconfig.worker.json" }
6+
]
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["@cloudflare/workers-tsconfig/base.json"],
3+
"include": ["vite.config.ts", "__tests__"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["@cloudflare/workers-tsconfig/worker.json"],
3+
"include": ["src"]
4+
}

0 commit comments

Comments
 (0)