Skip to content

Commit fd050c1

Browse files
committed
fix(e2e): replace yaml package with section-aware string manipulation
Remove yaml dependency (not available in CI e2e-test job) and use line-by-line parsing to replace the overrides section in pnpm-workspace.yaml. This correctly handles projects using pnpm catalogs by only modifying the overrides section without touching catalog entries.
1 parent 217c24b commit fd050c1

3 files changed

Lines changed: 39 additions & 11 deletions

File tree

ecosystem-ci/patch-project.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { existsSync } from 'node:fs';
33
import { readFile, writeFile } from 'node:fs/promises';
44
import { join } from 'node:path';
55

6-
import YAML from 'yaml';
7-
86
import { ecosystemCiDir, tgzDir } from './paths.ts';
97
import repos from './repo.json' with { type: 'json' };
108

@@ -51,16 +49,42 @@ if (forceFreshMigration) {
5149
// paths. pnpm overrides take precedence over catalog entries.
5250
const workspaceYamlPath = join(cwd, 'pnpm-workspace.yaml');
5351
if (existsSync(workspaceYamlPath)) {
54-
const doc = YAML.parseDocument(await readFile(workspaceYamlPath, 'utf-8'));
55-
let overrides = doc.get('overrides') as YAML.YAMLMap | undefined;
56-
if (!overrides) {
57-
overrides = new YAML.YAMLMap();
58-
doc.set('overrides', overrides);
52+
const yaml = await readFile(workspaceYamlPath, 'utf-8');
53+
const lines = yaml.split('\n');
54+
const result: string[] = [];
55+
let inOverrides = false;
56+
57+
for (const line of lines) {
58+
if (/^overrides:\s*$/.test(line)) {
59+
inOverrides = true;
60+
result.push('overrides:');
61+
// Replace entire overrides section with tgz paths
62+
for (const [name, value] of Object.entries(tgzPaths)) {
63+
const yamlKey = name.includes('@') ? `"${name}"` : name;
64+
result.push(` ${yamlKey}: ${value}`);
65+
}
66+
continue;
67+
}
68+
if (inOverrides) {
69+
// Skip existing override entries (2-space indented lines)
70+
if (line.startsWith(' ')) {
71+
continue;
72+
}
73+
inOverrides = false;
74+
}
75+
result.push(line);
5976
}
60-
for (const [name, value] of Object.entries(tgzPaths)) {
61-
overrides.set(name, value);
77+
78+
// If no overrides section existed, append one
79+
if (!inOverrides && !result.some((l) => l.startsWith('overrides:'))) {
80+
result.push('overrides:');
81+
for (const [name, value] of Object.entries(tgzPaths)) {
82+
const yamlKey = name.includes('@') ? `"${name}"` : name;
83+
result.push(` ${yamlKey}: ${value}`);
84+
}
6285
}
63-
await writeFile(workspaceYamlPath, doc.toString(), 'utf-8');
86+
87+
await writeFile(workspaceYamlPath, result.join('\n'), 'utf-8');
6488
}
6589
}
6690

ecosystem-ci/tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["."],
4+
"exclude": []
5+
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"vite": "catalog:",
3535
"vite-plus": "workspace:*",
3636
"vitest": "catalog:",
37-
"yaml": "catalog:",
3837
"zod": "catalog:"
3938
},
4039
"lint-staged": {

0 commit comments

Comments
 (0)