@@ -15,8 +15,8 @@ import type { Path } from "@david/path";
1515export async function runBuildCommand ( args : BuildCommand ) {
1616 const output = await runPreBuild ( args ) ;
1717
18- await args . outDir . ensureDir ( ) ;
19- await writeSnippets ( ) ;
18+ args . outDir . ensureDirSync ( ) ;
19+ writeSnippets ( ) ;
2020
2121 const files = args . inline
2222 ? await inlinePreBuild ( output , args )
@@ -25,17 +25,17 @@ export async function runBuildCommand(args: BuildCommand) {
2525 for ( const file of files ) {
2626 console . log ( ` write ${ colors . yellow ( file . path . toString ( ) ) } ` ) ;
2727 if ( typeof file . data === "string" ) {
28- await file . path . writeText ( file . data ) ;
28+ file . path . writeTextSync ( file . data ) ;
2929 } else {
30- await file . path . write ( file . data ) ;
30+ file . path . writeSync ( file . data ) ;
3131 }
3232 }
3333
3434 console . log (
3535 `${ colors . bold ( colors . green ( "Finished" ) ) } WebAssembly output` ,
3636 ) ;
3737
38- async function writeSnippets ( ) {
38+ function writeSnippets ( ) {
3939 const localModules = Array . from ( output . bindgen . localModules ) ;
4040 const snippets = Array . from ( output . bindgen . snippets ) ;
4141
@@ -46,25 +46,25 @@ export async function runBuildCommand(args: BuildCommand) {
4646 const snippetsDest = args . outDir . join ( "snippets" ) ;
4747 // start with a fresh directory in order to clear out any previously
4848 // created snippets which might have a different name
49- await snippetsDest . emptyDir ( ) ;
49+ snippetsDest . emptyDirSync ( ) ;
5050
5151 for ( const [ name , text ] of localModules ) {
5252 const filePath = snippetsDest . join ( name ) ;
5353 const dirPath = filePath . parentOrThrow ( ) ;
54- await dirPath . mkdir ( { recursive : true } ) ;
55- await filePath . writeText ( text ) ;
54+ dirPath . mkdirSync ( { recursive : true } ) ;
55+ filePath . writeTextSync ( text ) ;
5656 }
5757
5858 for ( const [ identifier , list ] of snippets ) {
5959 if ( list . length === 0 ) {
6060 continue ;
6161 }
6262 const dirPath = snippetsDest . join ( identifier ) ;
63- await dirPath . mkdir ( { recursive : true } ) ;
63+ dirPath . mkdirSync ( { recursive : true } ) ;
6464 for ( const [ i , text ] of list . entries ( ) ) {
6565 const name = `inline${ i } .js` ;
6666 const filePath = dirPath . join ( name ) ;
67- await filePath . writeText ( text ) ;
67+ filePath . writeTextSync ( text ) ;
6868 }
6969 }
7070 }
@@ -85,8 +85,8 @@ async function handleWasmModuleOutput(
8585 ) ,
8686 data : await getFormattedText ( `${ generatedHeader }
8787// @ts-self-types="./${ output . bindingDts . path . basename ( ) } "
88- // source-hash: ${ output . sourceHash }
8988
89+ // source-hash: ${ output . sourceHash }
9090import * as wasm from "./${ output . wasmFileName } ";
9191export * from "./${ output . bindingJsBg . path . basename ( ) } ";
9292import { __wbg_set_wasm } from "./${ output . bindingJsBg . path . basename ( ) } ";
@@ -116,18 +116,8 @@ async function inlinePreBuild(
116116 ) ,
117117 data : await getFormattedText ( `${ generatedHeader }
118118// @ts-self-types="./${ output . bindingDts . path . basename ( ) } "
119- // source-hash: ${ output . sourceHash }
120-
121- function base64decode(b64) {
122- const binString = atob(b64);
123- const size = binString.length;
124- const bytes = new Uint8Array(size);
125- for (let i = 0; i < size; i++) {
126- bytes[i] = binString.charCodeAt(i);
127- }
128- return bytes;
129- }
130119
120+ // source-hash: ${ output . sourceHash }
131121import * as imports from "./${ output . bindingJsBg . path . basename ( ) } ";
132122const bytes = base64decode("\\\n${
133123 base64 . encodeBase64 ( wasmBytes ) . replace ( / .{ 78 } / g, "$&\\\n" )
@@ -140,6 +130,16 @@ const wasm = new WebAssembly.Instance(wasmModule, {
140130export * from "./${ output . bindingJsBg . path . basename ( ) } ";
141131import { __wbg_set_wasm } from "./${ output . bindingJsBg . path . basename ( ) } ";
142132__wbg_set_wasm(wasm.exports);
133+
134+ function base64decode(b64) {
135+ const binString = atob(b64);
136+ const size = binString.length;
137+ const bytes = new Uint8Array(size);
138+ for (let i = 0; i < size; i++) {
139+ bytes[i] = binString.charCodeAt(i);
140+ }
141+ return bytes;
142+ }
143143` ) ,
144144 } , {
145145 path : output . bindingJsBg . path ,
0 commit comments