From 800f14ede281104aae5ec15847fef5bc3ee34914 Mon Sep 17 00:00:00 2001 From: dswbx Date: Mon, 29 Sep 2025 09:28:37 +0200 Subject: [PATCH] fix: fix wrangler platform proxy handling Modified the external dependencies in the build configuration to include "bknd" and its submodules. Added a new asynchronous function to handle platform proxy options, improving error handling for the "wrangler" import and providing clearer logging for version resolution. Additionally, ensured that the schema manager skips processing for tables without names. --- app/build.cli.ts | 2 +- app/src/adapter/cloudflare/proxy.ts | 22 +++++++++++++++++++++- app/src/cli/commands/run/run.ts | 3 +-- app/src/data/schema/SchemaManager.ts | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/build.cli.ts b/app/build.cli.ts index 1d36d69b..fee5373e 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 0ae3a376..b72aef53 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 7090a128..154d50c1 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 ab2d15fa..78708d60 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,