This repository was archived by the owner on Oct 23, 2026. It is now read-only.
Repository navigation
feat(upgrade): progress bars for delta-patch apply and full download #1281
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * Byte-driven progress reporting for long-running upgrade phases (patch apply, | ||
| * full-binary download). | ||
| * | ||
| * sentry upgrade already runs under `withProgress`, which animates a spinner | ||
| * and passes down a `setMessage(text)` callback. To avoid two competing | ||
| * in-place redraws fighting over the same terminal line, this helper does NOT | ||
| * draw its own bar — it formats a compact progress string and pushes it into | ||
| * that `setMessage` callback, so the byte counter rides on the existing spinner. | ||
| * | ||
| * Design contract: | ||
| * - Cosmetic ONLY — a formatting/callback failure must never abort the work. | ||
| * - Determinate ("152 MB / 310 MB [====> ] 49%") when a byte `total` is given; | ||
| * an indeterminate byte counter ("38 MB") otherwise (the decompressed | ||
| * download size isn't known ahead of time). | ||
| * - Updates are throttled so a fast byte stream doesn't spam the spinner. | ||
| */ | ||
|
|
||
| import { formatBytes } from "./formatters/numbers.js"; | ||
|
|
||
| /** Callback that sets the surrounding spinner's message text. */ | ||
| export type SetMessage = (message: string) => void; | ||
|
|
||
| export type ByteProgress = { | ||
| /** Report `bytes` additional bytes processed since the last call. */ | ||
| onProgress: (bytes: number) => void; | ||
| /** Emit a final message reflecting the total processed (best-effort). */ | ||
| done: () => void; | ||
| }; | ||
|
|
||
| const BAR_WIDTH = 16; | ||
| /** Minimum gap between spinner message updates. */ | ||
| const THROTTLE_MS = 100; | ||
|
|
||
| function renderBar(frac: number, width = BAR_WIDTH): string { | ||
| const filled = Math.max(0, Math.min(width, Math.round(width * frac))); | ||
| return "█".repeat(filled) + "░".repeat(width - filled); | ||
| } | ||
|
|
||
| /** | ||
| * Create a byte-progress reporter that feeds a spinner `setMessage` callback. | ||
| * | ||
| * @param label - Short label prefix (e.g. "Applying 3 patch(es)"). | ||
| * @param totalBytes - Expected total bytes; `null` renders an indeterminate | ||
| * byte counter instead of a bar. | ||
| * @param setMessage - Spinner message setter (from `withProgress`). When | ||
| * undefined (JSON mode / non-TTY / no surrounding spinner), this is a no-op | ||
| * so nothing is drawn. | ||
| * @param nowMs - Injectable clock for tests. | ||
| */ | ||
| export function makeByteProgress( | ||
| label: string, | ||
| totalBytes: number | null, | ||
| setMessage?: SetMessage, | ||
| nowMs: () => number = Date.now | ||
| ): ByteProgress { | ||
| let written = 0; | ||
| let lastEmit = 0; | ||
|
|
||
| const format = (): string => { | ||
| if (totalBytes === null || totalBytes <= 0) { | ||
| return `${label} ${formatBytes(written)}`; | ||
| } | ||
| const frac = Math.min(written / totalBytes, 1); | ||
| const pct = Math.round(frac * 100); | ||
| return ( | ||
| `${label} [${renderBar(frac)}] ` + | ||
| `${formatBytes(written)} / ${formatBytes(totalBytes)} (${pct}%)` | ||
| ); | ||
| }; | ||
|
|
||
| const emit = (): void => { | ||
| // Cosmetic only — a formatting or callback failure must never propagate. | ||
| try { | ||
| setMessage?.(format()); | ||
| } catch { | ||
| // ignore — progress is cosmetic | ||
| } | ||
| }; | ||
|
|
||
| const onProgress = (bytes: number): void => { | ||
| written += bytes; | ||
| if (!setMessage) { | ||
| return; | ||
| } | ||
| const now = nowMs(); | ||
| if (now - lastEmit < THROTTLE_MS) { | ||
| return; | ||
| } | ||
| lastEmit = now; | ||
| emit(); | ||
| }; | ||
|
|
||
| // Emit a final, un-throttled message so the last state is always shown. | ||
| const done = (): void => { | ||
| emit(); | ||
| }; | ||
|
|
||
| return { onProgress, done }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.