diff --git a/app/build.cli.ts b/app/build.cli.ts index 1d36d69..fee5373 100644 --- a/app/build.cli.ts +++ b/app/build.cli.ts @@ -4,7 +4,7 @@ import { formatNumber } from "bknd/utils"; import * as esbuild from "esbuild"; const deps = Object.keys(pkg.dependencies); -const external = ["jsonv-ts/*", "wrangler", ...deps]; +const external = ["jsonv-ts/*", "wrangler", "bknd", "bknd/*", ...deps]; if (process.env.DEBUG) { const result = await esbuild.build({ diff --git a/app/src/adapter/cloudflare/proxy.ts b/app/src/adapter/cloudflare/proxy.ts index 0ae3a37..b72aef5 100644 --- a/app/src/adapter/cloudflare/proxy.ts +++ b/app/src/adapter/cloudflare/proxy.ts @@ -18,6 +18,27 @@ export type WithPlatformProxyOptions = { proxyOptions?: GetPlatformProxyOptions; }; +async function getPlatformProxy(opts?: GetPlatformProxyOptions) { + try { + const { version } = await import("wrangler/package.json", { with: { type: "json" } }); + $console.log("Using wrangler version", version); + const { getPlatformProxy } = await import("wrangler"); + return getPlatformProxy(opts); + } catch (e) { + $console.error("Failed to import wrangler", String(e)); + const resolved = import.meta.resolve("wrangler"); + $console.log("Wrangler resolved to", resolved); + const file = resolved?.split("/").pop(); + if (file?.endsWith(".json")) { + $console.error( + "You have a `wrangler.json` in your current directory. Please change to .jsonc or .toml", + ); + } + } + + process.exit(1); +} + export function withPlatformProxy( config: CloudflareBkndConfig = {}, opts?: WithPlatformProxyOptions, @@ -31,7 +52,6 @@ export function withPlatformProxy( async function getEnv(env?: Env): Promise { if (use_proxy) { if (!proxy) { - const getPlatformProxy = await import("wrangler").then((mod) => mod.getPlatformProxy); proxy = await getPlatformProxy(opts?.proxyOptions); process.on("exit", () => { proxy?.dispose(); diff --git a/app/src/cli/commands/run/run.ts b/app/src/cli/commands/run/run.ts index 7090a12..154d50c 100644 --- a/app/src/cli/commands/run/run.ts +++ b/app/src/cli/commands/run/run.ts @@ -2,9 +2,8 @@ import type { Config } from "@libsql/client/node"; import { StorageLocalAdapter } from "adapter/node/storage"; import type { CliBkndConfig, CliCommand } from "cli/types"; import { Option } from "commander"; -import { config, type App, type CreateAppConfig, type MaybePromise } from "bknd"; +import { config, type App, type CreateAppConfig, type MaybePromise, registries } from "bknd"; import dotenv from "dotenv"; -import { registries } from "modules/registries"; import c from "picocolors"; import path from "node:path"; import { diff --git a/app/src/data/schema/SchemaManager.ts b/app/src/data/schema/SchemaManager.ts index ab2d15f..78708d6 100644 --- a/app/src/data/schema/SchemaManager.ts +++ b/app/src/data/schema/SchemaManager.ts @@ -65,6 +65,7 @@ export class SchemaManager { if (SchemaManager.EXCLUDE_TABLES.includes(table.name)) { continue; } + if (!table.name) continue; cleanTables.push({ ...table,