Skip to content

fix(init): rewrite bun-specific scripts for selected package manager#752

Open
ryanda9910 wants to merge 2 commits into
vercel:mainfrom
ryanda9910:fix/init-package-manager-scripts
Open

fix(init): rewrite bun-specific scripts for selected package manager#752
ryanda9910 wants to merge 2 commits into
vercel:mainfrom
ryanda9910:fix/init-package-manager-scripts

Conversation

@ryanda9910

Copy link
Copy Markdown

Description

When running npx next-forge@latest init and selecting a non-bun package manager (npm / pnpm / yarn), the generated project's package.json scripts still contained bun-specific commands and therefore only worked if bun was installed.

Problem. The init pipeline transforms several things for the selected package manager — it rewrites the packageManager field, the workspace config and the workspace:* dependency protocols — but it never rewrote the template's bun-specific scripts. The generated project is left with:

  • apps/app, apps/web, apps/api: "dev": "bun --bun next dev", "build": "bun --bun next build", "start": "bun --bun next start" (and api's next-dev).
  • root: bunx ... in bump-deps, bump-ui, migrate, migrate:deploy, db:push, plus bun install in bump-deps.

So pnpm dev / npm run build fail unless bun is installed — even though the docs state npm, yarn and pnpm "all work". This is an incomplete transformation / leaky-abstraction failure mode: the package-manager normalization stage skipped one of the artifacts it owns.

Root cause

scripts/initialize.ts had no step that rewrote the bun script tokens for the chosen package manager. The non-bun branch ran updatePackageManagerConfiguration and updateWorkspaceConfiguration but nothing touched scripts.

Fix

Add a single, focused updatePackageManagerScripts step (run only for non-bun managers, alongside the existing transforms) that rewrites the bun tokens in the root and app package.json files:

  • bun --bun <cmd><cmd> (drop the bun-runtime prefix)
  • bunx <pkg> → the selected manager's download-and-execute command (npx, pnpm dlx, yarn dlx)
  • bun install<pm> install

The rewrite logic is factored into a small pure helper (rewriteBunScripts) keyed off a dlxCommands map, mirroring the existing filterCommand pattern in the file. Managers without a mapping (bun, and anything else) are a no-op, so behaviour for the default bun flow is unchanged.

Test evidence

This is a deterministic transform that does not require the auth/db stack to verify. I exercised the real rewrite logic against the actual template package.json files for all three non-bun managers — every bun token is rewritten and zero residual bun tokens remain:

========== pnpm ==========
  [apps/app/package.json] dev:   BEFORE: bun --bun next dev -p 3000   AFTER: next dev -p 3000
  [package.json] migrate:        BEFORE: ... bunx prisma format ...    AFTER: ... pnpm dlx prisma format ...
  [package.json] bump-deps:      BEFORE: bunx ... && bun install       AFTER: pnpm dlx ... && pnpm install
========== npm ==========   (bunx -> npx,  bun install -> npm install)
========== yarn ==========  (bunx -> yarn dlx, bun install -> yarn install)

RESIDUAL BUN TOKENS AFTER REWRITE: 0
  • biome check scripts/initialize.ts (repo's ultracite 7.2.5 config): passes, no fixes applied.
  • tsc --noEmit: the change introduces no new type errors (verified the only remaining diagnostic — a @clack/prompts validate signature note in getName — is pre-existing on unmodified main and unrelated to this change).

I was not able to run a full next-forge init end-to-end here (it clones via create-next-app and installs a full monorepo), so verification is at the transform/lint/type level against the real template files rather than a full generated-project boot.

Checklist

  • My code follows the code style of this project.
  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation, if necessary. (No docs change needed.)
  • I have added tests that prove my fix is effective or my feature works. (The repo has no test harness for scripts/; verified via the transform run above.)
  • New and existing tests pass locally with my changes.

Closes #733

When a non-bun package manager is selected during `init`, the CLI
updated the packageManager field, workspace config and dependency
protocols but left the template's bun-specific scripts intact, so the
generated project's scripts only worked if bun was installed.

Rewrite `bun --bun next ...` -> `next ...`, `bunx` -> the selected
manager's dlx command, and `bun install` -> `<pm> install` across the
root and app package.json files.

Closes vercel#733
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@ryanda9910 is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread scripts/initialize.ts Outdated
next-forge pins Yarn Classic 1.22.x, which has no `dlx` subcommand
(added in Yarn 2/Berry). Map yarn's bunx-equivalent to `npx` instead of
`yarn dlx`. Per Vercel Agent Review feedback.
@ryanda9910 ryanda9910 marked this pull request as ready for review June 16, 2026 09:17
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.

CLI init: app scripts hardcode bun --bun regardless of selected package manager

1 participant