Skip to content

Commit

Permalink
fix(core): remove strong-log-transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Sep 25, 2024
1 parent 37523fa commit f30c821
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion e2e/nx-init/src/nx-init-npm-repo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('nx init (NPM repo - legacy)', () => {
);

const output = runCommand('npm run compound TEST');
expect(output).toContain('HELLO\n');
expect(output).toContain('HELLO');
expect(output).toContain('COMPOUND TEST');
expect(output).not.toContain('HELLO COMPOUND');
cleanupProject();
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@
"send": "0.17.1",
"shadergradient": "^1.2.14",
"string-width": "^4.2.3",
"strong-log-transformer": "^2.1.0",
"tailwind-merge": "^2.4.0",
"tailwindcss": "3.4.4",
"three": "^0.166.1",
Expand Down
1 change: 0 additions & 1 deletion packages/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"open": "^8.4.0",
"semver": "^7.5.3",
"string-width": "^4.2.3",
"strong-log-transformer": "^2.1.0",
"tar-stream": "~2.2.0",
"tmp": "~0.2.1",
"tsconfig-paths": "^4.1.2",
Expand Down
28 changes: 22 additions & 6 deletions packages/nx/src/tasks-runner/forked-process-task-runner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readFileSync, writeFileSync } from 'fs';
import { ChildProcess, fork, Serializable } from 'child_process';
import * as chalk from 'chalk';
import * as logTransformer from 'strong-log-transformer';
import { DefaultTasksRunnerOptions } from './default-tasks-runner';
import { output } from '../utils/output';
import { getCliPath, getPrintableCommandArgsForTask } from './utils';
Expand Down Expand Up @@ -326,15 +325,15 @@ export class ForkedProcessTaskRunner {
.pipe(
logClearLineToPrefixTransformer(color.bold(prefixText) + ' ')
)
.pipe(logTransformer({ tag: color.bold(prefixText) }))
.pipe(addPrefixTransformer(color.bold(prefixText)))
.pipe(process.stdout);
p.stderr
.pipe(logClearLineToPrefixTransformer(color(prefixText) + ' '))
.pipe(logTransformer({ tag: color(prefixText) }))
.pipe(addPrefixTransformer(color(prefixText)))
.pipe(process.stderr);
} else {
p.stdout.pipe(logTransformer()).pipe(process.stdout);
p.stderr.pipe(logTransformer()).pipe(process.stderr);
p.stdout.pipe(addPrefixTransformer()).pipe(process.stdout);
p.stderr.pipe(addPrefixTransformer()).pipe(process.stderr);
}
}

Expand Down Expand Up @@ -539,7 +538,7 @@ function getColor(projectName: string) {
/**
* Prevents terminal escape sequence from clearing line prefix.
*/
function logClearLineToPrefixTransformer(prefix) {
function logClearLineToPrefixTransformer(prefix: string) {
let prevChunk = null;
return new Transform({
transform(chunk, _encoding, callback) {
Expand All @@ -552,3 +551,20 @@ function logClearLineToPrefixTransformer(prefix) {
},
});
}

function addPrefixTransformer(prefix?: string) {
const newLineSeparator = process.platform.startsWith('win') ? '\r\n' : '\n';
return new Transform({
transform(chunk, _encoding, callback) {
const list = chunk.toString().split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
list
.filter(Boolean)
.forEach((m) =>
this.push(
prefix ? prefix + ' ' + m + newLineSeparator : m + newLineSeparator
)
);
callback();
},
});
}
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f30c821

Please sign in to comment.