From da5b7b20ae048a2a70b2a69cd48e3dba73f9cb81 Mon Sep 17 00:00:00 2001 From: Christophe Eynius Tranberg Date: Fri, 12 Jun 2026 23:49:30 +0200 Subject: [PATCH] Fix setup.sh: match real KV title and build pages before deploy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two first-run bugs in scripts/setup.sh: 1. KV title mismatch — the find-or-create step looked for a namespace titled "${WORKER_NAME}-OAUTH_KV", but `wrangler kv namespace create OAUTH_KV` titles it after the binding name ("OAUTH_KV"). The lookup never matched, so setup tried to create it and failed on "already exists" on any re-run. Match the title wrangler actually produces. 2. Missing page build — setup runs `wrangler deploy` directly, but the worker imports compiled SSR/client bundles from dist/** that only exist after `npm run build:pages`. A clean checkout failed the deploy on unresolved imports. Build the bundles before deploying. Co-Authored-By: Claude Opus 4.8 (1M context) --- mnemion-js/scripts/setup.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mnemion-js/scripts/setup.sh b/mnemion-js/scripts/setup.sh index c005e80..2c57529 100755 --- a/mnemion-js/scripts/setup.sh +++ b/mnemion-js/scripts/setup.sh @@ -18,7 +18,11 @@ CURRENT_KV_ID=$(awk ' /^\[/ { in_kv=0 } in_kv && /^id *= *"/ { match($0, /"[^"]+"/); print substr($0, RSTART+1, RLENGTH-2); exit } ' wrangler.toml) -EXPECTED_KV_TITLE="${WORKER_NAME}-OAUTH_KV" +# wrangler titles the namespace after the binding name (OAUTH_KV), NOT +# "${WORKER_NAME}-OAUTH_KV" — match what `wrangler kv namespace create OAUTH_KV` +# actually produces, otherwise find-or-create never matches and the create fails +# on "already exists". +EXPECTED_KV_TITLE="OAUTH_KV" # === KV namespace: find-or-create, patch wrangler.toml === echo "Checking KV namespace ${EXPECTED_KV_TITLE}..." @@ -107,6 +111,14 @@ echo "" echo "Setting master secret..." printf '%s' "$SECRET" | npx wrangler secret put MNEMION_SECRET 2>&1 | grep -v "^$" +# === Build page bundles === +# The worker imports compiled SSR/client bundles from dist/** (see [[rules]] in +# wrangler.toml). They must exist before `wrangler deploy`, or the deploy fails on +# unresolved imports. `npm run deploy` builds them; setup deploys directly, so do it here. +echo "" +echo "Building page bundles..." +npm run build:pages + # === Deploy === echo "" echo "Deploying..."