Self-review: drop the formatter re-export shim, import @shared/format directly
The prior commit kept a pass-through `export { fmtBytes, fmtSpeed, fmtEta }` in
main/lib/formatters.ts purely so existing importers wouldn't have to change —
which re-exported fmtSpeed (zero importers, dead) and left download.ts re-
exporting fmtBytes/fmtEta with no consumer at all, undercutting the "one home"
goal.
Now the real consumers import from the canonical module directly:
- probe.ts and the download.test import from @shared/format.
- formatters.ts keeps only its internal `import { fmtBytes }` (for parseProgress)
and no longer re-exports.
- download.ts re-exports only parseProgress (its own function); the dead
fmtBytes/fmtEta re-export is removed.
No behavior change. typecheck + 248 tests + eslint + prettier green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -80,9 +80,9 @@ export function hasActiveDownloads(): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Formatting helpers (raw yt-dlp numbers → human strings) ----------------
|
// --- Formatting helpers (raw yt-dlp numbers → human strings) ----------------
|
||||||
// Implementations live in lib/formatters.ts (no electron import chain) so they
|
// parseProgress lives in lib/formatters.ts (no electron import chain) so it can
|
||||||
// can be unit-tested in isolation (L37). Re-exported here for external callers.
|
// be unit-tested in isolation (L37). Byte/ETA formatters live in @shared/format.
|
||||||
export { fmtBytes, fmtEta, parseProgress } from './lib/formatters'
|
export { parseProgress } from './lib/formatters'
|
||||||
import { parseProgress } from './lib/formatters'
|
import { parseProgress } from './lib/formatters'
|
||||||
|
|
||||||
function send(wc: WebContents, ev: DownloadEvent): void {
|
function send(wc: WebContents, ev: DownloadEvent): void {
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import type { DownloadProgress } from '@shared/ipc'
|
|||||||
import { fmtBytes } from '@shared/format'
|
import { fmtBytes } from '@shared/format'
|
||||||
|
|
||||||
// yt-dlp progress-line parsing. Extracted from download.ts so it can be
|
// yt-dlp progress-line parsing. Extracted from download.ts so it can be
|
||||||
// unit-tested without pulling in the electron import chain (L37). The byte/
|
// unit-tested without pulling in the electron import chain (L37). Byte/speed/ETA
|
||||||
// speed/ETA formatters now live in @shared/format (one home for both sides of
|
// formatting lives in @shared/format — the one home for both sides of the IPC
|
||||||
// the IPC boundary); re-exported here so existing importers keep working.
|
// boundary; consumers import it directly.
|
||||||
export { fmtBytes, fmtSpeed, fmtEta } from '@shared/format'
|
|
||||||
|
|
||||||
function num(s?: string): number | undefined {
|
function num(s?: string): number | undefined {
|
||||||
if (!s || s === 'NA') return undefined
|
if (!s || s === 'NA') return undefined
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import { execFile } from 'child_process'
|
import { execFile } from 'child_process'
|
||||||
import { existsSync } from 'fs'
|
import { existsSync } from 'fs'
|
||||||
import { getYtdlpPath, YTDLP_MISSING_MSG } from './binaries'
|
import { getYtdlpPath, YTDLP_MISSING_MSG } from './binaries'
|
||||||
import { fmtBytes } from './lib/formatters'
|
import { fmtBytes } from '@shared/format'
|
||||||
import { cleanError } from './log'
|
import { cleanError } from './log'
|
||||||
import { assertHttpUrl } from './url'
|
import { assertHttpUrl } from './url'
|
||||||
import { entryUrl, fmtDuration, type RawEntry } from './indexerCore'
|
import { entryUrl, fmtDuration, type RawEntry } from './indexerCore'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { describe, it, expect } from 'vitest'
|
import { describe, it, expect } from 'vitest'
|
||||||
// Import from the pure formatter module directly — no electron import chain (L37).
|
// Import from the pure modules directly — no electron import chain (L37).
|
||||||
import { fmtBytes, fmtEta, parseProgress } from '../src/main/lib/formatters'
|
import { parseProgress } from '../src/main/lib/formatters'
|
||||||
|
import { fmtBytes, fmtEta } from '../src/shared/format'
|
||||||
|
|
||||||
describe('fmtBytes', () => {
|
describe('fmtBytes', () => {
|
||||||
it('formats bytes under 1 KB verbatim', () => {
|
it('formats bytes under 1 KB verbatim', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user