Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/tools/src/brand-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* 5. plugins/reporter.ts: Suppress redundant "vite v<version>" native reporter line
*/

import { execFileSync } from 'node:child_process';
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

Expand Down Expand Up @@ -52,10 +53,7 @@ function replaceInFile(
);
}

function removeAnyInFile(
filePath: string,
searches: Array<string | RegExp>,
): 'patched' | 'already' {
function removeAnyInFile(filePath: string, searches: Array<string | RegExp>): 'patched' {
const content = readFileSync(filePath, 'utf-8');
for (const search of searches) {
if (typeof search === 'string') {
Expand All @@ -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.`,
);
Comment thread
liangmiQwQ marked this conversation as resolved.
}

function logPatch(file: string, desc: string, result: 'patched' | 'already') {
Expand All @@ -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
Expand Down
Loading