Skip to content

Commit 9720556

Browse files
committed
compile to tmpdir
1 parent 70ec40b commit 9720556

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/cli/compile.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { Options, withOptions } from '../utils/options.js'
88
import { unreachable } from '../utils/ir.js'
99
import { reset } from '../utils/cache.js'
1010
import * as path from 'path'
11-
import { chmod, mkdir, readFile, writeFile } from 'fs/promises'
11+
import { chmod, mkdir, mkdtemp, readFile, rm, writeFile } from 'fs/promises'
1212
import { spawn, SpawnOptions } from 'node:child_process'
13+
import { tmpdir } from 'node:os'
1314
import { dirname } from './dirname.js'
1415
import { Compiler } from '../backend/compiler.js'
1516
import type { Sig } from '../middle/abstract.js'
@@ -179,6 +180,17 @@ const libPath = path.join(dirname, '../../dist/cli/lib.js')
179180
const execPath = path.join(dirname, '../../dist/cli/exec.js')
180181

181182
async 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

Comments
 (0)