Skip to content

Commit 9865894

Browse files
committed
fix(cli): add peerDependencyRules for standalone pnpm projects
When `vp create` or `vp migrate` sets up a standalone pnpm project, only `pnpm.overrides` was written to package.json. This caused noisy unmet peer dependency warnings because packages expecting `vite` saw the vite-plus version instead. Add `pnpm.peerDependencyRules` (allowAny + allowedVersions) alongside overrides to suppress these warnings, matching the behavior already present for monorepo projects via rewritePnpmWorkspaceYaml().
1 parent 3fc8005 commit 9865894

5 files changed

Lines changed: 69 additions & 5 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "migration-standalone-pnpm",
3+
"devDependencies": {
4+
"vite": "^7.0.0",
5+
"vitest": "^4.0.0"
6+
}
7+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
> vp migrate --no-interactive --no-hooks --package-manager pnpm # migration should work with pnpm, add overrides and peerDependencyRules
2+
VITE+ - The Unified Toolchain for the Web
3+
4+
◇ Migrated . to Vite+<repeat>
5+
• Node <semver> pnpm <semver>
6+
✓ Dependencies installed in <variable>ms
7+
• 1 config update applied
8+
9+
> cat package.json # check package.json has pnpm.overrides and pnpm.peerDependencyRules
10+
{
11+
"name": "migration-standalone-pnpm",
12+
"devDependencies": {
13+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
14+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest",
15+
"vite-plus": "latest"
16+
},
17+
"packageManager": "pnpm@<semver>",
18+
"pnpm": {
19+
"overrides": {
20+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
21+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
22+
},
23+
"peerDependencyRules": {
24+
"allowAny": [
25+
"vite",
26+
"vitest"
27+
],
28+
"allowedVersions": {
29+
"vite": "*",
30+
"vitest": "*"
31+
}
32+
}
33+
}
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"ignoredPlatforms": ["win32"],
3+
"env": {
4+
"VITE_DISABLE_AUTO_INSTALL": "1",
5+
"CI": "",
6+
"VP_SKIP_INSTALL": ""
7+
},
8+
"commands": [
9+
"vp migrate --no-interactive --no-hooks --package-manager pnpm # migration should work with pnpm, add overrides and peerDependencyRules",
10+
"cat package.json # check package.json has pnpm.overrides and pnpm.peerDependencyRules"
11+
]
12+
}

packages/cli/src/migration/migrator.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,10 @@ export function rewriteStandaloneProject(
698698
scripts?: Record<string, string>;
699699
pnpm?: {
700700
overrides?: Record<string, string>;
701-
// peerDependencyRules?: {
702-
// allowAny?: string[];
703-
// allowedVersions?: Record<string, string>;
704-
// };
701+
peerDependencyRules?: {
702+
allowAny?: string[];
703+
allowedVersions?: Record<string, string>;
704+
};
705705
};
706706
}>(packageJsonPath, (pkg) => {
707707
if (packageManager === PackageManager.yarn) {
@@ -715,17 +715,27 @@ export function rewriteStandaloneProject(
715715
...VITE_PLUS_OVERRIDE_PACKAGES,
716716
};
717717
} else if (packageManager === PackageManager.pnpm) {
718+
const overrideKeys = Object.keys(VITE_PLUS_OVERRIDE_PACKAGES);
718719
pkg.pnpm = {
719720
...pkg.pnpm,
720721
overrides: {
721722
...pkg.pnpm?.overrides,
722723
...VITE_PLUS_OVERRIDE_PACKAGES,
723724
...(isForceOverrideMode() ? { [VITE_PLUS_NAME]: VITE_PLUS_VERSION } : {}),
724725
},
726+
peerDependencyRules: {
727+
allowAny: [
728+
...new Set([...(pkg.pnpm?.peerDependencyRules?.allowAny ?? []), ...overrideKeys]),
729+
],
730+
allowedVersions: {
731+
...pkg.pnpm?.peerDependencyRules?.allowedVersions,
732+
...Object.fromEntries(overrideKeys.map((key) => [key, '*'])),
733+
},
734+
},
725735
};
726736
// remove packages from `resolutions` field if they exist
727737
// https://pnpm.io/9.x/package_json#resolutions
728-
for (const key of [...Object.keys(VITE_PLUS_OVERRIDE_PACKAGES), ...REMOVE_PACKAGES]) {
738+
for (const key of [...overrideKeys, ...REMOVE_PACKAGES]) {
729739
if (pkg.resolutions?.[key]) {
730740
delete pkg.resolutions[key];
731741
}

0 commit comments

Comments
 (0)