Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify @cloudflare/workers-shared exports #8193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
13 changes: 9 additions & 4 deletions packages/vite-plugin-cloudflare/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ export default defineConfig([
tsconfig: "tsconfig.plugin.json",
},
{
entry: [
"src/asset-workers/router-worker.ts",
"src/asset-workers/asset-worker.ts",
],
entry: ["src/asset-workers/router-worker.ts"],
format: "esm",
platform: "neutral",
outDir: "dist/asset-workers",
external: ["cloudflare:workers"],
tsconfig: "tsconfig.worker.json",
},
{
entry: ["src/asset-workers/asset-worker.ts"],
format: "esm",
platform: "neutral",
outDir: "dist/asset-workers",
Expand Down
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
14 changes: 1 addition & 13 deletions packages/workers-shared/asset-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
{
"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"
}
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
14 changes: 1 addition & 13 deletions packages/workers-shared/router-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
{
"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"
}
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
Loading