@naturalcycles/nodejs-lib 15.112.0 → 15.113.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 +11 -1
- package/dist/exec2/exec2.js +13 -2
- package/package.json +1 -1
- package/src/exec2/exec2.ts +27 -2
package/dist/exec2/exec2.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ declare class Exec2 {
|
|
|
37
37
|
* shell: true
|
|
38
38
|
* log: true
|
|
39
39
|
*/
|
|
40
|
-
spawn(cmd: string, opt?:
|
|
40
|
+
spawn(cmd: string, opt?: SpawnSyncOptions): void;
|
|
41
41
|
/**
|
|
42
42
|
* Reasons to use it:
|
|
43
43
|
*
|
|
@@ -105,6 +105,12 @@ export interface SpawnOutput {
|
|
|
105
105
|
stdout: string;
|
|
106
106
|
stderr: string;
|
|
107
107
|
}
|
|
108
|
+
export interface SpawnSyncOptions extends SpawnOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Defaults to 10 MiB (higher than Node's own default of 1 MiB).
|
|
111
|
+
*/
|
|
112
|
+
maxBuffer?: number;
|
|
113
|
+
}
|
|
108
114
|
export interface SpawnAsyncOptions extends SpawnOptions {
|
|
109
115
|
/**
|
|
110
116
|
* Defaults to true.
|
|
@@ -202,5 +208,9 @@ export interface ExecOptions {
|
|
|
202
208
|
* beware that stdio: 'inherit', means we don't get the output returned.
|
|
203
209
|
*/
|
|
204
210
|
stdio?: StdioOptions;
|
|
211
|
+
/**
|
|
212
|
+
* Defaults to 10 MiB (higher than Node's own default of 1 MiB).
|
|
213
|
+
*/
|
|
214
|
+
maxBuffer?: number;
|
|
205
215
|
}
|
|
206
216
|
export {};
|
package/dist/exec2/exec2.js
CHANGED
|
@@ -3,6 +3,15 @@ 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';
|
|
5
5
|
import { dimGrey, dimRed, hasColors, white } from '../colors/colors.js';
|
|
6
|
+
/**
|
|
7
|
+
* Default `maxBuffer` (in bytes) for the synchronous `exec`/`spawn`.
|
|
8
|
+
* Set to 10 MiB, which is higher than Node's own default of 1 MiB.
|
|
9
|
+
* Node's 1 MiB is too low for common large outputs (e.g. `git log`, `git diff`,
|
|
10
|
+
* `tsc`/`eslint` reports), while 10 MiB still bounds runaway processes to a
|
|
11
|
+
* memory level that won't OOM constrained deploy/CI environments.
|
|
12
|
+
* Can be overridden per-call via the `maxBuffer` option.
|
|
13
|
+
*/
|
|
14
|
+
const defaultMaxBuffer = 10 * 1024 * 1024;
|
|
6
15
|
/**
|
|
7
16
|
* Set of utility functions to work with Spawn / Exec.
|
|
8
17
|
*
|
|
@@ -40,7 +49,7 @@ class Exec2 {
|
|
|
40
49
|
* log: true
|
|
41
50
|
*/
|
|
42
51
|
spawn(cmd, opt = {}) {
|
|
43
|
-
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors, stdio = 'inherit', } = opt;
|
|
52
|
+
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors, stdio = 'inherit', maxBuffer = defaultMaxBuffer, } = opt;
|
|
44
53
|
opt.log ??= true; // by default log should be true, as we are printing the output
|
|
45
54
|
opt.logStart ??= opt.log;
|
|
46
55
|
opt.logFinish ??= opt.log;
|
|
@@ -51,6 +60,7 @@ class Exec2 {
|
|
|
51
60
|
stdio,
|
|
52
61
|
shell,
|
|
53
62
|
cwd,
|
|
63
|
+
maxBuffer,
|
|
54
64
|
env: {
|
|
55
65
|
...(passProcessEnv ? process.env : {}),
|
|
56
66
|
...(forceColor ? { FORCE_COLOR: '1' } : {}),
|
|
@@ -81,7 +91,7 @@ class Exec2 {
|
|
|
81
91
|
* log: false
|
|
82
92
|
*/
|
|
83
93
|
exec(cmd, opt = {}) {
|
|
84
|
-
const { cwd, env, passProcessEnv = true, timeout, stdio } = opt;
|
|
94
|
+
const { cwd, env, passProcessEnv = true, timeout, stdio, maxBuffer = defaultMaxBuffer } = opt;
|
|
85
95
|
opt.logStart ??= opt.log ?? false;
|
|
86
96
|
opt.logFinish ??= opt.log ?? false;
|
|
87
97
|
const started = Date.now();
|
|
@@ -93,6 +103,7 @@ class Exec2 {
|
|
|
93
103
|
// shell: undefined,
|
|
94
104
|
cwd,
|
|
95
105
|
timeout,
|
|
106
|
+
maxBuffer,
|
|
96
107
|
env: {
|
|
97
108
|
...(passProcessEnv ? process.env : {}),
|
|
98
109
|
...env,
|
package/package.json
CHANGED
package/src/exec2/exec2.ts
CHANGED
|
@@ -10,6 +10,16 @@ import type {
|
|
|
10
10
|
} from '@naturalcycles/js-lib/types'
|
|
11
11
|
import { dimGrey, dimRed, hasColors, white } from '../colors/colors.js'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Default `maxBuffer` (in bytes) for the synchronous `exec`/`spawn`.
|
|
15
|
+
* Set to 10 MiB, which is higher than Node's own default of 1 MiB.
|
|
16
|
+
* Node's 1 MiB is too low for common large outputs (e.g. `git log`, `git diff`,
|
|
17
|
+
* `tsc`/`eslint` reports), while 10 MiB still bounds runaway processes to a
|
|
18
|
+
* memory level that won't OOM constrained deploy/CI environments.
|
|
19
|
+
* Can be overridden per-call via the `maxBuffer` option.
|
|
20
|
+
*/
|
|
21
|
+
const defaultMaxBuffer = 10 * 1024 * 1024
|
|
22
|
+
|
|
13
23
|
/**
|
|
14
24
|
* Set of utility functions to work with Spawn / Exec.
|
|
15
25
|
*
|
|
@@ -46,7 +56,7 @@ class Exec2 {
|
|
|
46
56
|
* shell: true
|
|
47
57
|
* log: true
|
|
48
58
|
*/
|
|
49
|
-
spawn(cmd: string, opt:
|
|
59
|
+
spawn(cmd: string, opt: SpawnSyncOptions = {}): void {
|
|
50
60
|
const {
|
|
51
61
|
shell = true,
|
|
52
62
|
cwd,
|
|
@@ -54,6 +64,7 @@ class Exec2 {
|
|
|
54
64
|
passProcessEnv = true,
|
|
55
65
|
forceColor = hasColors,
|
|
56
66
|
stdio = 'inherit',
|
|
67
|
+
maxBuffer = defaultMaxBuffer,
|
|
57
68
|
} = opt
|
|
58
69
|
opt.log ??= true // by default log should be true, as we are printing the output
|
|
59
70
|
opt.logStart ??= opt.log
|
|
@@ -66,6 +77,7 @@ class Exec2 {
|
|
|
66
77
|
stdio,
|
|
67
78
|
shell,
|
|
68
79
|
cwd,
|
|
80
|
+
maxBuffer,
|
|
69
81
|
env: {
|
|
70
82
|
...(passProcessEnv ? process.env : {}),
|
|
71
83
|
...(forceColor ? { FORCE_COLOR: '1' } : {}),
|
|
@@ -99,7 +111,7 @@ class Exec2 {
|
|
|
99
111
|
* log: false
|
|
100
112
|
*/
|
|
101
113
|
exec(cmd: string, opt: ExecOptions = {}): string {
|
|
102
|
-
const { cwd, env, passProcessEnv = true, timeout, stdio } = opt
|
|
114
|
+
const { cwd, env, passProcessEnv = true, timeout, stdio, maxBuffer = defaultMaxBuffer } = opt
|
|
103
115
|
opt.logStart ??= opt.log ?? false
|
|
104
116
|
opt.logFinish ??= opt.log ?? false
|
|
105
117
|
const started = Date.now() as UnixTimestampMillis
|
|
@@ -112,6 +124,7 @@ class Exec2 {
|
|
|
112
124
|
// shell: undefined,
|
|
113
125
|
cwd,
|
|
114
126
|
timeout,
|
|
127
|
+
maxBuffer,
|
|
115
128
|
env: {
|
|
116
129
|
...(passProcessEnv ? process.env : {}),
|
|
117
130
|
...env,
|
|
@@ -355,6 +368,13 @@ export interface SpawnOutput {
|
|
|
355
368
|
stderr: string
|
|
356
369
|
}
|
|
357
370
|
|
|
371
|
+
export interface SpawnSyncOptions extends SpawnOptions {
|
|
372
|
+
/**
|
|
373
|
+
* Defaults to 10 MiB (higher than Node's own default of 1 MiB).
|
|
374
|
+
*/
|
|
375
|
+
maxBuffer?: number
|
|
376
|
+
}
|
|
377
|
+
|
|
358
378
|
export interface SpawnAsyncOptions extends SpawnOptions {
|
|
359
379
|
/**
|
|
360
380
|
* Defaults to true.
|
|
@@ -462,4 +482,9 @@ export interface ExecOptions {
|
|
|
462
482
|
* beware that stdio: 'inherit', means we don't get the output returned.
|
|
463
483
|
*/
|
|
464
484
|
stdio?: StdioOptions
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Defaults to 10 MiB (higher than Node's own default of 1 MiB).
|
|
488
|
+
*/
|
|
489
|
+
maxBuffer?: number
|
|
465
490
|
}
|