// transformers.js의 ONNX Runtime WASM을 public/ort 로 복사 → 오프라인 동작(CDN 불필요). // postinstall 및 빌드 전에 실행. (wasm은 용량이 커 git에는 올리지 않음 — gitignore) import { readdir, mkdir, copyFile, access } from 'node:fs/promises' import { constants } from 'node:fs' import { join, dirname } from 'node:path' import { fileURLToPath } from 'node:url' const __dirname = dirname(fileURLToPath(import.meta.url)) const SRC = join(__dirname, '..', 'node_modules', '@huggingface', 'transformers', 'dist') const DEST = join(__dirname, '..', 'public', 'ort') async function exists(p) { try { await access(p, constants.F_OK) return true } catch { return false } } async function main() { if (!(await exists(SRC))) { console.warn('transformers dist 없음 — ORT wasm 복사 건너뜀:', SRC) return } await mkdir(DEST, { recursive: true }) const files = await readdir(SRC) // ORT 런타임 파일(wasm + 로더 mjs)만 복사 const targets = files.filter((f) => /ort-.*\.(wasm|mjs)$/.test(f)) let n = 0 for (const f of targets) { await copyFile(join(SRC, f), join(DEST, f)) n++ } console.log(`ORT wasm 복사 완료: ${n}개 → ${DEST}`) } main().catch((e) => { console.error('ORT 복사 오류:', e.message) // 빌드를 막지 않도록 실패해도 통과 (CDN 폴백 가능) })