From b0821d7cebb65b07c60a7720c6e2364a52d93cf7 Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Sat, 9 Mar 2024 15:13:52 +0000 Subject: [PATCH 1/7] fix: filenames --- .github/workflows/CD.yml | 5 ++++- example/{auth => singleFileAuth}/app.ts | 2 +- lib/handlers/{static.ts => file.ts} | 0 index.ts => mod.ts | 11 ++++++----- 4 files changed, 11 insertions(+), 7 deletions(-) rename example/{auth => singleFileAuth}/app.ts (98%) rename lib/handlers/{static.ts => file.ts} (100%) rename index.ts => mod.ts (83%) diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index 77180fcd..7c89bf12 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -16,13 +16,16 @@ permissions: contents: read jobs: - deploy-cfw: + deploy-cloudflare-worker: runs-on: ubuntu-latest steps: - name: Setup repo uses: actions/checkout@v3 + - name: setup pnpm + run: npm install -g pnpm + - name: Setup Wrangler uses: cloudflare/wrangler-action@v3 with: diff --git a/example/auth/app.ts b/example/singleFileAuth/app.ts similarity index 98% rename from example/auth/app.ts rename to example/singleFileAuth/app.ts index 903b931d..c4027369 100644 --- a/example/auth/app.ts +++ b/example/singleFileAuth/app.ts @@ -1,4 +1,4 @@ -import * as Peko from "../../index.ts"; // "https://deno.land/x/peko/mod.ts" +import * as Peko from "../../lib/mod.ts"; // "https://deno.land/x/peko/mod.ts" const html = String; const router = new Peko.Router(); diff --git a/lib/handlers/static.ts b/lib/handlers/file.ts similarity index 100% rename from lib/handlers/static.ts rename to lib/handlers/file.ts diff --git a/index.ts b/mod.ts similarity index 83% rename from index.ts rename to mod.ts index e265fa71..e0d89e4d 100644 --- a/index.ts +++ b/mod.ts @@ -1,5 +1,5 @@ /** - * Featherweight HTTP routing and utils for apps on the edge. + * Featherweight apps on the edge */ // Core classes, functions & types @@ -7,20 +7,21 @@ export * from "./lib/Router.ts"; export * from "./lib/types.ts"; // Handlers -export * from "./lib/handlers/static.ts"; -export * from "./lib/handlers/ssr.ts"; +export * from "./lib/handlers/file.ts"; export * from "./lib/handlers/sse.ts"; +export * from "./lib/handlers/ssr.ts"; // Middlewares -export * from "./lib/middleware/logger.ts"; -export * from "./lib/middleware/cacher.ts"; export * from "./lib/middleware/authenticator.ts"; +export * from "./lib/middleware/cacher.ts"; +export * from "./lib/middleware/logger.ts"; // Utils export * from "./lib/utils/CacheItem.ts"; export * from "./lib/utils/Cascade.ts"; export * from "./lib/utils/Crypto.ts"; export * from "./lib/utils/helpers.ts"; +export * from "./lib/utils/Profiler.ts"; import { Router } from "./lib/Router.ts"; export default Router; From efa39eefe3559e221466425dae4adbe420d686a5 Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Sat, 9 Mar 2024 15:16:16 +0000 Subject: [PATCH 2/7] fix: filenames --- example/preactSSR/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/preactSSR/router.ts b/example/preactSSR/router.ts index 084b9db9..f75fb50e 100644 --- a/example/preactSSR/router.ts +++ b/example/preactSSR/router.ts @@ -6,7 +6,7 @@ import { cacher, ssr, file, -} from "../../index.ts"; //"https://deno.land/x/peko/mod.ts" +} from "../../mod.ts"; //"https://deno.land/x/peko/mod.ts" import { renderToString } from "preact-render-to-string"; // Preact page components and HTML template for ssrHandler render logic From 51a430c126b5484d9ee33e4fcd11e993f0b0cf22 Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Sat, 9 Mar 2024 15:19:35 +0000 Subject: [PATCH 3/7] fix: after_script CI --- .github/workflows/CI.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8e5dccb7..006e077f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -71,8 +71,9 @@ jobs: - name: bun run run: npm run test:bun - after_script: - - pkill bun + + after_script: + - pkill bun test-run-wrangler: runs-on: ubuntu-latest @@ -89,5 +90,6 @@ jobs: - name: wrangler dev run: npm run test:cfw - after_script: - - pkill node + + after_script: + - pkill node From fe3e21059a0b90a7d2f84c4eb191ffe6ac1b1431 Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Sat, 9 Mar 2024 15:23:47 +0000 Subject: [PATCH 4/7] fix: profile in CI --- .github/workflows/CI.yml | 64 +++++++++++++++------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 006e077f..ce4eddb1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -25,71 +25,55 @@ jobs: - name: setup repo uses: actions/checkout@v3 + - name: setup pnpm + run: npm install -g pnpm + - name: setup Deno uses: denoland/setup-deno@v1 with: deno-version: v1.x - name: Run profile - run: deno task profile + run: pnpm profile:deno - unit-test-deno: + profile-bun: runs-on: ubuntu-latest steps: - name: setup repo uses: actions/checkout@v3 - - name: setup Deno - uses: denoland/setup-deno@v1 - with: - deno-version: v1.x - - # - name: Verify formatting - # run: deno fmt --check - - - name: run linter - run: deno lint - - - name: run tests - run: deno task test - - test-run-bun: - runs-on: ubuntu-latest - - steps: - - name: setup repo - uses: actions/checkout@v3 + - name: setup pnpm + run: npm install -g pnpm - - name: setup Bun.sh + - name: setup Bun uses: oven-sh/setup-bun@v1 with: bun-version: latest - - name: bun intall - run: bun install - - - name: bun run - run: npm run test:bun - - after_script: - - pkill bun + - name: Run profile + run: pnpm profile:bun - test-run-wrangler: + unit-test-deno: runs-on: ubuntu-latest steps: - name: setup repo uses: actions/checkout@v3 - - name: npm intall - run: npm install + - name: setup pnpm + run: npm install -g pnpm - - name: setup Wrangler - run: npm install -g wrangler + - name: setup Deno + uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + + # - name: Verify formatting + # run: deno fmt --check - - name: wrangler dev - run: npm run test:cfw + - name: run linter + run: deno lint - after_script: - - pkill node + - name: run tests + run: pnpm test From 18c3d0043289623f0c1b24793d931a1940ea7f3d Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Sat, 9 Mar 2024 15:29:08 +0000 Subject: [PATCH 5/7] fix: rename file_test.ts --- example/preactSSR/src/pages/Home.ts | 2 +- example/singleFileAuth/app.ts | 2 +- tests/handlers/{static_test.ts => file_test.ts} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename tests/handlers/{static_test.ts => file_test.ts} (96%) diff --git a/example/preactSSR/src/pages/Home.ts b/example/preactSSR/src/pages/Home.ts index ada1fbf7..4c4aac9d 100644 --- a/example/preactSSR/src/pages/Home.ts +++ b/example/preactSSR/src/pages/Home.ts @@ -24,7 +24,7 @@ const Home = () => {

Handlers

diff --git a/example/singleFileAuth/app.ts b/example/singleFileAuth/app.ts index c4027369..9d38166a 100644 --- a/example/singleFileAuth/app.ts +++ b/example/singleFileAuth/app.ts @@ -1,4 +1,4 @@ -import * as Peko from "../../lib/mod.ts"; // "https://deno.land/x/peko/mod.ts" +import * as Peko from "../../mod.ts"; // "https://deno.land/x/peko/mod.ts" const html = String; const router = new Peko.Router(); diff --git a/tests/handlers/static_test.ts b/tests/handlers/file_test.ts similarity index 96% rename from tests/handlers/static_test.ts rename to tests/handlers/file_test.ts index fa11e390..4e0b7d74 100644 --- a/tests/handlers/static_test.ts +++ b/tests/handlers/file_test.ts @@ -1,8 +1,8 @@ import { assert } from "https://deno.land/std@0.218.0/assert/mod.ts"; import { Router, RequestContext } from "../../lib/Router.ts"; -import { file } from "../../lib/handlers/static.ts"; +import { file } from "../../lib/handlers/file.ts"; -Deno.test("HANDLER: Static", async (t) => { +Deno.test("HANDLER: File", async (t) => { const server = new Router(); const ctx = new RequestContext(server, new Request("http://localhost")); const fileURL = new URL(import.meta.url); From 9c45688013bab88ac10edc084da8b6ef65ab526f Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Sat, 9 Mar 2024 15:30:31 +0000 Subject: [PATCH 6/7] fix: install deps in CI --- .github/workflows/CI.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ce4eddb1..2ce9fe76 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -28,6 +28,9 @@ jobs: - name: setup pnpm run: npm install -g pnpm + - name: setup packages + run: pnpm install + - name: setup Deno uses: denoland/setup-deno@v1 with: @@ -46,6 +49,9 @@ jobs: - name: setup pnpm run: npm install -g pnpm + - name: setup packages + run: pnpm install + - name: setup Bun uses: oven-sh/setup-bun@v1 with: From ac56c57d3c7c799632461df98e8200d6b62ed60f Mon Sep 17 00:00:00 2001 From: Sebastien Ringrose Date: Sat, 9 Mar 2024 15:33:19 +0000 Subject: [PATCH 7/7] fix: ports in CI --- scripts/bun/profile.ts | 4 ++-- scripts/deno/main.ts | 7 ++++++- scripts/deno/profile.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/bun/profile.ts b/scripts/bun/profile.ts index 4a2c6fc9..eade3a18 100644 --- a/scripts/bun/profile.ts +++ b/scripts/bun/profile.ts @@ -3,7 +3,7 @@ import { getTestRouter } from "../../tests/mocks/middleware.ts"; const testRouter = getTestRouter(); const server = Bun.serve({ - port: 9797, + port: 8080, fetch(req) { return testRouter.handle(req); }, @@ -15,7 +15,7 @@ const handleResults = await Profiler.run(testRouter, { }); const serveResults = await Profiler.run(testRouter, { mode: "serve", - url: "http://localhost:7777", + url: "http://localhost:8080", count: 100, }); diff --git a/scripts/deno/main.ts b/scripts/deno/main.ts index 4958904f..d2e897e9 100644 --- a/scripts/deno/main.ts +++ b/scripts/deno/main.ts @@ -1,6 +1,11 @@ import router from "../../example/preactSSR/router.ts"; // Start Deno server with Peko router :^) -Deno.serve((req) => router.handle(req)); +Deno.serve( + { + port: 7777, + }, + (req) => router.handle(req) +); console.log("Deno server running with Peko router <3"); diff --git a/scripts/deno/profile.ts b/scripts/deno/profile.ts index 0b360685..9f388fce 100644 --- a/scripts/deno/profile.ts +++ b/scripts/deno/profile.ts @@ -5,7 +5,7 @@ const testRouter = getTestRouter(); const abortController = new AbortController(); Deno.serve( { - port: 7778, + port: 7777, signal: abortController.signal, }, (req) => testRouter.handle(req)