zarro 1.115.1 → 1.116.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/gulp-tasks/modules/spawn.js +28 -19
- package/gulp-tasks/modules/spawn.ts +37 -28
- package/package.json +1 -1
|
@@ -60,7 +60,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
60
60
|
try {
|
|
61
61
|
const child = child_process.spawn(executable, args, opts);
|
|
62
62
|
if (!child) {
|
|
63
|
-
|
|
63
|
+
reject(new Error(`unable to spawn ${executable} with args [${args.join(",")}]`));
|
|
64
64
|
}
|
|
65
65
|
debug(child);
|
|
66
66
|
const stdout = [];
|
|
@@ -73,26 +73,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
73
73
|
e.stdout = stdout;
|
|
74
74
|
reject(e);
|
|
75
75
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
result.stderr = stderr;
|
|
80
|
-
result.stdout = stdout;
|
|
81
|
-
if (code === 0) {
|
|
82
|
-
resolve(result);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
const err = new Error(`"${[executable]
|
|
86
|
-
.concat(args)
|
|
87
|
-
.join(" ")}" failed with exit code ${code}`);
|
|
88
|
-
err.exitCode = code;
|
|
89
|
-
err.stdout = stdout;
|
|
90
|
-
err.stderr = stderr;
|
|
91
|
-
return reject(err);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
76
|
+
let exited = false;
|
|
77
|
+
child.on("exit", generateExitHandler("exit"));
|
|
78
|
+
child.on("close", generateExitHandler("close"));
|
|
94
79
|
setupIoHandler(stdOutWriter, child.stdout, stdout, opts.lineBuffer);
|
|
95
80
|
setupIoHandler(stdErrWriter, child.stderr, stderr, opts.lineBuffer);
|
|
81
|
+
function generateExitHandler(eventName) {
|
|
82
|
+
return (code) => {
|
|
83
|
+
if (exited) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
exited = true;
|
|
87
|
+
debug(`child ${eventName}s: ${code}`);
|
|
88
|
+
result.exitCode = code;
|
|
89
|
+
result.stderr = stderr;
|
|
90
|
+
result.stdout = stdout;
|
|
91
|
+
if (code === 0) {
|
|
92
|
+
resolve(result);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const err = new Error(`"${[executable]
|
|
96
|
+
.concat(args)
|
|
97
|
+
.join(" ")}" failed with exit code ${code}`);
|
|
98
|
+
err.exitCode = code;
|
|
99
|
+
err.stdout = stdout;
|
|
100
|
+
err.stderr = stderr;
|
|
101
|
+
reject(err);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
96
105
|
}
|
|
97
106
|
catch (e) {
|
|
98
107
|
reject(`Unable to spawn process: ${e}\n${e.stack}`);
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import * as buffer from "buffer";
|
|
2
1
|
import { IoConsumer } from "./exec";
|
|
3
2
|
import { Readable } from "stream";
|
|
4
3
|
|
|
5
|
-
(function
|
|
4
|
+
(function() {
|
|
6
5
|
// use for spawning actual processes.
|
|
7
6
|
// You must use exec if you want to run batch files
|
|
8
7
|
|
|
9
|
-
const tryLoadDebug = function
|
|
8
|
+
const tryLoadDebug = function() {
|
|
10
9
|
try {
|
|
11
10
|
return require("debug")("spawn");
|
|
12
11
|
} catch (e) {
|
|
13
|
-
return function
|
|
12
|
+
return function() {
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
15
|
},
|
|
@@ -20,7 +19,7 @@ import { Readable } from "stream";
|
|
|
20
19
|
child_process = require("child_process");
|
|
21
20
|
|
|
22
21
|
const defaultOptions = {
|
|
23
|
-
stdio: [process.stdin, process.stdout, process.stderr],
|
|
22
|
+
stdio: [ process.stdin, process.stdout, process.stderr ],
|
|
24
23
|
cwd: process.cwd(),
|
|
25
24
|
shell: true,
|
|
26
25
|
lineBuffer: true
|
|
@@ -36,7 +35,7 @@ import { Readable } from "stream";
|
|
|
36
35
|
opts = Object.assign({}, defaultOptions, opts);
|
|
37
36
|
|
|
38
37
|
if (!opts.stdio) {
|
|
39
|
-
opts.stdio = [...defaultOptions.stdio];
|
|
38
|
+
opts.stdio = [ ...defaultOptions.stdio ];
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
let
|
|
@@ -46,7 +45,7 @@ import { Readable } from "stream";
|
|
|
46
45
|
stderrFnSpecified = typeof opts.stderr === "function";
|
|
47
46
|
|
|
48
47
|
if (stdoutFnSpecified || stderrFnSpecified && !Array.isArray(opts.stdio)) {
|
|
49
|
-
opts.stdio = [...defaultOptions.stdio];
|
|
48
|
+
opts.stdio = [ ...defaultOptions.stdio ];
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
if (stdoutFnSpecified) {
|
|
@@ -80,7 +79,7 @@ import { Readable } from "stream";
|
|
|
80
79
|
try {
|
|
81
80
|
const child = child_process.spawn(executable, args, opts);
|
|
82
81
|
if (!child) {
|
|
83
|
-
|
|
82
|
+
reject(new Error(`unable to spawn ${ executable } with args [${ args.join(",") }]`));
|
|
84
83
|
}
|
|
85
84
|
debug(child);
|
|
86
85
|
const stdout = [] as string[];
|
|
@@ -88,34 +87,44 @@ import { Readable } from "stream";
|
|
|
88
87
|
child.on("error", (err: string) => {
|
|
89
88
|
debug(`child error: ${ err }`);
|
|
90
89
|
const e = new Error(
|
|
91
|
-
`"${ [executable].concat(args).join(" ") }" failed with "${ err }"`
|
|
90
|
+
`"${ [ executable ].concat(args).join(" ") }" failed with "${ err }"`
|
|
92
91
|
) as SpawnError;
|
|
93
92
|
e.exitCode = -1;
|
|
94
93
|
e.stderr = stderr;
|
|
95
94
|
e.stdout = stdout;
|
|
96
95
|
reject(e);
|
|
97
96
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
result.stderr = stderr;
|
|
102
|
-
result.stdout = stdout;
|
|
103
|
-
if (code === 0) {
|
|
104
|
-
resolve(result);
|
|
105
|
-
} else {
|
|
106
|
-
const err = new Error(
|
|
107
|
-
`"${ [executable]
|
|
108
|
-
.concat(args)
|
|
109
|
-
.join(" ") }" failed with exit code ${ code }`
|
|
110
|
-
) as SpawnError;
|
|
111
|
-
err.exitCode = code;
|
|
112
|
-
err.stdout = stdout;
|
|
113
|
-
err.stderr = stderr;
|
|
114
|
-
return reject(err);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
97
|
+
let exited = false;
|
|
98
|
+
child.on("exit", generateExitHandler("exit"));
|
|
99
|
+
child.on("close", generateExitHandler("close"));
|
|
117
100
|
setupIoHandler(stdOutWriter, child.stdout, stdout, opts.lineBuffer);
|
|
118
101
|
setupIoHandler(stdErrWriter, child.stderr, stderr, opts.lineBuffer)
|
|
102
|
+
|
|
103
|
+
function generateExitHandler(eventName: string): (code: number) => void {
|
|
104
|
+
return (code: number) => {
|
|
105
|
+
if (exited) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
exited = true;
|
|
109
|
+
debug(`child ${ eventName }s: ${ code }`);
|
|
110
|
+
result.exitCode = code;
|
|
111
|
+
result.stderr = stderr;
|
|
112
|
+
result.stdout = stdout;
|
|
113
|
+
if (code === 0) {
|
|
114
|
+
resolve(result);
|
|
115
|
+
} else {
|
|
116
|
+
const err = new Error(
|
|
117
|
+
`"${ [ executable ]
|
|
118
|
+
.concat(args)
|
|
119
|
+
.join(" ") }" failed with exit code ${ code }`
|
|
120
|
+
) as SpawnError;
|
|
121
|
+
err.exitCode = code;
|
|
122
|
+
err.stdout = stdout;
|
|
123
|
+
err.stderr = stderr;
|
|
124
|
+
reject(err);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
119
128
|
} catch (e) {
|
|
120
129
|
reject(`Unable to spawn process: ${ e }\n${ (e as Error).stack }`);
|
|
121
130
|
}
|