@naturalcycles/nodejs-lib 13.34.1 → 13.34.3

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.
@@ -141,8 +141,8 @@ export interface SpawnOptions {
141
141
  cwd?: string;
142
142
  env?: AnyObject;
143
143
  /**
144
- * Defaults to false for security reasons.
145
- * Set to true to pass `process.env` to the spawned process.
144
+ * Defaults to true.
145
+ * Set to false to NOT pass `process.env` to the spawned process.
146
146
  */
147
147
  passProcessEnv?: boolean;
148
148
  /**
@@ -48,21 +48,21 @@ 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
51
53
  const started = Date.now();
52
54
  this.logStart(cmd, opt);
53
- const { shell = true, printWhileRunning = true, collectOutputWhileRunning = true, throwOnNonZeroCode = true, cwd, env, forceColor = colors_1.hasColors, } = opt;
54
55
  let stdout = '';
55
56
  let stderr = '';
56
- if (printWhileRunning)
57
- console.log(''); // 1-line padding before the output
57
+ // if (printWhileRunning) console.log('') // 1-line padding before the output
58
58
  return await new Promise((resolve, reject) => {
59
59
  const p = node_child_process_1.default.spawn(cmd, opt.args || [], {
60
60
  shell,
61
61
  cwd,
62
62
  env: {
63
- ...env,
64
- ...(opt.passProcessEnv ? process.env : {}),
63
+ ...(passProcessEnv ? process.env : {}),
65
64
  ...(forceColor ? { FORCE_COLOR: '1' } : {}),
65
+ ...env,
66
66
  },
67
67
  });
68
68
  p.stdout.on('data', data => {
@@ -84,8 +84,7 @@ class Exec2 {
84
84
  }
85
85
  });
86
86
  p.on('close', code => {
87
- if (printWhileRunning)
88
- console.log(''); // 1-line padding after the output
87
+ // if (printWhileRunning) console.log('') // 1-line padding after the output
89
88
  const isSuccessful = !code;
90
89
  this.logFinish(cmd, opt, started, isSuccessful);
91
90
  const exitCode = code || 0;
@@ -115,22 +114,23 @@ class Exec2 {
115
114
  * log: true
116
115
  */
117
116
  spawn(cmd, opt = {}) {
117
+ const { shell = true, cwd, env, passProcessEnv = true, forceColor = colors_1.hasColors } = opt;
118
+ opt.log ??= true; // by default log should be true, as we are printing the output
118
119
  const started = Date.now();
119
120
  this.logStart(cmd, opt);
120
- const { shell = true, cwd, env, forceColor = colors_1.hasColors } = opt;
121
- console.log(''); // 1-line padding before the output
121
+ // console.log('') // 1-line padding before the output
122
122
  const r = node_child_process_1.default.spawnSync(cmd, opt.args, {
123
123
  encoding: 'utf8',
124
124
  stdio: 'inherit',
125
125
  shell,
126
126
  cwd,
127
127
  env: {
128
- ...env,
129
- ...(opt.passProcessEnv ? process.env : {}),
128
+ ...(passProcessEnv ? process.env : {}),
130
129
  ...(forceColor ? { FORCE_COLOR: '1' } : {}),
130
+ ...env,
131
131
  },
132
132
  });
133
- console.log(''); // 1-line padding after the output
133
+ // console.log('') // 1-line padding after the output
134
134
  const isSuccessful = !r.error && !r.status;
135
135
  this.logFinish(cmd, opt, started, isSuccessful);
136
136
  if (r.error) {
@@ -157,7 +157,7 @@ class Exec2 {
157
157
  exec(cmd, opt = {}) {
158
158
  const started = Date.now();
159
159
  this.logStart(cmd, opt);
160
- const { cwd, env, timeout } = opt;
160
+ const { cwd, env, passProcessEnv = true, timeout } = opt;
161
161
  try {
162
162
  const s = node_child_process_1.default
163
163
  .execSync(cmd, {
@@ -168,8 +168,8 @@ class Exec2 {
168
168
  cwd,
169
169
  timeout,
170
170
  env: {
171
+ ...(passProcessEnv ? process.env : {}),
171
172
  ...env,
172
- ...(opt.passProcessEnv ? process.env : {}),
173
173
  },
174
174
  })
175
175
  .trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.34.1",
3
+ "version": "13.34.3",
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,
@@ -60,21 +58,25 @@ class Exec2 {
60
58
  throwOnNonZeroCode = true,
61
59
  cwd,
62
60
  env,
61
+ passProcessEnv = true,
63
62
  forceColor = hasColors,
64
63
  } = 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)
65
67
  let stdout = ''
66
68
  let stderr = ''
67
69
 
68
- if (printWhileRunning) console.log('') // 1-line padding before the output
70
+ // if (printWhileRunning) console.log('') // 1-line padding before the output
69
71
 
70
72
  return await new Promise<SpawnOutput>((resolve, reject) => {
71
73
  const p = cp.spawn(cmd, opt.args || [], {
72
74
  shell,
73
75
  cwd,
74
76
  env: {
75
- ...env,
76
- ...(opt.passProcessEnv ? process.env : {}),
77
+ ...(passProcessEnv ? process.env : {}),
77
78
  ...(forceColor ? { FORCE_COLOR: '1' } : {}),
79
+ ...env,
78
80
  },
79
81
  })
80
82
 
@@ -98,7 +100,7 @@ class Exec2 {
98
100
  })
99
101
 
100
102
  p.on('close', code => {
101
- if (printWhileRunning) console.log('') // 1-line padding after the output
103
+ // if (printWhileRunning) console.log('') // 1-line padding after the output
102
104
  const isSuccessful = !code
103
105
  this.logFinish(cmd, opt, started, isSuccessful)
104
106
  const exitCode = code || 0
@@ -129,10 +131,11 @@ class Exec2 {
129
131
  * log: true
130
132
  */
131
133
  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
132
136
  const started = Date.now()
133
137
  this.logStart(cmd, opt)
134
- const { shell = true, cwd, env, forceColor = hasColors } = opt
135
- console.log('') // 1-line padding before the output
138
+ // console.log('') // 1-line padding before the output
136
139
 
137
140
  const r = cp.spawnSync(cmd, opt.args, {
138
141
  encoding: 'utf8',
@@ -140,13 +143,13 @@ class Exec2 {
140
143
  shell,
141
144
  cwd,
142
145
  env: {
143
- ...env,
144
- ...(opt.passProcessEnv ? process.env : {}),
146
+ ...(passProcessEnv ? process.env : {}),
145
147
  ...(forceColor ? { FORCE_COLOR: '1' } : {}),
148
+ ...env,
146
149
  },
147
150
  })
148
151
 
149
- console.log('') // 1-line padding after the output
152
+ // console.log('') // 1-line padding after the output
150
153
  const isSuccessful = !r.error && !r.status
151
154
  this.logFinish(cmd, opt, started, isSuccessful)
152
155
 
@@ -175,7 +178,7 @@ class Exec2 {
175
178
  exec(cmd: string, opt: ExecOptions = {}): string {
176
179
  const started = Date.now()
177
180
  this.logStart(cmd, opt)
178
- const { cwd, env, timeout } = opt
181
+ const { cwd, env, passProcessEnv = true, timeout } = opt
179
182
 
180
183
  try {
181
184
  const s = cp
@@ -187,8 +190,8 @@ class Exec2 {
187
190
  cwd,
188
191
  timeout,
189
192
  env: {
193
+ ...(passProcessEnv ? process.env : {}),
190
194
  ...env,
191
- ...(opt.passProcessEnv ? process.env : {}),
192
195
  },
193
196
  })
194
197
  .trim()
@@ -326,8 +329,8 @@ export interface SpawnOptions {
326
329
 
327
330
  env?: AnyObject
328
331
  /**
329
- * Defaults to false for security reasons.
330
- * Set to true to pass `process.env` to the spawned process.
332
+ * Defaults to true.
333
+ * Set to false to NOT pass `process.env` to the spawned process.
331
334
  */
332
335
  passProcessEnv?: boolean
333
336
  /**