Files
sam-react-prod/scripts/patch-json-parse.cjs
권혁성 c3266e5d3f deploy: 2026-03-12 배포
- feat: [QMS] 점검표 템플릿 Mock→API 연동 + 로트심사 UI 개선
- feat: [견적] 제어기 타입 변경 + 가이드레일 제품연동 + 수식보기 개선
- feat: [생산/출하] 작업자 화면 step 서버 토글 + 출하 수주 조인 연동
- feat: [배포] Jenkinsfile 롤백 기능 추가
- feat: [입고] 성적서 파일 백엔드 연동 + CSP 도메인 허용
- feat: ESLint 정리 및 전체 코드 품질 개선
- fix: [QMS] 제품검사 성적서 렌더링 개선 + 빌드 타입 에러 수정
- fix: [품질검사] LegacyPhotoUpload images undefined 에러 수정
- fix: middleware publicRoutes 타입 에러 수정
2026-03-12 15:21:20 +09:00

47 lines
1.7 KiB
JavaScript

/**
* JSON.parse 글로벌 패치 - macOS 26 파일시스템 손상 대응
*
* macOS 26에서 atomic write(tmp + rename)가 실패하면
* .next/prerender-manifest.json 등의 파일에 데이터가 중복 기록됨.
* 이로 인해 "Unexpected non-whitespace character after JSON at position N" 발생.
*
* 이 패치는 JSON.parse 실패 시 유효한 JSON 부분만 추출하여 자동 복구.
* NODE_OPTIONS='--require ./scripts/patch-json-parse.cjs' 로 로드.
*/
'use strict';
const originalParse = JSON.parse;
JSON.parse = function patchedJsonParse(text, reviver) {
try {
return originalParse.call(this, text, reviver);
} catch (e) {
if (e instanceof SyntaxError && typeof text === 'string') {
// "Unexpected non-whitespace character after JSON at position N"
// → position N까지가 유효한 JSON
const match = e.message.match(/after JSON at position\s+(\d+)/);
if (match) {
const pos = parseInt(match[1], 10);
if (pos > 0) {
try {
const result = originalParse.call(this, text.substring(0, pos), reviver);
// 한 번만 경고 (같은 position이면 반복 출력 방지)
if (!patchedJsonParse._warned) patchedJsonParse._warned = new Set();
const key = pos + ':' + text.length;
if (!patchedJsonParse._warned.has(key)) {
patchedJsonParse._warned.add(key);
console.warn(
`[patch-json-parse] macOS 파일 손상 자동 복구 (position ${pos}, total ${text.length} bytes)`
);
}
return result;
} catch {
// truncation으로도 실패하면 원래 에러 throw
}
}
}
}
throw e;
}
};