@naturalcycles/nodejs-lib 15.20.1 → 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 +5 -8
- package/package.json +2 -2
- package/src/exec2/exec2.ts +24 -11
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,
|
|
@@ -245,9 +244,7 @@ class Exec2 {
|
|
|
245
244
|
.map(([k, v]) => [k, v].join('='))
|
|
246
245
|
.join(' ');
|
|
247
246
|
if (opt.name) {
|
|
248
|
-
console.log([' ',
|
|
249
|
-
.filter(Boolean)
|
|
250
|
-
.join(' '));
|
|
247
|
+
console.log([' ', white(opt.name), dimGrey('started...')].filter(Boolean).join(' '));
|
|
251
248
|
}
|
|
252
249
|
else {
|
|
253
250
|
console.log([
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.21.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@types/js-yaml": "^4",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/through2-concurrent": "^2",
|
|
26
|
-
"@naturalcycles/dev-lib": "
|
|
26
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
".": "./dist/index.js",
|
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,
|
|
@@ -276,11 +282,7 @@ class Exec2 {
|
|
|
276
282
|
.join(' ')
|
|
277
283
|
|
|
278
284
|
if (opt.name) {
|
|
279
|
-
console.log(
|
|
280
|
-
[' ', dimGrey(envString), white(opt.name), dimGrey('started...')]
|
|
281
|
-
.filter(Boolean)
|
|
282
|
-
.join(' '),
|
|
283
|
-
)
|
|
285
|
+
console.log([' ', white(opt.name), dimGrey('started...')].filter(Boolean).join(' '))
|
|
284
286
|
} else {
|
|
285
287
|
console.log(
|
|
286
288
|
[
|
|
@@ -402,6 +404,11 @@ export interface SpawnOptions {
|
|
|
402
404
|
* Set to false or true to override.
|
|
403
405
|
*/
|
|
404
406
|
forceColor?: boolean
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Defaults to "inherit"
|
|
410
|
+
*/
|
|
411
|
+
stdio?: StdioOptions
|
|
405
412
|
}
|
|
406
413
|
|
|
407
414
|
export interface ExecOptions {
|
|
@@ -433,4 +440,10 @@ export interface ExecOptions {
|
|
|
433
440
|
* Set to true to pass `process.env` to the spawned process.
|
|
434
441
|
*/
|
|
435
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
|
|
436
449
|
}
|