mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The rule table mapped HOG_ -> FN_ ahead of any POSTHOG rule, so POSTHOG_FOO split into POST + HOG_ and came out POSTFN_FOO. Nothing sets that. The live pods set INSIGHTS_SKIP_MIGRATION_CHECKS, which bin/migrate-check reads on the container entrypoint, so the misspelling does not degrade a feature -- it runs migrate --check against a database whose history this tree does not share and the container never starts. Both replacements are measured against the shipped tree rather than chosen: every HOG_ name with a counterpart there is spelled INSIGHTS_ (HOG_QL -> INSIGHTS_QL, HOG_FUNCTION_TEMPLATES -> INSIGHTS_FUNCTION_TEMPLATES, 12 of 12 determinate cases), and FN_ appears in it nowhere. Upstream carries 95 HOG_ tokens and zero FN_ ones, so repairing FN_ back out is exactly the inverse of the bad rule and cannot collide with an upstream name. The rule is fixed for the next convergence, and the tree it already produced is repaired in the same commit -- the codemod is idempotent against its own output, so it cannot undo this itself.
110 lines
3.4 KiB
TypeScript
110 lines
3.4 KiB
TypeScript
import { spawn, type ChildProcess } from 'child_process'
|
|
import { context, type Plugin } from 'esbuild'
|
|
// esbuild watch + node respawn — same bundling pipeline as build-hono.ts so
|
|
// dev and prod behave identically. tsx isn't used directly because it can't
|
|
// load the `.md` template imports or stub the `cloudflare:workers` builtin.
|
|
import { existsSync } from 'fs'
|
|
import { resolve } from 'path'
|
|
|
|
import { copyInstructions } from './copy-instructions'
|
|
import { createDevHonoChildEnv } from './dev-hono-env'
|
|
import { honoEsbuildOptions, honoOutfile } from './hono-esbuild-config'
|
|
|
|
// `.env` is the single local-dev env file (see .env.example). Wrangler reads
|
|
// it natively too (falling back from `.dev.vars`), so hono and the edge-proxy
|
|
// worker boot with the same env.
|
|
const dotEnv = resolve(process.cwd(), '.env')
|
|
if (existsSync(dotEnv)) {
|
|
process.loadEnvFile(dotEnv)
|
|
}
|
|
|
|
// Without these the server boots but misbehaves subtly (OAuth metadata
|
|
// advertises production, UI app resources aren't registered) - surface the
|
|
// misconfig loudly, especially for setups still holding config in the
|
|
// removed `.dev.vars` file.
|
|
const requiredVars = ['INSIGHTS_API_BASE_URL', 'MCP_APPS_BASE_URL']
|
|
const missingVars = requiredVars.filter((name) => !process.env[name])
|
|
if (missingVars.length > 0) {
|
|
console.warn(
|
|
`[dev-hono] missing required env var(s): ${missingVars.join(', ')}. ` +
|
|
'Support for `.dev.vars` was removed - move your local config to `.env` (see .env.example).'
|
|
)
|
|
}
|
|
|
|
copyInstructions()
|
|
|
|
// flox sets SSL_CERT_FILE; Node's TLS layer only reads NODE_EXTRA_CA_CERTS.
|
|
if (!process.env.NODE_EXTRA_CA_CERTS && process.env.SSL_CERT_FILE) {
|
|
process.env.NODE_EXTRA_CA_CERTS = process.env.SSL_CERT_FILE
|
|
}
|
|
|
|
let child: ChildProcess | undefined
|
|
|
|
const killChild = (): Promise<void> => {
|
|
return new Promise((resolve) => {
|
|
if (!child) {
|
|
resolve()
|
|
return
|
|
}
|
|
const proc = child
|
|
child = undefined
|
|
proc.removeAllListeners()
|
|
proc.on('exit', () => resolve())
|
|
proc.kill('SIGTERM')
|
|
})
|
|
}
|
|
|
|
const launch = async (): Promise<void> => {
|
|
await killChild()
|
|
child = spawn(process.execPath, [honoOutfile], {
|
|
stdio: 'inherit',
|
|
env: createDevHonoChildEnv(process.env),
|
|
})
|
|
child.on('exit', (code, signal) => {
|
|
if (signal === 'SIGTERM') {
|
|
return
|
|
}
|
|
if (code !== 0) {
|
|
console.warn(`[dev-hono] node exited with code=${code}; waiting for next rebuild...`)
|
|
}
|
|
})
|
|
}
|
|
|
|
const restartPlugin: Plugin = {
|
|
name: 'dev-hono-restart',
|
|
setup(build): void {
|
|
build.onEnd((result) => {
|
|
if (result.errors.length > 0) {
|
|
console.error(`[dev-hono] build failed with ${result.errors.length} error(s); not restarting`)
|
|
return
|
|
}
|
|
void launch()
|
|
})
|
|
},
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
const ctx = await context({
|
|
...honoEsbuildOptions({ dev: true, extraPlugins: [restartPlugin] }),
|
|
logLevel: 'info',
|
|
})
|
|
|
|
const shutdown = async (): Promise<void> => {
|
|
if (child) {
|
|
child.kill('SIGTERM')
|
|
}
|
|
await ctx.dispose()
|
|
process.exit(0)
|
|
}
|
|
process.on('SIGINT', shutdown)
|
|
process.on('SIGTERM', shutdown)
|
|
|
|
await ctx.watch()
|
|
console.info('[dev-hono] watching src/hono/** for changes')
|
|
}
|
|
|
|
main().catch((err: unknown) => {
|
|
console.error('[dev-hono] fatal:', err)
|
|
process.exit(1)
|
|
})
|