import assert from "assert" ; import fs from "fs/promises" ; import path from "path" ; ( async ( ) => { const pkg = JSON . parse ( await fs . readFile ( path . join ( "pkg" , "package.json" ) , "utf8" ) ) ; const glueName = pkg . files . find ( ( file ) => file . endsWith ( ".js" ) ) ; assert ( glueName ) ; const glueCode = await fs . readFile ( path . join ( "pkg" , glueName ) , "utf8" ) ; const code = await fs . readFile ( path . join ( "worker" , "worker.js" ) , "utf8" ) ; const generatedDir = path . join ( "worker" , "generated" ) ; await fs . mkdir ( generatedDir , { recursive : true } ) ; await fs . writeFile ( path . join ( generatedDir , "script.js" ) , `${ glueCode } ${ code }` , "utf8" ) ; const wasmName = pkg . files . find ( ( file ) => file . endsWith ( ".wasm" ) ) ; assert ( wasmName ) ; await fs . copyFile ( path . join ( "pkg" , wasmName ) , path . join ( generatedDir , "script.wasm" ) ) ; } ) ( ) ;