Skip to content

Commit de6b47a

Browse files
authored
log stdout and stderr from spawned build process to console (#237)
1 parent 6914a0e commit de6b47a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

packages/@apphosting/common/src/index.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,27 @@ export async function runBuild(opts: BuildOptions = getBuildOptions()): Promise<
3030
shell: true,
3131
stdio: ["inherit", "pipe", "pipe"],
3232
});
33-
let buildOutput = "";
33+
let stdout = "";
34+
let stderr = "";
3435

3536
child.stdout.on("data", (data: Buffer) => {
36-
buildOutput += data.toString();
37+
stdout += data.toString();
3738
});
39+
40+
child.stderr.on("data", (data: Buffer) => {
41+
stderr += data.toString();
42+
});
43+
44+
// Re-connect the child process's stdout and stderr to the console so that
45+
// build messages and errors are still logged in Cloud Build.
46+
child.stdout.pipe(process.stdout);
47+
child.stderr.pipe(process.stderr);
48+
3849
child.on("exit", (code) => {
3950
if (code !== 0) {
40-
reject(new Error(`Process exited with error code ${code}. Output: ${buildOutput}`));
41-
}
42-
if (!buildOutput) {
43-
reject(new Error("Unable to locate build manifest with output paths."));
51+
reject(new Error(`Build process exited with error code ${code}.`));
4452
}
45-
resolve({ stdout: buildOutput });
53+
resolve({ stdout: stdout, stderr: stderr });
4654
});
4755
});
4856
}

0 commit comments

Comments
 (0)