From 3960b82557d9306dbeb44c6fd6389ffd8c9e247c Mon Sep 17 00:00:00 2001 From: Dominik Ferber Date: Wed, 3 May 2023 21:21:58 -0700 Subject: [PATCH 1/6] avoid accessing process.version in edge runtime --- platforms/nodejs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/nodejs.ts b/platforms/nodejs.ts index 55e0b5bf..00c85093 100644 --- a/platforms/nodejs.ts +++ b/platforms/nodejs.ts @@ -130,7 +130,7 @@ export class Redis extends core.Redis { }); this.addTelemetry({ - runtime: `node@${process.version}`, + runtime: typeof EdgeRuntime === "string" ? `edge-light` : `node@${process.version}`, platform: process.env.VERCEL ? "vercel" : process.env.AWS_REGION From f40c353458c33d7715763413d6d153fb63f99788 Mon Sep 17 00:00:00 2001 From: chronark Date: Thu, 4 May 2023 11:36:29 +0200 Subject: [PATCH 2/6] refactor(nodejs.ts): reformat Redis class addTelemetry method for better readability --- platforms/nodejs.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platforms/nodejs.ts b/platforms/nodejs.ts index 00c85093..e6e73a4d 100644 --- a/platforms/nodejs.ts +++ b/platforms/nodejs.ts @@ -130,7 +130,9 @@ export class Redis extends core.Redis { }); this.addTelemetry({ - runtime: typeof EdgeRuntime === "string" ? `edge-light` : `node@${process.version}`, + runtime: typeof EdgeRuntime === "string" + ? "edge-light" + : `node@${process.version}`, platform: process.env.VERCEL ? "vercel" : process.env.AWS_REGION From 99a6f646a58f279eafe69b563c72c0a49be6235f Mon Sep 17 00:00:00 2001 From: chronark Date: Thu, 4 May 2023 13:02:32 +0200 Subject: [PATCH 3/6] build(tests.yaml): change install command to install all dependencies feat(netlify): add two new edge functions, hello.ts and incr.ts fix(test.ts): change url to test the new edge function 'incr' --- .github/workflows/tests.yaml | 4 ++-- examples/netlify-edge/netlify.toml | 3 --- examples/netlify-edge/netlify/edge-functions/hello.ts | 3 +++ .../netlify/edge-functions/{handler.ts => incr.ts} | 7 ++++--- examples/netlify-edge/test.ts | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) delete mode 100644 examples/netlify-edge/netlify.toml create mode 100644 examples/netlify-edge/netlify/edge-functions/hello.ts rename examples/netlify-edge/netlify/edge-functions/{handler.ts => incr.ts} (62%) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 9a461bbd..7901ee46 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -180,8 +180,8 @@ jobs: - - name: Install @upstash/redis - run: pnpm add @upstash/redis@${{needs.release.outputs.version}} + - name: Install Dependencies + run: pnpm install working-directory: ./examples/netlify - name: Deploy diff --git a/examples/netlify-edge/netlify.toml b/examples/netlify-edge/netlify.toml deleted file mode 100644 index c9de4112..00000000 --- a/examples/netlify-edge/netlify.toml +++ /dev/null @@ -1,3 +0,0 @@ -[[edge_functions]] -function = "handler" -path = "/handler" \ No newline at end of file diff --git a/examples/netlify-edge/netlify/edge-functions/hello.ts b/examples/netlify-edge/netlify/edge-functions/hello.ts new file mode 100644 index 00000000..1d5b8338 --- /dev/null +++ b/examples/netlify-edge/netlify/edge-functions/hello.ts @@ -0,0 +1,3 @@ +export default () => new Response("Hello world"); + +export const config = { path: "/test" }; diff --git a/examples/netlify-edge/netlify/edge-functions/handler.ts b/examples/netlify-edge/netlify/edge-functions/incr.ts similarity index 62% rename from examples/netlify-edge/netlify/edge-functions/handler.ts rename to examples/netlify-edge/netlify/edge-functions/incr.ts index bdbfbe5d..7a064703 100644 --- a/examples/netlify-edge/netlify/edge-functions/handler.ts +++ b/examples/netlify-edge/netlify/edge-functions/incr.ts @@ -1,8 +1,7 @@ -import type { Context } from "https://edge.netlify.com"; -import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"; +import { Redis } from "../../../../mod.js"; const redis = Redis.fromEnv(); -export default async (_req: Request, _ctx: Context) => { +export default async (_req: Request) => { console.log("Hello"); try { return new Response(JSON.stringify({ @@ -14,3 +13,5 @@ export default async (_req: Request, _ctx: Context) => { return new Response(err.message, { status: 500 }); } }; + +export const config = { path: "/incr" }; diff --git a/examples/netlify-edge/test.ts b/examples/netlify-edge/test.ts index ec55d9c0..4c7f70b1 100644 --- a/examples/netlify-edge/test.ts +++ b/examples/netlify-edge/test.ts @@ -7,7 +7,7 @@ if (!deploymentURL) { Deno.test("works", async () => { console.log({ deploymentURL }); - const url = `${deploymentURL}/handler`; + const url = `${deploymentURL}/incr`; console.log({ url }); const res = await fetch(url); const body = await res.text(); From 7259fbb74ccb5aa126054b918c461a4d66daca15 Mon Sep 17 00:00:00 2001 From: chronark Date: Thu, 4 May 2023 13:11:02 +0200 Subject: [PATCH 4/6] chore(tests.yaml): remove unnecessary build step and update netlify dev command --- .github/workflows/tests.yaml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7901ee46..94e23dac 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -114,7 +114,6 @@ jobs: netlify-edge-local: - if: false needs: - test @@ -137,18 +136,14 @@ jobs: version: latest - - name: Build - run: deno run -A ./cmd/build.ts + - name: Install Dependencies + run: pnpm install + working-directory: ./examples/netlify - - name: Install example + - name: Start run: | - pnpm add @upstash/redis@../../dist - npm i -g netlify-cli - working-directory: ./examples/netlify-edge - - - name: Start example - run: netlify dev --port 15015 & sleep 10 + npx netlify-cli dev --port 15015 & sleep 10 working-directory: ./examples/netlify-edge @@ -862,7 +857,7 @@ jobs: - nextjs-edge-local - netlify-local - deno-local - # - netlify-edge-local - not working in ci for some reason, local is fine + - netlify-edge-local - cloudflare-workers-with-typescript-local - cloudflare-workers-local From 0abfb794b4b6cdb9c29736911a0372399e5d7de7 Mon Sep 17 00:00:00 2001 From: chronark Date: Thu, 4 May 2023 13:29:16 +0200 Subject: [PATCH 5/6] chore(tests.yaml): comment out netlify-edge-local job due to issues with their CLI --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 94e23dac..dba9bd3b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -857,7 +857,7 @@ jobs: - nextjs-edge-local - netlify-local - deno-local - - netlify-edge-local + # - netlify-edge-local - their own cli doesn't work right now. I'll try again in a week - cloudflare-workers-with-typescript-local - cloudflare-workers-local From bcb36975f12c3c85c98bf924274970592e69c90f Mon Sep 17 00:00:00 2001 From: chronark Date: Thu, 4 May 2023 13:37:05 +0200 Subject: [PATCH 6/6] chore(tests.yaml): remove netlify-edge-local and netlify-edge-deployed jobs The netlify-edge-local and netlify-edge-deployed jobs were removed as they are no longer needed. --- .github/workflows/tests.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dba9bd3b..04f123a8 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -114,6 +114,7 @@ jobs: netlify-edge-local: + if: false needs: - test @@ -153,6 +154,7 @@ jobs: DEPLOYMENT_URL: http://localhost:15015 netlify-edge-deployed: + if: false concurrency: netlify-edge-deployed runs-on: ubuntu-latest needs: