Skip to content

Commit

Permalink
fix: show plugin name in progress log (#3337)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed May 24, 2021
1 parent 257e2eb commit b8a0932
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
6 changes: 5 additions & 1 deletion client-src/index.js
Expand Up @@ -106,7 +106,11 @@ const onSocketMessage = {
},
'progress-update': function progressUpdate(data) {
if (options.progress) {
log.info(`${data.percent}% - ${data.msg}.`);
log.info(
`${data.pluginName ? `[${data.pluginName}] ` : ''}${data.percent}% - ${
data.msg
}.`
);
}

sendMessage('Progress', data);
Expand Down
10 changes: 7 additions & 3 deletions lib/Server.js
Expand Up @@ -91,7 +91,7 @@ class Server {
setupProgressPlugin() {
const { ProgressPlugin } = require('webpack');

new ProgressPlugin((percent, msg, addInfo) => {
new ProgressPlugin((percent, msg, addInfo, pluginName) => {
percent = Math.floor(percent * 100);

if (percent === 100) {
Expand All @@ -102,10 +102,14 @@ class Server {
msg = `${msg} (${addInfo})`;
}

this.sockWrite(this.sockets, 'progress-update', { percent, msg });
this.sockWrite(this.sockets, 'progress-update', {
percent,
msg,
pluginName,
});

if (this.server) {
this.server.emit('progress-update', { percent, msg });
this.server.emit('progress-update', { percent, msg, pluginName });
}
}).apply(this.compiler);
}
Expand Down
4 changes: 4 additions & 0 deletions test/client/__snapshots__/index.test.js.snap.webpack4
Expand Up @@ -58,6 +58,10 @@ exports[`index should run onSocketMessage.progress and onSocketMessage['progress

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

exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name 1`] = `"Progress"`;

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

exports[`index should run onSocketMessage.warnings 1`] = `"Warnings while compiling."`;

exports[`index should run onSocketMessage.warnings 2`] = `"Warnings"`;
Expand Down
4 changes: 4 additions & 0 deletions test/client/__snapshots__/index.test.js.snap.webpack5
Expand Up @@ -58,6 +58,10 @@ exports[`index should run onSocketMessage.progress and onSocketMessage['progress

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

exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name 1`] = `"Progress"`;

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

exports[`index should run onSocketMessage.warnings 1`] = `"Warnings while compiling."`;

exports[`index should run onSocketMessage.warnings 2`] = `"Warnings"`;
Expand Down
19 changes: 19 additions & 0 deletions test/client/index.test.js
Expand Up @@ -128,6 +128,25 @@ describe('index', () => {
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
});

test("should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name", () => {
onSocketMessage.progress(false);
onSocketMessage['progress-update']({
msg: 'mock-msg',
percent: '12',
pluginName: 'mock-plugin',
});
expect(log.log.info).not.toBeCalled();
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();

onSocketMessage.progress(true);
onSocketMessage['progress-update']({
msg: 'mock-msg',
percent: '12',
pluginName: 'mock-plugin',
});
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
});

test('should run onSocketMessage.overlay with an argument is Object', () => {
onSocketMessage.overlay({
warnings: true,
Expand Down

0 comments on commit b8a0932

Please sign in to comment.