Skip to content

fix(deploy): detect bun.lock text format and walk up to monorepo root#119

Closed
harrisrobin wants to merge 2 commits intocloudflare:mainfrom
harrisrobin:fix/bun-lock-detection
Closed

fix(deploy): detect bun.lock text format and walk up to monorepo root#119
harrisrobin wants to merge 2 commits intocloudflare:mainfrom
harrisrobin:fix/bun-lock-detection

Conversation

@harrisrobin
Copy link
Copy Markdown
Contributor

Problem

detectPackageManager (and detectPackageManagerName) in utils/project.ts had two bugs that combined to make vinext deploy fail in Bun monorepos:

  1. Wrong lockfile name. The function only checked for bun.lockb — the legacy binary format. Bun v1.0+ writes a text-based bun.lock file. Projects using Bun ≥ v1.0 were not detected as Bun workspaces.

  2. No upward directory traversal. In a monorepo the lock file lives at the workspace root, not inside each app directory. When called from e.g. apps/web/, the function only checked that directory — missed the root — and fell through to npm install -D.

Both issues together produced this confusing error at the end of the npm fallback:

npm error Invalid Version:
Error: Command failed: npm install -D @cloudflare/vite-plugin@latest wrangler@latest @vitejs/plugin-rsc@latest
    at installDeps (dist/deploy.js:534:5)

Fix

  • Add bun.lock check alongside the existing bun.lockb check.
  • Walk up parent directories (stopping at the filesystem root) until a lock file is found, mirroring how npm/pnpm/yarn resolve workspace roots.
  • Both changes applied to detectPackageManager (returns install command) and detectPackageManagerName (returns pm name).

The helper is refactored into two small functions: checkLockFiles (single-directory check) and findLockFile (the upward walk), keeping each unit testable in isolation.

Tests

7 new unit tests in tests/deploy.test.ts:

  • pnpm detection via pnpm-lock.yaml
  • yarn detection via yarn.lock
  • bun detection via bun.lock (text, new)
  • bun detection via bun.lockb (binary, legacy)
  • npm fallback when no lock file found
  • monorepo root traversal (apps/web/ → lock file at workspace root)
  • closest-lock-wins precedence (inner pnpm-lock.yaml beats outer bun.lock)
✓ detects pnpm from pnpm-lock.yaml
✓ detects yarn from yarn.lock
✓ detects bun from bun.lock (text format, Bun v1.0+)
✓ detects bun from bun.lockb (legacy binary format)
✓ falls back to npm when no lock file is found
✓ walks up to parent directory to find lock file (monorepo root)
✓ prefers the closest lock file when both child and parent have one

pnpm run lint and pnpm run typecheck pass clean.

/bonk

detectPackageManager only checked for bun.lockb (the old binary lockfile),
missing bun.lock — the text-based format introduced in Bun v1.0. It also
only checked the immediate project directory, causing it to fall back to
npm in monorepo setups where the lock file lives at the workspace root.

Both issues together produce a confusing "npm error Invalid Version:" failure
when running vinext deploy from a Bun monorepo workspace.

Changes:
- Add bun.lock check alongside the existing bun.lockb check
- Walk up parent directories until a lock file is found (same behaviour as
  npm/pnpm/yarn when resolving workspace roots)
- Apply the same two fixes to detectPackageManagerName
- Add unit tests covering: pnpm, yarn, bun.lock, bun.lockb, npm fallback,
  monorepo root traversal, and closest-wins precedence
@harrisrobin
Copy link
Copy Markdown
Contributor Author

Superseded by #122, which combines this with #121 and refactors both into a shared walkUpUntil primitive.

harrisrobin added a commit to harrisrobin/vinext that referenced this pull request Feb 26, 2026
…factored)

Replaces the individual cloudflare#119 and cloudflare#121 fixes with the combined version from
PR cloudflare#122. Introduces walkUpUntil<T> as a shared primitive, with
detectPackageManager and findInNodeModules both built on top of it.
southpolesteve added a commit that referenced this pull request Feb 27, 2026
…nd supports SSR (#119)

Co-authored-by: ask-bonk[bot] <ask-bonk[bot]@users.noreply.github.com>
Co-authored-by: Steve Faulkner <sfaulkner@cloudflare.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