Repository navigation
perf(cli): Load syntax highlighting lazily and allow compiling it out - #1765
Merged
Merged
Conversation
`markdown.ts` imported `cli-highlight` at the top level, so every command that reaches `buildCommand` initialized all of highlight.js and parse5 (~1.2 MB of the npm bundle), even when it never renders a code block. Move highlighting into `formatters/highlight.ts`, the only importer of `cli-highlight`. It requires the package on the first code block through the existing `_require` + `REQUIRE_ALIAS_FILTER` pattern, so the CLI bundle keeps it but only runs it when needed. Bundles that don't need colored code blocks, like the MCP server, can set `__SENTRY_CLI_SYNTAX_HIGHLIGHT__` to `false`; esbuild then drops the whole stack. Code blocks fall back to the existing uniform yellow. Co-Authored-By: BYK <burak.kaya@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
BYK
approved these changes
Oct 31, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Groundwork for #1731. The plan there is to build
@sentry/mcp-serverfrom the real CLI runner with a smaller route map. That build doesn't fit the size budget today, and about 1.2 MB of the overage is syntax highlighting.buildCommand→formatters/output→human→markdownimportscli-highlightat the top level, which brings in all of highlight.js and parse5. So every command loads it, even if it never renders a fenced code block.formatters/highlight.tsis now the only module that importscli-highlight, and it does two things:cli-highlighton the first code block, using the same_require+REQUIRE_ALIAS_FILTERpattern asformatters/json. The npm bundle and the SEA bundle still include the code, but it only runs when needed. Rendered output doesn't change.define: { __SENTRY_CLI_SYNTAX_HIGHLIGHT__: "false" }. esbuild folds the guard, drops the deadrequire(), and leaves out highlight.js, parse5, and cli-highlight's copy of chalk. Code blocks then use the existing fallback color, uniform yellow, the same as an unknown language. I chose a define over aliasing the module because it's one line in any esbuild config, needs no resolver plugin, and follows the guard pattern already used forSENTRY_CLI_VERSIONand__SENTRY_DEBUG_ID__.Sizes from esbuild metafiles, using
script/bundle.tsoptions:__SENTRY_CLI_SYNTAX_HIGHLIGHT__=falsesrc/index.ts(full CLI)lib/command.tsgraphformatters/markdown.tsgraphThe default bundle grows by 186 B compared with
main. On the npm bundle in a sandbox (50 interleaved runs, medians), startup dropped from 658 to 614 ms forsentry --version, from 718 to 664 ms forsentry help, and from 701 to 643 ms forsentry org list --help.I also checked the rest of the formatter layer for eager heavy imports. None of them is a cheap win, so this PR leaves them alone:
human.ts→api-client.tsbrings in@sentry/api(~400 KB). The MCP server needs it anyway.sixel-dashboard.ts→sixel-image.tsbrings inpngjsandjpeg-js(~52 KB).help.ts→sixel.tsalso reaches them.markedis ~39 KB, and the renderer needs it.Plain output still runs the highlighter and then strips ANSI. It can't skip highlighting yet, because the stripped output doesn't always match the input byte for byte. That could be a follow-up.
via BYK.
--
View Session in Sentry