Skip to content

Commit

Permalink
fix(core): clear line escape code shouldn't erase prefix in output (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Mar 15, 2023
1 parent cd3d316 commit 72d64b6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/nx/src/tasks-runner/forked-process-task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from './batch/batch-messages';
import { stripIndents } from '../utils/strip-indents';
import { Task } from '../config/task-graph';
import { Transform } from 'stream';

const workerPath = join(__dirname, './batch/run-batch.js');

Expand Down Expand Up @@ -152,9 +153,13 @@ export class ForkedProcessTaskRunner {
const prefixText = `${task.target.project}:`;

p.stdout
.pipe(
logClearLineToPrefixTransformer(color.bold(prefixText) + ' ')
)
.pipe(logTransformer({ tag: color.bold(prefixText) }))
.pipe(process.stdout);
p.stderr
.pipe(logClearLineToPrefixTransformer(color(prefixText) + ' '))
.pipe(logTransformer({ tag: color(prefixText) }))
.pipe(process.stderr);
} else {
Expand Down Expand Up @@ -493,3 +498,20 @@ function getColor(projectName: string) {

return colors[colorIndex];
}

/**
* Prevents terminal escape sequence from clearing line prefix.
*/
function logClearLineToPrefixTransformer(prefix) {
let prevChunk = null;
return new Transform({
transform(chunk, _encoding, callback) {
if (prevChunk && prevChunk.toString() === '\x1b[2K') {
chunk = chunk.toString().replace(/\x1b\[1G/g, (m) => m + prefix);
}
this.push(chunk);
prevChunk = chunk;
callback();
},
});
}

1 comment on commit 72d64b6

@vercel
Copy link

@vercel vercel bot commented on 72d64b6 Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.