Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 55f4bd2

Browse files
Capture errors and timeouts that occur ing angular-cli-middleware.js
1 parent fbe41f4 commit 55f4bd2

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/Microsoft.AspNetCore.SpaServices.Extensions/Content/Node/angular-cli-middleware.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var childProcess = require('child_process');
55
var net = require('net');
66
var readline = require('readline');
77
var url = require('url');
8+
var timeoutSeconds = 50;
89

910
module.exports = {
1011
startAngularCliBuilder: function startAngularCliBuilder(callback, appName) {
@@ -14,7 +15,9 @@ module.exports = {
1415
'--watch'
1516
]);
1617
proc.stdout.pipe(process.stdout);
17-
waitForLine(proc.stdout, /chunk/, function () { callback() });
18+
waitForLine(proc.stdout, /chunk/, function () { callback() }, timeoutSeconds * 1000, function () {
19+
callback('The ng build process timed out after ' + timeoutSeconds + ' seconds. Check the output log for error information.');
20+
});
1821
},
1922

2023
startAngularCliServer: function startAngularCliServer(callback, options) {
@@ -42,20 +45,36 @@ module.exports = {
4245
callback(null, {
4346
Port: parseInt(devServerUrl.port)
4447
});
48+
}, timeoutSeconds * 1000, function () {
49+
callback('The @angular/cli service did not start within the timeout period of ' + timeoutSeconds + ' seconds. Check the output log for error information.');
4550
});
4651
});
4752
}
4853
};
4954

50-
function waitForLine(stream, regex, callback) {
55+
function waitForLine(stream, regex, successCallback, timeoutMilliseconds, timeoutCallback) {
5156
var lineReader = readline.createInterface({ input: stream });
5257
var listener = function (line) {
5358
var matches = regex.exec(line);
5459
if (matches) {
5560
lineReader.removeListener('line', listener);
56-
callback(matches);
61+
if (timeoutId !== null) {
62+
clearTimeout(timeoutId);
63+
}
64+
successCallback(matches);
5765
}
5866
};
67+
68+
var timeoutId = null;
69+
if (timeoutMilliseconds > 0) {
70+
timeoutId = setTimeout(function () {
71+
lineReader.removeListener('line', listener);
72+
if (timeoutCallback) {
73+
timeoutCallback();
74+
}
75+
}, timeoutMilliseconds);
76+
}
77+
5978
lineReader.addListener('line', listener);
6079
}
6180

0 commit comments

Comments
 (0)