Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show plugin name in progress log #3337

Merged
merged 4 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion client-src/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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