Skip to content

fix(cli): instrument new Cloudflare workers and harden the Wrangler flow - #2563

Open
sentry-junior[bot] wants to merge 12 commits into
feat/cli-wizard-sourcemaps-cloudflarefrom
feat/cli-wizard-sourcemaps-cloudflare-fixes
Open

sentry-junior[bot] wants to merge 12 commits into
feat/cli-wizard-sourcemaps-cloudflarefrom
feat/cli-wizard-sourcemaps-cloudflare-fixes

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2529. These fixes address Warden and Bugbot findings on that PR, and each one changes behaviour that sentry-wizard 9.1.0 shipped, so they're kept apart from the port. The fixes that keep upstream behaviour are on #2529 itself.

Behaviour changes against sentry-wizard 9.1.0

  • Cloudflare, missing main file (SHJ-RG7): when Wrangler's main points to a file that doesn't exist, the wizard creates the starter worker there and wraps it. Upstream skipped setup silently and still reported success.
  • Cloudflare, no main (YBF-MLA): the starter worker written to src/index.ts is now wrapped with Sentry.withSentry(). Upstream wrote a plain worker with no Sentry.
  • Cloudflare, existing src/index.ts with no main: the existing file is wrapped instead of being overwritten by the starter worker.
  • Cloudflare, wrangler.toml (WHX-UYU): the copy-paste snippet includes main = "src/index.ts" when the wizard sets main. Upstream left it out.
  • webpack, non-array plugins (UNB-FTW): plugins: existingPlugins or plugins: getPlugins() becomes [...existingPlugins, sentryWebpackPlugin(…)]. Upstream replaced the value and dropped those plugins. undefined and null are still replaced.
  • Wrangler, existing post<deploy> (5YD-7F8): an existing post<deploy> script is kept, with && <pm> sentry:sourcemaps added after it. Upstream overwrote it. It's left alone when it already runs sentry:sourcemaps.
  • Wrangler, Yarn 2+ (RP5-3PG): Yarn Berry doesn't run post scripts, so the upload is chained onto the deploy script (&& yarn sentry:sourcemaps). npm, pnpm, Yarn 1 and Bun keep the post<deploy> hook.
  • Wrangler, no deploy script (5WP-827): the wizard still writes sentry:sourcemaps, the .sentryclirc upload target and the auth token, then shows the deploy command to add. Upstream stopped before writing any of them and still reported success.
  • Wrangler, wrapped commands (HJA-K3Y): deploy scripts that run wrangler deploy through npx (including -y and wrangler@<version>), pnpx, bunx, pnpm / pnpm exec / pnpm dlx, yarn, bun x, cross-env, or a leading VAR=value are now edited. Upstream accepted only a bare wrangler deploy.
  • Wrangler, manual fallback: when the wizard can't edit the deploy script, it shows wrangler deploy with the --outdir, --var SENTRY_RELEASE:… and --upload-source-maps flags. Upstream showed the unchanged script.
  • Source maps, framework redirect (YSZ-BFQ): the SvelteKit and React Native redirect is offered only when this CLI version has that wizard. Without it, the wizard shows the framework's guides and asks whether to continue or exit, instead of throwing ValidationError once the redirect is accepted. SvelteKit shows up again on its own once its runner lands.
  • Cloudflare, missing .js or .mjs main: the starter worker written there is plain JavaScript. Only TypeScript entry points get the typed starter.
  • Wrangler, deploy text earlier in the script (EL5-RSX): the flags go on the real wrangler deploy command, not on earlier text that matches it, such as echo Running wrangler deploy. Upstream edited the first match.
  • Wrangler, rerun: a deploy script that already sets SENTRY_RELEASE doesn't get a second --var SENTRY_RELEASE:…. Upstream added one on every run.
  • Cloudflare, existing compatibility_date: the Worker's date is kept, and today's date is only added when the config has none. The TOML snippet marks it "only if not set yet". Upstream always overwrote it with today's date.
  • Wrangler, pages deploy and versions deploy: these aren't treated as a Workers deploy, bare or through a runner, so they don't get the Workers-only flags that would break them. The wizard shows the manual instructions instead. Upstream edited a bare wrangler pages deploy or wrangler versions deploy.

Product calls

  • Wrapping with withSentry: follows the Wrangler install guide and the existing wrap path for configured entry points.
  • post<deploy> hook, merged rather than overwritten: the Wrangler source maps guide uses a postdeploy hook, so that stays the default. An existing hook is kept, the way the other flows keep user scripts.
  • && chaining for Yarn 2+ only: matches how the sentry-cli flow attaches sentry:sourcemaps to the build script. Other package managers keep the hook from the docs.
  • Warn, not fail, with no deploy script: matches the sentry-cli flow, which writes the script and config and then shows what to add by hand.
  • Wrapped npx / pnpm exec deploy commands: the new flags go after the wrangler deploy segment, as they do for a bare command.

via @BYK.

--

View Session [Sentry]

Changes how the ported source maps and Cloudflare wizards behave where
sentry-wizard 9.1.0 left a project half set up:

- Cloudflare: create a missing entry point where Wrangler's `main` points,
  and wrap new and existing workers with `Sentry.withSentry()`
- Cloudflare: show `main` in the wrangler.toml snippet when it is added
- webpack: keep a non-array `plugins` value by spreading it
- Wrangler: keep an existing `post<deploy>` script, chain the upload onto
  the deploy script for Yarn 2+, and still set up the upload script and
  CLI config when no deploy script is picked
- Wrangler: edit deploy scripts that run wrangler through npx, pnpm exec,
  yarn, bunx, or cross-env, and show the flags to add when it can't
- Source maps: offer the SvelteKit or React Native wizard only when this
  version has it
@sentry-junior
sentry-junior Bot requested a review from BYK November 27, 2026 17:14
@sentry-junior
sentry-junior Bot added this pull request to stack #2564 November 27, 2026 17:14
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 27, 2026 11:22pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 27, 2026 11:22pm UTC

Request Review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

sentry-junior Bot and others added 2 commits November 27, 2026 22:05
The starter worker had TypeScript annotations whatever the entry point's
extension, so a missing `.js` or `.mjs` `main` got a worker Wrangler
couldn't bundle. Leave the annotations out unless the entry point is a
TypeScript file.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
The flags went to the first text match of the deploy command, so an
earlier command such as `echo Running wrangler deploy` got them instead
of the real `wrangler deploy`. Insert them at the deploy command's own
offset in the script.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

The deploy-script rewrite checked for an existing `--outdir` and
`--upload-source-maps`, but always appended `--var SENTRY_RELEASE:…`, so
each rerun stacked another one. Skip it when the script already sets
SENTRY_RELEASE, and leave the script alone when nothing is missing.
The Cloudflare wizard set `compatibility_date` to today, overwriting the
user's date and with it the Worker's runtime behaviour. Set it only when
the Wrangler config doesn't have one, and say so in the TOML snippet.
…deploy

Any `deploy` after `wrangler` counted as a Workers deploy, so
`wrangler pages deploy` and `wrangler versions deploy`, bare or run
through a runner such as `npx`, got the Workers-only `--outdir`,
`--upload-source-maps` and `--var` flags, which break those commands.
Skip them, so the wizard shows the manual instructions instead.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

The rerun guard only knew `SENTRY_RELEASE:` without quotes, so
`--var SENTRY_RELEASE=…` or a quoted binding still got a second
`--var SENTRY_RELEASE:…`. Match `=` or `:` and optional quotes, the
way the Spotlight `--var` check in `lib/wrangler.ts` does.
Any dash flag before `wrangler` counted as a runner arg, so in
`pnpm -C wrangler deploy`, `pnpm --filter wrangler deploy` or
`yarn --cwd wrangler deploy` the directory or package name `wrangler`
was taken for the CLI and the package's `deploy` script got Workers
flags. Skip the value of runner flags that take one.
@vercel
vercel Bot temporarily deployed to Preview – sentry-local November 27, 2026 23:03 Inactive

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

The value flags were one list for every runner, so `pnpm -w` and
`yarn -p`, which take no value, skipped the `wrangler` after them and the
deploy script wasn't recognized. Key the list by runner: `-p` and `-w`
take a value only for npx.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 698999a. Configure here.

The runner's value flags came from the first arg only, so after
`cross-env` or a leading `FOO=1` none applied, and in
`cross-env … yarn --cwd wrangler deploy` the directory was taken for the
CLI. Pick up the runner wherever it appears before `wrangler`.

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — d43fdb75 Deployed Nov 27, 2026 by vercel[bot]
Preview – sentry-local — d43fdb75 Deployed Nov 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant