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