diff --git a/docs/angular/api-workspace/builders/run-commands.md b/docs/angular/api-workspace/builders/run-commands.md index 469043dcb9571..e249824ae1763 100644 --- a/docs/angular/api-workspace/builders/run-commands.md +++ b/docs/angular/api-workspace/builders/run-commands.md @@ -30,6 +30,12 @@ Type: `string` Command to run in child process +### outputPath + +Type: `string` + +Tells Nx where the files will be created + ### parallel Default: `true` diff --git a/docs/react/api-workspace/builders/run-commands.md b/docs/react/api-workspace/builders/run-commands.md index 720fc086c4322..7d7ad5e0b2928 100644 --- a/docs/react/api-workspace/builders/run-commands.md +++ b/docs/react/api-workspace/builders/run-commands.md @@ -31,6 +31,12 @@ Type: `string` Command to run in child process +### outputPath + +Type: `string` + +Tells Nx where the files will be created + ### parallel Default: `true` diff --git a/docs/web/api-workspace/builders/run-commands.md b/docs/web/api-workspace/builders/run-commands.md index b6ccec1330383..58e3cfc3a76b8 100644 --- a/docs/web/api-workspace/builders/run-commands.md +++ b/docs/web/api-workspace/builders/run-commands.md @@ -31,6 +31,12 @@ Type: `string` Command to run in child process +### outputPath + +Type: `string` + +Tells Nx where the files will be created + ### parallel Default: `true` diff --git a/packages/cli/lib/run-cli.ts b/packages/cli/lib/run-cli.ts index ec258a14f66e4..70cf754422b8c 100644 --- a/packages/cli/lib/run-cli.ts +++ b/packages/cli/lib/run-cli.ts @@ -5,7 +5,7 @@ import { findWorkspaceRoot } from './find-workspace-root'; const workspace = findWorkspaceRoot(process.cwd()); if (process.env.NX_TERMINAL_OUTPUT_PATH) { - setUpOutputWatching(); + setUpOutputWatching(process.env.NX_TERMINAL_CAPTURE_STDERR === 'true'); } requireCli(); @@ -40,7 +40,7 @@ function requireCli() { * And the cached output should be correct unless the CLI bypasses process.stdout or console.log and uses some * C-binary to write to stdout. */ -function setUpOutputWatching() { +function setUpOutputWatching(captureStderr: boolean) { const stdoutWrite = process.stdout._write; const stderrWrite = process.stderr._write; @@ -60,7 +60,9 @@ function setUpOutputWatching() { encoding: string, callback: Function ) => { - out.push(chunk.toString()); + if (captureStderr) { + out.push(chunk.toString()); + } stderrWrite.apply(process.stderr, [chunk, encoding, callback]); }; diff --git a/packages/workspace/src/builders/run-commands/schema.json b/packages/workspace/src/builders/run-commands/schema.json index 290566f926819..975f218d9f5fa 100644 --- a/packages/workspace/src/builders/run-commands/schema.json +++ b/packages/workspace/src/builders/run-commands/schema.json @@ -34,6 +34,20 @@ "type": "boolean", "description": "Use colors when showing output of command", "default": false + }, + "outputPath": { + "description": "Tells Nx where the files will be created", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] } }, "required": ["commands"] diff --git a/packages/workspace/src/tasks-runner/task-orchestrator.ts b/packages/workspace/src/tasks-runner/task-orchestrator.ts index 1ce3af60fbc80..646b44c824056 100644 --- a/packages/workspace/src/tasks-runner/task-orchestrator.ts +++ b/packages/workspace/src/tasks-runner/task-orchestrator.ts @@ -117,6 +117,9 @@ export class TaskOrchestrator { const env = { ...process.env }; if (outputPath) { env.NX_TERMINAL_OUTPUT_PATH = outputPath; + if (this.options.captureStderr) { + env.NX_TERMINAL_CAPTURE_STDERR = 'true'; + } } const p = fork(this.getCommand(), this.getCommandArgs(task), { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], diff --git a/packages/workspace/src/tasks-runner/tasks-runner-v2.ts b/packages/workspace/src/tasks-runner/tasks-runner-v2.ts index 3cd710f9ee27f..713a01af228dd 100644 --- a/packages/workspace/src/tasks-runner/tasks-runner-v2.ts +++ b/packages/workspace/src/tasks-runner/tasks-runner-v2.ts @@ -32,6 +32,7 @@ export interface DefaultTasksRunnerOptions { cacheDirectory?: string; remoteCache?: RemoteCache; lifeCycle?: LifeCycle; + captureStderr?: boolean; } export const tasksRunnerV2: TasksRunner = (