Skip to content

Commit e3ad585

Browse files
committed
fix(migration): respect existing pnpm config location in package.json
When a project already has a "pnpm" field in package.json (e.g., with overrides, ignoredBuiltDependencies), keep using package.json for pnpm config instead of creating a new pnpm-workspace.yaml. Only use pnpm-workspace.yaml for projects without existing pnpm config. This fixes ecosystem CI failures where projects with existing pnpm.overrides in package.json (like dify) broke when overrides were moved to pnpm-workspace.yaml, since pnpm doesn't properly apply file: overrides from workspace yaml to transitive dependencies.
1 parent 2bc8f7e commit e3ad585

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

packages/cli/src/migration/__tests__/__snapshots__/migrator.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exports[`rewritePackageJson > should rewrite devDependencies and dependencies on
2828
"foo": "1.0.0",
2929
},
3030
"devDependencies": {
31-
"vite-plus": "catalog:",
31+
"vite-plus": "latest",
3232
},
3333
}
3434
`;

packages/cli/src/migration/migrator.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,11 @@ export function rewriteStandaloneProject(
696696
}
697697

698698
const packageManager = workspaceInfo.packageManager;
699-
if (packageManager === PackageManager.pnpm) {
699+
// Respect the project's existing pnpm config location: if package.json already
700+
// has a "pnpm" field, keep using package.json; otherwise use pnpm-workspace.yaml.
701+
const existingPkg = readJsonFile(packageJsonPath);
702+
const usePnpmWorkspaceYaml = packageManager === PackageManager.pnpm && !existingPkg.pnpm;
703+
if (usePnpmWorkspaceYaml) {
700704
rewritePnpmWorkspaceYaml(projectPath);
701705
}
702706
let extractedStagedConfig: Record<string, string | string[]> | null = null;
@@ -727,16 +731,23 @@ export function rewriteStandaloneProject(
727731
};
728732
} else if (packageManager === PackageManager.pnpm) {
729733
const overrideKeys = Object.keys(VITE_PLUS_OVERRIDE_PACKAGES);
730-
if (isForceOverrideMode()) {
731-
// In force-override mode, keep overrides in package.json pnpm.overrides
732-
// because pnpm ignores pnpm-workspace.yaml overrides when pnpm.overrides
733-
// exists in package.json (even with unrelated entries like rollup).
734+
if (!usePnpmWorkspaceYaml) {
735+
// Project already has pnpm config in package.json — keep using it.
734736
pkg.pnpm = {
735737
...pkg.pnpm,
736738
overrides: {
737739
...pkg.pnpm?.overrides,
738740
...VITE_PLUS_OVERRIDE_PACKAGES,
739-
[VITE_PLUS_NAME]: VITE_PLUS_VERSION,
741+
...(isForceOverrideMode() ? { [VITE_PLUS_NAME]: VITE_PLUS_VERSION } : {}),
742+
},
743+
peerDependencyRules: {
744+
allowAny: [
745+
...new Set([...(pkg.pnpm?.peerDependencyRules?.allowAny ?? []), ...overrideKeys]),
746+
],
747+
allowedVersions: {
748+
...pkg.pnpm?.peerDependencyRules?.allowedVersions,
749+
...Object.fromEntries(overrideKeys.map((key) => [key, '*'])),
750+
},
740751
},
741752
};
742753
} else {
@@ -791,12 +802,17 @@ export function rewriteStandaloneProject(
791802
}
792803
}
793804

794-
extractedStagedConfig = rewritePackageJson(pkg, packageManager, false, skipStagedMigration);
805+
extractedStagedConfig = rewritePackageJson(
806+
pkg,
807+
packageManager,
808+
usePnpmWorkspaceYaml,
809+
skipStagedMigration,
810+
);
795811

796812
// ensure vite-plus is in devDependencies
797813
if (!pkg.devDependencies?.[VITE_PLUS_NAME] || isForceOverrideMode()) {
798814
const version =
799-
packageManager === PackageManager.pnpm && !VITE_PLUS_VERSION.startsWith('file:')
815+
usePnpmWorkspaceYaml && !VITE_PLUS_VERSION.startsWith('file:')
800816
? 'catalog:'
801817
: VITE_PLUS_VERSION;
802818
pkg.devDependencies = {
@@ -1329,8 +1345,7 @@ export function rewritePackageJson(
13291345
const updated = rewriteScripts(JSON.stringify(config), readRulesYaml());
13301346
extractedStagedConfig = updated ? JSON.parse(updated) : config;
13311347
}
1332-
const supportCatalog =
1333-
packageManager === PackageManager.pnpm || (isMonorepo && packageManager !== PackageManager.npm);
1348+
const supportCatalog = isMonorepo && packageManager !== PackageManager.npm;
13341349
let needVitePlus = false;
13351350
for (const [key, version] of Object.entries(VITE_PLUS_OVERRIDE_PACKAGES)) {
13361351
const value = supportCatalog && !version.startsWith('file:') ? 'catalog:' : version;

0 commit comments

Comments
 (0)