Skip to content

Commit 0fecc75

Browse files
committed
fix(migrate): write pnpm catalog for standalone pnpm 9.5-10.6.1 projects
A standalone (non-monorepo) migration on pnpm 9.5.0-10.6.1 rewrote the toolchain edges to `catalog:` (catalogs are supported from 9.5.0) but never wrote the catalog entries to pnpm-workspace.yaml: that write was gated on `usePnpmWorkspaceYaml` (settings support, >= 10.6.2), so the install could not resolve `catalog:` and failed. Gate the pnpm-workspace.yaml write on `usePnpmWorkspaceYaml || supportCatalog` and pass `usePnpmWorkspaceYaml` as the `writeWorkspaceSettings` flag, so a 9.5-10.6.1 project gets a catalog-only file (settings stay in package.json), mirroring the monorepo orchestrator. 452cbf6 fixed the existing-Vite+ bootstrap path; this covers the standalone new-project path. Removes the now-redundant `shouldRewritePnpmWorkspaceYaml` state (it only ever mirrored `usePnpmWorkspaceYaml`). Adds a reproducing test. Claude-Session: https://claude.ai/code/session_01DQhS6o1fyQd1yjiee6W8jR
1 parent ab9a0b3 commit 0fecc75

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4439,6 +4439,35 @@ describe('rewriteStandaloneProject pnpm workspace yaml', () => {
44394439
expect(devDeps['vite-plus']).toBe('catalog:');
44404440
});
44414441

4442+
// PR #1891 review (P1): pnpm 9.5.0-10.6.1 supports catalogs (>= 9.5.0) but not
4443+
// moving settings to pnpm-workspace.yaml (< 10.6.2). The toolchain edges are
4444+
// rewritten to `catalog:` regardless, so the catalog ENTRIES must still be
4445+
// written to pnpm-workspace.yaml or the install cannot resolve them.
4446+
it('writes the catalog to pnpm-workspace.yaml for a standalone project on pnpm 9.5-10.6.1', () => {
4447+
fs.writeFileSync(
4448+
path.join(tmpDir, 'package.json'),
4449+
JSON.stringify({ name: 'test', devDependencies: { vite: '^7.0.0' } }),
4450+
);
4451+
const workspaceInfo = makeWorkspaceInfo(tmpDir, PackageManager.pnpm);
4452+
workspaceInfo.packageManagerVersion = '9.15.9';
4453+
workspaceInfo.downloadPackageManager.version = '9.15.9';
4454+
rewriteStandaloneProject(tmpDir, workspaceInfo, true, true);
4455+
4456+
// package.json emits catalog: specs (this part already works today).
4457+
const pkg = readJson(path.join(tmpDir, 'package.json'));
4458+
const devDeps = pkg.devDependencies as Record<string, string>;
4459+
expect(devDeps.vite).toBe('catalog:');
4460+
expect(devDeps['vite-plus']).toBe('catalog:');
4461+
4462+
// The catalog backing those specs must exist. Below 10.6.2 the pnpm settings
4463+
// stay in package.json, so the workspace file holds only the catalog.
4464+
expect(fs.existsSync(path.join(tmpDir, 'pnpm-workspace.yaml'))).toBe(true);
4465+
const yaml = readYaml(path.join(tmpDir, 'pnpm-workspace.yaml'));
4466+
expect(yaml).toContain('catalog:');
4467+
expect(yaml).toContain('vite-plus:');
4468+
expect(yaml).not.toContain('overrides:');
4469+
});
4470+
44424471
it('does not duplicate vite-plus into devDependencies when it already lives in dependencies', () => {
44434472
fs.writeFileSync(
44444473
path.join(tmpDir, 'package.json'),

packages/cli/src/migration/migrator/orchestrators.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export function rewriteStandaloneProject(
9191
const pnpmMajorVersion = pnpmMajor(workspaceInfo.downloadPackageManager.version);
9292
let extractedStagedConfig: Record<string, string | string[]> | null = null;
9393
let movedPnpmSettings: Record<string, unknown> | undefined;
94-
let shouldRewritePnpmWorkspaceYaml = false;
9594
let shouldAddPnpmWorkspaceVitePlusOverride = false;
9695
let shouldAllowBrowserProviderBuilds = false;
9796
// Whether the project uses vitest directly (a required-peer consumer, an
@@ -175,7 +174,6 @@ export function rewriteStandaloneProject(
175174
}
176175
} else if (packageManager === PackageManager.pnpm) {
177176
if (usePnpmWorkspaceYaml) {
178-
shouldRewritePnpmWorkspaceYaml = true;
179177
shouldAddPnpmWorkspaceVitePlusOverride = isForceOverrideMode();
180178
}
181179
const overrideKeys = Object.keys(managed);
@@ -280,14 +278,20 @@ export function rewriteStandaloneProject(
280278

281279
migratePnpmSettingsToWorkspaceYaml(projectPath, movedPnpmSettings);
282280

283-
if (shouldRewritePnpmWorkspaceYaml) {
281+
// Catalogs are supported from pnpm 9.5.0, but pnpm settings only move into
282+
// pnpm-workspace.yaml from 10.6.2. When the toolchain edges were rewritten to
283+
// `catalog:` (supportCatalog), the catalog entries backing them must be
284+
// written even below 10.6.2 or the install cannot resolve them; settings then
285+
// stay in package.json (writeWorkspaceSettings = usePnpmWorkspaceYaml). This
286+
// mirrors the monorepo orchestrator below.
287+
if (packageManager === PackageManager.pnpm && (usePnpmWorkspaceYaml || supportCatalog)) {
284288
rewritePnpmWorkspaceYaml(
285289
projectPath,
286290
pnpmMajorVersion,
287291
shouldAllowBrowserProviderBuilds,
288292
usesVitest,
289293
vitestEcosystemPackages,
290-
true,
294+
usePnpmWorkspaceYaml,
291295
providerCatalogAdditions,
292296
);
293297
}

0 commit comments

Comments
 (0)