Skip to content

Make assets field optional in the Worker config when using assets #8545

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

Merged
merged 16 commits into from
Mar 20, 2025

Conversation

jamesopstad
Copy link
Contributor

@jamesopstad jamesopstad commented Mar 18, 2025

Fixes #8301.

This makes the assets field optional when using assets. Assets are now included at build time if the client environment is being built.

I've also replaced use of assert in cases of user error and ensured that Worker config warnings are only displayed once at build time.


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • Wrangler E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because: N/A
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: coming soon
  • Wrangler V3 Backport
    • TODO (before merge)
    • PR:
    • Not necessary because: N/A

@jamesopstad jamesopstad added the vite-plugin Relating to the `@cloudflare/vite-plugin` package label Mar 18, 2025
@jamesopstad jamesopstad requested review from a team as code owners March 18, 2025 11:50
Copy link

changeset-bot bot commented Mar 18, 2025

🦋 Changeset detected

Latest commit: a43c246

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/vite-plugin 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

Copy link
Contributor

github-actions bot commented Mar 18, 2025

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/13958531711/npm-package-wrangler-8545

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

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

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-wrangler-8545 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-workers-bindings-extension-8545 -O ./cloudflare-workers-bindings-extension.0.0.0-v5b2018d36.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v5b2018d36.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-create-cloudflare-8545 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-kv-asset-handler-8545

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-miniflare-8545

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-pages-shared-8545

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-unenv-preset-8545

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-vite-plugin-8545

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-vitest-pool-workers-8545

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-workers-editor-shared-8545

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-workers-shared-8545

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13958531711/npm-package-cloudflare-workflows-shared-8545

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


wrangler@4.2.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 4.20250317.1
workerd 1.20250317.0 1.20250317.0
workerd --version 1.20250317.0 2025-03-17

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

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

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

Looks good to me, I just left a couple of small questions 🙂

Comment on lines +92 to +96
if (!configPath) {
throw new Error(
`Config not found. Have you created a wrangler.json(c) or wrangler.toml file?`
);
}
Copy link
Member

@dario-piotrowicz dario-piotrowicz Mar 18, 2025

Choose a reason for hiding this comment

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

like my other comment I am wondering about the reason to change this here, if we want to move away from asserts shouldn't the other assert calls in this file be converted as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally I believe that assertions should be checking that our assumptions about the state of the code is correct, e.g. that a value is indeed defined when we believe it should, or that a string is not empty, etc. A failing assert() call raises an AssertionError rather than an Error, which we could capture and send to Sentry, for example.

A failing assertion should indicate a bug in our code. We don't want "expected" user errors from polluting that signal.

I would be surprised if this is contentious.

Copy link
Member

@dario-piotrowicz dario-piotrowicz Mar 18, 2025

Choose a reason for hiding this comment

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

Makes sense to me, I was just wondering, thanks for the clarification 🙂

Copy link
Member

Choose a reason for hiding this comment

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

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 18, 2025
@jamesopstad jamesopstad force-pushed the james/zero-config-assets branch from f38f789 to a43c246 Compare March 19, 2025 23:16
@jamesopstad jamesopstad merged commit aadb49c into main Mar 20, 2025
25 of 27 checks passed
@jamesopstad jamesopstad deleted the james/zero-config-assets branch March 20, 2025 00:26
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vite-plugin Relating to the `@cloudflare/vite-plugin` package
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Make assets field optional when using assets
3 participants