From d2a9bf95224f052b75cbe295da256c2c2f401b30 Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Thu, 18 Jul 2024 10:07:20 -0700 Subject: [PATCH 1/4] =?UTF-8?q?Fix=20type=20of=20AppLoadContext=E2=80=99s?= =?UTF-8?q?=20cloudflare.caches=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/cloudflare-workers/load-context.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/templates/cloudflare-workers/load-context.ts b/templates/cloudflare-workers/load-context.ts index e9604b71ba0..23889d2d6a6 100644 --- a/templates/cloudflare-workers/load-context.ts +++ b/templates/cloudflare-workers/load-context.ts @@ -1,7 +1,14 @@ import { type PlatformProxy } from "wrangler"; +// NOTE: PlatformProxy’s caches property is incompatible with the caches global +// https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/api/integrations/platform/caches.ts +// TS error: Property 'default' is missing in type 'CacheStorage' but required in type 'CacheStorage_2'. +type Cloudflare = Omit, "dispose" | "caches"> & { + caches: CacheStorage; +}; + declare module "@remix-run/cloudflare" { interface AppLoadContext { - cloudflare: Omit, "dispose">; + cloudflare: Cloudflare; } } From eea1119dd252b1923f3e13ae62cb9d01636f5591 Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Thu, 18 Jul 2024 17:22:59 +0000 Subject: [PATCH 2/4] =?UTF-8?q?Rename=20server.js=20=E2=86=92=20worker.ts?= =?UTF-8?q?=20+=20fix=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/cloudflare-workers/package.json | 2 +- templates/cloudflare-workers/{server.js => worker.ts} | 11 +++++++---- templates/cloudflare-workers/wrangler.toml | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) rename templates/cloudflare-workers/{server.js => worker.ts} (75%) diff --git a/templates/cloudflare-workers/package.json b/templates/cloudflare-workers/package.json index 94c82f16be8..4c11b7a0047 100644 --- a/templates/cloudflare-workers/package.json +++ b/templates/cloudflare-workers/package.json @@ -7,7 +7,7 @@ "deploy": "wrangler deploy", "dev": "remix vite:dev", "lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .", - "start": "wrangler dev ./server.js", + "start": "wrangler dev ./worker.ts", "typegen": "wrangler types", "typecheck": "tsc" }, diff --git a/templates/cloudflare-workers/server.js b/templates/cloudflare-workers/worker.ts similarity index 75% rename from templates/cloudflare-workers/server.js rename to templates/cloudflare-workers/worker.ts index 034653d326a..7a988c47d9b 100644 --- a/templates/cloudflare-workers/server.js +++ b/templates/cloudflare-workers/worker.ts @@ -1,11 +1,14 @@ import { getAssetFromKV } from "@cloudflare/kv-asset-handler"; -import { createRequestHandler } from "@remix-run/cloudflare"; -import * as remixBuild from "./build/server"; +import { createRequestHandler, type ServerBuild } from "@remix-run/cloudflare"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore This file won’t exist if it hasn’t yet been built +import * as build from "./build/server"; // eslint-disable-line import/no-unresolved // eslint-disable-next-line import/no-unresolved import __STATIC_CONTENT_MANIFEST from "__STATIC_CONTENT_MANIFEST"; const MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST); -const handleRemixRequest = createRequestHandler(remixBuild); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const handleRemixRequest = createRequestHandler(build as any as ServerBuild); export default { async fetch(request, env, ctx) { @@ -50,4 +53,4 @@ export default { return new Response("An unexpected error occurred", { status: 500 }); } }, -}; +} satisfies ExportedHandler }>; diff --git a/templates/cloudflare-workers/wrangler.toml b/templates/cloudflare-workers/wrangler.toml index 51b671d52f8..6b8db7a7a2d 100644 --- a/templates/cloudflare-workers/wrangler.toml +++ b/templates/cloudflare-workers/wrangler.toml @@ -1,6 +1,6 @@ name = "remix-cloudflare-workers-template" -main = "./server.js" +main = "./worker.ts" workers_dev = true # https://developers.cloudflare.com/workers/platform/compatibility-dates compatibility_date = "2023-04-20" From 0c76ffc0774e6f1b639a49f371463ccd0c9f6c49 Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Thu, 18 Jul 2024 17:23:56 +0000 Subject: [PATCH 3/4] Remove redundant wrangler dev script arg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the wrangler docs: “Only required if your wrangler.toml does not include a main key” Source: https://developers.cloudflare.com/workers/wrangler/commands/#dev --- templates/cloudflare-workers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cloudflare-workers/package.json b/templates/cloudflare-workers/package.json index 4c11b7a0047..5c226bfde73 100644 --- a/templates/cloudflare-workers/package.json +++ b/templates/cloudflare-workers/package.json @@ -7,7 +7,7 @@ "deploy": "wrangler deploy", "dev": "remix vite:dev", "lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .", - "start": "wrangler dev ./worker.ts", + "start": "wrangler dev", "typegen": "wrangler types", "typecheck": "tsc" }, From d446ab6fdba07324790cfc749968568418ff8eac Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Fri, 26 Jul 2024 11:41:06 +1000 Subject: [PATCH 4/4] Review --- templates/cloudflare-workers/load-context.ts | 3 +-- templates/cloudflare-workers/{worker.ts => server.ts} | 0 templates/cloudflare-workers/wrangler.toml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) rename templates/cloudflare-workers/{worker.ts => server.ts} (100%) diff --git a/templates/cloudflare-workers/load-context.ts b/templates/cloudflare-workers/load-context.ts index 23889d2d6a6..5fc575ba11c 100644 --- a/templates/cloudflare-workers/load-context.ts +++ b/templates/cloudflare-workers/load-context.ts @@ -1,8 +1,7 @@ import { type PlatformProxy } from "wrangler"; -// NOTE: PlatformProxy’s caches property is incompatible with the caches global +// PlatformProxy’s caches property is incompatible with the caches global // https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/api/integrations/platform/caches.ts -// TS error: Property 'default' is missing in type 'CacheStorage' but required in type 'CacheStorage_2'. type Cloudflare = Omit, "dispose" | "caches"> & { caches: CacheStorage; }; diff --git a/templates/cloudflare-workers/worker.ts b/templates/cloudflare-workers/server.ts similarity index 100% rename from templates/cloudflare-workers/worker.ts rename to templates/cloudflare-workers/server.ts diff --git a/templates/cloudflare-workers/wrangler.toml b/templates/cloudflare-workers/wrangler.toml index 6b8db7a7a2d..bdebe9f88ea 100644 --- a/templates/cloudflare-workers/wrangler.toml +++ b/templates/cloudflare-workers/wrangler.toml @@ -1,6 +1,6 @@ name = "remix-cloudflare-workers-template" -main = "./worker.ts" +main = "./server.ts" workers_dev = true # https://developers.cloudflare.com/workers/platform/compatibility-dates compatibility_date = "2023-04-20"