Skip to content

perf(cli): Bundle only Zod's English locale - #1763

Merged
BYK merged 1 commit into
mainfrom
perf/zod-english-locales
Oct 31, 2026
Merged

BYK merged 1 commit into
mainfrom
perf/zod-english-locales

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Part of #1761.

Zod 4's core, classic, and mini entry points all re-export locales/index.js, which statically imports every locale. Nothing we bundle calls z.config(z.locales.xx()); Zod sets its English default by importing locales/en.js directly. A new esbuild plugin, script/lib/zod-locales-plugin.ts, resolves Zod's locales index to a module that exports only en. Error messages stay the same, and z.locales.en still works.

The npm bundle (script/bundle.ts) and the standalone binary (script/build.ts) now use the plugin. Both inline @sentry/mcp-core for sentry mcp. The plugin lives in script/lib/ so the @sentry/mcp-server bundle from #1731 can import it next to require-alias-plugin.ts.

before after
CLI dist/index.cjs 7,869,567 B 7,605,958 B (−263.6 KB)
Zod in the CLI bundle 547,614 B 284,024 B
sentry --version max RSS 210.4 MB 207.6 MB
sentry mcp --version max RSS 178.0 MB 175.0 MB
sentry mcp idle max RSS (initialize + tools/list) 180.5 MB 177.3 MB
@sentry/mcp-server bundle (#1731 branch, plugin applied locally) 3,663,084 B 3,399,473 B
sentry-mcp --version / idle max RSS (#1731) 137 / 143 MB 134 / 141 MB

Byte counts come from the esbuild metafile. RSS is process.resourceUsage().maxRSS from a -r preload, on Node 22, 3 runs each.

The new test bundles real Zod, ESM and CJS, with and without the plugin. It checks that the messages match and that z.locales has only en.

This touches script/bundle.ts in two lines, an import and one entry at the top of the plugins array. #1762 adds code just below that array, so the two may need a trivial rebase.

via BYK.

--

View Session in Sentry

Zod 4's core, classic, and mini entry points re-export locales/index.js,
which pulls every locale into the bundle. Nothing we bundle switches the
locale, so a shared esbuild plugin now resolves that index to an en-only
module. Error messages are unchanged and z.locales.en still works.

The npm bundle and the standalone binary use the plugin. It lives in
script/lib so the @sentry/mcp-server bundle can reuse it.

Part of #1761

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 30, 2026 11:30pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 30, 2026
sentry-junior Bot added a commit that referenced this pull request Oct 31, 2026
`@sentry/mcp-server` no longer has its own entry logic. `mcp-server.ts`
runs `cli.ts`'s runner with `mcp-server-app.ts`, a route map of the
CLI's real `mcp` (the default command), `auth`, and `help`. So
`sentry-mcp auth status|list|switch|logout` work, and flags and help
for `sentry mcp` and `sentry-mcp` come from one Stricli definition.

- The runner takes a `CliEntry` that loads the application, and starts
  `mcp` without the CLI's telemetry, recovery middleware, and update
  check. The command resolves when the client closes stdin, and only
  then does the runner release the network.
- `lib/app-identity.ts` replaces `login-command.ts`: hints and help
  examples name `sentry-mcp`, or `npx -y @sentry/mcp-server` under npx.
- `--flag=` and values with line breaks still parse, as they did with
  the old parser (`splitInlineFlagValues`).
- A bare `--version` answers before the application loads (86 MB,
  140 ms). The server stack loads only when `mcp` serves.
- The bundle adds #1763's Zod English-locale plugin, compiles out syntax
  highlighting and the Ink picker, and stubs MCP SDK v1's `McpServer`
  and `zod/v3`. It is 3,689,911 bytes; the budget is 3.75 MiB.

Co-Authored-By: BYK <burak.kaya@sentry.io>
@BYK
BYK merged commit c6e305c into main Oct 31, 2026
27 checks passed
@BYK
BYK deleted the perf/zod-english-locales branch October 31, 2026 13:56
sentry-junior Bot added a commit that referenced this pull request Oct 31, 2026
Brings in the squash-merged #1763 (Zod English locale), #1764 (lazy server
stack) and #1765 (lazy syntax highlighting), which this branch had merged
from their PR branches.

Conflicts:
- packages/mcp-server/src/index.ts: kept deleted. #1764's lazy loading is
  already applied to the unified entry (commands/mcp.ts -> lib/mcp.ts ->
  lib/mcp/server.ts).
- script/bundle.ts, script/build.ts: kept the zod/v3 stub plugin. bundle.ts
  keeps the shared script/lib/require-alias-plugin.ts (the
  @sentry/mcp-server bundle uses it too) instead of main's inline copy.
  main's filter also lists list-command.ts, but on this branch that file no
  longer uses _require (the route registry replaced it), so it stays out.
- formatters/highlight.ts, syntax-highlight-bundle.test.ts: identical to
  main apart from comments that point at the shared require-alias plugin.
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 — f9ba7f93 Deployed Oct 30, 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