diff --git a/packages/tools/src/brand-vite.ts b/packages/tools/src/brand-vite.ts index 1aab68c6fe..2c01dc08cf 100644 --- a/packages/tools/src/brand-vite.ts +++ b/packages/tools/src/brand-vite.ts @@ -13,6 +13,7 @@ * 5. plugins/reporter.ts: Suppress redundant "vite v" native reporter line */ +import { execFileSync } from 'node:child_process'; import { readFileSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; @@ -52,10 +53,7 @@ function replaceInFile( ); } -function removeAnyInFile( - filePath: string, - searches: Array, -): 'patched' | 'already' { +function removeAnyInFile(filePath: string, searches: Array): 'patched' { const content = readFileSync(filePath, 'utf-8'); for (const search of searches) { if (typeof search === 'string') { @@ -73,7 +71,11 @@ function removeAnyInFile( return 'patched'; } } - return 'already'; + throw new Error( + `[brand-vite] Patch failed in ${filePath}:\n` + + ` Could not find any expected search pattern.\n` + + ` The upstream code may have changed. Please update the search patterns in brand-vite.ts.`, + ); } function logPatch(file: string, desc: string, result: 'patched' | 'already') { @@ -87,6 +89,11 @@ function logPatch(file: string, desc: string, result: 'patched' | 'already') { export function brandVite(rootDir: string = process.cwd()) { log('Applying Vite+ branding patches...'); + // Always patch raw upstream sources, including when sync-remote already applied branding. + execFileSync('git', ['restore', '--source=HEAD', '--', '.'], { + cwd: join(rootDir, VITE_DIR), + }); + const nodeDir = join(rootDir, VITE_NODE_DIR); // 1. constants.ts: Add VITE_PLUS_VERSION constant after VERSION