11import { dirname , resolve , sep , normalize } from 'node:path' ;
22import { tmpdir , freemem } from 'node:os' ;
3- import { spawnSync , type SpawnSyncOptionsWithStringEncoding } from 'node:child_process' ;
3+ import {
4+ spawnSync ,
5+ type SpawnSyncOptionsWithStringEncoding ,
6+ } from 'node:child_process' ;
47import {
58 mkdir ,
69 readFile ,
@@ -29,23 +32,24 @@ async function getTmpDir() {
2932}
3033
3134export type CompileApplicationToWasmParams = {
32- input : string ,
33- output : string ,
34- wasmEngine : string ,
35- enableHttpCache : boolean ,
36- enableExperimentalHighResolutionTimeMethods : boolean ,
37- enableAOT : boolean ,
38- aotCache : string ,
39- enableStackTraces : boolean ,
40- excludeSources : boolean ,
41- debugIntermediateFilesDir : string | undefined ,
42- moduleMode : boolean ,
43- doBundle : boolean ,
44- env : Record < string , string > ,
35+ input : string ;
36+ output : string ;
37+ wasmEngine : string ;
38+ enableHttpCache : boolean ;
39+ enableExperimentalHighResolutionTimeMethods : boolean ;
40+ enableAOT : boolean ;
41+ aotCache : string ;
42+ enableStackTraces : boolean ;
43+ excludeSources : boolean ;
44+ debugIntermediateFilesDir : string | undefined ;
45+ moduleMode : boolean ;
46+ doBundle : boolean ;
47+ env : Record < string , string > ;
4548} ;
4649
47- export async function compileApplicationToWasm ( params : CompileApplicationToWasmParams ) {
48-
50+ export async function compileApplicationToWasm (
51+ params : CompileApplicationToWasmParams ,
52+ ) {
4953 const {
5054 output,
5155 wasmEngine,
@@ -80,7 +84,8 @@ export async function compileApplicationToWasm(params: CompileApplicationToWasmP
8084 try {
8185 await readFile ( input , { encoding : 'utf-8' } ) ;
8286 } catch ( maybeError : unknown ) {
83- const error = maybeError instanceof Error ? maybeError : new Error ( String ( maybeError ) ) ;
87+ const error =
88+ maybeError instanceof Error ? maybeError : new Error ( String ( maybeError ) ) ;
8489 console . error (
8590 `Error: Failed to open the \`input\` (${ input } )` ,
8691 error . message ,
@@ -138,7 +143,10 @@ export async function compileApplicationToWasm(params: CompileApplicationToWasmP
138143 recursive : true ,
139144 } ) ;
140145 } catch ( maybeError : unknown ) {
141- const error = maybeError instanceof Error ? maybeError : new Error ( String ( maybeError ) ) ;
146+ const error =
147+ maybeError instanceof Error
148+ ? maybeError
149+ : new Error ( String ( maybeError ) ) ;
142150 console . error (
143151 `Error: Failed to create the \`debug-intermediate-files\` (${ debugIntermediateFilesDir } ) directory` ,
144152 error . message ,
@@ -164,7 +172,10 @@ export async function compileApplicationToWasm(params: CompileApplicationToWasmP
164172 enableStackTraces,
165173 } ) ;
166174 } catch ( maybeError : unknown ) {
167- const error = maybeError instanceof Error ? maybeError : new Error ( String ( maybeError ) ) ;
175+ const error =
176+ maybeError instanceof Error
177+ ? maybeError
178+ : new Error ( String ( maybeError ) ) ;
168179 console . error ( `Error:` , error . message ) ;
169180 process . exit ( 1 ) ;
170181 }
@@ -215,7 +226,10 @@ export async function compileApplicationToWasm(params: CompileApplicationToWasmP
215226 if ( enableStackTraces ) {
216227 // Compose source maps
217228 const replaceSourceMapToken = '__FINAL_SOURCE_MAP__' ;
218- let excludePatterns : ExcludePattern [ ] = [ 'forbid-entry:/**' , 'node_modules/**' ] ;
229+ let excludePatterns : ExcludePattern [ ] = [
230+ 'forbid-entry:/**' ,
231+ 'node_modules/**' ,
232+ ] ;
219233 if ( excludeSources ) {
220234 excludePatterns = [ ( ) => true ] ;
221235 }
@@ -274,7 +288,9 @@ export async function compileApplicationToWasm(params: CompileApplicationToWasmP
274288 ENABLE_EXPERIMENTAL_HIGH_RESOLUTION_TIME_METHODS :
275289 enableExperimentalHighResolutionTimeMethods ? '1' : '0' ,
276290 ENABLE_EXPERIMENTAL_HTTP_CACHE : enableHttpCache ? '1' : '0' ,
277- RUST_MIN_STACK : String ( Math . max ( 8 * 1024 * 1024 , Math . floor ( freemem ( ) * 0.1 ) ) ) ,
291+ RUST_MIN_STACK : String (
292+ Math . max ( 8 * 1024 * 1024 , Math . floor ( freemem ( ) * 0.1 ) ) ,
293+ ) ,
278294 } ,
279295 } satisfies SpawnSyncOptionsWithStringEncoding ;
280296
@@ -364,7 +380,8 @@ export async function compileApplicationToWasm(params: CompileApplicationToWasmP
364380 }
365381 }
366382 } catch ( maybeError : unknown ) {
367- const error = maybeError instanceof Error ? maybeError : new Error ( String ( maybeError ) ) ;
383+ const error =
384+ maybeError instanceof Error ? maybeError : new Error ( String ( maybeError ) ) ;
368385 throw new Error (
369386 `Error: Failed to compile JavaScript to Wasm:\n${ error . message } ` ,
370387 ) ;
0 commit comments