Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ module.exports = (compiler, opts) => {

const compile = (comp) => {
const compilerName = comp.name || '<unnamed compiler>';
options.stats = null;
options.lastJsonStats = null;
log.info('webpack: Compiling...');
server.broadcast(payload('compile', { compilerName }));
};

const done = (result) => {
const done = (stats) => {
log.info('webpack: Compiling Done');
options.stats = result;

const jsonStats = options.stats.toJson(options.stats);
const jsonStats = stats.toJson(options.stats);
options.lastJsonStats = jsonStats;

/* istanbul ignore if */
if (!jsonStats) {
Expand Down
11 changes: 2 additions & 9 deletions lib/socket-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,8 @@ function onConnection(server, options) {

// only send stats to newly connected clients, if no previous clients have
// connected and stats has been modified by webpack
if (options.stats && options.stats.toJson && server.clients.size === 1) {
const jsonStats = options.stats.toJson(options.stats);

/* istanbul ignore if */
if (!jsonStats) {
options.log.error('Client Connection: `stats` is undefined');
}

server.send(jsonStats);
if (options.lastJsonStats && server.clients.size === 1) {
server.send(options.lastJsonStats);
}
});
}
Expand Down
11 changes: 5 additions & 6 deletions test/socket-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ describe('socket server', () => {
});

test('send via stats', (done) => {
const stats = {
context: process.cwd(),
toJson: () => {
return { hash: '111111', warnings: [] };
},
const lastJsonStats = {
hash: '111111',
warnings: [],
};
const opts = getOptions({ logLevel: 'silent', stats });
const opts = getOptions({ logLevel: 'silent' });
opts.lastJsonStats = lastJsonStats;
const server = getServer(opts);
const { close } = server;

Expand Down