teen_process 3.0.6 → 4.0.1
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/build/lib/exec.d.ts +32 -107
- package/build/lib/exec.d.ts.map +1 -1
- package/build/lib/exec.js +60 -103
- package/build/lib/exec.js.map +1 -1
- package/build/lib/helpers.d.ts +1 -12
- package/build/lib/helpers.d.ts.map +1 -1
- package/build/lib/helpers.js +17 -13
- package/build/lib/helpers.js.map +1 -1
- package/build/lib/index.d.ts +4 -6
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +7 -43
- package/build/lib/index.js.map +1 -1
- package/build/lib/subprocess.d.ts +106 -61
- package/build/lib/subprocess.d.ts.map +1 -1
- package/build/lib/subprocess.js +145 -143
- package/build/lib/subprocess.js.map +1 -1
- package/build/lib/types.d.ts +79 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/test/circular-buffer-specs.d.ts +2 -0
- package/build/test/circular-buffer-specs.d.ts.map +1 -0
- package/build/test/circular-buffer-specs.js +40 -0
- package/build/test/circular-buffer-specs.js.map +1 -0
- package/build/test/exec-specs.d.ts +2 -0
- package/build/test/exec-specs.d.ts.map +1 -0
- package/build/test/exec-specs.js +167 -0
- package/build/test/exec-specs.js.map +1 -0
- package/build/test/fixtures/bigbuffer.d.ts +3 -0
- package/build/test/fixtures/bigbuffer.d.ts.map +1 -0
- package/build/test/fixtures/bigbuffer.js +13 -0
- package/build/test/fixtures/bigbuffer.js.map +1 -0
- package/build/test/helpers.d.ts +3 -0
- package/build/test/helpers.d.ts.map +1 -0
- package/build/test/helpers.js +15 -0
- package/build/test/helpers.js.map +1 -0
- package/build/test/subproc-specs.d.ts +2 -0
- package/build/test/subproc-specs.d.ts.map +1 -0
- package/build/test/subproc-specs.js +414 -0
- package/build/test/subproc-specs.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/lib/circular-buffer.ts +1 -1
- package/lib/exec.ts +158 -0
- package/lib/helpers.ts +44 -0
- package/lib/index.ts +8 -0
- package/lib/subprocess.ts +353 -0
- package/lib/types.ts +95 -0
- package/package.json +5 -5
- package/index.js +0 -1
- package/lib/exec.js +0 -191
- package/lib/helpers.js +0 -38
- package/lib/index.js +0 -9
- package/lib/subprocess.js +0 -329
package/build/lib/exec.d.ts
CHANGED
|
@@ -1,108 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
export type TeenProcessLogger = {
|
|
35
|
-
debug: (...args: any[]) => void;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Options for {@link exec teen_process.exec}.
|
|
39
|
-
*/
|
|
40
|
-
export type TeenProcessExecOptions = import("child_process").SpawnOptions & TeenProcessProps;
|
|
41
|
-
/**
|
|
42
|
-
* The value {@link exec teen_process.exec} resolves to when `isBuffer` is `false`
|
|
43
|
-
*/
|
|
44
|
-
export type TeenProcessExecStringResult = {
|
|
45
|
-
/**
|
|
46
|
-
* - Stdout
|
|
47
|
-
*/
|
|
48
|
-
stdout: string;
|
|
49
|
-
/**
|
|
50
|
-
* - Stderr
|
|
51
|
-
*/
|
|
52
|
-
stderr: string;
|
|
53
|
-
/**
|
|
54
|
-
* - Exit code
|
|
55
|
-
*/
|
|
56
|
-
code: number | null;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* The value {@link exec teen_process.exec} resolves to when `isBuffer` is `true`
|
|
60
|
-
*/
|
|
61
|
-
export type TeenProcessExecBufferResult = {
|
|
62
|
-
/**
|
|
63
|
-
* - Stdout
|
|
64
|
-
*/
|
|
65
|
-
stdout: Buffer;
|
|
66
|
-
/**
|
|
67
|
-
* - Stderr
|
|
68
|
-
*/
|
|
69
|
-
stderr: Buffer;
|
|
70
|
-
/**
|
|
71
|
-
* - Exit code
|
|
72
|
-
*/
|
|
73
|
-
code: number | null;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Extra props {@link exec teen_process.exec} adds to its error objects
|
|
77
|
-
*/
|
|
78
|
-
export type TeenProcessExecErrorProps = {
|
|
79
|
-
/**
|
|
80
|
-
* - STDOUT
|
|
81
|
-
*/
|
|
82
|
-
stdout: string;
|
|
83
|
-
/**
|
|
84
|
-
* - STDERR
|
|
85
|
-
*/
|
|
86
|
-
stderr: string;
|
|
87
|
-
/**
|
|
88
|
-
* - Exit code
|
|
89
|
-
*/
|
|
90
|
-
code: number | null;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Error thrown by {@link exec teen_process.exec}
|
|
94
|
-
*/
|
|
95
|
-
export type TeenProcessExecError = Error & TeenProcessExecErrorProps;
|
|
96
|
-
export type BufferProp<MaybeBuffer extends {
|
|
97
|
-
isBuffer?: boolean;
|
|
98
|
-
}> = MaybeBuffer["isBuffer"];
|
|
99
|
-
/**
|
|
100
|
-
* Spawns a process
|
|
101
|
-
* @template {TeenProcessExecOptions} T
|
|
102
|
-
* @param {string} cmd - Program to execute
|
|
103
|
-
* @param {string[]} [args] - Arguments to pass to the program
|
|
104
|
-
* @param {T} [originalOpts] - Options
|
|
105
|
-
* @returns {Promise<BufferProp<T> extends true ? TeenProcessExecBufferResult : TeenProcessExecStringResult>}
|
|
106
|
-
*/
|
|
107
|
-
export function exec<T extends TeenProcessExecOptions>(cmd: string, args?: string[], originalOpts?: T): Promise<BufferProp<T> extends true ? TeenProcessExecBufferResult : TeenProcessExecStringResult>;
|
|
1
|
+
import type { TeenProcessExecOptions, ExecResult, BufferProp } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Spawns a child process and collects its output.
|
|
4
|
+
*
|
|
5
|
+
* This is a promisified version of Node's spawn that collects stdout and stderr,
|
|
6
|
+
* handles timeouts, and provides error context.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The options type extending TeenProcessExecOptions
|
|
9
|
+
* @param cmd - The command to execute
|
|
10
|
+
* @param args - Array of arguments to pass to the command (default: [])
|
|
11
|
+
* @param originalOpts - Execution options including timeout, encoding, environment, etc.
|
|
12
|
+
* @returns Promise resolving to an object with stdout, stderr, and exit code
|
|
13
|
+
*
|
|
14
|
+
* @throws {TeenProcessExecError} When the process exits with non-zero code or times out
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Simple execution
|
|
19
|
+
* const {stdout, stderr, code} = await exec('ls', ['-la']);
|
|
20
|
+
*
|
|
21
|
+
* // With timeout and custom encoding
|
|
22
|
+
* const result = await exec('long-running-cmd', [], {
|
|
23
|
+
* timeout: 5000,
|
|
24
|
+
* encoding: 'utf8',
|
|
25
|
+
* cwd: '/custom/path'
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Return output as Buffer
|
|
29
|
+
* const {stdout} = await exec('cat', ['image.png'], {isBuffer: true});
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function exec<T extends TeenProcessExecOptions = TeenProcessExecOptions>(cmd: string, args?: string[], originalOpts?: T): Promise<ExecResult<BufferProp<T>>>;
|
|
108
33
|
//# sourceMappingURL=exec.d.ts.map
|
package/build/lib/exec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../lib/exec.
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../lib/exec.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,sBAAsB,EACtB,UAAU,EACV,UAAU,EAGb,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CA4GpC"}
|
package/build/lib/exec.js
CHANGED
|
@@ -4,27 +4,47 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.exec = exec;
|
|
7
|
-
const
|
|
7
|
+
const node_child_process_1 = require("node:child_process");
|
|
8
8
|
const shell_quote_1 = require("shell-quote");
|
|
9
9
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
10
10
|
const lodash_1 = __importDefault(require("lodash"));
|
|
11
11
|
const helpers_1 = require("./helpers");
|
|
12
12
|
const circular_buffer_1 = require("./circular-buffer");
|
|
13
13
|
/**
|
|
14
|
-
* Spawns a process
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
14
|
+
* Spawns a child process and collects its output.
|
|
15
|
+
*
|
|
16
|
+
* This is a promisified version of Node's spawn that collects stdout and stderr,
|
|
17
|
+
* handles timeouts, and provides error context.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The options type extending TeenProcessExecOptions
|
|
20
|
+
* @param cmd - The command to execute
|
|
21
|
+
* @param args - Array of arguments to pass to the command (default: [])
|
|
22
|
+
* @param originalOpts - Execution options including timeout, encoding, environment, etc.
|
|
23
|
+
* @returns Promise resolving to an object with stdout, stderr, and exit code
|
|
24
|
+
*
|
|
25
|
+
* @throws {TeenProcessExecError} When the process exits with non-zero code or times out
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Simple execution
|
|
30
|
+
* const {stdout, stderr, code} = await exec('ls', ['-la']);
|
|
31
|
+
*
|
|
32
|
+
* // With timeout and custom encoding
|
|
33
|
+
* const result = await exec('long-running-cmd', [], {
|
|
34
|
+
* timeout: 5000,
|
|
35
|
+
* encoding: 'utf8',
|
|
36
|
+
* cwd: '/custom/path'
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Return output as Buffer
|
|
40
|
+
* const {stdout} = await exec('cat', ['image.png'], {isBuffer: true});
|
|
41
|
+
* ```
|
|
20
42
|
*/
|
|
21
|
-
async function exec(cmd, args = [], originalOpts =
|
|
43
|
+
async function exec(cmd, args = [], originalOpts = {}) {
|
|
22
44
|
// get a quoted representation of the command for error strings
|
|
23
45
|
const rep = (0, shell_quote_1.quote)([cmd, ...args]);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const opts = /** @type {T} */ (lodash_1.default.defaults(originalOpts, {
|
|
27
|
-
timeout: null,
|
|
46
|
+
const defaults = {
|
|
47
|
+
timeout: undefined,
|
|
28
48
|
encoding: 'utf8',
|
|
29
49
|
killSignal: 'SIGTERM',
|
|
30
50
|
cwd: undefined,
|
|
@@ -36,141 +56,78 @@ async function exec(cmd, args = [], originalOpts = /** @type {T} */ ({})) {
|
|
|
36
56
|
logger: undefined,
|
|
37
57
|
maxStdoutBufferSize: circular_buffer_1.MAX_BUFFER_SIZE,
|
|
38
58
|
maxStderrBufferSize: circular_buffer_1.MAX_BUFFER_SIZE,
|
|
39
|
-
}
|
|
59
|
+
};
|
|
60
|
+
const opts = lodash_1.default.defaults({}, originalOpts, defaults);
|
|
40
61
|
const isBuffer = Boolean(opts.isBuffer);
|
|
41
|
-
// this is an async function, so return a promise
|
|
42
62
|
return await new bluebird_1.default((resolve, reject) => {
|
|
43
|
-
|
|
44
|
-
// the other 'spawn' options through the API
|
|
45
|
-
const proc = (0, child_process_1.spawn)(cmd, args, { cwd: opts.cwd, env: opts.env, shell: opts.shell });
|
|
63
|
+
const proc = (0, node_child_process_1.spawn)(cmd, args, { cwd: opts.cwd, env: opts.env, shell: opts.shell });
|
|
46
64
|
const stdoutBuffer = new circular_buffer_1.CircularBuffer(opts.maxStdoutBufferSize);
|
|
47
65
|
const stderrBuffer = new circular_buffer_1.CircularBuffer(opts.maxStderrBufferSize);
|
|
48
66
|
let timer = null;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
67
|
+
proc.on('error', async (err) => {
|
|
68
|
+
let error = err;
|
|
69
|
+
if (error.code === 'ENOENT') {
|
|
70
|
+
error = await (0, helpers_1.formatEnoent)(error, cmd, opts.cwd?.toString());
|
|
53
71
|
}
|
|
54
|
-
reject(
|
|
72
|
+
reject(error);
|
|
55
73
|
});
|
|
56
74
|
if (proc.stdin) {
|
|
57
|
-
proc.stdin.on('error',
|
|
75
|
+
proc.stdin.on('error', (err) => {
|
|
58
76
|
reject(new Error(`Standard input '${err.syscall}' error: ${err.stack}`));
|
|
59
77
|
});
|
|
60
78
|
}
|
|
61
|
-
const handleStream = (
|
|
62
|
-
|
|
79
|
+
const handleStream = (streamType, buffer) => {
|
|
80
|
+
const stream = proc[streamType];
|
|
81
|
+
if (!stream) {
|
|
63
82
|
return;
|
|
64
83
|
}
|
|
65
|
-
|
|
84
|
+
stream.on('error', (err) => {
|
|
66
85
|
reject(new Error(`${lodash_1.default.capitalize(streamType)} '${err.syscall}' error: ${err.stack}`));
|
|
67
86
|
});
|
|
68
87
|
if (opts.ignoreOutput) {
|
|
69
88
|
// https://github.com/nodejs/node/issues/4236
|
|
70
|
-
|
|
89
|
+
stream.on('data', () => { });
|
|
71
90
|
return;
|
|
72
91
|
}
|
|
73
|
-
|
|
74
|
-
proc[streamType].on('data', (/** @type {Buffer} */ chunk) => {
|
|
92
|
+
stream.on('data', (chunk) => {
|
|
75
93
|
buffer.add(chunk);
|
|
76
|
-
if (opts.logger && lodash_1.default.isFunction(opts.logger.debug)) {
|
|
94
|
+
if (opts.logger?.debug && lodash_1.default.isFunction(opts.logger.debug)) {
|
|
77
95
|
opts.logger.debug(chunk.toString());
|
|
78
96
|
}
|
|
79
97
|
});
|
|
80
98
|
};
|
|
81
99
|
handleStream('stdout', stdoutBuffer);
|
|
82
100
|
handleStream('stderr', stderrBuffer);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*/
|
|
88
|
-
function getStdio(isBuffer) {
|
|
89
|
-
const stdout = isBuffer ? stdoutBuffer.value() : stdoutBuffer.value().toString(opts.encoding);
|
|
90
|
-
const stderr = isBuffer ? stderrBuffer.value() : stderrBuffer.value().toString(opts.encoding);
|
|
91
|
-
return /** @type {U extends true ? {stdout: Buffer, stderr: Buffer} : {stdout: string, stderr: string}} */ ({ stdout, stderr });
|
|
101
|
+
function getStdio(wantBuffer) {
|
|
102
|
+
const stdout = wantBuffer ? stdoutBuffer.value() : stdoutBuffer.value().toString(opts.encoding);
|
|
103
|
+
const stderr = wantBuffer ? stderrBuffer.value() : stderrBuffer.value().toString(opts.encoding);
|
|
104
|
+
return { stdout, stderr };
|
|
92
105
|
}
|
|
93
|
-
// if the process ends, either resolve or reject the promise based on the
|
|
94
|
-
// exit code of the process. either way, attach stdout, stderr, and code.
|
|
95
|
-
// Also clean up the timer if it exists
|
|
96
106
|
proc.on('close', (code) => {
|
|
97
107
|
if (timer) {
|
|
98
108
|
clearTimeout(timer);
|
|
99
109
|
}
|
|
100
110
|
const { stdout, stderr } = getStdio(isBuffer);
|
|
101
111
|
if (code === 0) {
|
|
102
|
-
resolve(
|
|
112
|
+
resolve({ stdout, stderr, code });
|
|
103
113
|
}
|
|
104
114
|
else {
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
const err = Object.assign(new Error(`Command '${rep}' exited with code ${code}`), {
|
|
116
|
+
stdout,
|
|
117
|
+
stderr,
|
|
118
|
+
code,
|
|
119
|
+
});
|
|
107
120
|
reject(err);
|
|
108
121
|
}
|
|
109
122
|
});
|
|
110
|
-
// if we set a timeout on the child process, cut into the execution and
|
|
111
|
-
// reject if the timeout is reached. Attach the stdout/stderr we currently
|
|
112
|
-
// have in case it's helpful in debugging
|
|
113
123
|
if (opts.timeout) {
|
|
114
124
|
timer = setTimeout(() => {
|
|
115
125
|
const { stdout, stderr } = getStdio(isBuffer);
|
|
116
|
-
|
|
117
|
-
err = Object.assign(err, { stdout, stderr, code: null });
|
|
126
|
+
const err = Object.assign(new Error(`Command '${rep}' timed out after ${opts.timeout}ms`), { stdout, stderr, code: null });
|
|
118
127
|
reject(err);
|
|
119
|
-
|
|
120
|
-
// above
|
|
121
|
-
proc.kill(opts.killSignal);
|
|
128
|
+
proc.kill(opts.killSignal ?? 'SIGTERM');
|
|
122
129
|
}, opts.timeout);
|
|
123
130
|
}
|
|
124
131
|
});
|
|
125
132
|
}
|
|
126
|
-
exports.default = exec;
|
|
127
|
-
/**
|
|
128
|
-
* Options on top of `SpawnOptions`, unique to `teen_process.`
|
|
129
|
-
* @typedef {Object} TeenProcessProps
|
|
130
|
-
* @property {boolean} [ignoreOutput] - Ignore & discard all output
|
|
131
|
-
* @property {boolean} [isBuffer] - Return output as a Buffer
|
|
132
|
-
* @property {TeenProcessLogger} [logger] - Logger to use for debugging
|
|
133
|
-
* @property {number} [maxStdoutBufferSize] - Maximum size of `stdout` buffer
|
|
134
|
-
* @property {number} [maxStderrBufferSize] - Maximum size of `stderr` buffer
|
|
135
|
-
* @property {BufferEncoding} [encoding='utf8'] - Encoding to use for output
|
|
136
|
-
*/
|
|
137
|
-
/**
|
|
138
|
-
* A logger object understood by {@link exec teen_process.exec}.
|
|
139
|
-
* @typedef {Object} TeenProcessLogger
|
|
140
|
-
* @property {(...args: any[]) => void} debug
|
|
141
|
-
*/
|
|
142
|
-
/**
|
|
143
|
-
* Options for {@link exec teen_process.exec}.
|
|
144
|
-
* @typedef {import('child_process').SpawnOptions & TeenProcessProps} TeenProcessExecOptions
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* The value {@link exec teen_process.exec} resolves to when `isBuffer` is `false`
|
|
148
|
-
* @typedef {Object} TeenProcessExecStringResult
|
|
149
|
-
* @property {string} stdout - Stdout
|
|
150
|
-
* @property {string} stderr - Stderr
|
|
151
|
-
* @property {number?} code - Exit code
|
|
152
|
-
*/
|
|
153
|
-
/**
|
|
154
|
-
* The value {@link exec teen_process.exec} resolves to when `isBuffer` is `true`
|
|
155
|
-
* @typedef {Object} TeenProcessExecBufferResult
|
|
156
|
-
* @property {Buffer} stdout - Stdout
|
|
157
|
-
* @property {Buffer} stderr - Stderr
|
|
158
|
-
* @property {number?} code - Exit code
|
|
159
|
-
*/
|
|
160
|
-
/**
|
|
161
|
-
* Extra props {@link exec teen_process.exec} adds to its error objects
|
|
162
|
-
* @typedef {Object} TeenProcessExecErrorProps
|
|
163
|
-
* @property {string} stdout - STDOUT
|
|
164
|
-
* @property {string} stderr - STDERR
|
|
165
|
-
* @property {number?} code - Exit code
|
|
166
|
-
*/
|
|
167
|
-
/**
|
|
168
|
-
* Error thrown by {@link exec teen_process.exec}
|
|
169
|
-
* @typedef {Error & TeenProcessExecErrorProps} TeenProcessExecError
|
|
170
|
-
*/
|
|
171
|
-
/**
|
|
172
|
-
* @template {{isBuffer?: boolean}} MaybeBuffer
|
|
173
|
-
* @typedef {MaybeBuffer['isBuffer']} BufferProp
|
|
174
|
-
* @private
|
|
175
|
-
*/
|
|
176
133
|
//# sourceMappingURL=exec.js.map
|
package/build/lib/exec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../lib/exec.
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../lib/exec.ts"],"names":[],"mappings":";;;;;AA6CA,oBAgHC;AA7JD,2DAAyC;AACzC,6CAAkC;AAClC,wDAAyB;AACzB,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gBACN,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,GAAG,sBAAsB,IAAI,EAAE,CAAC,EAAE;oBAChF,MAAM;oBACN,MAAM;oBACN,IAAI;iBACL,CAAyB,CAAC;gBAC3B,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACtB,MAAM,EAAC,MAAM,EAAE,MAAM,EAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CACvB,IAAI,KAAK,CAAC,YAAY,GAAG,qBAAqB,IAAI,CAAC,OAAO,IAAI,CAAC,EAC/D,EAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAC,CACL,CAAC;gBAC1B,MAAM,CAAC,GAAG,CAAC,CAAC;gBACZ,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,SAAS,CAAC,CAAC;YAC1C,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/build/lib/helpers.d.ts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Decorates ENOENT error received from a spawn system call
|
|
3
|
-
* with a more descriptive message, so it could be properly handled by a user.
|
|
4
|
-
*
|
|
5
|
-
* @param {NodeJS.ErrnoException} error Original error instance. !!! The instance is mutated after
|
|
6
|
-
* this helper function invocation
|
|
7
|
-
* @param {string} cmd Original command to execute
|
|
8
|
-
* @param {string?} [cwd] Optional path to the current working dir
|
|
9
|
-
* @returns {Promise<NodeJS.ErrnoException>} Mutated error instance with an improved description or an
|
|
10
|
-
* unchanged error instance
|
|
11
|
-
*/
|
|
12
|
-
export function formatEnoent(error: NodeJS.ErrnoException, cmd: string, cwd?: string | null): Promise<NodeJS.ErrnoException>;
|
|
1
|
+
export {};
|
|
13
2
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../lib/helpers.
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../lib/helpers.ts"],"names":[],"mappings":""}
|
package/build/lib/helpers.js
CHANGED
|
@@ -4,20 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.formatEnoent = formatEnoent;
|
|
7
|
-
const
|
|
8
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* with a more descriptive message, so it could be properly handled by a user.
|
|
10
|
+
* Enhances ENOENT errors from spawn with descriptive messages.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
12
|
+
* This is an internal helper that mutates the error object to provide context about:
|
|
13
|
+
* - Invalid working directory paths
|
|
14
|
+
* - Missing executables in PATH
|
|
15
|
+
*
|
|
16
|
+
* @param error - The original ENOENT error from spawn
|
|
17
|
+
* @param cmd - The command that was attempted to execute
|
|
18
|
+
* @param cwd - The working directory used (if any)
|
|
19
|
+
* @returns The same error object with an enhanced message
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
19
22
|
*/
|
|
20
|
-
async function formatEnoent(error, cmd, cwd
|
|
23
|
+
async function formatEnoent(error, cmd, cwd) {
|
|
21
24
|
if (cwd) {
|
|
22
25
|
try {
|
|
23
26
|
const stat = await promises_1.default.stat(cwd);
|
|
@@ -27,13 +30,14 @@ async function formatEnoent(error, cmd, cwd = null) {
|
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
catch (e) {
|
|
30
|
-
|
|
33
|
+
const err = e;
|
|
34
|
+
if (err.code === 'ENOENT') {
|
|
31
35
|
error.message = `The working directory '${cwd}' of '${cmd}' does not exist`;
|
|
32
36
|
return error;
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
|
-
const curDir =
|
|
40
|
+
const curDir = node_path_1.default.resolve(cwd ?? process.cwd());
|
|
37
41
|
const pathMsg = process.env.PATH ?? 'which is not defined for the process';
|
|
38
42
|
error.message = `'${cmd}' executable is not found neither in the process working folder (${curDir}) ` +
|
|
39
43
|
`nor in any folders specified in the PATH environment variable (${pathMsg})`;
|
package/build/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../lib/helpers.
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../lib/helpers.ts"],"names":[],"mappings":";;;;;AAiBA,oCA0BC;AA3CD,0DAA6B;AAC7B,gEAAkC;AAElC;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,YAAY,CAChC,KAA4B,EAC5B,GAAW,EACX,GAAY;IAEZ,IAAI,GAAG,EAAE,CAAC;QACR,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,KAAK,CAAC,OAAO,GAAG,0BAA0B,GAAG,SAAS,GAAG,8BAA8B,CAAC;gBACxF,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,GAAG,GAAG,CAA0B,CAAC;YACvC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC1B,KAAK,CAAC,OAAO,GAAG,0BAA0B,GAAG,SAAS,GAAG,kBAAkB,CAAC;gBAC5E,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,mBAAI,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,sCAAsC,CAAC;IAC3E,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,oEAAoE,MAAM,IAAI;QACnG,kEAAkE,OAAO,GAAG,CAAC;IAC/E,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/build/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
import * as cp from 'child_process';
|
|
6
|
-
import * as spIndex from './subprocess';
|
|
1
|
+
export { spawn } from 'node:child_process';
|
|
2
|
+
export { SubProcess } from './subprocess';
|
|
3
|
+
export { exec } from './exec';
|
|
4
|
+
export type { TeenProcessExecOptions, ExecResult, SubProcessOptions } from './types';
|
|
7
5
|
//# sourceMappingURL=index.d.ts.map
|
package/build/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,YAAY,EACV,sBAAsB,EACtB,UAAU,EACV,iBAAiB,EAClB,MAAM,SAAS,CAAC"}
|
package/build/lib/index.js
CHANGED
|
@@ -1,46 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
exports.SubProcess = SubProcess;
|
|
44
|
-
const { exec } = execIndex;
|
|
45
|
-
exports.exec = exec;
|
|
3
|
+
exports.exec = exports.SubProcess = exports.spawn = void 0;
|
|
4
|
+
var node_child_process_1 = require("node:child_process");
|
|
5
|
+
Object.defineProperty(exports, "spawn", { enumerable: true, get: function () { return node_child_process_1.spawn; } });
|
|
6
|
+
var subprocess_1 = require("./subprocess");
|
|
7
|
+
Object.defineProperty(exports, "SubProcess", { enumerable: true, get: function () { return subprocess_1.SubProcess; } });
|
|
8
|
+
var exec_1 = require("./exec");
|
|
9
|
+
Object.defineProperty(exports, "exec", { enumerable: true, get: function () { return exec_1.exec; } });
|
|
46
10
|
//# sourceMappingURL=index.js.map
|
package/build/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,yDAAyC;AAAjC,2GAAA,KAAK,OAAA;AACb,2CAAwC;AAAhC,wGAAA,UAAU,OAAA;AAClB,+BAA4B;AAApB,4FAAA,IAAI,OAAA"}
|