Skip to content

Commit 03a592f

Browse files
committed
use spawning for child process, update version
1 parent de7613a commit 03a592f

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-7z-archive",
3-
"version": "0.9.11",
3+
"version": "1.0.0",
44
"description": "ESM front-end to 7-Zip, featuring alternative full 7z CLI tools, binaries for Linux, Windows, Mac OSX, seamlessly create 7zip SFX self extracting archives targeting different platforms.",
55
"type": "module",
66
"main": "lib/index.mjs",

util/run.mjs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {
33
EOL
44
} from 'os';
5-
import { spawn } from 'child_process';
5+
import { spawning } from 'node-sys';
66
import when from 'when';
77
import {
88
normalize,
@@ -92,34 +92,38 @@ export default function (binary = '7z', command = null, switches = {}, override
9292
// error's message. Otherwise progress with stdout message.
9393
let err;
9494
let reg = new RegExp('Error:(' + EOL + '|)?(.*)', 'i');
95+
let onprogress = (object) => {
96+
progress(object.output);
97+
return args;
98+
};
99+
100+
let onerror = (data) => {
101+
let res = reg.exec(data);
102+
if (res) {
103+
err = new Error(res[2].substr(0, res[2].length - 1));
104+
return err;
105+
}
106+
};
107+
95108
let res = {
96109
cmd: cmd,
97110
args: args,
98111
options: {
99-
stdio: 'pipe'
112+
stdio: 'pipe',
113+
onprogress: onprogress,
114+
onerror: onerror
100115
}
101116
};
102117

103-
//console.log('>> ', res.cmd, res.args.join(' '), res.options,' <<');
104-
let run = spawn(res.cmd, res.args, res.options);
105-
run.stderr.on('data', function (data) {
106-
let res = reg.exec(data.toString());
107-
if (res) {
108-
err = new Error(res[2].substr(0, res[2].length - 1));
109-
}
110-
});
111-
run.stdout.on('data', function (data) {
112-
return progress(data.toString());
113-
});
114-
run.on('error', function (err) {
115-
reject(err);
116-
});
117-
run.on('close', function (code) {
118-
if (code === 0) {
119-
return fulfill(args);
120-
}
121-
return reject(err, code);
122-
});
118+
spawning(res.cmd, res.args, res.options)
119+
.then((data) => {
120+
if (data === args)
121+
return fulfill(args);
123122

123+
return reject(err);
124+
})
125+
.catch((err) => {
126+
return reject(err);
127+
});
124128
});
125129
};

0 commit comments

Comments
 (0)