-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad94fea
commit 3c6de8f
Showing
2 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"hardhat": patch | ||
--- | ||
|
||
Run solcjs in a subprocess |
33 changes: 22 additions & 11 deletions
33
packages/hardhat-core/src/internal/solidity/compiler/solcjs-runner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |