Skip to content

Commit

Permalink
Add ack and only log disconnect if not at build success.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-roemer committed Apr 17, 2019
1 parent 893b762 commit c819882
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
8 changes: 4 additions & 4 deletions bin/webpack-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ const main = (module.exports = opts => {
server.on("connection", socket => {
socket.emit("mode", { minimal: program.minimal || false });

socket.on("message", message => {
socket.on("message", (message, ack) => {
if (message.type !== "log") {
dashboard.setData(message);
dashboard.setData(message, ack);
}
});
});
Expand Down Expand Up @@ -95,8 +95,8 @@ const main = (module.exports = opts => {
});
} else {
server.on("connection", socket => {
socket.on("message", message => {
dashboard.setData(message);
socket.on("message", (message, ack) => {
dashboard.setData(message, ack);
});
});
}
Expand Down
7 changes: 6 additions & 1 deletion dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Dashboard {
this.screen.render();
}

setData(dataArray) {
setData(dataArray, ack) {
dataArray
.map(data =>
data.error
Expand All @@ -105,6 +105,11 @@ class Dashboard {
});

this.screen.render();

// Send ack back if requested.
if (ack) {
ack();
}
}

setProgress(data) {
Expand Down
60 changes: 34 additions & 26 deletions plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class DashboardPlugin {

apply(compiler) {
let handler = this.handler;
let reachedSuccess = false;
let timer;

if (!handler) {
Expand All @@ -90,8 +91,10 @@ class DashboardPlugin {
console.log(err);
});
this.socket.on("disconnect", () => {
// eslint-disable-next-line no-console
console.log("Socket.io disconnected.");
if (!reachedSuccess) {
// eslint-disable-next-line no-console
console.log("Socket.io disconnected before completing build lifecycle.");
}
});
}

Expand Down Expand Up @@ -180,32 +183,37 @@ class DashboardPlugin {
warnings: true
};

handler([
{
type: "status",
value: "Success"
},
{
type: "progress",
value: 1
},
{
type: "operations",
value: `idle${getTimeMessage(timer)}`
},
{
type: "stats",
value: {
errors: stats.hasErrors(),
warnings: stats.hasWarnings(),
data: stats.toJson(statsJsonOptions)
handler(
[
{
type: "status",
value: "Success"
},
{
type: "progress",
value: 1
},
{
type: "operations",
value: `idle${getTimeMessage(timer)}`
},
{
type: "stats",
value: {
errors: stats.hasErrors(),
warnings: stats.hasWarnings(),
data: stats.toJson(statsJsonOptions)
}
},
{
type: "log",
value: stats.toString(statsOptions)
}
},
{
type: "log",
value: stats.toString(statsOptions)
],
() => {
reachedSuccess = true;
}
]);
);

if (!this.minimal) {
this.observeMetrics(stats).subscribe({
Expand Down

0 comments on commit c819882

Please sign in to comment.