Skip to content

Commit

Permalink
feat(webpack): add webpack blocker
Browse files Browse the repository at this point in the history
 - Prevents  karma from running tests until build is finished
  • Loading branch information
ibash authored and joshwiens committed Jan 14, 2017
1 parent 67d8845 commit 03f6495
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var webpackDevMiddleware = require("webpack-dev-middleware");
var webpack = require("webpack");
var SingleEntryDependency = require("webpack/lib/dependencies/SingleEntryDependency");

var blocked = []
var isBlocked = false

function Plugin(
webpackOptions, /* config.webpack */
webpackServerOptions, /* config.webpackServer */
Expand Down Expand Up @@ -61,6 +64,10 @@ function Plugin(
compiler.plugin("make", this.make.bind(this));
}, this);

compiler.plugin("compile", function() {
isBlocked = true
})

compiler.plugin("done", function(stats) {
var applyStats = Array.isArray(stats.stats) ? stats.stats : [stats];
var assets = [];
Expand All @@ -84,6 +91,12 @@ function Plugin(
cb();
});
}

isBlocked = false
for (var i = 0; i < blocked.length; i++) {
blocked[i]();
}
blocked = []
}.bind(this));
compiler.plugin("invalid", function() {
if(!this.waiting) this.waiting = [];
Expand Down Expand Up @@ -188,7 +201,18 @@ function createPreprocesor( /* config.basePath */ basePath, webpackPlugin) {
};
}

function createWebpackBlocker() {
return function (request, response, next) {
if (isBlocked) {
blocked.push(next)
} else {
next()
}
}
}

module.exports = {
"webpackPlugin": ["type", Plugin],
"preprocessor:webpack": ["factory", createPreprocesor]
"preprocessor:webpack": ["factory", createPreprocesor],
"middleware:webpackBlocker": ["factory", createWebpackBlocker]
};

0 comments on commit 03f6495

Please sign in to comment.