Skip to content
This repository was archived by the owner on Oct 15, 2026. It is now read-only.

refactor(background): split index.ts into domain modules - #10

Merged
kevinraymond merged 2 commits into
mainfrom
claude/modularize-background-service-worker-qChjG
Apr 27, 2026
Merged

kevinraymond merged 2 commits into
mainfrom
claude/modularize-background-service-worker-qChjG

Conversation

@kevinraymond

@kevinraymond kevinraymond commented Apr 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Trims src/background/index.ts from 1756 → 142 lines by moving message handlers, lifecycle logic, and listener bodies into domain modules. Future PRs can touch one concern at a time without re-reading the entire service worker.

The MV3 service worker still registers all listeners synchronously at module top level so wake-up events aren't dropped during cold start.

Layout

  • messages/{suspension,sessions,cloud,pro,recovery,exportReminder,dedup,backupHealth,devtools}.ts — one handler per slice of the MessageType union
  • messages/index.ts — central handleMessage dispatcher (with exhaustiveness check)
  • messages/types.ts — the unchanged MessageType union
  • lifecycle/{hibernation,onInstalled,onStartup}.ts — install/startup handlers and the post-startup re-discard guard (its comment block moved with it)
  • state.ts, badge.ts, alarms.ts, contextMenus.ts — shared helpers
  • listeners.ts — listener bodies (registrations stay in index.ts)

No behavior change. The MessageType union is unchanged.

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test --run (745/745 passing)
  • Manual: force-stop the service worker via DevTools → Application → Service Workers, then trigger Alt+Shift+S and confirm the active tab discards (validates synchronous listener registration on wake)

https://claude.ai/code/session_012cj1ZbkZ5aJop1tCDtJ9QQ


Generated by Claude Code

Trim src/background/index.ts from 1756 to 142 lines by moving
message handlers, lifecycle logic, and listener bodies into
domain modules. The MV3 service worker still registers all
listeners synchronously at module top level so wake-up events
aren't missed.

- messages/{suspension,sessions,cloud,pro,recovery,exportReminder,
  dedup,backupHealth,devtools}.ts: one handler per slice of the
  MessageType union; messages/index.ts is the central dispatcher
- lifecycle/{hibernation,onInstalled,onStartup}.ts: install/startup
  handlers and the post-startup re-discard guard
- state.ts, badge.ts, alarms.ts, contextMenus.ts: shared helpers
- listeners.ts: listener bodies (registrations stay in index.ts)

No behavior change. The MessageType union is unchanged.
@codecov-commenter

codecov-commenter commented Apr 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 53 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/background/alarms.ts 0.00% 15 Missing ⚠️
src/background/state.ts 0.00% 15 Missing ⚠️
src/background/contextMenus.ts 0.00% 14 Missing ⚠️
src/background/badge.ts 0.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

Mirror the pre-PR coverage semantics. The old src/background/index.ts
was excluded by the src/**/index.ts entry-point rule, so the handler
code inside it was never measured. Now that the same code lives in
src/background/{listeners,lifecycle/*,messages/*}.ts, codecov sees
643 "newly uncovered" lines on what is in fact unchanged code.

Add the moved files to the exclude list so the coverage signal
reflects what's actually been tested.

https://claude.ai/code/session_012cj1ZbkZ5aJop1tCDtJ9QQ
@kevinraymond
kevinraymond merged commit 7792933 into main Apr 27, 2026
7 checks passed
@kevinraymond
kevinraymond deleted the claude/modularize-background-service-worker-qChjG branch April 27, 2026 07:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants