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

fix(workers-shared): Stabilise Workers naming across workers-shared #6588

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
7 changes: 7 additions & 0 deletions .changeset/fast-pears-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/workers-shared": patch
---

fix: Stabilize Workers naming across `workers-shared`

The Asset Worker and Router Worker use inconsistent naming conventions across `workers-shared`. This commit stabilizes the naming to Asset Worker and Router Worker and permutations of those.
4 changes: 2 additions & 2 deletions packages/miniflare/src/plugins/kv/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ const encodeManifest = (manifest: Uint8Array[]) => {
// ASSET REVERSE MAP
//
// In prod, the contentHash is used as the key for the KV store that holds the assets.
// ASW will hash the path of an incoming request, look for that pathHash in the stored manifest,
// and get the corresponding contentHash to use as the KV key.
// Asset Worker will hash the path of an incoming request, look for that pathHash in
// the stored manifest, and get the corresponding contentHash to use as the KV key.
// In dev, we fake out this KV store and just get the assets from disk. However we still need
// to map a given "contentHash" to the filePath. This is what the ASSET REVERSE MAP is for.
// This is available to the FAKE_KV_NAMESPACE service (assets.worker.ts) as a binding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function parseRedirects(input: string): ParsedRedirects {
}

// We want to always block the `/* /index.html` redirect - this will cause TOO_MANY_REDIRECTS errors as
// the asset server will redirect it back to `/`, removing the `/index.html`. This is the case for regular
// the asset worker will redirect it back to `/`, removing the `/index.html`. This is the case for regular
// redirects, as well as proxied (200) rewrites. We only want to run this on relative urls
if (/\/\*?$/.test(from) && /\/index(.html)?$/.test(to) && !urlHasHost(to)) {
invalid.push({
Expand Down
6 changes: 3 additions & 3 deletions packages/workers-shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

This is a package that is used at Cloudflare to power some internal features of [Cloudflare Workers](https://developers.cloudflare.com/workers/), as well as their open-source equivalents here in workers-sdk and Wrangler.

## `asset-server`
## `asset-worker`

The Asset Server Worker.
The Asset Worker.

For more details please refer to the dedicated README file.

## `router-worker`

Router Worker.
The Router Worker.

For more details please refer to the dedicated README file.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `asset-server`
# `asset-worker`

The Asset Server is a [Cloudflare Worker](https://developers.cloudflare.com/workers/) that is responsible of serving assets for Workers deployed on the edge, that contain static assets as well.
The Asset Worker is a [Cloudflare Worker](https://developers.cloudflare.com/workers/) that is responsible of serving assets for Workers deployed on the edge, that contain static assets as well.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
##
# Configuration file for the Asset Server Worker
# Configuration file for the Asset Worker
#
# Please note that wrangler has a dependency on this file, and will
# attempt to read it as part of setting up a new Miniflare instance
# in developemnt mode. We should ensure that any configuration changes
# to this file are persisted in wrangler as well, when necessary.
# (see packages/wrangler/src/dev/miniflare.ts -> buildMiniflareOptions())
##
name = "asset-server-worker"
name = "asset-worker"
main = "src/index.ts"
compatibility_date = "2024-07-31"
4 changes: 2 additions & 2 deletions packages/workers-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
],
"scripts": {
"build": "pnpm run clean && pnpm run bundle:asset-worker:prod && pnpm run bundle:router-worker:prod",
"bundle:asset-worker": "esbuild asset-server-worker/src/index.ts --format=esm --bundle --outfile=dist/asset-server-worker.mjs --sourcemap=external --external:cloudflare:*",
"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",
"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",
"check:lint": "eslint . --max-warnings=0",
"check:type": "pnpm run check:type:tests && tsc",
"check:type:tests": "tsc -p ./asset-server-worker/tests/tsconfig.json",
"check:type:tests": "tsc -p ./asset-worker/tests/tsconfig.json",
"clean": "rimraf dist",
"dev": "pnpm run clean && concurrently -n bundle:asset-worker,bundle:router-worker -c blue,magenta \"pnpm run bundle:asset-worker --watch\" \"pnpm run bundle:router-worker --watch\"",
"test": "vitest",
Expand Down
4 changes: 2 additions & 2 deletions packages/workers-shared/router-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Fetcher, Request } from "@cloudflare/workers-types";

interface Env {
ASSET_SERVER: Fetcher;
ASSET_WORKER: Fetcher;
USER_WORKER: Fetcher;
}
export default {
async fetch(request: Request, env: Env) {
const result = await env.ASSET_SERVER.fetch(request);
const result = await env.ASSET_WORKER.fetch(request);
if (!result.ok) {
if (result.status === 404) {
return await env.USER_WORKER.fetch(request);
Expand Down
2 changes: 1 addition & 1 deletion packages/workers-shared/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default mergeConfig(
configShared,
defineProject({
test: {
include: ["asset-server-worker/tests/**.{test,spec}.{ts,js}"],
include: ["asset-worker/tests/**.{test,spec}.{ts,js}"],
globals: true,
},
})
Expand Down
10 changes: 4 additions & 6 deletions packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,7 @@ export function buildMiniflareBindingOptions(config: MiniflareBindingsConfig): {
// Setup service bindings to external services
const serviceBindings: NonNullable<WorkerOptions["serviceBindings"]> = {
...config.serviceBindings,
...(config.experimentalAssets
? { ASSET_SERVER: "asset-server-worker" }
: {}),
...(config.experimentalAssets ? { ASSET_WORKER: "asset-worker" } : {}),
};

const notFoundServices = new Set<string>();
Expand Down Expand Up @@ -924,18 +922,18 @@ function getAssetServerWorker(
return [];
}
const assetServerModulePath = require.resolve(
"@cloudflare/workers-shared/dist/asset-server-worker.mjs"
"@cloudflare/workers-shared/dist/asset-worker.mjs"
);
const assetServerConfigPath = require.resolve(
"@cloudflare/workers-shared/asset-server-worker/wrangler.toml"
"@cloudflare/workers-shared/asset-worker/wrangler.toml"
);
let assetServerConfig: Config | undefined;

try {
assetServerConfig = readConfig(assetServerConfigPath, {});
} catch (err) {
throw new UserError(
"Failed to read the Asset Server Worker configuration file.\n" + `${err}`
"Failed to read the Asset Worker configuration file.\n" + `${err}`
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/templates/no-op-assets-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
* this Worker is.
*/
type Env = {
ASSET_SERVER: Fetcher;
ASSET_WORKER: Fetcher;
};

export default {
async fetch(request: Request, env: Env) {
return env.ASSET_SERVER.fetch(request);
return env.ASSET_WORKER.fetch(request);
},
};
Loading