Skip to content

Commit

Permalink
Run solcjs in a subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed May 8, 2024
1 parent ad94fea commit 3c6de8f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-mugs-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Run solcjs in a subprocess
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
// @ts-check
const fs = require("node:fs");

function readStdInSync() {
process.stdin.resume();
async function readStream(stream, encoding = "utf8") {
stream.setEncoding(encoding);

const response = fs.readFileSync(process.stdin.fd, { encoding: "utf-8" });
return new Promise((resolve, reject) => {
let data = "";

process.stdin.pause();

return response;
stream.on("data", (chunk) => (data += chunk));
stream.on("end", () => resolve(data));
stream.on("error", (error) => reject(error));
});
}

function getSolcJs(solcJsPath) {
const solcWrapper = require("solc/wrapper");
return solcWrapper(require(solcJsPath));
}

const solcjsPath = process.argv[2];
const solc = getSolcJs(solcjsPath);
const output = solc.compile(readStdInSync());
async function main() {
const input = await readStream(process.stdin);

const solcjsPath = process.argv[2];
const solc = getSolcJs(solcjsPath);

const output = solc.compile(input);

console.log(output);
}

console.log(output);
main().catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit 3c6de8f

Please sign in to comment.