@@ -8,8 +8,9 @@ import { Options, withOptions } from '../utils/options.js'
88import { unreachable } from '../utils/ir.js'
99import { reset } from '../utils/cache.js'
1010import * as path from 'path'
11- import { chmod , mkdir , readFile , writeFile } from 'fs/promises'
11+ import { chmod , mkdir , mkdtemp , readFile , rm , writeFile } from 'fs/promises'
1212import { spawn , SpawnOptions } from 'node:child_process'
13+ import { tmpdir } from 'node:os'
1314import { dirname } from './dirname.js'
1415import { Compiler } from '../backend/compiler.js'
1516import type { Sig } from '../middle/abstract.js'
@@ -179,6 +180,17 @@ const libPath = path.join(dirname, '../../dist/cli/lib.js')
179180const execPath = path . join ( dirname , '../../dist/cli/exec.js' )
180181
181182async function exec ( file : string , args : string [ ] = [ ] , config ?: CompileConfig ) : Promise < void > {
182- if ( path . extname ( file ) . toLowerCase ( ) !== '.wasm' ) [ , file ] = await compile ( file , config )
183- await run ( 'node' , [ '--enable-source-maps' , '--experimental-wasm-jspi' , execPath , file , ...args ] , { stdio : 'inherit' } )
183+ if ( path . extname ( file ) . toLowerCase ( ) === '.wasm' ) {
184+ await run ( 'node' , [ '--enable-source-maps' , '--experimental-wasm-jspi' , execPath , file , ...args ] , { stdio : 'inherit' } )
185+ return
186+ }
187+ const dir = await mkdtemp ( path . join ( tmpdir ( ) , 'raven-exec-' ) )
188+ const base = path . basename ( file , path . extname ( file ) )
189+ const output = path . join ( dir , `${ base } .wasm` )
190+ try {
191+ [ , file ] = await compile ( file , { ...config , output } )
192+ await run ( 'node' , [ '--enable-source-maps' , '--experimental-wasm-jspi' , execPath , file , ...args ] , { stdio : 'inherit' } )
193+ } finally {
194+ await rm ( dir , { recursive : true , force : true } )
195+ }
184196}
0 commit comments