Skip to content

Commit 9eb7a50

Browse files
author
月满
committed
fix: use sync mode when process.stdio is connected to pipe
1 parent c1f8f1f commit 9eb7a50

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "4.0.30-beta.6",
3+
"version": "4.0.30-beta.7",
44
"types": "src/node/index.ts",
55
"main": "built/node/index.js",
66
"scripts": {

src/utils/lint.ts

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class DefaultOptions {
2929
}
3030

3131
export async function lint(options?: Partial<DefaultOptions>) {
32+
// https://nodejs.org/api/process.html#process_a_note_on_process_i_o
33+
// 通过 child_process 运行 pri,stdio 设置 pipe 模式时, 标准输出是异步的, 导致输出被截断,
34+
// 此处判断在 pipe 模式设置成同步输出
35+
if (!process.stdout.isTTY) {
36+
(process.stdout as any)?._handle?.setBlocking(true);
37+
(process.stderr as any)?._handle?.setBlocking(true);
38+
}
3239
const { CLIEngine } = await import('eslint');
3340
const lintRules = fs.readJsonSync(path.join(globalState.projectRootPath, '.eslintrc'));
3441
const mergedOptions = _.defaults(options || {}, new DefaultOptions());

0 commit comments

Comments
 (0)