feat: support custom worker output path for easier integration of cloudflare worker handlers #14029
+77
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #13692
closes #10117
closes #1712
This PR introduces a new
workerScriptPath
option toAdapterOptions
, allowing users to specify the output path for the generated worker script. This option takes precedence over themain
field in thewrangler
config, enabling more flexible integration with custom Cloudflare Worker handlers.The Problem
Currently,
@sveltejs/adapter-cloudflare
outputs the compiled worker to.svelte-kit/cloudflare/_worker.js
, and this is hardcoded as the entrypoint via themain
field inwrangler.jsonc
. This setup makes it difficult to extend the Worker with custom handlers (e.g.,fetch
,queue
,scheduled
, etc.) since the generated file isn't easily imported or wrapped.After this PR
With this change, you can override the default worker script path and use your own file (e.g.,
src/index.ts
) as themain
entry in thewrangler
config, allowing for easier extension and composition.Example setup
Update
svelte.config.js
:Update
wrangler.jsonc
:Create
src/index.ts
:You can now extend this file with additional handlers, just like a standard Cloudflare Worker script. For example, you can add
queue
,scheduled
, or custom logic before or after callingsveltekit.fetch()
.✅ Result
.svelte-kit/cloudflare/_worker.js
) is now controlled viaworkerScriptPath
.src/index.ts
).fetch
,queue
,scheduled
, etc.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits