@naturalcycles/nodejs-lib 15.20.2 → 15.21.0
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.
- package/dist/exec2/exec2.d.ts +10 -0
- package/dist/exec2/exec2.js +4 -5
- package/package.json +1 -1
- package/src/exec2/exec2.ts +23 -6
package/dist/exec2/exec2.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StdioOptions } from 'node:child_process';
|
|
1
2
|
import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
|
|
2
3
|
import type { AnyObject, NumberOfMilliseconds } from '@naturalcycles/js-lib/types';
|
|
3
4
|
/**
|
|
@@ -164,6 +165,10 @@ export interface SpawnOptions {
|
|
|
164
165
|
* Set to false or true to override.
|
|
165
166
|
*/
|
|
166
167
|
forceColor?: boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Defaults to "inherit"
|
|
170
|
+
*/
|
|
171
|
+
stdio?: StdioOptions;
|
|
167
172
|
}
|
|
168
173
|
export interface ExecOptions {
|
|
169
174
|
/**
|
|
@@ -192,5 +197,10 @@ export interface ExecOptions {
|
|
|
192
197
|
* Set to true to pass `process.env` to the spawned process.
|
|
193
198
|
*/
|
|
194
199
|
passProcessEnv?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Defaults to undefined.
|
|
202
|
+
* beware that stdio: 'inherit', means we don't get the output returned.
|
|
203
|
+
*/
|
|
204
|
+
stdio?: StdioOptions;
|
|
195
205
|
}
|
|
196
206
|
export {};
|
package/dist/exec2/exec2.js
CHANGED
|
@@ -40,7 +40,7 @@ class Exec2 {
|
|
|
40
40
|
* log: true
|
|
41
41
|
*/
|
|
42
42
|
spawn(cmd, opt = {}) {
|
|
43
|
-
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt;
|
|
43
|
+
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors, stdio = 'inherit', } = opt;
|
|
44
44
|
opt.log ??= true; // by default log should be true, as we are printing the output
|
|
45
45
|
opt.logStart ??= opt.log;
|
|
46
46
|
opt.logFinish ??= opt.log;
|
|
@@ -48,7 +48,7 @@ class Exec2 {
|
|
|
48
48
|
this.logStart(cmd, opt);
|
|
49
49
|
const r = spawnSync(cmd, opt.args, {
|
|
50
50
|
encoding: 'utf8',
|
|
51
|
-
stdio
|
|
51
|
+
stdio,
|
|
52
52
|
shell,
|
|
53
53
|
cwd,
|
|
54
54
|
env: {
|
|
@@ -81,7 +81,7 @@ class Exec2 {
|
|
|
81
81
|
* log: false
|
|
82
82
|
*/
|
|
83
83
|
exec(cmd, opt = {}) {
|
|
84
|
-
const { cwd, env, passProcessEnv = true, timeout } = opt;
|
|
84
|
+
const { cwd, env, passProcessEnv = true, timeout, stdio } = opt;
|
|
85
85
|
opt.logStart ??= opt.log ?? false;
|
|
86
86
|
opt.logFinish ??= opt.log ?? false;
|
|
87
87
|
const started = Date.now();
|
|
@@ -89,8 +89,7 @@ class Exec2 {
|
|
|
89
89
|
try {
|
|
90
90
|
const s = execSync(cmd, {
|
|
91
91
|
encoding: 'utf8',
|
|
92
|
-
|
|
93
|
-
stdio: undefined,
|
|
92
|
+
stdio,
|
|
94
93
|
// shell: undefined,
|
|
95
94
|
cwd,
|
|
96
95
|
timeout,
|
package/package.json
CHANGED
package/src/exec2/exec2.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execSync, spawn, spawnSync } from 'node:child_process'
|
|
1
|
+
import { execSync, spawn, spawnSync, type StdioOptions } from 'node:child_process'
|
|
2
2
|
import { _since } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
3
3
|
import { AppError } from '@naturalcycles/js-lib/error/error.util.js'
|
|
4
4
|
import { _substringAfterLast } from '@naturalcycles/js-lib/string/string.util.js'
|
|
@@ -46,7 +46,14 @@ class Exec2 {
|
|
|
46
46
|
* log: true
|
|
47
47
|
*/
|
|
48
48
|
spawn(cmd: string, opt: SpawnOptions = {}): void {
|
|
49
|
-
const {
|
|
49
|
+
const {
|
|
50
|
+
shell = true,
|
|
51
|
+
cwd,
|
|
52
|
+
env,
|
|
53
|
+
passProcessEnv = true,
|
|
54
|
+
forceColor = hasColors,
|
|
55
|
+
stdio = 'inherit',
|
|
56
|
+
} = opt
|
|
50
57
|
opt.log ??= true // by default log should be true, as we are printing the output
|
|
51
58
|
opt.logStart ??= opt.log
|
|
52
59
|
opt.logFinish ??= opt.log
|
|
@@ -55,7 +62,7 @@ class Exec2 {
|
|
|
55
62
|
|
|
56
63
|
const r = spawnSync(cmd, opt.args, {
|
|
57
64
|
encoding: 'utf8',
|
|
58
|
-
stdio
|
|
65
|
+
stdio,
|
|
59
66
|
shell,
|
|
60
67
|
cwd,
|
|
61
68
|
env: {
|
|
@@ -91,7 +98,7 @@ class Exec2 {
|
|
|
91
98
|
* log: false
|
|
92
99
|
*/
|
|
93
100
|
exec(cmd: string, opt: ExecOptions = {}): string {
|
|
94
|
-
const { cwd, env, passProcessEnv = true, timeout } = opt
|
|
101
|
+
const { cwd, env, passProcessEnv = true, timeout, stdio } = opt
|
|
95
102
|
opt.logStart ??= opt.log ?? false
|
|
96
103
|
opt.logFinish ??= opt.log ?? false
|
|
97
104
|
const started = Date.now() as UnixTimestampMillis
|
|
@@ -100,8 +107,7 @@ class Exec2 {
|
|
|
100
107
|
try {
|
|
101
108
|
const s = execSync(cmd, {
|
|
102
109
|
encoding: 'utf8',
|
|
103
|
-
|
|
104
|
-
stdio: undefined,
|
|
110
|
+
stdio,
|
|
105
111
|
// shell: undefined,
|
|
106
112
|
cwd,
|
|
107
113
|
timeout,
|
|
@@ -398,6 +404,11 @@ export interface SpawnOptions {
|
|
|
398
404
|
* Set to false or true to override.
|
|
399
405
|
*/
|
|
400
406
|
forceColor?: boolean
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Defaults to "inherit"
|
|
410
|
+
*/
|
|
411
|
+
stdio?: StdioOptions
|
|
401
412
|
}
|
|
402
413
|
|
|
403
414
|
export interface ExecOptions {
|
|
@@ -429,4 +440,10 @@ export interface ExecOptions {
|
|
|
429
440
|
* Set to true to pass `process.env` to the spawned process.
|
|
430
441
|
*/
|
|
431
442
|
passProcessEnv?: boolean
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Defaults to undefined.
|
|
446
|
+
* beware that stdio: 'inherit', means we don't get the output returned.
|
|
447
|
+
*/
|
|
448
|
+
stdio?: StdioOptions
|
|
432
449
|
}
|