@@ -3,28 +3,30 @@ import assert from "assert";
33import fs from "fs/promises" ;
44import path from "path" ;
55
6- // 1. Load package.json file generated by wasm-bindgen containing filenames
7- const pkg : { files : string [ ] } = JSON . parse (
8- await fs . readFile ( path . join ( "pkg" , "package.json" ) , "utf8" )
9- ) ;
6+ ; ( async ( ) => {
7+ // 1. Load package.json file generated by wasm-bindgen containing filenames
8+ const pkg : { files : string [ ] } = JSON . parse (
9+ await fs . readFile ( path . join ( "pkg" , "package.json" ) , "utf8" )
10+ ) ;
1011
11- // 2. Concatenate wasm-bindgen glue and worker code into worker/generated/script.js
12- const glueName = pkg . files . find ( ( file ) => file . endsWith ( ".js" ) ) ;
13- assert ( glueName ) ;
14- const glueCode = await fs . readFile ( path . join ( "pkg" , glueName ) , "utf8" ) ;
15- const code = await fs . readFile ( path . join ( "worker" , "worker.js" ) , "utf8" ) ;
16- const generatedDir = path . join ( "worker" , "generated" ) ;
17- await fs . mkdir ( generatedDir , { recursive : true } ) ;
18- await fs . writeFile (
19- path . join ( generatedDir , "script.js" ) ,
20- `${ glueCode } ${ code } ` ,
21- "utf8"
22- ) ;
12+ // 2. Concatenate wasm-bindgen glue and worker code into worker/generated/script.js
13+ const glueName = pkg . files . find ( ( file ) => file . endsWith ( ".js" ) ) ;
14+ assert ( glueName ) ;
15+ const glueCode = await fs . readFile ( path . join ( "pkg" , glueName ) , "utf8" ) ;
16+ const code = await fs . readFile ( path . join ( "worker" , "worker.js" ) , "utf8" ) ;
17+ const generatedDir = path . join ( "worker" , "generated" ) ;
18+ await fs . mkdir ( generatedDir , { recursive : true } ) ;
19+ await fs . writeFile (
20+ path . join ( generatedDir , "script.js" ) ,
21+ `${ glueCode } ${ code } ` ,
22+ "utf8"
23+ ) ;
2324
24- // 3. Copy *_bg.wasm file into worker/generated/script.wasm
25- const wasmName = pkg . files . find ( ( file ) => file . endsWith ( ".wasm" ) ) ;
26- assert ( wasmName ) ;
27- await fs . copyFile (
28- path . join ( "pkg" , wasmName ) ,
29- path . join ( generatedDir , "script.wasm" )
30- ) ;
25+ // 3. Copy *_bg.wasm file into worker/generated/script.wasm
26+ const wasmName = pkg . files . find ( ( file ) => file . endsWith ( ".wasm" ) ) ;
27+ assert ( wasmName ) ;
28+ await fs . copyFile (
29+ path . join ( "pkg" , wasmName ) ,
30+ path . join ( generatedDir , "script.wasm" )
31+ ) ;
32+ } ) ( ) ;
0 commit comments