Skip to content

Commit 00ad1a1

Browse files
committed
fix: harden Prisma and Netlify scaffolds
1 parent efd39a6 commit 00ad1a1

11 files changed

Lines changed: 139 additions & 28 deletions

File tree

.changeset/honest-partner-paths.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/create': patch
3+
---
4+
5+
Fix pnpm 11 build approvals for Prisma and Netlify projects, make generated Prisma MySQL apps use their configured `DATABASE_URL`, and update the Prisma demo to current server-function and package-script APIs.

packages/create/src/frameworks/react/add-ons/prisma/assets/prisma/seed.ts.ejs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { PrismaClient } from "../src/generated/prisma/client.js";
2+
<% if (addOnOption.prisma.database !== 'sqlite') { %>
3+
import { getDatabaseUrl } from '../src/database-url.js'
4+
<% } %>
25

36
<% if (addOnOption.prisma.database === 'postgres') { %>
47
import { PrismaPg } from '@prisma/adapter-pg';
58
69
const adapter = new PrismaPg({
7-
connectionString: process.env.DATABASE_URL!,
10+
connectionString: getDatabaseUrl(),
811
});<% } %>
912

1013
<% if (addOnOption.prisma.database === 'mysql') { %>
1114
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
12-
const adapter = new PrismaMariaDb({
13-
host: "localhost",
14-
port: 3306,
15-
connectionLimit: 5
16-
});<% } %>
15+
const adapter = new PrismaMariaDb(getDatabaseUrl());<% } %>
1716

1817
<% if (addOnOption.prisma.database === 'sqlite') { %>
1918
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<% if (addOnOption.prisma.database === 'sqlite') { ignoreFile(); return; } -%>
2+
export function getDatabaseUrl() {
3+
const databaseUrl = process.env.DATABASE_URL
4+
5+
if (!databaseUrl) {
6+
throw new Error('DATABASE_URL is required')
7+
}
8+
9+
return databaseUrl
10+
}

packages/create/src/frameworks/react/add-ons/prisma/assets/src/db.ts.ejs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { PrismaClient } from './generated/prisma/client.js'
2+
<% if (addOnOption.prisma.database !== 'sqlite') { %>
3+
import { getDatabaseUrl } from './database-url.js'
4+
<% } %>
25

36
<% if (addOnOption.prisma.database === 'postgres') { %>
47
import { PrismaPg } from '@prisma/adapter-pg';
58
69
const adapter = new PrismaPg({
7-
connectionString: process.env.DATABASE_URL!,
10+
connectionString: getDatabaseUrl(),
811
});<% } %>
912

1013
<% if (addOnOption.prisma.database === 'mysql') { %>
1114
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
12-
const adapter = new PrismaMariaDb({
13-
host: "localhost",
14-
port: 3306,
15-
connectionLimit: 5
16-
});<% } %>
15+
const adapter = new PrismaMariaDb(getDatabaseUrl());<% } %>
1716

1817
<% if (addOnOption.prisma.database === 'sqlite') { %>
1918
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';

packages/create/src/frameworks/react/add-ons/prisma/assets/src/routes/demo/prisma.tsx.ejs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const getTodos = createServerFn({
1313
const createTodo = createServerFn({
1414
method: 'POST',
1515
})
16-
.inputValidator((data: { title: string }) => data)
16+
.validator((data: { title: string }) => data)
1717
.handler(async ({ data }) => {
1818
return await prisma.todo.create({
1919
data,
@@ -31,15 +31,15 @@ function DemoPrisma() {
3131

3232
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
3333
e.preventDefault()
34-
const formData = new FormData(e.target as HTMLFormElement)
35-
const title = formData.get('title') as string
34+
const form = e.currentTarget
35+
const title = new FormData(form).get('title')
3636

37-
if (!title) return
37+
if (typeof title !== 'string' || !title) return
3838

3939
try {
4040
await createTodo({ data: { title } })
4141
router.invalidate()
42-
;(e.target as HTMLFormElement).reset()
42+
form.reset()
4343
} catch (error) {
4444
console.error('Failed to create todo:', error)
4545
}
@@ -99,7 +99,7 @@ function DemoPrisma() {
9999
Powered by Prisma ORM
100100
</h3>
101101
<p className="demo-muted mb-4 text-sm">
102-
Next-generation ORM for Node.js & TypeScript with PostgreSQL
102+
Next-generation ORM for Node.js & TypeScript with <%= addOnOption.prisma.database === 'postgres' ? 'PostgreSQL' : addOnOption.prisma.database === 'mysql' ? 'MySQL' : 'SQLite' %>
103103
</p>
104104
<div className="space-y-2 text-sm">
105105
<p className="font-medium">Setup Instructions:</p>
@@ -112,19 +112,19 @@ function DemoPrisma() {
112112
<li>
113113
Run:{' '}
114114
<code>
115-
<%- getPackageManagerExecuteScript('prisma', ['generate']) %>
115+
<%- getPackageManagerRunScript('db:generate') %>
116116
</code>
117117
</li>
118118
<li>
119119
Run:{' '}
120120
<code>
121-
<%- getPackageManagerExecuteScript('prisma', ['db', 'push']) %>
121+
<%- getPackageManagerRunScript('db:push') %>
122122
</code>
123123
</li>
124124
<li>
125125
Optional:{' '}
126126
<code>
127-
<%- getPackageManagerExecuteScript('prisma', ['studio']) %>
127+
<%- getPackageManagerRunScript('db:studio') %>
128128
</code>
129129
</li>
130130
</ol>

packages/create/src/frameworks/react/add-ons/prisma/package.json.ejs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
"db:migrate": "dotenv -e .env.local -- prisma migrate dev",
1818
"db:studio": "dotenv -e .env.local -- prisma studio",
1919
"db:seed": "dotenv -e .env.local -- prisma db seed"
20-
}<% if (addOnOption.prisma.database === 'sqlite') { %>,
20+
},
2121
"pnpm": {
22-
"onlyBuiltDependencies": ["better-sqlite3"]
22+
"onlyBuiltDependencies": [
23+
"@prisma/engines",
24+
"prisma"<% if (addOnOption.prisma.database === 'sqlite') { %>,
25+
"better-sqlite3"<% } %>
26+
]
2327
}
24-
<% } %>
2528
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"devDependencies": {
33
"@netlify/vite-plugin-tanstack-start": "^1.2.15"
4+
},
5+
"pnpm": {
6+
"onlyBuiltDependencies": [
7+
"sharp"
8+
]
49
}
510
}

packages/create/src/frameworks/react/project/base/pnpm-workspace.yaml.ejs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ allowBuilds:
55
<% if (addOnEnabled.sentry) { -%>
66
'@sentry/cli': true
77
<% } -%>
8-
<% if (addOnEnabled.cloudflare) { -%>
8+
<% if (addOnEnabled.cloudflare || addOnEnabled.netlify) { -%>
99
sharp: true
10+
<% } -%>
11+
<% if (addOnEnabled.cloudflare) { -%>
1012
workerd: true
1113
<% } -%>
12-
<% if (addOnEnabled.drizzle || addOnEnabled.prisma) { -%>
14+
<% if (addOnEnabled.prisma) { -%>
15+
'@prisma/engines': true
16+
prisma: true
17+
<% } -%>
18+
<% if (addOnEnabled.drizzle || (addOnEnabled.prisma && addOnOption.prisma.database === 'sqlite')) { -%>
1319
better-sqlite3: true
1420
<% } -%>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"devDependencies": {
33
"@netlify/vite-plugin-tanstack-start": "^1.2.15"
4+
},
5+
"pnpm": {
6+
"onlyBuiltDependencies": [
7+
"sharp"
8+
]
49
}
510
}

packages/create/src/frameworks/solid/project/base/pnpm-workspace.yaml.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
allowBuilds:
33
esbuild: true
44
lightningcss: true
5-
<% if (addOnEnabled.cloudflare) { -%>
5+
<% if (addOnEnabled.cloudflare || addOnEnabled.netlify) { -%>
66
sharp: true
7+
<% } -%>
8+
<% if (addOnEnabled.cloudflare) { -%>
79
workerd: true
810
<% } -%>

0 commit comments

Comments
 (0)