@naturalcycles/nodejs-lib 13.34.2 → 13.34.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,7 +68,7 @@ declare class Exec2 {
68
68
  * Defaults:
69
69
  *
70
70
  * shell: true
71
- * log: true
71
+ * log: false
72
72
  */
73
73
  exec(cmd: string, opt?: ExecOptions): string;
74
74
  throwOnNonZeroExitCode(o: SpawnOutput): void;
@@ -48,13 +48,15 @@ class Exec2 {
48
48
  * log: true
49
49
  */
50
50
  async spawnAsync(cmd, opt = {}) {
51
+ const { shell = true, printWhileRunning = true, collectOutputWhileRunning = true, throwOnNonZeroCode = true, cwd, env, passProcessEnv = true, forceColor = colors_1.hasColors, } = opt;
52
+ opt.log ??= printWhileRunning; // by default log should be true, as we are printing the output
53
+ opt.logStart ??= opt.log;
54
+ opt.logFinish ??= opt.log;
51
55
  const started = Date.now();
52
56
  this.logStart(cmd, opt);
53
- const { shell = true, printWhileRunning = true, collectOutputWhileRunning = true, throwOnNonZeroCode = true, cwd, env, passProcessEnv = true, forceColor = colors_1.hasColors, } = opt;
54
57
  let stdout = '';
55
58
  let stderr = '';
56
- if (printWhileRunning)
57
- console.log(''); // 1-line padding before the output
59
+ // if (printWhileRunning) console.log('') // 1-line padding before the output
58
60
  return await new Promise((resolve, reject) => {
59
61
  const p = node_child_process_1.default.spawn(cmd, opt.args || [], {
60
62
  shell,
@@ -84,8 +86,7 @@ class Exec2 {
84
86
  }
85
87
  });
86
88
  p.on('close', code => {
87
- if (printWhileRunning)
88
- console.log(''); // 1-line padding after the output
89
+ // if (printWhileRunning) console.log('') // 1-line padding after the output
89
90
  const isSuccessful = !code;
90
91
  this.logFinish(cmd, opt, started, isSuccessful);
91
92
  const exitCode = code || 0;
@@ -115,10 +116,13 @@ class Exec2 {
115
116
  * log: true
116
117
  */
117
118
  spawn(cmd, opt = {}) {
119
+ const { shell = true, cwd, env, passProcessEnv = true, forceColor = colors_1.hasColors } = opt;
120
+ opt.log ??= true; // by default log should be true, as we are printing the output
121
+ opt.logStart ??= opt.log;
122
+ opt.logFinish ??= opt.log;
118
123
  const started = Date.now();
119
124
  this.logStart(cmd, opt);
120
- const { shell = true, cwd, env, passProcessEnv = true, forceColor = colors_1.hasColors } = opt;
121
- console.log(''); // 1-line padding before the output
125
+ // console.log('') // 1-line padding before the output
122
126
  const r = node_child_process_1.default.spawnSync(cmd, opt.args, {
123
127
  encoding: 'utf8',
124
128
  stdio: 'inherit',
@@ -130,7 +134,7 @@ class Exec2 {
130
134
  ...env,
131
135
  },
132
136
  });
133
- console.log(''); // 1-line padding after the output
137
+ // console.log('') // 1-line padding after the output
134
138
  const isSuccessful = !r.error && !r.status;
135
139
  this.logFinish(cmd, opt, started, isSuccessful);
136
140
  if (r.error) {
@@ -152,12 +156,14 @@ class Exec2 {
152
156
  * Defaults:
153
157
  *
154
158
  * shell: true
155
- * log: true
159
+ * log: false
156
160
  */
157
161
  exec(cmd, opt = {}) {
162
+ const { cwd, env, passProcessEnv = true, timeout } = opt;
163
+ opt.logStart ??= opt.log ?? false;
164
+ opt.logFinish ??= opt.log ?? false;
158
165
  const started = Date.now();
159
166
  this.logStart(cmd, opt);
160
- const { cwd, env, passProcessEnv = true, timeout } = opt;
161
167
  try {
162
168
  const s = node_child_process_1.default
163
169
  .execSync(cmd, {
@@ -195,7 +201,7 @@ class Exec2 {
195
201
  }
196
202
  }
197
203
  logStart(cmd, opt) {
198
- if (!opt.logStart && !opt.log)
204
+ if (!opt.logStart)
199
205
  return;
200
206
  console.log([
201
207
  (0, colors_1.dimGrey)(...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('='))),
@@ -206,7 +212,7 @@ class Exec2 {
206
212
  .join(' '));
207
213
  }
208
214
  logFinish(cmd, opt, started, isSuccessful) {
209
- if (isSuccessful && !opt.logFinish && !opt.log)
215
+ if (isSuccessful && !opt.logFinish)
210
216
  return;
211
217
  console.log([
212
218
  (0, colors_1.white)(opt.name || cmd),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.34.2",
3
+ "version": "13.34.4",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
package/src/util/exec2.ts CHANGED
@@ -51,8 +51,6 @@ class Exec2 {
51
51
  * log: true
52
52
  */
53
53
  async spawnAsync(cmd: string, opt: SpawnAsyncOptions = {}): Promise<SpawnOutput> {
54
- const started = Date.now()
55
- this.logStart(cmd, opt)
56
54
  const {
57
55
  shell = true,
58
56
  printWhileRunning = true,
@@ -63,10 +61,15 @@ class Exec2 {
63
61
  passProcessEnv = true,
64
62
  forceColor = hasColors,
65
63
  } = opt
64
+ opt.log ??= printWhileRunning // by default log should be true, as we are printing the output
65
+ opt.logStart ??= opt.log
66
+ opt.logFinish ??= opt.log
67
+ const started = Date.now()
68
+ this.logStart(cmd, opt)
66
69
  let stdout = ''
67
70
  let stderr = ''
68
71
 
69
- if (printWhileRunning) console.log('') // 1-line padding before the output
72
+ // if (printWhileRunning) console.log('') // 1-line padding before the output
70
73
 
71
74
  return await new Promise<SpawnOutput>((resolve, reject) => {
72
75
  const p = cp.spawn(cmd, opt.args || [], {
@@ -99,7 +102,7 @@ class Exec2 {
99
102
  })
100
103
 
101
104
  p.on('close', code => {
102
- if (printWhileRunning) console.log('') // 1-line padding after the output
105
+ // if (printWhileRunning) console.log('') // 1-line padding after the output
103
106
  const isSuccessful = !code
104
107
  this.logFinish(cmd, opt, started, isSuccessful)
105
108
  const exitCode = code || 0
@@ -130,10 +133,13 @@ class Exec2 {
130
133
  * log: true
131
134
  */
132
135
  spawn(cmd: string, opt: SpawnOptions = {}): void {
136
+ const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt
137
+ opt.log ??= true // by default log should be true, as we are printing the output
138
+ opt.logStart ??= opt.log
139
+ opt.logFinish ??= opt.log
133
140
  const started = Date.now()
134
141
  this.logStart(cmd, opt)
135
- const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt
136
- console.log('') // 1-line padding before the output
142
+ // console.log('') // 1-line padding before the output
137
143
 
138
144
  const r = cp.spawnSync(cmd, opt.args, {
139
145
  encoding: 'utf8',
@@ -147,7 +153,7 @@ class Exec2 {
147
153
  },
148
154
  })
149
155
 
150
- console.log('') // 1-line padding after the output
156
+ // console.log('') // 1-line padding after the output
151
157
  const isSuccessful = !r.error && !r.status
152
158
  this.logFinish(cmd, opt, started, isSuccessful)
153
159
 
@@ -171,12 +177,14 @@ class Exec2 {
171
177
  * Defaults:
172
178
  *
173
179
  * shell: true
174
- * log: true
180
+ * log: false
175
181
  */
176
182
  exec(cmd: string, opt: ExecOptions = {}): string {
183
+ const { cwd, env, passProcessEnv = true, timeout } = opt
184
+ opt.logStart ??= opt.log ?? false
185
+ opt.logFinish ??= opt.log ?? false
177
186
  const started = Date.now()
178
187
  this.logStart(cmd, opt)
179
- const { cwd, env, passProcessEnv = true, timeout } = opt
180
188
 
181
189
  try {
182
190
  const s = cp
@@ -217,7 +225,7 @@ class Exec2 {
217
225
  }
218
226
 
219
227
  private logStart(cmd: string, opt: SpawnOptions | ExecOptions): void {
220
- if (!opt.logStart && !opt.log) return
228
+ if (!opt.logStart) return
221
229
 
222
230
  console.log(
223
231
  [
@@ -236,7 +244,7 @@ class Exec2 {
236
244
  started: UnixTimestampMillisNumber,
237
245
  isSuccessful: boolean,
238
246
  ): void {
239
- if (isSuccessful && !opt.logFinish && !opt.log) return
247
+ if (isSuccessful && !opt.logFinish) return
240
248
 
241
249
  console.log(
242
250
  [