@gnuechtel/shared-util 1.0.2 → 1.1.0-13211763982
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/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gnuechtel/shared-util",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-13211763982",
|
|
4
4
|
"description": "Shared utility functions for gnuechtel projects",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://gitlab.com/gnuechtel/open-source.git",
|
|
9
|
+
"directory": "libs/shared-util"
|
|
10
|
+
},
|
|
6
11
|
"dependencies": {
|
|
7
12
|
"tslib": "^2.3.0",
|
|
8
13
|
"wait-on": "^7.0.1"
|
|
@@ -3,12 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createProcess = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
|
+
const outputLimit = 200000;
|
|
7
|
+
function appendOutput(current, next) {
|
|
8
|
+
const nextAsString = Buffer.isBuffer(next) ? next.toString() : `${next || ''}`;
|
|
9
|
+
if (!nextAsString)
|
|
10
|
+
return current;
|
|
11
|
+
const merged = current + nextAsString;
|
|
12
|
+
return merged.length <= outputLimit ? merged : merged.slice(-outputLimit);
|
|
13
|
+
}
|
|
6
14
|
function createProcess(command_1, params_1) {
|
|
7
15
|
return tslib_1.__awaiter(this, arguments, void 0, function* (command, params, processOptions = undefined) {
|
|
8
16
|
return new Promise((resolve, reject) => {
|
|
9
17
|
var _a, _b;
|
|
10
18
|
let processState;
|
|
11
19
|
let childProcessKilled = false;
|
|
20
|
+
let stdoutOutput = '';
|
|
21
|
+
let stderrOutput = '';
|
|
12
22
|
const isSilent = () => (processOptions === null || processOptions === void 0 ? void 0 : processOptions.silent) || processState === 'stopped'; // ignore output when process was stopped or silent is true
|
|
13
23
|
const nameOrCommand = (processOptions === null || processOptions === void 0 ? void 0 : processOptions.name) || command;
|
|
14
24
|
const options = { env: Object.assign({}, process.env), cwd: processOptions === null || processOptions === void 0 ? void 0 : processOptions.cwd };
|
|
@@ -28,6 +38,7 @@ function createProcess(command_1, params_1) {
|
|
|
28
38
|
return; // Already stopped
|
|
29
39
|
processState = 'stopping';
|
|
30
40
|
childProcessKilled = childProcess.kill();
|
|
41
|
+
removeProcessExitListeners();
|
|
31
42
|
if (processOptions === null || processOptions === void 0 ? void 0 : processOptions.onStopping)
|
|
32
43
|
processOptions.onStopping(childProcessKilled);
|
|
33
44
|
processState = 'stopped';
|
|
@@ -37,11 +48,18 @@ function createProcess(command_1, params_1) {
|
|
|
37
48
|
};
|
|
38
49
|
}
|
|
39
50
|
const processExitListener = () => childProcessKilled || childProcess.kill(); // Ensure the child process is killed when the parent exits
|
|
51
|
+
const removeProcessExitListeners = () => {
|
|
52
|
+
process.off('exit', processExitListener);
|
|
53
|
+
process.off('SIGTERM', processExitListener);
|
|
54
|
+
process.off('SIGINT', processExitListener);
|
|
55
|
+
process.off('SIGHUP', processExitListener);
|
|
56
|
+
};
|
|
40
57
|
process.on('exit', processExitListener);
|
|
41
58
|
process.on('SIGTERM', processExitListener);
|
|
42
59
|
process.on('SIGINT', processExitListener);
|
|
43
60
|
process.on('SIGHUP', processExitListener);
|
|
44
61
|
(_a = childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
62
|
+
stdoutOutput = appendOutput(stdoutOutput, data);
|
|
45
63
|
if (!isSilent())
|
|
46
64
|
process.stdout.write(data);
|
|
47
65
|
const dataAsString = data.toString();
|
|
@@ -53,6 +71,7 @@ function createProcess(command_1, params_1) {
|
|
|
53
71
|
}
|
|
54
72
|
});
|
|
55
73
|
(_b = childProcess === null || childProcess === void 0 ? void 0 : childProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
74
|
+
stderrOutput = appendOutput(stderrOutput, data);
|
|
56
75
|
if (!isSilent())
|
|
57
76
|
process.stderr.write(data);
|
|
58
77
|
});
|
|
@@ -66,10 +85,17 @@ function createProcess(command_1, params_1) {
|
|
|
66
85
|
}
|
|
67
86
|
const messagePart2 = exitCode ? `with exit code ${exitCode}` : `and an error occurred: ${err.message}`;
|
|
68
87
|
console.error(`${nameOrCommand} was ${processState} ${messagePart2}`);
|
|
69
|
-
|
|
88
|
+
const processError = new Error(`Command failed: ${command}\nParameters: ${paramsAsString}\nExit code: ${exitCode}`);
|
|
89
|
+
const errorWithOutput = processError;
|
|
90
|
+
errorWithOutput.stdout = stdoutOutput;
|
|
91
|
+
errorWithOutput.stderr = stderrOutput;
|
|
92
|
+
errorWithOutput.cause = err;
|
|
93
|
+
reject(errorWithOutput);
|
|
70
94
|
};
|
|
71
95
|
childProcess.on('error', rejectConditionallyWithMessage);
|
|
72
96
|
childProcess.on('exit', (exitCode) => {
|
|
97
|
+
processState = 'stopped';
|
|
98
|
+
removeProcessExitListeners();
|
|
73
99
|
rejectConditionallyWithMessage(undefined, exitCode); // reject only if exit code is not zero
|
|
74
100
|
resolve(processInstance()); // finally we resolve here, when no background process was started or readyWhen did not match
|
|
75
101
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-process.js","sourceRoot":"","sources":["../../../../../libs/shared-util/src/lib/create-process.ts"],"names":[],"mappings":";;;;AAAA,iDAAyD;AAsBzD,SAAsB,aAAa;iEACjC,OAAe,EACf,MAAgB,EAChB,iBAA6C,SAAS;QAEtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;;YACrC,IAAI,YAA0B,CAAC;YAC/B,IAAI,kBAAkB,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"create-process.js","sourceRoot":"","sources":["../../../../../libs/shared-util/src/lib/create-process.ts"],"names":[],"mappings":";;;;AAAA,iDAAyD;AAsBzD,MAAM,WAA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