Skip to content

Commit 28a7042

Browse files
Brooooooklynclaude
andcommitted
fix(ci): harden upgrade-deps script for slash-escaping and mocker patch sync
- Switch `replace('/', '\\/')` to `replaceAll` in both regex builders so a future vitest sub-key with multiple slashes can't silently produce a broken pattern. - Always persist `updateVitestMockerPatch`'s in-memory rewrite when the content changed, not only when the key version moved — fixes a case where the key already matches `vitestVersion` but the value's patch-file suffix is stale, which would otherwise leak through and trigger ERR_PNPM_PATCHED_PKG_DOES_NOT_MATCH on install. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e984440 commit 28a7042

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

.github/scripts/upgrade-deps.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async function updatePnpmWorkspace(versions: PnpmWorkspaceVersions): Promise<voi
160160
];
161161
const vitestBrowserEntries: PnpmWorkspaceEntry[] = vitestBrowserPackages.map((pkg) => ({
162162
name: pkg,
163-
pattern: new RegExp(`'${pkg.replace('/', '\\/')}': ([\\d.]+(?:-[\\w.]+)?)`),
163+
pattern: new RegExp(`'${pkg.replaceAll('/', '\\/')}': ([\\d.]+(?:-[\\w.]+)?)`),
164164
replacement: `'${pkg}': ${versions.vitest}`,
165165
newVersion: versions.vitest,
166166
}));
@@ -311,7 +311,7 @@ async function updateTestVpCreateWorkflow(vitestVersion: string): Promise<void>
311311
];
312312
let updated = content;
313313
for (const key of vitestKeys) {
314-
const pattern = new RegExp(`"${key.replace('/', '\\/')}":"([\\d.]+(?:-[\\w.]+)?)"`);
314+
const pattern = new RegExp(`"${key.replaceAll('/', '\\/')}":"([\\d.]+(?:-[\\w.]+)?)"`);
315315
let matched = false;
316316
updated = updated.replace(pattern, (_match: string, _captured: string) => {
317317
matched = true;
@@ -365,9 +365,15 @@ async function updateVitestMockerPatch(vitestVersion: string): Promise<void> {
365365
);
366366
}
367367
fs.renameSync(oldPatch, newPatch);
368-
fs.writeFileSync(filePath, updated);
369368
console.log(`Renamed @vitest/mocker patch ${oldVersion} -> ${vitestVersion}`);
370369
}
370+
// Also covers the case where the key version already matches `vitestVersion`
371+
// but the value's patch-file suffix had drifted — `content.replace` repaired
372+
// the line in memory and we must persist it, otherwise pnpm install can hit
373+
// ERR_PNPM_PATCHED_PKG_DOES_NOT_MATCH.
374+
if (updated !== content) {
375+
fs.writeFileSync(filePath, updated);
376+
}
371377
recordChange('@vitest/mocker patch', oldVersion, vitestVersion);
372378
}
373379

0 commit comments

Comments
 (0)