Skip to content

feat(wrangler): watch mode for Workers + Assets#6574

Merged
CarmenPopoviciu merged 5 commits intomainfrom
carmen/watch-mode
Aug 30, 2024
Merged

feat(wrangler): watch mode for Workers + Assets#6574
CarmenPopoviciu merged 5 commits intomainfrom
carmen/watch-mode

Conversation

@CarmenPopoviciu
Copy link
Copy Markdown
Contributor

@CarmenPopoviciu CarmenPopoviciu commented Aug 23, 2024

What this PR solves / how to test

This PR implements watch mode for Workers with assets, more specifically:

  • it watches the static assets directory for changes (add/delete files or directories)
  • it reacts to config file changes and ensures we're still watching for the relevant asset directory

Fixes WC-2554

Clean commit history is caring 🫶 so pls review per commit

How this was tested

Beside e2e tests, these changes were also manually tested in the following scenarios:

[wrangler dev | wrangler dev --x-dev-env]

  • add/remove files & directories in the assets directory
Screenshot 2024-08-28 at 12 37 21
  • change the assets folder in wrangler.toml + file changes in new assets directory + file changes in old assets directory to ensure it is not watched anymore
Screenshot 2024-08-28 at 12 38 12

[wrangler dev --x-assets="dist" | wrangler dev --x-dev-env --x-assets="dist"]

  • add/remove files & directories in the assets directory
  • change the assets folder in wrangler.toml + file changes in that assets directory to ensure we are still watching the assets dir specified by --x-assets
Screenshot 2024-08-28 at 12 46 40

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Included
    • Not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required / Maybe required
    • Not required because:
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Not necessary because: Workers + Assets is not documented yet

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 23, 2024

🦋 Changeset detected

Latest commit: ee6ff15

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@cloudflare/vitest-pool-workers Patch

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 23, 2024

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/10629771784/npm-package-wrangler-6574

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6574/npm-package-wrangler-6574

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-wrangler-6574 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-create-cloudflare-6574 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-cloudflare-kv-asset-handler-6574
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-miniflare-6574
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-cloudflare-pages-shared-6574
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-cloudflare-vitest-pool-workers-6574
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-cloudflare-workers-editor-shared-6574
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10629771784/npm-package-cloudflare-workers-shared-6574

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.72.3 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240821.0
workerd 1.20240821.1 1.20240821.1
workerd --version 1.20240821.1 2024-08-21

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/watch-mode branch 2 times, most recently from d1b5f95 to f1b3795 Compare August 27, 2024 17:04
@CarmenPopoviciu CarmenPopoviciu marked this pull request as ready for review August 27, 2024 17:04
@CarmenPopoviciu CarmenPopoviciu requested a review from a team as a code owner August 27, 2024 17:04
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two fns that can potentially throw here are readConfig and processExperimentalAssetsArg. Since we're in watch mode, we ideally don't want to error and exit every time there's a config file read error or we couldn't properly resolve the assets directory path. The better user experience IMO is to log the error and allow users to fix as they go, without having them re-start the dev process every single time. This brings the watch mode experience in line with pages dev, which we recently refactored for precisely the same reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically for the same reason as in https://github.com/cloudflare/workers-sdk/pull/6574/files#r1733250847. But I would like some sanity check on whether this gets executed only in watch mode. If not, we might need to rethink the logic here, in case throwing and exiting the dev process is expected to happen in some use cases

Copy link
Copy Markdown
Contributor Author

@CarmenPopoviciu CarmenPopoviciu Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if for this use case we shouldn't show a warning or log message reminding users that they are currently running wrangler dev with the -x--assets/--experimental-assets flag, and therefore config file changes related to experimental_assets will not be reflected in the current dev process, since args override config 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per our async convo, I will put smth in place here

@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/watch-mode branch 2 times, most recently from 3d02114 to 0c87849 Compare August 27, 2024 20:37
@workers-devprod workers-devprod added the e2e Run wrangler + vite-plugin e2e tests on a PR label Aug 27, 2024
@CarmenPopoviciu CarmenPopoviciu changed the title wip(wrangler): WIP watch mode for Workers with assets feat(wrangler): watch mode for Workers + Assets Aug 27, 2024
@CarmenPopoviciu CarmenPopoviciu force-pushed the carmen/watch-mode branch 3 times, most recently from dd3e946 to 84b771a Compare August 28, 2024 10:55
@CarmenPopoviciu CarmenPopoviciu merged commit dff8d44 into main Aug 30, 2024
@CarmenPopoviciu CarmenPopoviciu deleted the carmen/watch-mode branch August 30, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run wrangler + vite-plugin e2e tests on a PR

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants