@vbarbarosh/node-helpers 2.0.1 → 2.0.2
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 +4 -7
- package/src/fs_read_buffer.js +8 -0
- package/src/shell.js +12 -0
- package/src/shell_spawn.js +33 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@vbarbarosh/node-helpers",
|
|
5
|
-
"version": "2.0.
|
|
5
|
+
"version": "2.0.2",
|
|
6
6
|
"description": "A set of helpers for JavaScript/Node.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"src"
|
|
@@ -23,17 +23,14 @@
|
|
|
23
23
|
"url": "https://github.com/vbarbarosh/node-helpers/issues"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"axios": "^
|
|
26
|
+
"axios": "^1.3.2",
|
|
27
27
|
"bluebird": "^3.7.2",
|
|
28
28
|
"form-data": "^4.0.0",
|
|
29
|
-
"json-stable-stringify": "^1.0.
|
|
29
|
+
"json-stable-stringify": "^1.0.2",
|
|
30
30
|
"sanitize-filename": "^1.6.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"
|
|
34
|
-
"@babel/register": "^7.14.5",
|
|
35
|
-
"babel": "^6.23.0",
|
|
36
|
-
"mocha": "^9.0.2",
|
|
33
|
+
"mocha": "^10.2.0",
|
|
37
34
|
"throttle": "^1.0.3"
|
|
38
35
|
}
|
|
39
36
|
}
|
package/src/shell.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const child_process = require('child_process');
|
|
2
|
+
|
|
3
|
+
function shell(args, options)
|
|
4
|
+
{
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
child_process.execFile(args[0], args.slice(1), options, function (error, stdout, stderr) {
|
|
7
|
+
error ? reject(error) : resolve({stdout, stderr});
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = shell;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const child_process = require('child_process');
|
|
2
|
+
|
|
3
|
+
function shell_spawn(args, options)
|
|
4
|
+
{
|
|
5
|
+
const proc = child_process.spawn(args[0], args.slice(1), options);
|
|
6
|
+
let promise;
|
|
7
|
+
proc.promise = function () {
|
|
8
|
+
let is_pending = true;
|
|
9
|
+
return promise = promise || new Promise(function (resolve, reject) {
|
|
10
|
+
proc.on('error', on_error);
|
|
11
|
+
proc.on('exit', on_exit);
|
|
12
|
+
function on_error(error) {
|
|
13
|
+
if (is_pending) {
|
|
14
|
+
is_pending = false;
|
|
15
|
+
proc.off('error', on_error);
|
|
16
|
+
proc.off('exit', on_exit);
|
|
17
|
+
reject(error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function on_exit(code, signal) {
|
|
21
|
+
if (is_pending) {
|
|
22
|
+
is_pending = false;
|
|
23
|
+
proc.off('error', on_error);
|
|
24
|
+
proc.off('exit', on_exit);
|
|
25
|
+
resolve({code, signal});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
return proc;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = shell_spawn;
|