Skip to content

Commit 4c284c2

Browse files
committed
fix(e2e): add tgz overrides to package.json pnpm.overrides post-migration
pnpm ignores pnpm-workspace.yaml overrides when pnpm.overrides exists in package.json. vp migrate also overwrites overrides set before it runs. Fix: add tgz overrides to pnpm.overrides AFTER migration so @voidzero-dev/vite-plus-core@0.0.0 and @voidzero-dev/vite-plus-test@0.0.0 resolve to the locally built tgz files.
1 parent 3f84f78 commit 4c284c2

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

ecosystem-ci/patch-project.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ if (forceFreshMigration) {
3939
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'));
4040
delete pkg.devDependencies?.['vite-plus'];
4141
delete pkg.dependencies?.['vite-plus'];
42+
4243
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf-8');
4344

44-
// Update pnpm-workspace.yaml overrides to redirect vite-plus packages to tgz files.
45-
// Projects using pnpm catalogs (e.g. vinext) have entries like:
46-
// catalog: { vite: "npm:@voidzero-dev/vite-plus-core@...", ... }
47-
// overrides: { vite: "catalog:", vitest: "catalog:" }
48-
// Catalog doesn't support file: protocol, so we set overrides directly to tgz
49-
// paths. pnpm overrides take precedence over catalog entries.
45+
// Also update pnpm-workspace.yaml overrides for projects that don't have
46+
// pnpm.overrides in package.json (pnpm-workspace.yaml overrides are only
47+
// used when package.json has no overrides).
5048
const workspaceYamlPath = join(cwd, 'pnpm-workspace.yaml');
5149
if (existsSync(workspaceYamlPath)) {
5250
const yaml = await readFile(workspaceYamlPath, 'utf-8');
@@ -58,15 +56,13 @@ if (forceFreshMigration) {
5856
if (/^overrides:\s*$/.test(line)) {
5957
inOverrides = true;
6058
result.push('overrides:');
61-
// Replace entire overrides section with tgz paths
6259
for (const [name, value] of Object.entries(tgzPaths)) {
6360
const yamlKey = name.includes('@') ? `"${name}"` : name;
6461
result.push(` ${yamlKey}: ${value}`);
6562
}
6663
continue;
6764
}
6865
if (inOverrides) {
69-
// Skip existing override entries (2-space indented lines)
7066
if (line.startsWith(' ')) {
7167
continue;
7268
}
@@ -75,7 +71,6 @@ if (forceFreshMigration) {
7571
result.push(line);
7672
}
7773

78-
// If no overrides section existed, append one
7974
if (!inOverrides && !result.some((l) => l.startsWith('overrides:'))) {
8075
result.push('overrides:');
8176
for (const [name, value] of Object.entries(tgzPaths)) {
@@ -111,3 +106,21 @@ execSync(`${cli} migrate --no-agent --no-interactive`, {
111106
VITE_PLUS_VERSION: tgzPaths['vite-plus'],
112107
},
113108
});
109+
110+
// Post-migration: ensure tgz overrides are set in pnpm.overrides in package.json.
111+
// vp migrate may overwrite overrides set before migration, and pnpm ignores
112+
// pnpm-workspace.yaml overrides when pnpm.overrides exists in package.json.
113+
if (forceFreshMigration) {
114+
const pkgPath = join(cwd, 'package.json');
115+
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'));
116+
if (!pkg.pnpm) {
117+
pkg.pnpm = {};
118+
}
119+
if (!pkg.pnpm.overrides) {
120+
pkg.pnpm.overrides = {};
121+
}
122+
for (const [name, value] of Object.entries(tgzPaths)) {
123+
pkg.pnpm.overrides[name] = value;
124+
}
125+
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf-8');
126+
}

0 commit comments

Comments
 (0)