Skip to content

Commit

Permalink
chore(repo): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jan 29, 2025
1 parent 91e243b commit 8bed8d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/generated/devkit/Task.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Determines if a given task should be cacheable.

### continuous

**continuous**: `boolean`
`Optional` **continuous**: `boolean`

This denotes if the task runs continuously

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/config/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface Task {
/**
* This denotes if the task runs continuously
*/
continuous: boolean;
continuous?: boolean;
}

/**
Expand Down
18 changes: 13 additions & 5 deletions packages/nx/src/tasks-runner/forked-process-task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export class ForkedProcessTaskRunner {
task: Task,
{
streamOutput,
temporaryOutputPath,
taskGraph,
env,
}: {
Expand Down Expand Up @@ -250,8 +251,17 @@ export class ForkedProcessTaskRunner {
});
this.processes.add(cp);

cp.onExit(() => {
cp.onExit((code, terminalOutput) => {
this.processes.delete(cp);

if (!streamOutput) {
this.options.lifeCycle.printTaskTerminalOutput(
task,
code === 0 ? 'success' : 'failure',
terminalOutput
);
}
this.writeTerminalOutput(temporaryOutputPath, terminalOutput);
});

return cp;
Expand Down Expand Up @@ -284,9 +294,7 @@ export class ForkedProcessTaskRunner {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
env,
});
const cp = new NodeChildProcessWithDirectOutput(p, {
temporaryOutputPath,
});
const cp = new NodeChildProcessWithDirectOutput(p, temporaryOutputPath);

this.processes.add(cp);

Expand All @@ -300,10 +308,10 @@ export class ForkedProcessTaskRunner {

cp.onExit((code, signal) => {
this.processes.delete(cp);
const terminalOutput = cp.getTerminalOutput();
// we didn't print any output as we were running the command
// print all the collected output
try {
const terminalOutput = cp.getTerminalOutput();
if (!streamOutput) {
this.options.lifeCycle.printTaskTerminalOutput(
task,
Expand Down
21 changes: 10 additions & 11 deletions packages/nx/src/tasks-runner/running-tasks/node-child-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { readFileSync } from 'fs';
export class NodeChildProcessWithNonDirectOutput implements RunningTask {
private terminalOutput: string;
private exitCode: number;
private exitCallbacks: Array<(code: number) => void> = [];
private exitCallbacks: Array<(code: number, terminalOutput: string) => void> =
[];

constructor(
private childProcess: ChildProcess,
Expand Down Expand Up @@ -39,7 +40,7 @@ export class NodeChildProcessWithNonDirectOutput implements RunningTask {

this.onExit(() => {
for (const cb of this.exitCallbacks) {
cb(this.exitCode);
cb(this.exitCode, this.terminalOutput);
}
});

Expand All @@ -58,7 +59,7 @@ export class NodeChildProcessWithNonDirectOutput implements RunningTask {
});
}

onExit(cb: (code: number) => void) {
onExit(cb: (code: number, terminalOutput: string) => void) {
this.exitCallbacks.push(cb);
}

Expand Down Expand Up @@ -155,15 +156,15 @@ function logClearLineToPrefixTransformer(prefix: string) {
}

export class NodeChildProcessWithDirectOutput implements RunningTask {
private terminalOutput = '';
private terminalOutput: string | undefined;
private exitCallbacks: Array<(code: number, signal: string) => void> = [];

private exited = false;
private exitCode: number;

constructor(
private childProcess: ChildProcess,
{ temporaryOutputPath }: { temporaryOutputPath: string }
private temporaryOutputPath: string
) {
// Re-emit any messages from the task process
this.childProcess.on('message', (message) => {
Expand All @@ -182,10 +183,6 @@ export class NodeChildProcessWithDirectOutput implements RunningTask {
cb(code, signal);
}
});

this.onExit(() => {
this.terminalOutput = readFileSync(temporaryOutputPath).toString();
});
}

send(message: Serializable): void {
Expand All @@ -199,16 +196,17 @@ export class NodeChildProcessWithDirectOutput implements RunningTask {
}

async getResults(): Promise<{ code: number; terminalOutput: string }> {
const terminalOutput = this.getTerminalOutput();
if (this.exited) {
return Promise.resolve({
code: this.exitCode,
terminalOutput: this.terminalOutput,
terminalOutput,
});
}
await this.waitForExit();
return Promise.resolve({
code: this.exitCode,
terminalOutput: this.terminalOutput,
terminalOutput,
});
}

Expand All @@ -219,6 +217,7 @@ export class NodeChildProcessWithDirectOutput implements RunningTask {
}

getTerminalOutput() {
this.terminalOutput ??= readFileSync(this.temporaryOutputPath).toString();
return this.terminalOutput;
}

Expand Down

0 comments on commit 8bed8d6

Please sign in to comment.