Skip to content

Commit 61289fb

Browse files
committed
fix(migration): mirror vite override as devDep on bun
Bun walks transitive peer-deps before resolving overrides. vitest@4.1.5 declares peer \`vite ^6 || ^7 || ^8\` and aborts with "vite@... failed to resolve" if \`vite\` isn't a direct dep somewhere in the tree, even when the user's overrides would redirect it to vite-plus-core. pnpm, npm, and yarn don't enforce this; bun is uniquely strict. See oven-sh/bun#8406. For both standalone and monorepo-root bun migrations, mirror the \`vite\` override as a top-level devDependency so bun's resolver sees a direct \`vite\` dep at install time. The override configured alongside still redirects the resolved package at vite-plus-core, so the user's actual import behavior is unchanged — they still get vite-plus-core for \`import 'vite'\`. The only snap.txt that needed updating is new-vite-monorepo-bun, which scaffolds a fresh bun monorepo without an existing \`vite\` dep at the root. migration-monorepo-bun and create-from-bun-monorepo-subdir already start with \`vite\` in devDeps and are unaffected.
1 parent 5e5ae3f commit 61289fb

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/cli/snap-tests-global/new-vite-monorepo-bun/snap.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ vite.config.ts
2626
"prepare": "vp config"
2727
},
2828
"devDependencies": {
29+
"vite": "catalog:",
2930
"vite-plus": "catalog:"
3031
},
3132
"overrides": {

packages/cli/src/migration/migrator.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,19 @@ export function rewriteStandaloneProject(
916916
...pkg.overrides,
917917
...VITE_PLUS_OVERRIDE_PACKAGES,
918918
};
919+
if (packageManager === PackageManager.bun) {
920+
// Bun walks transitive peer-deps before resolving overrides; vitest
921+
// 4.1.5 declares peer `vite ^6 || ^7 || ^8` and aborts with
922+
// "vite@... failed to resolve" if `vite` isn't a direct dep somewhere
923+
// in the tree, even when the override would redirect it. Mirror the
924+
// override as a devDep so bun's resolver sees `vite` immediately;
925+
// the override above still points it at vite-plus-core.
926+
// See https://github.com/oven-sh/bun/issues/8406.
927+
pkg.devDependencies = {
928+
...pkg.devDependencies,
929+
vite: VITE_PLUS_OVERRIDE_PACKAGES.vite,
930+
};
931+
}
919932
} else if (packageManager === PackageManager.pnpm) {
920933
// If package.json already has a "pnpm" field, keep using it;
921934
// otherwise use pnpm-workspace.yaml.
@@ -1731,6 +1744,19 @@ function rewriteRootWorkspacePackageJson(
17311744
};
17321745
} else if (packageManager === PackageManager.bun) {
17331746
// bun overrides are handled in rewriteBunCatalog() with catalog: references
1747+
// Bun walks transitive peer-deps before resolving overrides; vitest 4.1.5
1748+
// declares peer `vite ^6 || ^7 || ^8` and aborts unless `vite` is a direct
1749+
// dep at the workspace root. Mirror the override as a devDep; the override
1750+
// configured in rewriteBunCatalog still redirects it to vite-plus-core.
1751+
// See https://github.com/oven-sh/bun/issues/8406.
1752+
pkg.devDependencies = {
1753+
...pkg.devDependencies,
1754+
vite: getCatalogDependencySpec(
1755+
pkg.devDependencies?.vite,
1756+
VITE_PLUS_OVERRIDE_PACKAGES.vite,
1757+
true,
1758+
),
1759+
};
17341760
} else if (packageManager === PackageManager.pnpm) {
17351761
const overrideKeys = Object.keys(VITE_PLUS_OVERRIDE_PACKAGES);
17361762
if (isForceOverrideMode()) {

0 commit comments

Comments
 (0)