-
Notifications
You must be signed in to change notification settings - Fork 716
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
feat(workers-shared): Add Asset Server Worker behaviour #6539
Conversation
🦋 Changeset detectedLatest commit: c0bcf8d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-wrangler-6539 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6539/npm-package-wrangler-6539 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-wrangler-6539 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-create-cloudflare-6539 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-cloudflare-kv-asset-handler-6539 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-miniflare-6539 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-cloudflare-pages-shared-6539 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-cloudflare-vitest-pool-workers-6539 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-cloudflare-workers-editor-shared-6539 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10523785777/npm-package-cloudflare-workers-shared-6539 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
e2dd4eb
to
ad3a948
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with additional small pieces here: #6542
@GregBrimble thanks for reviewing this. I've incorporated the changes you suggested in this commit |
db338a2
to
5b7156f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I left a bunch of comments.
I'd really really like to see some tests of this worker.
packages/workers-shared/package.json
Outdated
@@ -23,7 +23,7 @@ | |||
], | |||
"scripts": { | |||
"build": "pnpm run clean && pnpm run bundle:asset-server:prod", | |||
"bundle:asset-server": "esbuild asset-server-worker/src/index.ts --format=esm --bundle --outfile=dist/asset-server-worker.mjs --sourcemap=external", | |||
"bundle:asset-server": "esbuild asset-server-worker/src/index.ts --format=esm --bundle --outfile=dist/asset-server-worker.mjs --sourcemap=external --external:cloudflare:*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could use wrangler deploy --dry-run --outdir=dist/asset-worker.mjs
to do this so that we don't have to keep the esbuild settings in sync?
assetEntry | ||
); | ||
console.log(assetResponse); | ||
if (!assetResponse || !assetResponse.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like assetResponse.value
being falsy is a programming error on our part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically this should be just a sanity check, but felt like we should check nonetheless. I'll ask the EWC folks if we want to throw a different error here. IMO a 500
sounds like the right thing to return
827b4fc
to
e11c3ef
Compare
f395487
to
25c0ce4
Compare
cb8fcab
to
eed70a0
Compare
eed70a0
to
786c1a7
Compare
const newResponse = new Response(response.body, response); | ||
// ensure the runtime will return the metadata we need | ||
newResponse.headers.append( | ||
"cf-kv-metadata", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,12 @@ | |||
import { defineProject, mergeConfig } from "vitest/config"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no vite expert so I would appreciate a sanity check here on this config 🙏
1154d63
to
c0bcf8d
Compare
@@ -4,6 +4,11 @@ const CONTENT_HASH_SIZE = 16; | |||
const TAIL_SIZE = 8; | |||
const ENTRY_SIZE = PATH_HASH_SIZE + CONTENT_HASH_SIZE + TAIL_SIZE; | |||
|
|||
export type AssetEntry = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this ends up being used anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right. must be some leftover from all the iterations 😅 . will remove as part of WC-2597
let { pathname } = url; | ||
|
||
const assetsManifest = new AssetsManifest(this.env.ASSETS_MANIFEST); | ||
pathname = globalThis.decodeURIComponent(pathname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this should be decoded because the assetManifest uses encoded pathnames?
Might be worth adding a test for url encoding with a funky pathname. Not high priority though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so funky path names def don't work, with or without this decoding. Let's have a look together, and I'll add the proper fix/tests in a follow-up PR. Tracking in WC-2597
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with this - very nice work!
What this PR solves / how to test
[Workers + Assets]
This PR adds a proper-ish implementation of a very un-opinionated Asset Server Worker. Proper-ish because it handles the essential things needed for ASW to work, but I expect some other details we'll be needed as Workers + Assets work progresses further.
Fixes WC-2434
Author has addressed the following