teen_process 4.1.1 → 4.1.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.
- package/CHANGELOG.md +12 -0
- package/build/lib/exec.d.ts.map +1 -1
- package/build/lib/exec.js +9 -7
- package/build/lib/exec.js.map +1 -1
- package/build/lib/subprocess.d.ts +2 -2
- package/build/lib/subprocess.d.ts.map +1 -1
- package/build/lib/subprocess.js +18 -20
- package/build/lib/subprocess.js.map +1 -1
- package/lib/exec.ts +17 -4
- package/lib/subprocess.ts +24 -19
- package/package.json +1 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [4.1.3](https://github.com/appium/node-teen_process/compare/v4.1.2...v4.1.3) (2026-05-06)
|
|
2
|
+
|
|
3
|
+
### Miscellaneous Chores
|
|
4
|
+
|
|
5
|
+
* replace lodash with native utilities ([#476](https://github.com/appium/node-teen_process/issues/476)) ([2f976f4](https://github.com/appium/node-teen_process/commit/2f976f48c625acf58284f50c28cd17ce01bc2581))
|
|
6
|
+
|
|
7
|
+
## [4.1.2](https://github.com/appium/node-teen_process/compare/v4.1.1...v4.1.2) (2026-04-25)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* lint warnings ([#475](https://github.com/appium/node-teen_process/issues/475)) ([8f10e95](https://github.com/appium/node-teen_process/commit/8f10e95ec2349e86d057705bfbd673837b36b616))
|
|
12
|
+
|
|
1
13
|
## [4.1.1](https://github.com/appium/node-teen_process/compare/v4.1.0...v4.1.1) (2026-04-10)
|
|
2
14
|
|
|
3
15
|
### Miscellaneous Chores
|
package/build/lib/exec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../lib/exec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../lib/exec.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,UAAU,EAGX,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,IAAI,CAAC,CAAC,SAAS,sBAAsB,GAAG,sBAAsB,EAClF,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAM,EAAO,EACnB,YAAY,GAAE,CAAW,GACxB,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAoH/C"}
|
package/build/lib/exec.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.exec = exec;
|
|
7
4
|
const node_child_process_1 = require("node:child_process");
|
|
8
5
|
const shell_quote_1 = require("shell-quote");
|
|
9
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
10
6
|
const helpers_1 = require("./helpers");
|
|
11
7
|
const circular_buffer_1 = require("./circular-buffer");
|
|
12
8
|
/**
|
|
@@ -56,7 +52,7 @@ async function exec(cmd, args = [], originalOpts = {}) {
|
|
|
56
52
|
maxStdoutBufferSize: circular_buffer_1.MAX_BUFFER_SIZE,
|
|
57
53
|
maxStderrBufferSize: circular_buffer_1.MAX_BUFFER_SIZE,
|
|
58
54
|
};
|
|
59
|
-
const opts =
|
|
55
|
+
const opts = applyDefaults(defaults, originalOpts);
|
|
60
56
|
const isBuffer = Boolean(opts.isBuffer);
|
|
61
57
|
const spawnOpts = buildSpawnOptions(opts, originalOpts);
|
|
62
58
|
return await new Promise((resolve, reject) => {
|
|
@@ -82,7 +78,8 @@ async function exec(cmd, args = [], originalOpts = {}) {
|
|
|
82
78
|
return;
|
|
83
79
|
}
|
|
84
80
|
stream.on('error', (err) => {
|
|
85
|
-
|
|
81
|
+
const capitalizedStreamType = streamType.charAt(0).toUpperCase() + streamType.slice(1).toLowerCase();
|
|
82
|
+
reject(new Error(`${capitalizedStreamType} '${err.syscall}' error: ${err.stack}`));
|
|
86
83
|
});
|
|
87
84
|
if (opts.ignoreOutput) {
|
|
88
85
|
// https://github.com/nodejs/node/issues/4236
|
|
@@ -91,7 +88,7 @@ async function exec(cmd, args = [], originalOpts = {}) {
|
|
|
91
88
|
}
|
|
92
89
|
stream.on('data', (chunk) => {
|
|
93
90
|
buffer.add(chunk);
|
|
94
|
-
if (opts.logger?.debug
|
|
91
|
+
if (typeof opts.logger?.debug === 'function') {
|
|
95
92
|
opts.logger.debug(chunk.toString());
|
|
96
93
|
}
|
|
97
94
|
});
|
|
@@ -138,6 +135,11 @@ async function exec(cmd, args = [], originalOpts = {}) {
|
|
|
138
135
|
}
|
|
139
136
|
});
|
|
140
137
|
}
|
|
138
|
+
function applyDefaults(defaults, originalOpts) {
|
|
139
|
+
const normalizedOriginalOpts = originalOpts !== null && typeof originalOpts === 'object' ? originalOpts : {};
|
|
140
|
+
const definedOriginalOpts = Object.fromEntries(Object.entries(normalizedOriginalOpts).filter(([, value]) => value !== undefined));
|
|
141
|
+
return { ...defaults, ...definedOriginalOpts };
|
|
142
|
+
}
|
|
141
143
|
function buildSpawnOptions(opts, originalOpts) {
|
|
142
144
|
return {
|
|
143
145
|
cwd: opts.cwd,
|
package/build/lib/exec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../lib/exec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../lib/exec.ts"],"names":[],"mappings":";;AA0CA,oBAwHC;AAlKD,2DAAyC;AACzC,6CAAkC;AAClC,uCAAuC;AACvC,uDAAkE;AASlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACI,KAAK,UAAU,IAAI,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G;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;QACvD,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5F,CAAC;AACJ,CAAC"}
|
|
@@ -38,13 +38,14 @@ import type { SubProcessOptions, StartDetector } from './types';
|
|
|
38
38
|
*/
|
|
39
39
|
export declare class SubProcess<TSubProcessOptions extends SubProcessOptions = SubProcessOptions> extends EventEmitter {
|
|
40
40
|
proc: ChildProcess | null;
|
|
41
|
+
readonly rep: string;
|
|
41
42
|
private args;
|
|
42
43
|
private cmd;
|
|
43
44
|
private opts;
|
|
44
45
|
private expectingExit;
|
|
45
|
-
readonly rep: string;
|
|
46
46
|
constructor(cmd: string, args?: string[], opts?: TSubProcessOptions);
|
|
47
47
|
get isRunning(): boolean;
|
|
48
|
+
get pid(): number | null;
|
|
48
49
|
/**
|
|
49
50
|
* Starts the subprocess and waits for it to be ready.
|
|
50
51
|
*
|
|
@@ -119,7 +120,6 @@ export declare class SubProcess<TSubProcessOptions extends SubProcessOptions = S
|
|
|
119
120
|
* @throws {Error} When process was not created with 'detached' option
|
|
120
121
|
*/
|
|
121
122
|
detachProcess(): void;
|
|
122
|
-
get pid(): number | null;
|
|
123
123
|
private emitLines;
|
|
124
124
|
}
|
|
125
125
|
//# sourceMappingURL=subprocess.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subprocess.d.ts","sourceRoot":"","sources":["../../lib/subprocess.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"subprocess.d.ts","sourceRoot":"","sources":["../../lib/subprocess.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAKzC,OAAO,KAAK,EAAC,iBAAiB,EAAE,aAAa,EAA4B,MAAM,SAAS,CAAC;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,UAAU,CACrB,kBAAkB,SAAS,iBAAiB,GAAG,iBAAiB,CAChE,SAAQ,YAAY;IACpB,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,IAAI,CAAW;IACvB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,aAAa,CAAU;gBAEnB,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAO,EAAE,IAAI,CAAC,EAAE,kBAAkB;IAwBvE,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,CAEvB;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,KAAK,CACT,aAAa,GAAE,aAAa,CAAC,kBAAkB,CAAC,GAAG,MAAM,GAAG,OAAO,GAAG,IAAW,EACjF,SAAS,GAAE,MAAM,GAAG,OAAO,GAAG,IAAW,EACzC,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,IAAI,CAAC;IAsJhB;;;;;;;;;;;;;;;;;;;OAmBG;IACG,IAAI,CAAC,MAAM,GAAE,MAAM,CAAC,OAAmB,EAAE,OAAO,SAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAc9E;;;;;;;;;;;;;;;;OAgBG;IACG,IAAI,CAAC,gBAAgB,GAAE,MAAM,EAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgBpE;;;;;;;OAOG;IACH,aAAa,IAAI,IAAI;IASrB,OAAO,CAAC,SAAS;CAYlB"}
|
package/build/lib/subprocess.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.SubProcess = void 0;
|
|
7
4
|
const node_child_process_1 = require("node:child_process");
|
|
8
5
|
const node_events_1 = require("node:events");
|
|
9
6
|
const shell_quote_1 = require("shell-quote");
|
|
10
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
11
7
|
const helpers_1 = require("./helpers");
|
|
12
8
|
const node_readline_1 = require("node:readline");
|
|
13
9
|
/**
|
|
@@ -47,32 +43,35 @@ const node_readline_1 = require("node:readline");
|
|
|
47
43
|
*/
|
|
48
44
|
class SubProcess extends node_events_1.EventEmitter {
|
|
49
45
|
proc;
|
|
46
|
+
rep;
|
|
50
47
|
args;
|
|
51
48
|
cmd;
|
|
52
49
|
opts;
|
|
53
50
|
expectingExit;
|
|
54
|
-
rep;
|
|
55
51
|
constructor(cmd, args = [], opts) {
|
|
56
52
|
super();
|
|
57
53
|
if (!cmd) {
|
|
58
54
|
throw new Error('Command is required');
|
|
59
55
|
}
|
|
60
|
-
if (!
|
|
56
|
+
if (typeof cmd !== 'string' && !(cmd instanceof String)) {
|
|
61
57
|
throw new Error('Command must be a string');
|
|
62
58
|
}
|
|
63
|
-
if (!
|
|
59
|
+
if (!Array.isArray(args)) {
|
|
64
60
|
throw new Error('Args must be an array');
|
|
65
61
|
}
|
|
66
|
-
this.cmd = cmd;
|
|
62
|
+
this.cmd = String(cmd);
|
|
67
63
|
this.args = args;
|
|
68
64
|
this.proc = null;
|
|
69
65
|
this.opts = opts ?? {};
|
|
70
66
|
this.expectingExit = false;
|
|
71
|
-
this.rep = (0, shell_quote_1.quote)([cmd, ...args]);
|
|
67
|
+
this.rep = (0, shell_quote_1.quote)([String(cmd), ...args]);
|
|
72
68
|
}
|
|
73
69
|
get isRunning() {
|
|
74
70
|
return !!this.proc;
|
|
75
71
|
}
|
|
72
|
+
get pid() {
|
|
73
|
+
return this.proc?.pid ?? null;
|
|
74
|
+
}
|
|
76
75
|
/**
|
|
77
76
|
* Starts the subprocess and waits for it to be ready.
|
|
78
77
|
*
|
|
@@ -105,21 +104,23 @@ class SubProcess extends node_events_1.EventEmitter {
|
|
|
105
104
|
if (startDetector === null) {
|
|
106
105
|
detector = genericStartDetector;
|
|
107
106
|
}
|
|
108
|
-
if (
|
|
109
|
-
startDelay = startDetector;
|
|
107
|
+
if (typeof startDetector === 'number' || startDetector instanceof Number) {
|
|
108
|
+
startDelay = Number(startDetector);
|
|
110
109
|
detector = null;
|
|
111
110
|
}
|
|
112
|
-
else if (
|
|
111
|
+
else if (typeof startDetector === 'function') {
|
|
113
112
|
detector = startDetector;
|
|
114
113
|
}
|
|
115
|
-
if (
|
|
114
|
+
if ((typeof startDetector === 'boolean' || startDetector instanceof Boolean) &&
|
|
115
|
+
Boolean(startDetector)) {
|
|
116
116
|
if (!this.opts.detached) {
|
|
117
117
|
throw new Error(`Unable to detach process that is not started with 'detached' option`);
|
|
118
118
|
}
|
|
119
119
|
detach = true;
|
|
120
120
|
detector = genericStartDetector;
|
|
121
121
|
}
|
|
122
|
-
else if (
|
|
122
|
+
else if ((typeof timeoutMs === 'boolean' || timeoutMs instanceof Boolean) &&
|
|
123
|
+
Boolean(timeoutMs)) {
|
|
123
124
|
if (!this.opts.detached) {
|
|
124
125
|
throw new Error(`Unable to detach process that is not started with 'detached' option`);
|
|
125
126
|
}
|
|
@@ -197,10 +198,10 @@ class SubProcess extends node_events_1.EventEmitter {
|
|
|
197
198
|
if (!detector) {
|
|
198
199
|
setTimeout(() => resolve(), startDelay);
|
|
199
200
|
}
|
|
200
|
-
if (
|
|
201
|
+
if (typeof timeoutMs === 'number' || timeoutMs instanceof Number) {
|
|
201
202
|
setTimeout(() => {
|
|
202
203
|
reject(new Error(`The process did not start within ${timeoutMs}ms (cmd: '${this.rep}')`));
|
|
203
|
-
}, timeoutMs);
|
|
204
|
+
}, Number(timeoutMs));
|
|
204
205
|
}
|
|
205
206
|
}).finally(() => {
|
|
206
207
|
if (detach && this.proc) {
|
|
@@ -289,12 +290,9 @@ class SubProcess extends node_events_1.EventEmitter {
|
|
|
289
290
|
this.proc.unref();
|
|
290
291
|
}
|
|
291
292
|
}
|
|
292
|
-
get pid() {
|
|
293
|
-
return this.proc?.pid ?? null;
|
|
294
|
-
}
|
|
295
293
|
emitLines(streamName, lines) {
|
|
296
294
|
const doEmit = (line) => this.emit('stream-line', `[${streamName.toUpperCase()}] ${line}`);
|
|
297
|
-
if (
|
|
295
|
+
if (typeof lines === 'string' || lines instanceof String) {
|
|
298
296
|
doEmit(lines);
|
|
299
297
|
}
|
|
300
298
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subprocess.js","sourceRoot":"","sources":["../../lib/subprocess.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subprocess.js","sourceRoot":"","sources":["../../lib/subprocess.ts"],"names":[],"mappings":";;;AAAA,2DAAyC;AAEzC,6CAAyC;AACzC,6CAAkC;AAClC,uCAAuC;AACvC,iDAA8C;AAI9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,UAEX,SAAQ,0BAAY;IACpB,IAAI,CAAsB;IACjB,GAAG,CAAS;IACb,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B,MAAM,CAAC,IAAI,CAAC,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA7TD,gCA6TC"}
|
package/lib/exec.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {spawn} from 'node:child_process';
|
|
2
2
|
import {quote} from 'shell-quote';
|
|
3
|
-
import _ from 'lodash';
|
|
4
3
|
import {formatEnoent} from './helpers';
|
|
5
4
|
import {CircularBuffer, MAX_BUFFER_SIZE} from './circular-buffer';
|
|
6
5
|
import type {
|
|
@@ -64,7 +63,7 @@ export async function exec<T extends TeenProcessExecOptions = TeenProcessExecOpt
|
|
|
64
63
|
maxStderrBufferSize: MAX_BUFFER_SIZE,
|
|
65
64
|
};
|
|
66
65
|
|
|
67
|
-
const opts =
|
|
66
|
+
const opts = applyDefaults(defaults, originalOpts);
|
|
68
67
|
const isBuffer = Boolean(opts.isBuffer);
|
|
69
68
|
const spawnOpts = buildSpawnOptions(opts, originalOpts);
|
|
70
69
|
|
|
@@ -95,7 +94,9 @@ export async function exec<T extends TeenProcessExecOptions = TeenProcessExecOpt
|
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
stream.on('error', (err: NodeJS.ErrnoException) => {
|
|
98
|
-
|
|
97
|
+
const capitalizedStreamType =
|
|
98
|
+
streamType.charAt(0).toUpperCase() + streamType.slice(1).toLowerCase();
|
|
99
|
+
reject(new Error(`${capitalizedStreamType} '${err.syscall}' error: ${err.stack}`));
|
|
99
100
|
});
|
|
100
101
|
|
|
101
102
|
if (opts.ignoreOutput) {
|
|
@@ -106,7 +107,7 @@ export async function exec<T extends TeenProcessExecOptions = TeenProcessExecOpt
|
|
|
106
107
|
|
|
107
108
|
stream.on('data', (chunk: Buffer) => {
|
|
108
109
|
buffer.add(chunk);
|
|
109
|
-
if (opts.logger?.debug
|
|
110
|
+
if (typeof opts.logger?.debug === 'function') {
|
|
110
111
|
opts.logger.debug(chunk.toString());
|
|
111
112
|
}
|
|
112
113
|
});
|
|
@@ -161,6 +162,18 @@ export async function exec<T extends TeenProcessExecOptions = TeenProcessExecOpt
|
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
164
|
|
|
165
|
+
function applyDefaults<T extends TeenProcessExecOptions>(
|
|
166
|
+
defaults: TeenProcessExecOptions,
|
|
167
|
+
originalOpts: T,
|
|
168
|
+
): T {
|
|
169
|
+
const normalizedOriginalOpts =
|
|
170
|
+
originalOpts !== null && typeof originalOpts === 'object' ? originalOpts : ({} as T);
|
|
171
|
+
const definedOriginalOpts = Object.fromEntries(
|
|
172
|
+
Object.entries(normalizedOriginalOpts).filter(([, value]) => value !== undefined),
|
|
173
|
+
) as Partial<T>;
|
|
174
|
+
return {...defaults, ...definedOriginalOpts} as T;
|
|
175
|
+
}
|
|
176
|
+
|
|
164
177
|
function buildSpawnOptions<T extends TeenProcessExecOptions>(opts: T, originalOpts: T) {
|
|
165
178
|
return {
|
|
166
179
|
cwd: opts.cwd,
|
package/lib/subprocess.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {spawn} from 'node:child_process';
|
|
|
2
2
|
import type {ChildProcess} from 'node:child_process';
|
|
3
3
|
import {EventEmitter} from 'node:events';
|
|
4
4
|
import {quote} from 'shell-quote';
|
|
5
|
-
import _ from 'lodash';
|
|
6
5
|
import {formatEnoent} from './helpers';
|
|
7
6
|
import {createInterface} from 'node:readline';
|
|
8
7
|
import type {Readable} from 'node:stream';
|
|
@@ -47,11 +46,11 @@ export class SubProcess<
|
|
|
47
46
|
TSubProcessOptions extends SubProcessOptions = SubProcessOptions,
|
|
48
47
|
> extends EventEmitter {
|
|
49
48
|
proc: ChildProcess | null;
|
|
49
|
+
readonly rep: string;
|
|
50
50
|
private args: string[];
|
|
51
51
|
private cmd: string;
|
|
52
52
|
private opts: TSubProcessOptions;
|
|
53
53
|
private expectingExit: boolean;
|
|
54
|
-
readonly rep: string;
|
|
55
54
|
|
|
56
55
|
constructor(cmd: string, args: string[] = [], opts?: TSubProcessOptions) {
|
|
57
56
|
super();
|
|
@@ -60,27 +59,31 @@ export class SubProcess<
|
|
|
60
59
|
throw new Error('Command is required');
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
if (!
|
|
62
|
+
if (typeof cmd !== 'string' && !((cmd as any) instanceof String)) {
|
|
64
63
|
throw new Error('Command must be a string');
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
if (!
|
|
66
|
+
if (!Array.isArray(args)) {
|
|
68
67
|
throw new Error('Args must be an array');
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
this.cmd = cmd;
|
|
70
|
+
this.cmd = String(cmd);
|
|
72
71
|
this.args = args;
|
|
73
72
|
this.proc = null;
|
|
74
73
|
this.opts = opts ?? ({} as TSubProcessOptions);
|
|
75
74
|
this.expectingExit = false;
|
|
76
75
|
|
|
77
|
-
this.rep = quote([cmd, ...args]);
|
|
76
|
+
this.rep = quote([String(cmd), ...args]);
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
get isRunning(): boolean {
|
|
81
80
|
return !!this.proc;
|
|
82
81
|
}
|
|
83
82
|
|
|
83
|
+
get pid(): number | null {
|
|
84
|
+
return this.proc?.pid ?? null;
|
|
85
|
+
}
|
|
86
|
+
|
|
84
87
|
/**
|
|
85
88
|
* Starts the subprocess and waits for it to be ready.
|
|
86
89
|
*
|
|
@@ -121,20 +124,26 @@ export class SubProcess<
|
|
|
121
124
|
detector = genericStartDetector;
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
if (
|
|
125
|
-
startDelay = startDetector;
|
|
127
|
+
if (typeof startDetector === 'number' || (startDetector as any) instanceof Number) {
|
|
128
|
+
startDelay = Number(startDetector);
|
|
126
129
|
detector = null;
|
|
127
|
-
} else if (
|
|
130
|
+
} else if (typeof startDetector === 'function') {
|
|
128
131
|
detector = startDetector;
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
if (
|
|
134
|
+
if (
|
|
135
|
+
(typeof startDetector === 'boolean' || (startDetector as any) instanceof Boolean) &&
|
|
136
|
+
Boolean(startDetector)
|
|
137
|
+
) {
|
|
132
138
|
if (!this.opts.detached) {
|
|
133
139
|
throw new Error(`Unable to detach process that is not started with 'detached' option`);
|
|
134
140
|
}
|
|
135
141
|
detach = true;
|
|
136
142
|
detector = genericStartDetector;
|
|
137
|
-
} else if (
|
|
143
|
+
} else if (
|
|
144
|
+
(typeof timeoutMs === 'boolean' || (timeoutMs as any) instanceof Boolean) &&
|
|
145
|
+
Boolean(timeoutMs)
|
|
146
|
+
) {
|
|
138
147
|
if (!this.opts.detached) {
|
|
139
148
|
throw new Error(`Unable to detach process that is not started with 'detached' option`);
|
|
140
149
|
}
|
|
@@ -242,10 +251,10 @@ export class SubProcess<
|
|
|
242
251
|
setTimeout(() => resolve(), startDelay);
|
|
243
252
|
}
|
|
244
253
|
|
|
245
|
-
if (
|
|
254
|
+
if (typeof timeoutMs === 'number' || (timeoutMs as any) instanceof Number) {
|
|
246
255
|
setTimeout(() => {
|
|
247
256
|
reject(new Error(`The process did not start within ${timeoutMs}ms (cmd: '${this.rep}')`));
|
|
248
|
-
}, timeoutMs);
|
|
257
|
+
}, Number(timeoutMs));
|
|
249
258
|
}
|
|
250
259
|
}).finally(() => {
|
|
251
260
|
if (detach && this.proc) {
|
|
@@ -338,16 +347,12 @@ export class SubProcess<
|
|
|
338
347
|
}
|
|
339
348
|
}
|
|
340
349
|
|
|
341
|
-
get pid(): number | null {
|
|
342
|
-
return this.proc?.pid ?? null;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
350
|
private emitLines(streamName: StreamName, lines: Iterable<string> | string): void {
|
|
346
351
|
const doEmit = (line: string) =>
|
|
347
352
|
this.emit('stream-line', `[${streamName.toUpperCase()}] ${line}`);
|
|
348
353
|
|
|
349
|
-
if (
|
|
350
|
-
doEmit(lines);
|
|
354
|
+
if (typeof lines === 'string' || (lines as any) instanceof String) {
|
|
355
|
+
doEmit(lines as string);
|
|
351
356
|
} else {
|
|
352
357
|
for (const line of lines) {
|
|
353
358
|
doEmit(line);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teen_process",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"description": "A grown up version of Node's spawn/exec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"child_process",
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
"singleQuote": true
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"lodash": "^4.17.21",
|
|
54
53
|
"shell-quote": "^1.8.1"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
@@ -59,7 +58,6 @@
|
|
|
59
58
|
"@appium/types": "^1.0.0-rc.1",
|
|
60
59
|
"@semantic-release/changelog": "^6.0.3",
|
|
61
60
|
"@semantic-release/git": "^10.0.1",
|
|
62
|
-
"@types/lodash": "^4.14.202",
|
|
63
61
|
"@types/mocha": "10.0.10",
|
|
64
62
|
"@types/node": "^25.0.0",
|
|
65
63
|
"@types/shell-quote": "^1.7.5",
|