fix(init): rewrite bun-specific scripts for selected package manager#752
Open
ryanda9910 wants to merge 2 commits into
Open
fix(init): rewrite bun-specific scripts for selected package manager#752ryanda9910 wants to merge 2 commits into
ryanda9910 wants to merge 2 commits into
Conversation
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
Contributor
|
@ryanda9910 is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When running
npx next-forge@latest initand selecting a non-bun package manager (npm / pnpm / yarn), the generated project'spackage.jsonscripts 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
packageManagerfield, the workspace config and theworkspace:*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"(andapi'snext-dev).bunx ...inbump-deps,bump-ui,migrate,migrate:deploy,db:push, plusbun installinbump-deps.So
pnpm dev/npm run buildfail 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.tshad no step that rewrote the bun script tokens for the chosen package manager. The non-bun branch ranupdatePackageManagerConfigurationandupdateWorkspaceConfigurationbut nothing touchedscripts.Fix
Add a single, focused
updatePackageManagerScriptsstep (run only for non-bun managers, alongside the existing transforms) that rewrites the bun tokens in the root and apppackage.jsonfiles: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> installThe rewrite logic is factored into a small pure helper (
rewriteBunScripts) keyed off adlxCommandsmap, mirroring the existingfilterCommandpattern 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.jsonfiles for all three non-bun managers — every bun token is rewritten and zero residual bun tokens remain: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/promptsvalidatesignature note ingetName— is pre-existing on unmodifiedmainand unrelated to this change).I was not able to run a full
next-forge initend-to-end here (it clones viacreate-next-appand 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
scripts/; verified via the transform run above.)Closes #733