mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-25 11:47:57 +00:00
Add support for esm and cjs modules
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { parentPort } from 'worker_threads';
|
||||
|
||||
parentPort.on('message', async (inputJson) => {
|
||||
const { default: createRevive } = await import(new URL('./resolc.js', import.meta.url));
|
||||
const revive = await createRevive();
|
||||
|
||||
revive.setStdinData(inputJson);
|
||||
|
||||
let stdoutString = "";
|
||||
revive.setStdoutCallback(function(char) {
|
||||
if (char.charCodeAt(0) === '\n') {
|
||||
console.log("new line")
|
||||
exit
|
||||
}
|
||||
stdoutString += char;
|
||||
});
|
||||
|
||||
let stderrString = "";
|
||||
revive.setStderrCallback(function(char) {
|
||||
stderrString += char;
|
||||
});
|
||||
|
||||
// Call main on the new instance
|
||||
const output = revive.callMain(['--recursive-process']);
|
||||
|
||||
if (stderrString.length > 0) {
|
||||
// If /err is not empty, throw an error with its content
|
||||
throw new Error(stderrString);
|
||||
} else {
|
||||
parentPort.postMessage({ output: stdoutString });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user