From e2c3e5340eb89b538cefed2553806eadc7c987b7 Mon Sep 17 00:00:00 2001 From: Rahul Sethi <5822355+RamIdeas@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:24:06 +0100 Subject: [PATCH] multi-worker fixture --- fixtures/multi-worker/README.md | 11 ++++++++++ fixtures/multi-worker/packages/package.json | 7 +++++++ .../packages/worker-a/package.json | 15 +++++++++++++ .../packages/worker-a/src/index.ts | 21 +++++++++++++++++++ .../packages/worker-a/tsconfig.json | 13 ++++++++++++ .../packages/worker-a/wrangler.toml | 7 +++++++ .../packages/worker-b/package.json | 15 +++++++++++++ .../packages/worker-b/src/index.ts | 7 +++++++ .../packages/worker-b/tsconfig.json | 13 ++++++++++++ .../packages/worker-b/wrangler.toml | 5 +++++ 10 files changed, 114 insertions(+) create mode 100644 fixtures/multi-worker/README.md create mode 100644 fixtures/multi-worker/packages/package.json create mode 100644 fixtures/multi-worker/packages/worker-a/package.json create mode 100644 fixtures/multi-worker/packages/worker-a/src/index.ts create mode 100644 fixtures/multi-worker/packages/worker-a/tsconfig.json create mode 100644 fixtures/multi-worker/packages/worker-a/wrangler.toml create mode 100644 fixtures/multi-worker/packages/worker-b/package.json create mode 100644 fixtures/multi-worker/packages/worker-b/src/index.ts create mode 100644 fixtures/multi-worker/packages/worker-b/tsconfig.json create mode 100644 fixtures/multi-worker/packages/worker-b/wrangler.toml diff --git a/fixtures/multi-worker/README.md b/fixtures/multi-worker/README.md new file mode 100644 index 000000000000..5405829321be --- /dev/null +++ b/fixtures/multi-worker/README.md @@ -0,0 +1,11 @@ +# multi-worker + +The aim of this fixture is to use `wrangler dev` for multiple workers in the same project. + +## Usage + +```sh +npx wrangler dev --x-dev-env \ + -c packages/worker-a/wrangler.toml \ + -c packages/worker-b/wrangler.toml +``` diff --git a/fixtures/multi-worker/packages/package.json b/fixtures/multi-worker/packages/package.json new file mode 100644 index 000000000000..0ffc113f5e1f --- /dev/null +++ b/fixtures/multi-worker/packages/package.json @@ -0,0 +1,7 @@ +{ + "name": "multi-worker", + "workspaces": [ + "worker-a", + "worker-b" + ] +} diff --git a/fixtures/multi-worker/packages/worker-a/package.json b/fixtures/multi-worker/packages/worker-a/package.json new file mode 100644 index 000000000000..ba039d19c8e1 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-a/package.json @@ -0,0 +1,15 @@ +{ + "name": "worker-a", + "private": true, + "scripts": { + "deploy": "wrangler deploy", + "start": "wrangler dev --x-dev-env" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20240909.0", + "wrangler": "workspace:*" + }, + "volta": { + "extends": "../../package.json" + } +} diff --git a/fixtures/multi-worker/packages/worker-a/src/index.ts b/fixtures/multi-worker/packages/worker-a/src/index.ts new file mode 100644 index 000000000000..e54d567a7e75 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-a/src/index.ts @@ -0,0 +1,21 @@ +export default { + async fetch( + request: Request, + env: Env, + ctx: ExecutionContext + ): Promise { + const result = await env.WORKER_B.hello(); + + return new Response( + `Worker A called Worker B: ${result}` + ); + }, +}; + + + + + +export interface Env { + WORKER_B: { hello(): Promise }; +} \ No newline at end of file diff --git a/fixtures/multi-worker/packages/worker-a/tsconfig.json b/fixtures/multi-worker/packages/worker-a/tsconfig.json new file mode 100644 index 000000000000..2431bac6e945 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-a/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es2021", + "lib": ["es2021"], + "module": "es2022", + "types": ["@cloudflare/workers-types/experimental"], + "noEmit": true, + "isolatedModules": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + } +} diff --git a/fixtures/multi-worker/packages/worker-a/wrangler.toml b/fixtures/multi-worker/packages/worker-a/wrangler.toml new file mode 100644 index 000000000000..dc1952da5d64 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-a/wrangler.toml @@ -0,0 +1,7 @@ +name = "worker-a" +main = "src/index.ts" +compatibility_date = "2024-09-22" + +services = [ + { binding = "WORKER_B", service = "worker-b", entrypoint = "default" } +] diff --git a/fixtures/multi-worker/packages/worker-b/package.json b/fixtures/multi-worker/packages/worker-b/package.json new file mode 100644 index 000000000000..3e8f5d8d8e96 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-b/package.json @@ -0,0 +1,15 @@ +{ + "name": "worker-b", + "private": true, + "scripts": { + "deploy": "wrangler deploy", + "start": "wrangler dev --x-dev-env" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20240909.0", + "wrangler": "workspace:*" + }, + "volta": { + "extends": "../../package.json" + } +} diff --git a/fixtures/multi-worker/packages/worker-b/src/index.ts b/fixtures/multi-worker/packages/worker-b/src/index.ts new file mode 100644 index 000000000000..c32893f29161 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-b/src/index.ts @@ -0,0 +1,7 @@ +import { WorkerEntrypoint } from "cloudflare:workers"; + +export default class extends WorkerEntrypoint { + async hello() { + return "Hello World from Worker B!"; + } +} diff --git a/fixtures/multi-worker/packages/worker-b/tsconfig.json b/fixtures/multi-worker/packages/worker-b/tsconfig.json new file mode 100644 index 000000000000..2431bac6e945 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es2021", + "lib": ["es2021"], + "module": "es2022", + "types": ["@cloudflare/workers-types/experimental"], + "noEmit": true, + "isolatedModules": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + } +} diff --git a/fixtures/multi-worker/packages/worker-b/wrangler.toml b/fixtures/multi-worker/packages/worker-b/wrangler.toml new file mode 100644 index 000000000000..1a4845bd1072 --- /dev/null +++ b/fixtures/multi-worker/packages/worker-b/wrangler.toml @@ -0,0 +1,5 @@ +name = "worker-b" +main = "src/index.ts" +compatibility_date = "2024-09-22" + +dev.port = 8788 \ No newline at end of file