Skip to content

Switch package manager from npm to bun (experiment + benchmark) - #97204

Draft
roryabraham wants to merge 3 commits into
mainfrom
rory/npm-to-bun-migration
Draft

Switch package manager from npm to bun (experiment + benchmark)#97204
roryabraham wants to merge 3 commits into
mainfrom
rory/npm-to-bun-migration

Conversation

@roryabraham

Copy link
Copy Markdown
Contributor

Note

Draft / experiment. This migrates the package manager from npm to bun and benchmarks install performance. Opened as a draft because the CI-side changes cannot be validated locally (they only run on GitHub Actions) and a few items need a human decision before merge (see Open items below). Not tied to a GitHub issue.

Explanation of Change

Switches the root Expensify/App project from npm to bun as the package manager. bun was already present as a runtime (test runner, several scripts, .bun-version, engines.bun); this makes it the install/lockfile toolchain too. The Mobile-Expensify submodule (a separate repo) intentionally stays on npm until a companion PR migrates it.

Install benchmark (npm vs bun), median wall-clock on this branch (macOS/APFS/arm64):

Scenario npm bun Speedup
cold, --ignore-scripts (pure resolve+link) 52.48s 40.04s 1.3×
cold, full (with postinstall) 69.55s 52.63s 1.3×
warm, --ignore-scripts (pure resolve+link) 30.25s 2.39s 12.7×
warm, full (with postinstall) 44.24s 17.26s 2.6×

Cold = empty package-manager cache; warm = primed cache (both with node_modules removed). Caches were isolated to temp dirs so global caches were untouched. The warm case (the common one in dev and CI-with-cache) is dramatically faster.

What the migration changes (and the bun-specific gotchas it resolves)
  • Lockfile: generate bun.lock via bun pm migrate (preserves npm's exact locked versions so all 148 patch-package patches still apply unchanged); remove package-lock.json. A plain bun install that auto-migrates the npm lockfile 404s on an npm: alias (strip-ansi-cjs); bun pm migrate avoids that.
  • bunfig.toml: linker = "hoisted" — patch-package walks a flat node_modules/<pkg> tree, which bun's default isolated linker does not produce.
  • package.json: add packageManager: "bun@1.3.14"; add a trustedDependencies allowlist (bun blocks dependency lifecycle scripts by default — this re-enables the ones that download/build binaries: @sentry/cli, esbuild, sharp, protobufjs, bun, lefthook, shellcheck, @expensify/nitro-utils). Remove 9 nested overrides bun doesn't support (all redundant with direct deps — verified single expo@56.0.8 copy, etc.) and add a flat typescript-eslint override so the pin is clean-resolve-stable.
  • postInstall.sh: prune bun's dangling workspace symlinks so the victory-chart-renderer workspace resolves its deps from the hoisted root; keep the Mobile-Expensify submodule install on npm i.
  • CI: setupNode composite action installs bun (oven-sh/setup-bun) and runs bun install --frozen-lockfile; cache keys rekeyed on bun.lock and ~/.bun/install/cache; the jq lockfile-version-normalization is removed (bun.lock does not embed the root version). All workflow/script npm runbun run, npxbunx. Version tooling uses bun pm version. The ncc-compiled GitHub Action bundles were regenerated under bun (deterministic; validateGithubActions reproduces them).
  • Docs: contributor setup guides, CLAUDE.md, and skills updated to bun.
  • .npmrc (engine-strict) removed; toolchain pinned via .bun-version + packageManager + engines.
Peer review (3 rounds, converged)

Independent subagent reviewers audited the diff across install/lockfile, CI, scripts/version-tooling, benchmark methodology, submodule/docs, and the regenerated action bundles.

  • Round 1 surfaced 1 blocker (stale ncc bundles → rebuilt) and majors (Mobile-Expensify prematurely on bun → reverted to npm incl. cache keys; setup docs still said npm → converted; missed npm test/npx) — all fixed.
  • Round 2 verified the fixes and cleared the highest-risk question: the 23 regenerated action bundles are correct (17 are cosmetic webpack module-id renumbering, 2 are the intended source edits, 3 have one benign transitive bump — supports-color via debug's unpinned optional peer — not an unbuilt-dep bug). New items were doc-consistency + a CLAUDE.md footgun → fixed.
  • Round 3 confirmed stabilization; only a doc long-tail remained → converted.

Verified locally (green): bun install end-to-end (2358 pkgs), 148 patches apply, bun install --frozen-lockfile stable, bun run typecheck-tsgo, bun run test:bun (32/32).

Warning

Open items before merge — (1) pin oven-sh/setup-bun to a full commit SHA (currently @v2 with a TODO, matching the repo's SHA-pinning convention); (2) the CI changes can only be validated by running the workflows; (3) a companion Mobile-Expensify PR must migrate that submodule to bun before its CI Mobile-Expensify/bun.lock cache path and a bun-based old-dot install become correct; (4) engine-strict install-time enforcement is lost (bun ignores it) — CI still pins node via .nvmrc.

Benchmark caveats: numbers are macOS/APFS/arm64 local, not Linux CI — the warm speedup leans partly on APFS copy-on-write and won't transfer 1:1. npm was measured with package-lock.json present (pre-removal) against main's package.json, i.e. the same version set bun.lock was migrated from. The --ignore-scripts rows are the clean pure-PM comparison; the full rows also reflect bun running fewer dependency lifecycle scripts.

Fixed Issues

$ N/A — exploratory package-manager migration, not tied to a GitHub issue.
PROPOSAL: N/A

Tests

  1. Check out this branch and run bun install from the repo root; verify it completes and prints patch-package succeeded without errors or warnings.
  2. Run bun install --frozen-lockfile; verify it succeeds with no lockfile-drift error.
  3. Run bun run typecheck-tsgo; verify it exits 0.
  4. Run bun run test:bun; verify all tests pass (32/32).
  5. Run bun run web and verify the dev server boots at https://dev.new.expensify.com:8082/.
  6. Verify that no errors appear in the JS console.
  • Verify that no errors appear in the JS console

Offline tests

N/A — this is a build-tooling/package-manager change with no runtime or network behavior in the app.

QA Steps

[No QA] — package-manager/tooling change with no user-facing behavior. Validation is via CI (install, lint, typecheck, test, build workflows) and the local Tests above.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run bun run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

N/A — package-manager/tooling change with no UI impact.

Android: Native

N/A

Android: mWeb Chrome

N/A

iOS: Native

N/A

iOS: mWeb Safari

N/A

MacOS: Chrome / Safari

N/A

🤖 Generated with Claude Code

roryabraham and others added 3 commits July 28, 2026 01:00
Migrate the root Expensify/App project from npm to bun as the package
manager. Mobile-Expensify (a separate-repo submodule) stays on npm until a
companion PR migrates it.

Key changes:
- Generate bun.lock via `bun pm migrate` (preserves npm's exact locked
  versions so all patch-package patches still apply); remove package-lock.json.
- bunfig.toml: linker = "hoisted" so patch-package finds packages at the
  top level of node_modules (Bun's default isolated linker does not).
- package.json: packageManager "bun@1.3.14"; trustedDependencies allowlist
  for build deps (Bun blocks dependency lifecycle scripts by default);
  remove 9 nested overrides Bun does not support (redundant with direct
  deps) and add a flat typescript-eslint override for clean-resolve stability.
- postInstall.sh: prune Bun's dangling workspace symlinks so the
  victory-chart-renderer workspace resolves deps from the hoisted root; keep
  the Mobile-Expensify submodule install on npm.
- Convert scripts and CI to bun/bunx (setupNode installs bun and runs
  `bun install --frozen-lockfile`, cache keys rekeyed on bun.lock); version
  tooling uses `bun pm version`; remove the now-unnecessary lockfile version
  normalization. Regenerate the ncc-compiled GitHub Action bundles under bun.
- Remove .npmrc (engine-strict); pin the toolchain via .bun-version.
- Update contributor setup docs to bun.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follow-up from peer review of the npm→bun migration. Convert developer- and
agent-facing references that the first pass missed:

- CLAUDE.md: Command Reference, Post-Edit Checklist, and Dev Server commands
  npm→bun (leaving the third-party `npm install -g agent-device`).
- lefthook.yml: pre-commit oxfmt hook `npx`→`bunx`.
- src/CONST/index.ts: stale comment referenced the removed package-lock.json;
  point it at bun.lock.
- .oxfmtrc.json: drop dead package-lock.json ignore entry.
- Docs/config consistency: HYBRID_APP.md, SETUP_IOS/ANDROID (`npx rock`→`bunx rock`),
  victory-chart-renderer README, docs/README, check-compiler.sh,
  ExpensifyNitroUtils scripts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Final doc-consistency pass from peer review. Convert the contributor guides
and Claude skill docs that still referenced npm to bun (npm run -> bun run,
npx -> bunx): LINTING, REACT_COMPILER, STYLE, STORYBOOK, DEPLOYING,
REASSURE_PERFORMANCE_TEST, PATCHES, PERFORMANCE, and the agent-device /
playwright-app-testing / measure-telemetry-span skills. Third-party global
installs (npm install -g agent-device, npm root -g) are left as-is.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant