Skip to content

ref(cli): Read the route tree from a registry instead of app.ts - #1766

Merged
BYK merged 2 commits into
mainfrom
ref/cli-route-registry
Oct 31, 2026
Merged

BYK merged 2 commits into
mainfrom
ref/cli-route-registry

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

This is groundwork for #1731. That PR builds @sentry/mcp-server from the real CLI runner with a smaller route map ({ mcp, auth, help }, mcp as the default command). Today that can't work: lib/help.ts and lib/completions.ts import routes from app.ts, and lib/list-command.ts loads it lazily with require(). Every command imports help.ts through buildCommand, so bundling any one command pulls in the whole CLI: every other command, sentry init, and Mastra.

app.ts now registers its route map with setRoutes() in the new lib/route-registry.ts. help, completions, list-command, and the schema command read it from there. getRoutes() throws a clear error when nothing has been registered. list-command uses findRoutes() instead, so a command's func called on its own, as unit tests do, still runs without subcommand hints, as it did before. Another entry point can register a smaller map.

Output doesn't change: sentry --help, sentry help --json, sentry cli completion bash, sentry schema issues --json, and sentry projects list --help are byte-identical before and after, from source and from the npm bundle. The plural-alias hint (sentry projects list → Tip: "list" is a subcommand) still works in the bundle.

Bundle size with an esbuild metafile (minified ESM, the same plugins as script/bundle.ts):

Entry Before After
commands/auth/whoami.ts 1822 modules, 194 command files, 5.62 MB 1156 modules, 1 command file, 2.89 MB
lib/command.ts 1822 modules, 5.62 MB 1107 modules, 2.55 MB
commands/auth/index.ts 1822 modules, 5.62 MB 1171 modules, 2.93 MB
commands/mcp.ts 1822 modules, 5.62 MB 1108 modules, 2.55 MB

After the change, none of these include app.ts or @mastra/*.

Guard: test/lib/route-registry.test.ts bundles every module in src/lib/ and fails, naming the importer, if any of them reaches app.ts. It follows lazy _require() loads too. sdk-invoke.ts is the one exception: it's the library-mode runner, reached only from src/index.ts, and it executes the whole app. The three interceptSubcommand tests that were skipped because that require() failed under vitest now run. list-command no longer needs the require-alias rewrite, so it's removed from the filters in script/build.ts and script/bundle.ts.

Not included, left for #1731 or later PRs: cli.ts still imports ./app.js for run() and unknown-command reporting. Making the application injectable is the next step. I left cli.ts alone here to stay clear of #1762. This branch merges cleanly with #1762. whoami also still reaches lib/init/ui/ink-ui.ts through resolve-target.ts (the Ink prompt UI, not the init wizard).

via BYK.

--

View Session in Sentry

help.ts and completions.ts imported the route map from app.ts, and
list-command.ts loaded it lazily with require(). Every command imports
help.ts through buildCommand, so bundling any one command pulled in the
whole CLI: every other command, sentry init, and Mastra.

app.ts now registers its route map with setRoutes() in
lib/route-registry.ts, and help, completions, list-command, and schema
read it from there. getRoutes() throws when nothing is registered yet.
list-command uses findRoutes() so a command's func called on its own
(as unit tests do) still runs without subcommand hints, as before.

Another entry point can register a smaller map. Bundling
commands/auth/whoami.ts goes from 1822 modules (5.6 MB) to 1156
(2.9 MB), and no longer includes app.ts or Mastra.

A test bundles every module in src/lib/ and fails if one reaches
app.ts, following lazy _require() loads too. The interceptSubcommand
tests that were skipped because that require() failed under vitest now
run.

Co-Authored-By: BYK <burak.kaya@sentry.io>
@vercel

vercel Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 31, 2026 2:33pm UTC

Request Review

# Conflicts:
#	packages/cli/script/build.ts
#	packages/cli/script/bundle.ts
@BYK
BYK enabled auto-merge (squash) October 31, 2026 14:34
@BYK
BYK merged commit 62afa42 into main Oct 31, 2026
26 checks passed
@BYK
BYK deleted the ref/cli-route-registry branch October 31, 2026 14:43
sentry-junior Bot added a commit that referenced this pull request Oct 31, 2026
Brings in the #1766 squash (route registry). This branch already merged
#1766's branch, and its final head only added main's #1763-#1765, which
are here too, so every conflict (`app.ts`, `lib/help.ts`,
`script/bundle.ts`) resolves to this branch's version: the application
setup and `setRoutes()` live in `lib/application.ts`, help names come from
`lib/app-identity.ts`, and the require-alias filter is the shared
`script/lib/require-alias-plugin.ts`. The tree is unchanged.

This branch was previously deployed

1 inactive deployment
Preview — 276095a6 Deployed Oct 31, 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