2 lines
1.5 KiB
JavaScript
2 lines
1.5 KiB
JavaScript
import fs from "node:fs";import path from "node:path";import{createRequire}from"node:module";import{parentPort,workerData}from"node:worker_threads";import{pathToFileURL}from"node:url";const f=await import(pathToFileURL(workerData.facadePath)),e=await import(pathToFileURL(workerData.envelopePath));globalThis.__dirname=`${workerData.build}${path.sep}`;globalThis.require=createRequire(import.meta.url);const wj=path.join(workerData.build,"FreeCADWebTechDrawRuntimeProbe.worker.js"),wc=path.join(workerData.build,"FreeCADWebTechDrawRuntimeProbe.worker.cjs");if(!fs.existsSync(wc)&&fs.existsSync(wj))fs.copyFileSync(wj,wc);const l=await import(pathToFileURL(path.join(workerData.build,"FreeCADWebTechDrawRuntimeProbe.js"))),k=await l.default({wasmBinary:fs.readFileSync(path.join(workerData.build,"FreeCADWebTechDrawRuntimeProbe.wasm")),locateFile:file=>file.endsWith(".worker.js")&&fs.existsSync(wc)?wc:path.join(workerData.build,file),print:()=>{},printErr:()=>{}}),q=new e.FacadeSerialQueue();parentPort.postMessage({kind:"ready",action:f.TECHDRAW_SAVE_COMMAND});parentPort.on("message",async m=>{if(e.isFacadeCancel(m)){if(!q.cancel(m))parentPort.postMessage(e.createFailure(m.requestId,"cancel_rejected","request is not active"));return}if(f.isTechDrawSaveRequest(m)){const s=m.requestId==="td-save-act-e-cancel"?new Promise(r=>setTimeout(()=>r(k),25)):k;parentPort.postMessage(await f.dispatchTechDrawSave(q,m,s));return}parentPort.postMessage(e.createFailure("invalid","invalid_request","TechDraw save envelope invalid"))});
|