Skip to content

Commit

Permalink
fix too many pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Oct 22, 2023
1 parent 20a414c commit 390b538
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions loader/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,8 @@ export async function load({
const workerProcess = fork(workerFilePath, {
// Note: this is required for PostCSS.
cwd: rootDir,
stdio: "pipe",
stdio: "inherit",
});
workerProcess.stdout?.pipe(prettyLoggerStream);
workerProcess.stderr?.pipe(prettyLoggerStream);
const killWorker = async () => {
if (workerPromise?.resolved) {
workerPromise.resolved.exiting = true;
Expand Down Expand Up @@ -340,6 +338,9 @@ export async function load({
resolveWorkerReady(message);
rejectWorkerReady = null;
break;
case "log":
prettyLoggerStream.write(message.message);
break;
case "crash":
logger.error(message.message);
rejectWorkerReady?.(new Error(message.message));
Expand Down
4 changes: 4 additions & 0 deletions loader/src/worker-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export type FromWorkerMessage =
kind: "ready";
port: number;
}
| {
kind: "log";
message: string;
}
| {
kind: "crash";
message: string;
Expand Down
17 changes: 11 additions & 6 deletions loader/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assertNever from "assert-never";
import createLogger from "pino";
import prettyLogger from "pino-pretty";
import { loadModules } from "./modules";
import type {
FromWorkerMessage,
Expand All @@ -21,11 +20,17 @@ async function runWorker({
port,
onServerStartModuleName,
}: WorkerData) {
const prettyLoggerStream = prettyLogger({
colorize: true,
destination: process.stdout,
});
const logger = createLogger({ level: logLevel }, prettyLoggerStream);
const logger = createLogger(
{ level: logLevel },
{
write(message) {
sendMessageFromWorker({
kind: "log",
message,
});
},
}
);
const { core, vfs, frameworkPlugins, onServerStart } = await loadModules({
logger,
installDir,
Expand Down

0 comments on commit 390b538

Please sign in to comment.