Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions adminforth/commands/callTsProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export function callTsProxy(tsCode, silent=false) {
const child = spawn("tsx", [path.join(currentFileFolder, "proxy.ts")], {
env: process.env,
});
let stdout = "";
let stderr = "";
let stdoutLogs = [];

child.stdout.on("data", (data) => {
stdout += data;
stdoutLogs.push(data.toString());
});

child.stderr.on("data", (data) => {
Expand All @@ -39,7 +39,12 @@ export function callTsProxy(tsCode, silent=false) {
child.on("close", (code) => {
if (code === 0) {
try {
const preparedStdout = stdout.slice(stdout.indexOf("{"), stdout.lastIndexOf("}") + 1);
const tsProxyResult = stdoutLogs.find(log => log.includes('>>>>>>> <-- found this in stream start reading'));
const preparedStdout = tsProxyResult.slice(tsProxyResult.indexOf('>>>>>>> <-- found this in stream start reading') + 46, tsProxyResult.lastIndexOf('<<<<<<< <-- found end'));
const preparedStdoutLogs = stdoutLogs.filter(log => !log.includes('>>>>>>> <-- found this in stream start reading'));
for (const log of preparedStdoutLogs) {
console.log(log);
}
const parsed = JSON.parse(preparedStdout);
if (!silent) {
parsed.capturedLogs.forEach((log) => {
Expand All @@ -52,10 +57,10 @@ export function callTsProxy(tsCode, silent=false) {
}
resolve(parsed.result);
} catch (e) {
reject(new Error("Invalid JSON from tsproxy: " + stdout));
reject(new Error("Invalid JSON from tsproxy: " + preparedStdout));
}
} else {
console.error(`tsproxy exited with non-0, this should never happen, stdout: ${stdout}, stderr: ${stderr}`);
console.error(`tsproxy exited with non-0, this should never happen, stdout: ${preparedStdout}, stderr: ${stderr}`);
reject(new Error(stderr));
}
});
Expand Down
28 changes: 18 additions & 10 deletions adminforth/commands/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,27 @@ import path from 'path';

// Restore original console.log
console.log = origLog;
console.log(JSON.stringify({
result,
capturedLogs,
error: null
}));
console.log(
">>>>>>> <-- found this in stream start reading"+
JSON.stringify({
result,
capturedLogs,
error: null
})
+"<<<<<<< <-- found end"
);
} catch (error: any) {
// Restore original console.log
console.log = origLog;
console.log(JSON.stringify({
error: error.message,
stack: error.stack,
capturedLogs
}));
console.log(
">>>>>>> <-- found this in stream start reading"+
JSON.stringify({
error: error.message,
stack: error.stack,
capturedLogs
})
+"<<<<<<< <-- found end"
);
} finally {
await unlink(tmpFile).catch(() => {});
}
Expand Down