mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-13 19:20:04 +00:00
ddb5794826
* chore: clean up LOBE-XXX annotations from codebase comments - Remove 【LOBE-XXX】 bracket markers - Remove LOBE-XXXX references from inline comments - Clean up test descriptions containing LOBE identifiers - Preserve linear.app URLs and code-level regex patterns - Generated: 2026-05-23 02:30:09 * 🐛 fix(tests): restore () in arrow callbacks broken by annotation cleanup The LOBE-XXX annotation cleanup script over-matched `(LOBE-XXXX', () =>` and stripped the callback `()`, leaving invalid syntax like `describe(..., => {` and `it(..., async => {` across 24 test files. This caused parse failures in Test Packages, Test Desktop App, Test Database lint, and Test App shard runs. Restoring `()` / `async ()` unblocks the suites while keeping the ticket-text cleanup intact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * 🐛 fix(hintFormat-test): restore label + ellipsis in stripMarkdownLinks fixture The annotation cleanup stripped `LOBE-8516` from a markdown-link's *label* (`[LOBE-8516](/task/T-1)` → `[](/task/T-1)`), which then survived `stripMarkdownLinks` because the pattern requires non-empty link text — the test expected the link to disappear and asserted equality on a LOBE-free output. The same line also lost a `.` from the trailing `...` indicator in both input and expected strings. Substitute a neutral Chinese label (`发布计划`) so the link continues to exercise the multi-link substitution path, and restore the full `...` ellipsis. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Arvin Xu <arvinxx@lobehub.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
139 lines
4.3 KiB
TypeScript
139 lines
4.3 KiB
TypeScript
#!/usr/bin/env bun
|
|
/**
|
|
* Script to migrate SPA internal components from @/libs/next/navigation
|
|
* to React Router version hooks.
|
|
*
|
|
* For files in (main) directory:
|
|
* - usePathname -> @/app/[variants]/(main)/hooks/usePathname
|
|
* - useSearchParams -> @/app/[variants]/(main)/hooks/useSearchParams
|
|
* - useRouter -> @/app/[variants]/(main)/hooks/useRouter
|
|
*
|
|
* @see RFC 147: - Phase 3
|
|
*/
|
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
// Files that should be migrated to React Router version
|
|
const SPA_FILES = [
|
|
// (main) directory files using @/libs/next/navigation
|
|
'src/app/[variants]/(main)/community/_layout/Sidebar/Header/Nav.tsx',
|
|
'src/app/[variants]/(main)/group/_layout/Sidebar/Header/Nav.tsx',
|
|
'src/app/[variants]/(main)/group/_layout/Sidebar/Topic/hooks/useTopicNavigation.ts',
|
|
'src/app/[variants]/(main)/group/_layout/Sidebar/Topic/hooks/useThreadNavigation.ts',
|
|
'src/app/[variants]/(main)/chat/_layout/Sidebar/Header/Nav.tsx',
|
|
'src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/hooks/useTopicNavigation.ts',
|
|
'src/app/[variants]/(main)/chat/_layout/Sidebar/Topic/hooks/useThreadNavigation.ts',
|
|
'src/app/[variants]/(main)/memory/_layout/Sidebar/Header/Nav.tsx',
|
|
];
|
|
|
|
interface MigrationResult {
|
|
changes: string[];
|
|
filePath: string;
|
|
}
|
|
|
|
async function migrateFile(relativePath: string): Promise<MigrationResult | null> {
|
|
const fullPath = join(__dirname, '..', relativePath);
|
|
const content = await readFile(fullPath, 'utf8');
|
|
let newContent = content;
|
|
const changes: string[] = [];
|
|
|
|
// Check what hooks are being imported from @/libs/next/navigation
|
|
const importMatch = content.match(
|
|
/import\s*\{([^}]+)\}\s*from\s*["']@\/libs\/next\/navigation["']/,
|
|
);
|
|
|
|
if (!importMatch) {
|
|
console.log(`⏭️ ${relativePath} - No @/libs/next/navigation import found`);
|
|
return null;
|
|
}
|
|
|
|
const importedHooks = importMatch[1]
|
|
.split(',')
|
|
.map((s) => s.trim())
|
|
.filter(Boolean);
|
|
|
|
console.log(`📝 ${relativePath}`);
|
|
console.log(` Imported hooks: ${importedHooks.join(', ')}`);
|
|
|
|
// Build new imports
|
|
const newImports: string[] = [];
|
|
|
|
for (const hook of importedHooks) {
|
|
switch (hook) {
|
|
case 'usePathname': {
|
|
newImports.push(`import { usePathname } from '@/app/[variants]/(main)/hooks/usePathname';`);
|
|
changes.push('usePathname -> React Router version');
|
|
|
|
break;
|
|
}
|
|
case 'useSearchParams': {
|
|
newImports.push(
|
|
`import { useSearchParams } from '@/app/[variants]/(main)/hooks/useSearchParams';`,
|
|
);
|
|
changes.push('useSearchParams -> React Router version');
|
|
|
|
break;
|
|
}
|
|
case 'useRouter': {
|
|
newImports.push(`import { useRouter } from '@/app/[variants]/(main)/hooks/useRouter';`);
|
|
changes.push('useRouter -> React Router version');
|
|
|
|
break;
|
|
}
|
|
default: {
|
|
// Keep other imports (like notFound, redirect) from next/navigation
|
|
console.log(` ⚠️ Unknown hook "${hook}" - keeping original import`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (newImports.length === 0) {
|
|
console.log(` ⏭️ No hooks to migrate`);
|
|
return null;
|
|
}
|
|
|
|
// Replace the old import with new imports
|
|
newContent = newContent.replace(
|
|
/import\s*\{[^}]+\}\s*from\s*["']@\/libs\/next\/navigation["'];?\n?/,
|
|
newImports.join('\n') + '\n',
|
|
);
|
|
|
|
if (newContent !== content) {
|
|
await writeFile(fullPath, newContent, 'utf8');
|
|
for (const change of changes) {
|
|
console.log(` ✅ ${change}`);
|
|
}
|
|
return { changes, filePath: relativePath };
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
async function main() {
|
|
console.log('🚀 Starting SPA navigation migration...\n');
|
|
|
|
const results: MigrationResult[] = [];
|
|
|
|
for (const file of SPA_FILES) {
|
|
try {
|
|
const result = await migrateFile(file);
|
|
if (result) {
|
|
results.push(result);
|
|
}
|
|
} catch (error) {
|
|
console.error(`❌ Error processing ${file}:`, error);
|
|
}
|
|
}
|
|
|
|
console.log('\n' + '='.repeat(60));
|
|
console.log(`📊 Migration Summary:`);
|
|
console.log(` - Files processed: ${SPA_FILES.length}`);
|
|
console.log(` - Files modified: ${results.length}`);
|
|
console.log('\n✨ SPA navigation migration complete!');
|
|
}
|
|
|
|
await main();
|