50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
|
|
/**
|
||
|
|
* .next 빌드 캐시 무결성 검증
|
||
|
|
*
|
||
|
|
* macOS 26 파일시스템 이슈로 .next/ 내 JSON 파일이 손상될 수 있음.
|
||
|
|
* (atomic write 실패 → 데이터 중복 기록)
|
||
|
|
* dev 서버 시작 전 자동 검증하여 손상 시 .next 삭제.
|
||
|
|
*/
|
||
|
|
import { readFileSync, rmSync, existsSync, readdirSync } from 'fs';
|
||
|
|
import { join } from 'path';
|
||
|
|
|
||
|
|
const NEXT_DIR = '.next';
|
||
|
|
|
||
|
|
if (!existsSync(NEXT_DIR)) {
|
||
|
|
process.exit(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
const jsonFiles = [];
|
||
|
|
try {
|
||
|
|
// .next/ 루트의 JSON 파일들
|
||
|
|
for (const f of readdirSync(NEXT_DIR)) {
|
||
|
|
if (f.endsWith('.json')) jsonFiles.push(join(NEXT_DIR, f));
|
||
|
|
}
|
||
|
|
// .next/server/ 의 JSON 파일들
|
||
|
|
const serverDir = join(NEXT_DIR, 'server');
|
||
|
|
if (existsSync(serverDir)) {
|
||
|
|
for (const f of readdirSync(serverDir)) {
|
||
|
|
if (f.endsWith('.json')) jsonFiles.push(join(serverDir, f));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} catch {
|
||
|
|
// 디렉토리 읽기 실패 시 무시
|
||
|
|
}
|
||
|
|
|
||
|
|
let corrupted = false;
|
||
|
|
for (const file of jsonFiles) {
|
||
|
|
try {
|
||
|
|
const content = readFileSync(file, 'utf8');
|
||
|
|
JSON.parse(content);
|
||
|
|
} catch (e) {
|
||
|
|
console.warn(`⚠️ 손상된 캐시 발견: ${file}`);
|
||
|
|
console.warn(` ${e.message}`);
|
||
|
|
corrupted = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (corrupted) {
|
||
|
|
console.warn('🗑️ .next 캐시를 삭제하고 재빌드합니다...');
|
||
|
|
rmSync(NEXT_DIR, { recursive: true, force: true });
|
||
|
|
}
|