Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit ae9dcca

Browse files
fix(exec2): spawn/spawnAsync will log by default, as they already print output
1 parent c597e31 commit ae9dcca

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

scripts/exec2.script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { exec2 } from '../src/util/exec2'
1010
runScript(async () => {
1111
await exec2.spawnAsync('node', {
1212
args: ['scripts/dot.script.js', '--error'],
13-
log: true,
13+
// log: true,
1414
shell: true,
1515
// forceColor: false,
1616
// passProcessEnv: true,

src/util/exec2.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class Exec2 {
5151
* log: true
5252
*/
5353
async spawnAsync(cmd: string, opt: SpawnAsyncOptions = {}): Promise<SpawnOutput> {
54-
const started = Date.now()
55-
this.logStart(cmd, opt)
5654
const {
5755
shell = true,
5856
printWhileRunning = true,
@@ -63,10 +61,13 @@ class Exec2 {
6361
passProcessEnv = true,
6462
forceColor = hasColors,
6563
} = opt
64+
opt.log ??= printWhileRunning // by default log should be true, as we are printing the output
65+
const started = Date.now()
66+
this.logStart(cmd, opt)
6667
let stdout = ''
6768
let stderr = ''
6869

69-
if (printWhileRunning) console.log('') // 1-line padding before the output
70+
// if (printWhileRunning) console.log('') // 1-line padding before the output
7071

7172
return await new Promise<SpawnOutput>((resolve, reject) => {
7273
const p = cp.spawn(cmd, opt.args || [], {
@@ -99,7 +100,7 @@ class Exec2 {
99100
})
100101

101102
p.on('close', code => {
102-
if (printWhileRunning) console.log('') // 1-line padding after the output
103+
// if (printWhileRunning) console.log('') // 1-line padding after the output
103104
const isSuccessful = !code
104105
this.logFinish(cmd, opt, started, isSuccessful)
105106
const exitCode = code || 0
@@ -130,10 +131,11 @@ class Exec2 {
130131
* log: true
131132
*/
132133
spawn(cmd: string, opt: SpawnOptions = {}): void {
134+
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt
135+
opt.log ??= true // by default log should be true, as we are printing the output
133136
const started = Date.now()
134137
this.logStart(cmd, opt)
135-
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt
136-
console.log('') // 1-line padding before the output
138+
// console.log('') // 1-line padding before the output
137139

138140
const r = cp.spawnSync(cmd, opt.args, {
139141
encoding: 'utf8',
@@ -147,7 +149,7 @@ class Exec2 {
147149
},
148150
})
149151

150-
console.log('') // 1-line padding after the output
152+
// console.log('') // 1-line padding after the output
151153
const isSuccessful = !r.error && !r.status
152154
this.logFinish(cmd, opt, started, isSuccessful)
153155

0 commit comments

Comments
 (0)