All files / webpack-hot-socketio hook-handler.js

100% Statements 21/21
66.67% Branches 4/6
100% Functions 4/4
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x 1x   7x 7x 7x 7x 3x 3x     7x 7x 1x 1x 6x 6x 6x       4x 4x 4x     7x 7x 7x      
const fs = require('fs');
module.exports = class HookHandler {
	constructor(compiler, socketHandler, opts) {
		this.lastStatsResult = null;
		this.opts = opts;
		this.socketHandler = socketHandler;
		this.socketHandler.listen('connect', () => {
			Eif (this.lastStatsResult) {
				this.socketHandler.sendStats('sync', this.lastStatsResult);
			}
		});
		this.log = this.opts.log;
		if (compiler.hooks) {
			compiler.hooks.invalid.tap('webpack-hot-socketio', this.onInvalid.bind(this));
			compiler.hooks.done.tap('webpack-hot-socketio', this.onDone.bind(this));
		} else Eif (compiler.plugin) {
			compiler.plugin('invalid', this.onInvalid.bind(this));
			compiler.plugin('done', this.onDone.bind(this));
		}
	}
	onInvalid() {
		this.log('webpack building...');
		this.lastStatsResult = null;
		this.socketHandler.sendStats('building');
	}
	onDone(statsResult) {
		this.log('webpack built.');
		this.lastStatsResult = statsResult;
		this.socketHandler.sendStats('built', statsResult);
	}
}