workers-sdk
workers-sdk copied to clipboard
Convert Templates and Examples to use Module Workers Format
Fixes https://github.com/cloudflare/workers-sdk/issues/2788.
What this PR solves / how to test: This PR converts the templates still using Service Workers syntax to module format syntax.
Associated docs issue(s)/PR(s):
- https://github.com/cloudflare/workers-sdk/pull/2781#pullrequestreview-1312065836
Author has included the following, where applicable:
- [ ] Tests
- [ ] Changeset (Changeset guidelines)
Reviewer has performed the following, where applicable:
- [ ] Checked for inclusion of relevant tests
- [ ] Checked for inclusion of a relevant changeset
- [ ] Checked for creation of associated docs updates
- [ ] Manually pulled down the changes and spot-tested
⚠️ No Changeset found
Latest commit: aa0311c6b473e72151a59896bba7150a3b6bcd65
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a 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/8754949549/npm-package-wrangler-2928
You can reference the automatically updated head of this PR with:
npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/2928/npm-package-wrangler-2928
Or you can use npx
with this latest build directly:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8754949549/npm-package-wrangler-2928 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8754949549/npm-package-create-cloudflare-2928 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8754949549/npm-package-cloudflare-kv-asset-handler-2928
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8754949549/npm-package-miniflare-2928
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8754949549/npm-package-cloudflare-pages-shared-2928
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8754949549/npm-package-cloudflare-vitest-pool-workers-2928
Note that these links will no longer work once the GitHub Actions artifact expires.
[email protected]
includes the following runtime dependencies:
Package | Constraint | Resolved |
---|---|---|
miniflare |
workspace:* | 3.20240405.2 |
workerd |
1.20240405.0 | 1.20240405.0 |
workerd --version |
1.20240405.0 | 2024-04-05 |
Please ensure constraints are pinned, and miniflare
/workerd
minor versions match.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 70.38%. Comparing base (
2789f26
) to head (159b7f3
). Report is 48 commits behind head on main.
:exclamation: Current head 159b7f3 differs from pull request most recent head aa0311c. Consider uploading reports for the commit aa0311c to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## main #2928 +/- ##
==========================================
- Coverage 72.44% 70.38% -2.07%
==========================================
Files 331 298 -33
Lines 17298 15515 -1783
Branches 4422 3987 -435
==========================================
- Hits 12532 10920 -1612
+ Misses 4766 4595 -171
hi @lauragift21 :) are you still aiming to land this PR or should it be closed?
hey @lauragift21 :) are you still planning on landing this? if so, can you resolve the failing test and comment here so we know if we should re-review? thanks!
@lauragift21 and i spoke and she will update the PR and fix the tests 👍
I've resolved the comments and fixed tests cc @lrapoport-cf
thanks @lauragift21 ! we'll work on getting this re-reviewed :)
@1000hz @mrbbot is this good to re-review or are there outstanding changes that you'd still like to see addressed?
It looks like there are still a few places where Cina's comment needs to be addressed:
We also need to make sure we're passing
env
andctx
down through the functions that call those that depend on these values. Alternatively, we can restructure the code such that these dependent functions are inner functions of thefetch
handler (orprocessRequest
) so they have the objects in scope.
For example, the GetCurrentCacheVersion()
function takes an env
parameter, but this is not being passed at the call sites:
- https://github.com/cloudflare/workers-sdk/blob/d19b36c365474a31798cea502476b5bf3ea295fe/templates/examples/edge-cache-html/edge-cache-html.js#L198
- https://github.com/cloudflare/workers-sdk/blob/d19b36c365474a31798cea502476b5bf3ea295fe/templates/examples/edge-cache-html/edge-cache-html.js#L252
- https://github.com/cloudflare/workers-sdk/blob/d19b36c365474a31798cea502476b5bf3ea295fe/templates/examples/edge-cache-html/edge-cache-html.js#L323
This would require the addition of an env
parameter to the cacheResponse
function, which would then have to be passed through at each of its call sites.
I'm not sure how much extra work this would be, but it may be worth converting these templates to TypeScript so these become type errors.
@lauragift21 - are you able to take another look at this?
@lauragift21 can you resolve the merge conflicts?
@mrbbot @penalosa can you take another look at this PR and confirm if your feedback has been addressed?