Skip to content

fix: isolate expo-task-manager/expo-background-task to /wallet/expo/background#487

Open
pietro909 wants to merge 1 commit into
masterfrom
fix/expo-background-static-imports
Open

fix: isolate expo-task-manager/expo-background-task to /wallet/expo/background#487
pietro909 wants to merge 1 commit into
masterfrom
fix/expo-background-static-imports

Conversation

@pietro909
Copy link
Copy Markdown
Contributor

@pietro909 pietro909 commented May 12, 2026

  • Fix Lazy require() of expo-task-manager / expo-background-task is invisible to Metro #486: defineExpoBackgroundTask (and registerExpoBackgroundTask / unregisterExpoBackgroundTask) failed at JS startup because lazy require() in /wallet/expo was invisible to Metro's static dependency collector, so expo-task-manager / expo-background-task never entered the bundle graph.
  • Split task helpers into a new @arkade-os/sdk/wallet/expo/background subpath that uses static imports. /wallet/expo itself no longer references the optional Expo packages — react-native-web and Node consumers are unaffected.
  • Drop OS-task registration from ExpoWallet.setup() / .dispose(). Consumers call registerExpoBackgroundTask / unregisterExpoBackgroundTask explicitly.
  • README migration callout + teardown example updated.

Testing

Direct port of arkade-os/boltz-swap#146, whose validated build pattern is in production in Trixie Wallet. Test changes:

  • test/wallet/expo/background.test.ts rewritten to mock expo-task-manager / expo-background-task via vi.hoisted + vi.mock — the previous Module.prototype.require patching does not intercept static imports.
  • test/wallet/expo/wallet.test.ts drops the taskName / minimumBackgroundInterval mocks (those fields are gone) and adds coverage for the new warnOnRemovedBackgroundFields JS-caller guard.
  • Smoke-check after pnpm build: grep'ing dist/{esm,cjs}/wallet/expo/{index,wallet}.js shows zero runtime imports of expo-task-manager / expo-background-task — only /wallet/expo/background.{js,cjs} pulls them in.

Summary by CodeRabbit

  • New Features

    • Background helpers moved to a dedicated subpath for explicit OS registration.
    • Added ambient TypeScript types for Expo background-task APIs.
  • Documentation

    • Updated Expo background setup, examples, and architecture notes to show explicit register/unregister calls and new import paths.
    • Wallet setup examples updated to reflect removed config fields.
  • Breaking / API Changes

    • Wallet no longer auto-registers OS background tasks; background config no longer accepts taskName or minimumBackgroundInterval.
    • Added runtime warning for removed legacy background fields.
  • Tests

    • Background-task tests refactored to use static mocks; added tests for the removal-warning helper.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91be3f06-dba1-47fd-af24-c081a5005ba1

📥 Commits

Reviewing files that changed from the base of the PR and between 81f7976 and 3a6d95b.

📒 Files selected for processing (8)
  • package.json
  • src/wallet/expo/background.ts
  • src/wallet/expo/expo-modules.d.ts
  • src/wallet/expo/index.ts
  • src/wallet/expo/wallet.ts
  • src/worker/expo/README.md
  • test/wallet/expo/background.test.ts
  • test/wallet/expo/wallet.test.ts
✅ Files skipped from review due to trivial changes (2)
  • package.json
  • src/worker/expo/README.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/wallet/expo/index.ts
  • src/wallet/expo/expo-modules.d.ts
  • src/wallet/expo/wallet.ts
  • test/wallet/expo/background.test.ts
  • src/wallet/expo/background.ts
  • test/wallet/expo/wallet.test.ts

Walkthrough

This PR moves Expo background helpers to ./wallet/expo/background, replaces lazy require() with static imports of expo-task-manager and expo-background-task, removes OS-task registration from ExpoWallet.setup()/dispose(), narrows the wallet background config, and adds a runtime migration warning helper.

Changes

Expo Background Task Module Split

Layer / File(s) Summary
Type declarations and background config
src/wallet/expo/expo-modules.d.ts, src/wallet/expo/wallet.ts
Add ambient TypeScript declarations for expo-task-manager and expo-background-task; narrow ExpoBackgroundConfig (remove taskName and minimumBackgroundInterval); add exported warnOnRemovedBackgroundFields() helper.
Background module static imports and APIs
src/wallet/expo/background.ts
Replace dynamic require() with static top-level imports of Expo task packages; use TaskManager.defineTask and BackgroundTask.registerTaskAsync/unregisterTaskAsync directly in the background subpath.
API surface and ExpoWallet refactor
src/wallet/expo/index.ts, src/wallet/expo/wallet.ts
Remove background helpers from the foreground-only index; ExpoWallet.setup() no longer registers OS tasks and calls the migration warning; dispose() no longer attempts OS unregistration; update JSDoc and examples.
Package export map update
package.json
Add ./wallet/expo/background export subpath mapping to dist declaration, ESM, and CJS artifacts.
Docs and README updates
src/worker/expo/README.md
Add breaking-change warning, update import paths to the new background subpath, and show explicit registerExpoBackgroundTask() / unregisterExpoBackgroundTask() usage in examples.
Tests: mocks and migration helper
test/wallet/expo/background.test.ts, test/wallet/expo/wallet.test.ts
Refactor background tests to static vi.mock() for Expo packages; drop OS-registration expectations from wallet tests; add tests covering warnOnRemovedBackgroundFields() behavior.

Sequence Diagram(s)

sequenceDiagram
  participant Consumer
  participant ExpoWallet
  participant BackgroundTask as expo-background-task
  participant TaskManager as expo-task-manager
  Consumer->>ExpoWallet: call setup({ background: { taskQueue, foregroundIntervalMs } })
  ExpoWallet->>TaskManager: defineTask(taskName, executor) [module scope]
  Consumer->>BackgroundTask: registerTaskAsync(taskName, { minimumInterval })
  BackgroundTask->>TaskManager: trigger task executor event
  TaskManager->>ExpoWallet: executor invokes taskRunner/processors
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

Possibly related PRs

  • arkade-os/ts-sdk#336: Modifies the same src/wallet/expo/background.ts and background task runner logic; related to background-task refactoring.

Suggested reviewers

  • Kukks
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: isolating expo-task-manager and expo-background-task dependencies to a new /wallet/expo/background subpath, which is the core fix for the Metro bundler issue described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/expo-background-static-imports

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pietro909 pietro909 requested a review from Kukks May 12, 2026 13:37
Copy link
Copy Markdown
Contributor

@arkanaai arkanaai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: #487 — isolate expo-task-manager/expo-background-task

Verdict: APPROVE

Clean, well-motivated fix. The architectural split is sound and the implementation is tight.

What this PR does

Fixes #486 by moving expo-task-manager / expo-background-task from lazy require() (invisible to Metro's static dep collector) into a dedicated @arkade-os/sdk/wallet/expo/background subpath with static imports. The /wallet/expo entrypoint no longer touches those packages at all, so react-native-web and Node consumers aren't affected.

Breaking change: taskName and minimumBackgroundInterval removed from ExpoBackgroundConfig; OS-level registration is now the consumer's explicit responsibility.

Reviewed files

File Assessment
package.json ✅ New subpath export correctly wired (types, ESM, CJS, default)
src/wallet/expo/background.ts ✅ Static imports replace lazy require(); inline type declarations removed in favor of ambient .d.ts
src/wallet/expo/expo-modules.d.ts ✅ Ambient declarations cover the subset of APIs used; sits inside src/ so tsconfig.json "include": ["src"] picks it up
src/wallet/expo/index.ts ✅ Background re-exports removed — consumers must import from the new subpath
src/wallet/expo/wallet.ts import type from ./background — erased at compile time, no runtime dep chain. warnOnRemovedBackgroundFields catches JS callers still passing stale fields
src/worker/expo/README.md ✅ Migration table, updated examples, teardown example added
test/wallet/expo/background.test.ts vi.hoisted + vi.mock replaces brittle Module.prototype.require patching — correct for static imports
test/wallet/expo/wallet.test.ts ✅ Background mock removed (no longer imported by wallet.ts), warnOnRemovedBackgroundFields thoroughly tested including edge cases

Key architectural check

The critical invariant — /wallet/expo must not transitively import expo-task-manager or expo-background-task at runtime — is preserved:

  • wallet.ts:34 uses import type { PersistedBackgroundConfig } from "./background" → erased by TypeScript.
  • index.ts re-exports only from ./wallet, not from ./background.
  • The PR description confirms a post-build grep of dist/ validates this.

Minor observations (non-blocking)

  1. DefineBackgroundTaskOptions / PersistedBackgroundConfig no longer re-exported from /wallet/expo — they were previously in index.ts. They're now only accessible via @arkade-os/sdk/wallet/expo/background. This is correct behavior (consumers of background types should import from the background subpath), but worth noting in changelog.

  2. registerExpoBackgroundTask default interval math (background.ts:162): (options?.minimumInterval ?? 15) * 60 converts minutes to seconds. The expo-background-task API expects seconds, so this is correct. The JSDoc correctly documents the param as minutes.

  3. No cross-repo breakage: Searched all repos under /root/arkana/repos/ — zero consumers currently import from @arkade-os/sdk/wallet/expo. The primary downstream consumer (Trixie Wallet) is referenced in the PR description as already validated against the equivalent boltz-swap#146 change.

Protocol safety

This PR does not touch VTXO handling, transaction signing, forfeit paths, round lifecycle, connector trees, or exit paths. The background task handler reconstructs providers and calls runTasks + extendVtxo — but that logic is unchanged. The only changes are import/export topology and the consumer-facing registration API.

No protocol-critical review needed.


🤖 Reviewed by Arkana (opus)

@pietro909 pietro909 force-pushed the fix/expo-background-static-imports branch from a5b2a90 to 81f7976 Compare May 13, 2026 07:44
…wallet/expo/background

Lazy require() in /wallet/expo/background.ts was invisible to Metro's
static dependency collector, so expo-task-manager / expo-background-task
never entered the bundle graph. Split helpers into a new
@arkade-os/sdk/wallet/expo/background subpath using static imports;
OS-task registration is now the consumer's responsibility.

Fixes #486.
@pietro909 pietro909 force-pushed the fix/expo-background-static-imports branch from 81f7976 to 3a6d95b Compare May 15, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazy require() of expo-task-manager / expo-background-task is invisible to Metro

1 participant