Skip to content

Commit b8a0932

Browse files
authored
fix: show plugin name in progress log (#3337)
1 parent 257e2eb commit b8a0932

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

client-src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ const onSocketMessage = {
106106
},
107107
'progress-update': function progressUpdate(data) {
108108
if (options.progress) {
109-
log.info(`${data.percent}% - ${data.msg}.`);
109+
log.info(
110+
`${data.pluginName ? `[${data.pluginName}] ` : ''}${data.percent}% - ${
111+
data.msg
112+
}.`
113+
);
110114
}
111115

112116
sendMessage('Progress', data);

lib/Server.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Server {
9191
setupProgressPlugin() {
9292
const { ProgressPlugin } = require('webpack');
9393

94-
new ProgressPlugin((percent, msg, addInfo) => {
94+
new ProgressPlugin((percent, msg, addInfo, pluginName) => {
9595
percent = Math.floor(percent * 100);
9696

9797
if (percent === 100) {
@@ -102,10 +102,14 @@ class Server {
102102
msg = `${msg} (${addInfo})`;
103103
}
104104

105-
this.sockWrite(this.sockets, 'progress-update', { percent, msg });
105+
this.sockWrite(this.sockets, 'progress-update', {
106+
percent,
107+
msg,
108+
pluginName,
109+
});
106110

107111
if (this.server) {
108-
this.server.emit('progress-update', { percent, msg });
112+
this.server.emit('progress-update', { percent, msg, pluginName });
109113
}
110114
}).apply(this.compiler);
111115
}

test/client/__snapshots__/index.test.js.snap.webpack4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ exports[`index should run onSocketMessage.progress and onSocketMessage['progress
5858

5959
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] 2`] = `"12% - mock-msg."`;
6060

61+
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name 1`] = `"Progress"`;
62+
63+
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name 2`] = `"[mock-plugin] 12% - mock-msg."`;
64+
6165
exports[`index should run onSocketMessage.warnings 1`] = `"Warnings while compiling."`;
6266

6367
exports[`index should run onSocketMessage.warnings 2`] = `"Warnings"`;

test/client/__snapshots__/index.test.js.snap.webpack5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ exports[`index should run onSocketMessage.progress and onSocketMessage['progress
5858

5959
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] 2`] = `"12% - mock-msg."`;
6060

61+
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name 1`] = `"Progress"`;
62+
63+
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name 2`] = `"[mock-plugin] 12% - mock-msg."`;
64+
6165
exports[`index should run onSocketMessage.warnings 1`] = `"Warnings while compiling."`;
6266

6367
exports[`index should run onSocketMessage.warnings 2`] = `"Warnings"`;

test/client/index.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ describe('index', () => {
128128
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
129129
});
130130

131+
test("should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name", () => {
132+
onSocketMessage.progress(false);
133+
onSocketMessage['progress-update']({
134+
msg: 'mock-msg',
135+
percent: '12',
136+
pluginName: 'mock-plugin',
137+
});
138+
expect(log.log.info).not.toBeCalled();
139+
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();
140+
141+
onSocketMessage.progress(true);
142+
onSocketMessage['progress-update']({
143+
msg: 'mock-msg',
144+
percent: '12',
145+
pluginName: 'mock-plugin',
146+
});
147+
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
148+
});
149+
131150
test('should run onSocketMessage.overlay with an argument is Object', () => {
132151
onSocketMessage.overlay({
133152
warnings: true,

0 commit comments

Comments
 (0)