Skip to content

Commit e3e7d5e

Browse files
committed
fixed the packages/start
1 parent 75c9066 commit e3e7d5e

File tree

19 files changed

+455
-290
lines changed

19 files changed

+455
-290
lines changed

.changeset/warm-panthers-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@electric-sql/start': major
3+
---
4+
5+
feat: publish the @electric-sql/start package
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
nodejs 24.11.1
1+
nodejs 24.11.1
2+
caddy 2.10.2

examples/tanstack-db-web-starter/drizzle.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "dotenv/config"
1+
import "@dotenvx/dotenvx/config"
22
import { defineConfig } from "drizzle-kit"
33

44
export default defineConfig({

examples/tanstack-db-web-starter/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
},
99
"scripts": {
1010
"dev": "pnpm dev:cloud",
11-
"dev:cloud": "vite dev",
12-
"dev:docker": "docker compose up -d && vite dev",
11+
"dev:cloud": "USE_ELECTRIC_URL=true vite dev",
12+
"dev:docker": "docker compose up -d && USE_ELECTRIC_URL=false vite dev",
1313
"backend:up": "docker compose up -d",
1414
"backend:down": "docker compose down",
1515
"backend:clear": "docker compose down -v",
1616
"start": "node .output/server/index.mjs",
1717
"build": "vite build",
1818
"migrate": "drizzle-kit migrate",
1919
"migrate:generate": "drizzle-kit generate",
20+
"psql": "dotenvx run -- sh -c 'psql \"$DATABASE_URL\"'",
2021
"serve": "vite preview",
2122
"test": "echo 'No tests yet'",
2223
"lint:check": "eslint .",
@@ -48,6 +49,7 @@
4849
"zod": "^4.0.14"
4950
},
5051
"devDependencies": {
52+
"@dotenvx/dotenvx": "^1.51.2",
5153
"@eslint/compat": "^1.3.1",
5254
"@eslint/js": "^9.32.0",
5355
"@tanstack/devtools-vite": "^0.3.11",
@@ -61,12 +63,12 @@
6163
"@typescript-eslint/parser": "^8.46.0",
6264
"@vitejs/plugin-react": "^5.0.4",
6365
"drizzle-kit": "^0.31.4",
64-
"dotenv": "^17.2.1",
6566
"eslint": "^9.32.0",
6667
"eslint-config-prettier": "^10.1.8",
6768
"eslint-plugin-prettier": "^5.5.3",
6869
"eslint-plugin-react": "^7.37.5",
6970
"jsdom": "^27.0.0",
71+
"open-cli": "^8.0.0",
7072
"prettier": "^3.6.2",
7173
"tsx": "^4.20.3",
7274
"typescript": "^5.7.2",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "dotenv/config"
1+
import "@dotenvx/dotenvx/config"
22
import { drizzle } from "drizzle-orm/node-postgres"
33

44
export const db = drizzle(process.env.DATABASE_URL!, { casing: `snake_case` })

examples/tanstack-db-web-starter/src/lib/electric-proxy.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import "dotenv/config"
1+
import "@dotenvx/dotenvx/config"
22
import { ELECTRIC_PROTOCOL_QUERY_PARAMS } from "@electric-sql/client"
33

44
/**
5-
* Gets the Electric SQL endpoint URL based on environment configuration
6-
* Priority: ELECTRIC_URL env var > production default > local docker default
5+
* Gets the Electric SQL endpoint URL based on environment configuration.
6+
*
7+
* If running in production, or `USE_ELECTRIC_URL` is set to `true`, the `ELECTRIC_URL` env var is used,
8+
* if available, otherwise the default cloud endpoint is used.
9+
* Otherwise, the local docker endpoint is used, assuming default port 30000.
710
*/
811
function getElectricUrl(): string {
9-
if (process.env.ELECTRIC_URL) {
10-
return process.env.ELECTRIC_URL
11-
}
12-
return process.env.NODE_ENV === `production`
13-
? `https://api.electric-sql.cloud`
12+
return process.env.NODE_ENV === `production` ||
13+
process.env.USE_ELECTRIC_URL === `true`
14+
? process.env.ELECTRIC_URL || `https://api.electric-sql.cloud`
1415
: `http://localhost:30000`
1516
}
1617

examples/tanstack-db-web-starter/src/vite-plugin-caddy.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn, type ChildProcess } from "child_process"
1+
import { spawn, spawnSync, type ChildProcess } from "child_process"
22
import { writeFileSync } from "fs"
33
import { readFileSync } from "fs"
44
import { networkInterfaces } from "os"
@@ -124,9 +124,28 @@ ${networkIP} {
124124
const startCaddyIfReady = (projectName: string) => {
125125
if (autoStart && vitePort && !caddyStarted) {
126126
caddyStarted = true
127+
128+
// Check if `caddy` binary is available before starting (sync)
129+
try {
130+
const check = spawnSync(`caddy`, [`--version`], { stdio: `ignore` })
131+
if (check.error || check.status !== 0) {
132+
throw new Error(
133+
`\`caddy\` binary not found or is not working. Please ensure Caddy is installed and available in your PATH.`
134+
)
135+
}
136+
} catch (_err) {
137+
console.error(
138+
`\`caddy\` binary not found or is not working. Please ensure Caddy is installed and available in your PATH.`,
139+
`\nCaddy is required to be able to serve local development with HTTP2 support.`,
140+
`\n - Install Caddy: https://caddyserver.com/docs/install`,
141+
`\n - If you have \`asdf\`, run \`asdf install\``
142+
)
143+
process.exit(1)
144+
}
127145
// Generate Caddyfile
128146
const caddyConfig = generateCaddyfile(projectName, vitePort)
129147
writeFileSync(configPath, caddyConfig)
148+
130149
// Start Caddy
131150
startCaddy(configPath)
132151
}
@@ -172,8 +191,10 @@ ${networkIP} {
172191
console.log()
173192
console.log(` ➜ Local: https://${projectName}.localhost/`)
174193
console.log(` ➜ Network: https://${networkIP}/`)
175-
console.log(` ➜ press h + enter to show help`)
176194
console.log()
195+
console.log(
196+
` Note: running through Caddy. You might be prompted for password to install HTTPS certificates for local development.`
197+
)
177198
}
178199

179200
server.middlewares.use((_req, _res, next) => {
@@ -185,12 +206,12 @@ ${networkIP} {
185206
})
186207

187208
const originalListen = server.listen
188-
server.listen = function (port?: number, ...args: unknown[]) {
209+
server.listen = function (port?: number, isRestart?: boolean) {
189210
if (port) {
190211
vitePort = port
191212
}
192213

193-
const result = originalListen.call(this, port, ...args)
214+
const result = originalListen.call(this, port, isRestart)
194215

195216
// Try to start Caddy after server is listening
196217
if (result && typeof result.then === `function`) {

examples/tanstack-db-web-starter/vite.config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ const config = defineConfig({
1616
}),
1717
caddyPlugin(),
1818
tailwindcss(),
19-
tanstackStart({
20-
router: {
21-
srcDirectory: `src`,
22-
},
23-
}),
19+
tanstackStart(),
2420
viteReact(),
2521
],
2622
optimizeDeps: {

packages/start/.eslintrc.cjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ module.exports = {
3232
],
3333
},
3434
ignorePatterns: [
35-
'**/node_modules/**',
36-
'**/dist/**',
37-
'tsup.config.ts',
38-
'vitest.config.ts',
39-
'.eslintrc.js',
35+
`**/node_modules/**`,
36+
`**/dist/**`,
37+
`tsup.config.ts`,
38+
`vitest.config.ts`,
39+
`.eslintrc.js`,
4040
],
41-
}
41+
}

packages/start/.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"semi": false,
44
"tabWidth": 2,
55
"singleQuote": true
6-
}
6+
}

0 commit comments

Comments
 (0)