Skip to content

Commit

Permalink
Simplify @cloudflare/workers-shared exports
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble committed Feb 19, 2025
1 parent 693d63e commit deb587b
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-pears-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/workers-shared": minor
---

chore: Remove Workers from @cloudflare/workers-shared exports
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-ignore
import AssetWorker from "@cloudflare/workers-shared/dist/asset-worker.mjs";
import AssetWorker from "@cloudflare/workers-shared/asset-worker/src/index";
import { UNKNOWN_HOST } from "../shared";
import type { WorkerEntrypoint } from "cloudflare:workers";

Expand All @@ -8,7 +7,7 @@ interface Env {
__VITE_FETCH_ASSET__: Fetcher;
}

export default class CustomAssetWorker extends (AssetWorker as typeof WorkerEntrypoint<Env>) {
export default class CustomAssetWorker extends (AssetWorker as typeof WorkerEntrypoint as typeof WorkerEntrypoint<Env>) {
override async fetch(request: Request): Promise<Response> {
const response = await super.fetch!(request);
const modifiedResponse = new Response(response.body, response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import routerWorker from "@cloudflare/workers-shared/dist/router-worker.mjs";
import routerWorker from "@cloudflare/workers-shared/router-worker/src/index";

export default routerWorker;
8 changes: 6 additions & 2 deletions packages/workers-shared/asset-worker/src/assets-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ export const compare = (a: Uint8Array, b: Uint8Array) => {
}

for (const [i, v] of a.entries()) {
if (v < b[i]) {
const other = b[i];
if (other === undefined) {
return 1;
}
if (v < other) {
return -1;
}
if (v > b[i]) {
if (v > other) {
return 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/workers-shared/asset-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type Env = {
* they are still in flux and that they are not an established API contract.
*/
export default class extends WorkerEntrypoint<Env> {
async fetch(request: Request): Promise<Response> {
override async fetch(request: Request): Promise<Response> {
let sentry: ReturnType<typeof setupSentry> | undefined;
const analytics = new Analytics(this.env.ANALYTICS);
const performance = new PerformanceTimer(this.env.UNSAFE_PERFORMANCE);
Expand Down
15 changes: 2 additions & 13 deletions packages/workers-shared/asset-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"types": ["@cloudflare/workers-types/experimental"],
"noEmit": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
"extends": "@cloudflare/workers-tsconfig/worker.json",
"include": ["./src/**/*"]
}
6 changes: 1 addition & 5 deletions packages/workers-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
"dist"
],
"scripts": {
"build": "pnpm run clean && pnpm run bundle:asset-worker:prod && pnpm run bundle:router-worker:prod && pnpm run types:emit",
"bundle:asset-worker": "esbuild asset-worker/src/index.ts --format=esm --bundle --outfile=dist/asset-worker.mjs --sourcemap=external --external:cloudflare:*",
"bundle:asset-worker:prod": "pnpm run bundle:asset-worker --minify && node -r esbuild-register scripts/copy-config-file.ts",
"bundle:router-worker": "esbuild router-worker/src/index.ts --format=esm --bundle --outfile=dist/router-worker.mjs --sourcemap=external",
"bundle:router-worker:prod": "pnpm run bundle:router-worker --minify",
"build": "pnpm run clean && pnpm run types:emit",
"check:lint": "eslint . --max-warnings=0",
"check:type": "pnpm run check:type:tests && tsc",
"check:type:tests": "tsc -p ./asset-worker/tests/tsconfig.json && tsc -p ./router-worker/tests/tsconfig.json",
Expand Down
15 changes: 2 additions & 13 deletions packages/workers-shared/router-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"module": "NodeNext",
"moduleResolution": "nodenext",
"types": ["@cloudflare/workers-types/experimental"],
"noEmit": true,
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
"extends": "@cloudflare/workers-tsconfig/worker.json",
"include": ["./src/**/*"]
}
16 changes: 0 additions & 16 deletions packages/workers-shared/scripts/copy-config-file.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/workers-shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@cloudflare/workers-tsconfig/tsconfig.json",
"compilerOptions": {
"alwaysStrict": true,
"module": "esnext",
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit deb587b

Please sign in to comment.