/** Compiler-only transform; target imports stay external and target code is never run. */ import {createRequire} from 'node:module'; import {pathToFileURL} from 'node:url'; import {createHash} from 'node:crypto'; import {definePlan} from './vite_define_plan.mjs'; const require=createRequire(import.meta.url), vr=createRequire(require.resolve('vite/package.json')); const {rolldown,VERSION}=await import(pathToFileURL(vr.resolve('rolldown')).href); let raw='';for await(const chunk of process.stdin){raw+=chunk;if(raw.length>524288)throw Error('DEFINE_INPUT_BUDGET');} const r=JSON.parse(raw),plan=definePlan(r.config,r.package,r.config_path); if(typeof r.source!=='string'||Buffer.byteLength(r.source)>262144)throw Error('DEFINE_SOURCE_BUDGET'); const bundle=await rolldown({input:'virtual-entry',treeshake:false,transform:{define:plan.constants}, onLog(level,log){if(level==='warn'||level==='error')throw Error('DEFINE_COMPILER_WARNING:'+log.code);}, makeAbsoluteExternalsRelative:false,plugins:[{name:'frozen-single-module', resolveId(id,importer){if(!importer&&id==='virtual-entry')return id;if(importer==='virtual-entry')return {id,external:'absolute'};throw Error('DEFINE_HOST_RESOLUTION_DENIED');}, load(id){if(id==='virtual-entry')return r.source;throw Error('DEFINE_HOST_LOAD_DENIED');}}]}); let result;try{result=await bundle.generate({format:'es',minify:true,sourcemap:false});}finally{await bundle.close();} if(result.output.length!==1||result.output[0].type!=='chunk'||Buffer.byteLength(result.output[0].code)>65536)throw Error('DEFINE_OUTPUT_BUDGET'); const code=result.output[0].code,sha=s=>createHash('sha256').update(s).digest('hex'); console.log(JSON.stringify({plan,source_sha256:sha(r.source),after_sha256:sha(code),code, compiler:{name:'rolldown',version:VERSION},source_executed:false}));