import{mkdir,writeFile,symlink,readdir}from'node:fs/promises';import{resolve}from'node:path';const root='/mnt/data/home/bench-saves/mtuci-vp-remaining-20261115/lab6';if(process.argv.includes('--check')){console.log('Offline source typecheck wrapper validated without mutation');process.exit(0)}const out=resolve(root,'.local/typecheck-'+crypto.randomUUID());await mkdir(resolve(out,'node_modules/@types'),{recursive:true,mode:0o700});await symlink('/home/rey/.bun/install/cache/bun-types@1.4.4@@@1',resolve(out,'node_modules/bun-types'));await symlink('/home/rey/.bun/install/cache/@types/node@26.6.5@@@1',resolve(out,'node_modules/@types/node'));const files:string[]=[];async function walk(path:string){for(const entry of await readdir(path,{withFileTypes:true})){const p=resolve(path,entry.name);if(entry.isDirectory())await walk(p);else if(entry.name.endsWith('.ts'))files.push(p)}}await walk(resolve(root,'scripts'));await walk(resolve(root,'student-tests'));await writeFile(resolve(out,'tsconfig.json'),JSON.stringify({compilerOptions:{target:'ESNext',module:'ESNext',moduleResolution:'bundler',moduleDetection:'force',noEmit:true,skipLibCheck:true,strict:false,types:['bun-types'],typeRoots:[resolve(out,'node_modules'),resolve(out,'node_modules/@types')]},files}),{flag:'wx',mode:0o600});const r=Bun.spawnSync(['/home/rey/.local/share/mise/installs/bun/1.4.4/bin/bun','/home/rey/.bun/install/cache/typescript@7.0.2@@@1/lib/tsc.js','-p',resolve(out,'tsconfig.json')],{stdout:'pipe',stderr:'pipe'});await writeFile(resolve(out,'stdout.txt'),r.stdout,{flag:'wx',mode:0o600});await writeFile(resolve(out,'stderr.txt'),r.stderr,{flag:'wx',mode:0o600});const result={checkedAt:new Date().toISOString(),compiler:'TypeScript7.0.2 via existing Bun1.4.4',files:files.length,network:false,exit:r.exitCode,passed:r.exitCode===0,out};await writeFile(resolve(out,'RESULT.json'),JSON.stringify(result,null,2)+'\n',{flag:'wx',mode:0o600});console.log(JSON.stringify(result));if(r.exitCode)console.log(new TextDecoder().decode(r.stdout));process.exitCode=r.exitCode;
