diff --git a/lib/index.js b/lib/index.js index 1339820..4f89db2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,16 +23,16 @@ module.exports = (compiler, opts) => { const compile = (comp) => { const compilerName = comp.name || ''; - 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) { diff --git a/lib/socket-server.js b/lib/socket-server.js index 29be1da..6076691 100644 --- a/lib/socket-server.js +++ b/lib/socket-server.js @@ -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); } }); } diff --git a/test/socket-server.test.js b/test/socket-server.test.js index f4cadcc..3f6d57a 100644 --- a/test/socket-server.test.js +++ b/test/socket-server.test.js @@ -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;