Repository navigation
feat(cli): add the wizard's shared AST and URL helpers - #2520
Conversation
Port `ast-utils` and `url` from getsentry/sentry-wizard into `src/lib/wizard/utils/`. The SvelteKit, Remix, React Router, Angular, Nuxt, source maps, Cloudflare, React Native and Android wizards all use them, so they land once here and the platform PRs that follow build on them in parallel. `ast-utils` edits recast ASTs, so recast and ast-types become direct dev dependencies; both already came in through magicast. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
📊 MCP Server Token Cost ReportSummary
Per-Tool Breakdown
Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better. MCP Apps viewsEach
The budget applies to raw bytes, and the view's generator fails over it. |
…st-helpers Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…st-helpers Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
| */ | ||
| export function getLastRequireIndex(program: t.Program): number { | ||
| let lastRequireIdex = -1; | ||
| program.body.forEach((s, i) => { |
There was a problem hiding this comment.
We should be using for .. of, isn't this enforced by a lint rule already?
There was a problem hiding this comment.
No lint rule was enforcing it. 2c987511 enables unicorn/no-array-for-each repo-wide in .oxlintrc.json and converts all 34 .forEach sites to for…of, getLastRequireIndex included. The other 33 are in cli, mcp-core, mcp-cloudflare, apps/local and apps/games-api. A return inside a callback became continue.
| * Checks if a file where we don't know its concrete file type yet exists | ||
| * and returns the full path to the file with the correct file type. | ||
| */ | ||
| export function findFile( |
There was a problem hiding this comment.
We should have this functionality already in the CLI under DSN discovery code or something like that.
There was a problem hiding this comment.
The DSN code has no extension-probing helper, but lib/dsn/fs-utils.ts has isRegularFile. 2c987511 moves findFile there and builds it on isRegularFile, so a directory or FIFO with a matching name is skipped. It's async now, and it has tests. The platform PRs will update their call sites when they next pick up this base.
| * | ||
| * Example: https://org-slug.sentry.io/issues/?project=1234567 | ||
| */ | ||
| export function getIssueStreamUrl({ |
There was a problem hiding this comment.
We should already have a URL builder somewhere in the codebase?
There was a problem hiding this comment.
There was one. 2c987511 adds buildProjectIssuesUrl(orgSlug, projectId) to lib/sentry-urls.ts, built on getOrgBaseUrl like buildEventSearchUrl, with SaaS and self-hosted tests. It also deletes wizard/utils/url.ts.
Address review feedback on the shared wizard helpers: - Enable unicorn/no-array-for-each repo-wide and convert every .forEach call site to for...of, including getLastRequireIndex. - Add buildProjectIssuesUrl to lib/sentry-urls.ts, built on getOrgBaseUrl like buildEventSearchUrl, and delete the wizard-specific wizard/utils/url.ts. - Move findFile into lib/dsn/fs-utils.ts and build it on isRegularFile, so a directory or FIFO with a matching name is skipped. It is async now. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2c98751. Configure here.
Re-export buildProjectIssuesUrl from lib/sentry-web-urls.ts through withSentryBaseUrl(getApiBaseUrl()), like the other user-facing link builders, so self-hosted and regional logins get links on the host they are authenticated against. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…eat/cli-wizard-shared-ast-helpers Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…izard base Merges origin/feat/cli-wizard-shared-ast-helpers at f0a48de (#2520, the chart-app fix and #2519's positional rework) and fixes what it breaks: - `runWizard` no longer takes `debug`, so the redirect to another wizard drops it. - `wizard/utils/url.ts` is gone. The source maps outro links to the project's issues with `buildProjectIssuesUrl` from `lib/sentry-web-urls`. - `findFile` now comes from `lib/dsn/fs-utils` and is async, so the tsc, Vite and webpack tools await it. - The new `no-array-for-each` lint rule: two `forEach` loops become `for...of`. - The wizard docs fragment keeps the base's flag table and the source maps paragraph from this branch. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Before v4.0.0, the setup wizards of getsentry/sentry-wizard move into the CLI as `sentry wizard`, so there is one tool, one login and one telemetry client, and the wizards call v4 `sentry` commands instead of sentry-cli v2. Tracking issue: #2511 (part of #1965). This is the first PR in that stack: the command, its login, and the Next.js flow. ## Changes - **`sentry wizard [<org>/<project>] [<integration>]`**: the target comes first, like other commands, and both are optional. The integration takes the `@sentry/wizard -i` ids, one at a time; without it the picker runs. The target uses the CLI's org/project syntax and resolves after login like other commands' targets; without it the org and project pickers run, with no detection. A bare integration id is never read as a target and a single bare word is always read as an integration, so a project spelled like one is written `my-org/nextjs`. `-f/--force` is the only flag: it changes a project with uncommitted changes without asking and force-installs the SDK. Everything else comes from the CLI: the instance from `SENTRY_URL` or the stored login, Spotlight mode from `SENTRY_SPOTLIGHT`, telemetry from the CLI's settings, and debug output from `--verbose`/`--log-level`. No other `@sentry/wizard` flag or `SENTRY_WIZARD_*` variable is accepted, hidden or not; a test pins the flags and `ci:policy` rejects `SENTRY_WIZARD_` under `packages/cli/src`. - **Sign-up flags are removed.** `-s/--signup`, `--promo-code` and `--coming-from` fail as unknown flags, because the CLI's login has no sign-up or partner step. `promoCode`/`comingFrom` are gone from the wizard options, the welcome banner and the CI step. - **The Next.js flow** is ported as-is in `src/lib/wizard/nextjs/`, with its tests. Each flow loads lazily. The picker lists only ported flows, and naming an unported integration says it isn't available in this version yet. Cordova and Electron are dropped along with sentry-wizard's `lib/`. - **Shared helpers** are in `src/lib/wizard/utils/`. A small pnpm catalog reader replaces js-yaml. - **Login uses the CLI's own login** instead of the `account/settings/wizard/<hash>` browser flow: the stored `sentry auth login` session, an agent handoff from `SENTRY_HANDOFF`, or the device flow with `org:ci` and `org:tokens`. The wizard then picks the org, picks or creates the project for the flow's platform, reads its DSN, and creates an org auth token for source map uploads. If it can't create a token, for example when there's no TTY to add scopes, it writes the placeholder token and says so. - **No `sentry-cli` binary needed.** The wizard runs inside the CLI, so it never installs or checks for `sentry-cli`; the old `get-cli` + `sentry-cli --version` check isn't ported. - **Telemetry** goes through the CLI's Sentry client and follows the CLI's telemetry settings (`SENTRY_CLI_NO_TELEMETRY`, `DO_NOT_TRACK`, `sentry cli defaults`). - `sentry init` still prints the agent setup guide. Its help points to `sentry wizard`, and the wizard's help points back to `init`. Merging the two is #2510, after v4. This adds one dependency: `magicast@0.2.11`, which brings recast. They stay until the config edits move to the shared flow in #2510. **Breaking for `@sentry/wizard` users:** the command line changes to `sentry wizard [<org>/<project>] [<integration>]` with only `-f/--force`. Every other `@sentry/wizard` flag, including `--signup`, `--promo-code` and `--coming-from`, now fails as an unknown flag, `SENTRY_WIZARD_*` variables are ignored, and the Cordova and Electron wizards are gone. ## Rest of the stack 1. This PR: scaffold, auth, Next.js 2. #2520: shared AST and URL helpers 3. JS frameworks: SvelteKit, Remix, React Router, Nuxt, Angular 4. Source maps and Cloudflare, with sentry-cli v2 calls moved to v4 `sentry` commands 5. Mobile: iOS and Apple Snapshots, React Native, Android, Flutter 6. Wizard e2e tests in toolkit CI <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A23ba814e02fcece5f64e00f096d03341 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A23ba814e02fcece5f64e00f096d03341) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A23ba814e02fcece5f64e00f096d03341/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
#2519 and #2520 were squash-merged into main, so this branch's base is now main. The add/add conflicts came from the squashed wizard files. main's copies of run.ts and test/commands/wizard.test.ts equal f0a48de, which this branch already merged, so this branch's Android and Flutter additions are kept. project-data.ts and its test take main's copy, which has the #2559 fix for the origin trust check. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
#2519 and #2520 were squash-merged, so this PR's base is now main. Resolved the add/add conflicts: run.ts keeps this branch's runner registrations (main's copy equals the old base), and project-data.ts and its test take main's copy, with the #2559 context-scoped origin trust fix (this branch didn't change them). Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>

Stacked on #2519. Tracking issue: #2511.
Nine of the remaining sentry-wizard flows (SvelteKit, Remix, React Router, Angular, Nuxt, source maps, Cloudflare, React Native, Android) use the same two helpers. Landing them here, once, lets those platform PRs stack on this one in parallel without each one re-adding the same files.
src/lib/wizard/utils/ast-utils.ts: finds and edits nodes in recast ASTs and reads and writes JSON-C. It's ported from sentry-wizard with strict types (unknownin place ofany), and invalid JSON-C now goes to the wizard's debug log instead of being dropped.src/lib/wizard/utils/url.ts: builds the issue stream URL the wizards print once setup finishes.test/lib/wizard/utils/ast-utils.test.ts.recastandast-typesbecome direct dev dependencies. Both already came in through magicast, so nothing new is bundled. They stay until the wizard's config edits move to the sharedinit/wizardflow in #2510.via @BYK.
--
View Session [Sentry]