Skip to content

Commit

Permalink
feat(core): minor cache improvements to improve dev ergonomics
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Feb 4, 2020
1 parent 33107b0 commit 04a9c5e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/angular/api-workspace/builders/run-commands.md
Expand Up @@ -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`
Expand Down
6 changes: 6 additions & 0 deletions docs/react/api-workspace/builders/run-commands.md
Expand Up @@ -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`
Expand Down
6 changes: 6 additions & 0 deletions docs/web/api-workspace/builders/run-commands.md
Expand Up @@ -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`
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/lib/run-cli.ts
Expand Up @@ -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();

Expand Down Expand Up @@ -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;

Expand All @@ -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]);
};

Expand Down
14 changes: 14 additions & 0 deletions packages/workspace/src/builders/run-commands/schema.json
Expand Up @@ -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"]
Expand Down
3 changes: 3 additions & 0 deletions packages/workspace/src/tasks-runner/task-orchestrator.ts
Expand Up @@ -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'],
Expand Down
1 change: 1 addition & 0 deletions packages/workspace/src/tasks-runner/tasks-runner-v2.ts
Expand Up @@ -32,6 +32,7 @@ export interface DefaultTasksRunnerOptions {
cacheDirectory?: string;
remoteCache?: RemoteCache;
lifeCycle?: LifeCycle;
captureStderr?: boolean;
}

export const tasksRunnerV2: TasksRunner<DefaultTasksRunnerOptions> = (
Expand Down

0 comments on commit 04a9c5e

Please sign in to comment.