mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-10-20 18:56:17 +00:00
Emscripten 4.0.12 introduced breaking change by changing module factory to always return promise even if `WASM_ASYNC_COMPILATION=0`. To overcome this, build emscripten compiler without MODULARIZE with custom export of `createRevive`.
33 lines
807 B
JavaScript
33 lines
807 B
JavaScript
const soljson = require("solc/soljson");
|
|
const createRevive = require("./resolc.js");
|
|
|
|
function compile(standardJsonInput) {
|
|
if (!standardJsonInput) {
|
|
throw new Error("Input JSON for the Solidity compiler is required.");
|
|
}
|
|
|
|
// Initialize the compiler
|
|
const compiler = createRevive();
|
|
compiler.soljson = soljson;
|
|
|
|
// Provide input to the compiler
|
|
compiler.writeToStdin(JSON.stringify(standardJsonInput));
|
|
|
|
// Run the compiler
|
|
compiler.callMain(["--standard-json"]);
|
|
|
|
// Collect output
|
|
const stdout = compiler.readFromStdout();
|
|
const stderr = compiler.readFromStderr();
|
|
|
|
// Check for errors and throw if stderr exists
|
|
if (stderr) {
|
|
throw new Error(`Compilation failed: ${stderr}`);
|
|
}
|
|
|
|
// Return the output if no errors
|
|
return stdout;
|
|
}
|
|
|
|
module.exports = { compile };
|