@naturalcycles/nodejs-lib 15.111.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/dist/stream/pipeline.d.ts +5 -5
- package/package.json +2 -2
- package/src/exec2/exec2.ts +27 -2
- package/src/stream/pipeline.ts +5 -4
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,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Transform } from 'node:stream';
|
|
2
2
|
import type { ReadableStream as WebReadableStream } from 'node:stream/web';
|
|
3
3
|
import type { ZlibOptions, ZstdOptions } from 'node:zlib';
|
|
4
|
-
import type { AbortableAsyncMapper, AsyncIndexedMapper, AsyncPredicate, END, IndexedMapper, Integer, NonNegativeInteger, PositiveInteger, Predicate, SKIP } from '@naturalcycles/js-lib/types';
|
|
4
|
+
import type { AbortableAsyncMapper, AbortableMapper, AsyncIndexedMapper, AsyncPredicate, END, IndexedMapper, Integer, NonNegativeInteger, PositiveInteger, Predicate, SKIP } from '@naturalcycles/js-lib/types';
|
|
5
5
|
import type { ReadableTyped, TransformOptions, TransformTyped, WritableTyped } from './stream.model.js';
|
|
6
6
|
import type { TransformLogProgressOptions } from './transform/transformLogProgress.js';
|
|
7
7
|
import type { TransformMapOptions } from './transform/transformMap.js';
|
|
@@ -68,8 +68,8 @@ export declare class Pipeline<T = unknown> {
|
|
|
68
68
|
filter(asyncPredicate: AsyncPredicate<T>, opt?: TransformMapOptions): this;
|
|
69
69
|
filterSync(predicate: Predicate<T>, opt?: TransformOptions): this;
|
|
70
70
|
offset(opt: TransformOffsetOptions): this;
|
|
71
|
-
tap(fn: AsyncIndexedMapper<T,
|
|
72
|
-
tapSync(fn: IndexedMapper<T,
|
|
71
|
+
tap(fn: AsyncIndexedMapper<T, void>, opt?: TransformOptions): this;
|
|
72
|
+
tapSync(fn: IndexedMapper<T, void>, opt?: TransformOptions): this;
|
|
73
73
|
throttle(opt: TransformThrottleOptions): this;
|
|
74
74
|
throttleByRSS(opt: TransformThrottleByRSSOptions): this;
|
|
75
75
|
/**
|
|
@@ -113,7 +113,7 @@ export declare class Pipeline<T = unknown> {
|
|
|
113
113
|
*/
|
|
114
114
|
toNDJsonFile(outputFilePath: string, level?: Integer): Promise<void>;
|
|
115
115
|
to(destination: WritableTyped<T>): Promise<void>;
|
|
116
|
-
forEach(fn:
|
|
117
|
-
forEachSync(fn:
|
|
116
|
+
forEach(fn: AbortableAsyncMapper<T, void>, opt?: TransformMapOptions<T, void> & TransformLogProgressOptions<T>): Promise<void>;
|
|
117
|
+
forEachSync(fn: AbortableMapper<T, void>, opt?: TransformMapSyncOptions<T, void> & TransformLogProgressOptions<T>): Promise<void>;
|
|
118
118
|
run(): Promise<void>;
|
|
119
119
|
}
|
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.113.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@standard-schema/spec": "^1",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@typescript/native-preview": "beta",
|
|
21
|
-
"@naturalcycles/dev-lib": "
|
|
21
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
".": "./dist/index.js",
|
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
|
}
|
package/src/stream/pipeline.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { createAbortableSignal } from '@naturalcycles/js-lib'
|
|
|
8
8
|
import { _passthroughPredicate } from '@naturalcycles/js-lib/types'
|
|
9
9
|
import type {
|
|
10
10
|
AbortableAsyncMapper,
|
|
11
|
+
AbortableMapper,
|
|
11
12
|
AsyncIndexedMapper,
|
|
12
13
|
AsyncPredicate,
|
|
13
14
|
END,
|
|
@@ -236,12 +237,12 @@ export class Pipeline<T = unknown> {
|
|
|
236
237
|
return this
|
|
237
238
|
}
|
|
238
239
|
|
|
239
|
-
tap(fn: AsyncIndexedMapper<T,
|
|
240
|
+
tap(fn: AsyncIndexedMapper<T, void>, opt?: TransformOptions): this {
|
|
240
241
|
this.transforms.push(transformTap(fn, opt))
|
|
241
242
|
return this
|
|
242
243
|
}
|
|
243
244
|
|
|
244
|
-
tapSync(fn: IndexedMapper<T,
|
|
245
|
+
tapSync(fn: IndexedMapper<T, void>, opt?: TransformOptions): this {
|
|
245
246
|
this.transforms.push(transformTapSync(fn, opt))
|
|
246
247
|
return this
|
|
247
248
|
}
|
|
@@ -420,7 +421,7 @@ export class Pipeline<T = unknown> {
|
|
|
420
421
|
}
|
|
421
422
|
|
|
422
423
|
async forEach(
|
|
423
|
-
fn:
|
|
424
|
+
fn: AbortableAsyncMapper<T, void>,
|
|
424
425
|
opt: TransformMapOptions<T, void> & TransformLogProgressOptions<T> = {},
|
|
425
426
|
): Promise<void> {
|
|
426
427
|
this.transforms.push(
|
|
@@ -437,7 +438,7 @@ export class Pipeline<T = unknown> {
|
|
|
437
438
|
}
|
|
438
439
|
|
|
439
440
|
async forEachSync(
|
|
440
|
-
fn:
|
|
441
|
+
fn: AbortableMapper<T, void>,
|
|
441
442
|
opt: TransformMapSyncOptions<T, void> & TransformLogProgressOptions<T> = {},
|
|
442
443
|
): Promise<void> {
|
|
443
444
|
this.transforms.push(
|