mirror of https://github.com/webpack/webpack.git
allow to ignore errors and fire events
This commit is contained in:
parent
59527bf3c7
commit
bd35d4f65d
|
@ -19,11 +19,15 @@ if(module.hot) {
|
|||
module.hot.apply({
|
||||
ignoreUnaccepted: true,
|
||||
ignoreDeclined: true,
|
||||
ignoreErrored: true,
|
||||
onUnaccepted: function(data) {
|
||||
console.warn("Ignored an update to unaccepted module " + data.chain.join(" -> "));
|
||||
},
|
||||
onDeclined: function(data) {
|
||||
console.warn("Ignored an update to declined module " + data.chain.join(" -> "));
|
||||
},
|
||||
onErrored: function(data) {
|
||||
console.warn("Ignored an error while updating module " + data.moduleId + " (" + data.type + ")");
|
||||
}
|
||||
}).then(function(renewedModules) {
|
||||
if(!upToDate()) {
|
||||
|
|
|
@ -256,8 +256,8 @@ module.exports = function() {
|
|||
var module;
|
||||
var moduleId;
|
||||
|
||||
function getAffectedStuff(module) {
|
||||
var outdatedModules = [module];
|
||||
function getAffectedStuff(updateModuleId) {
|
||||
var outdatedModules = [updateModuleId];
|
||||
var outdatedDependencies = {};
|
||||
|
||||
var queue = outdatedModules.slice().map(function(id) {
|
||||
|
@ -317,6 +317,7 @@ module.exports = function() {
|
|||
|
||||
return {
|
||||
type: "accepted",
|
||||
moduleId: updateModuleId,
|
||||
outdatedModules: outdatedModules,
|
||||
outdatedDependencies: outdatedDependencies
|
||||
};
|
||||
|
@ -480,14 +481,24 @@ module.exports = function() {
|
|||
for(i = 0; i < callbacks.length; i++) {
|
||||
cb = callbacks[i];
|
||||
try {
|
||||
cb(outdatedDependencies);
|
||||
cb(moduleOutdatedDependencies);
|
||||
} catch(err) {
|
||||
if(options.onErrored) {
|
||||
options.onErrored({
|
||||
type: "accept-errored",
|
||||
moduleId: moduleId,
|
||||
dependencyId: moduleOutdatedDependencies[i],
|
||||
error: err
|
||||
});
|
||||
}
|
||||
if(!options.ignoreErrored) {
|
||||
if(!error)
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load self accepted modules
|
||||
for(i = 0; i < outdatedSelfAcceptedModules.length; i++) {
|
||||
|
@ -500,14 +511,37 @@ module.exports = function() {
|
|||
if(typeof item.errorHandler === "function") {
|
||||
try {
|
||||
item.errorHandler(err);
|
||||
} catch(err) {
|
||||
} catch(err2) {
|
||||
if(options.onErrored) {
|
||||
options.onErrored({
|
||||
type: "self-accept-error-handler-errored",
|
||||
moduleId: moduleId,
|
||||
error: err2,
|
||||
orginalError: err
|
||||
});
|
||||
}
|
||||
if(!options.ignoreErrored) {
|
||||
if(!error)
|
||||
error = err2;
|
||||
}
|
||||
if(!error)
|
||||
error = err;
|
||||
}
|
||||
} else if(!error)
|
||||
} else {
|
||||
if(options.onErrored) {
|
||||
options.onErrored({
|
||||
type: "self-accept-errored",
|
||||
moduleId: moduleId,
|
||||
error: err
|
||||
});
|
||||
}
|
||||
if(!options.ignoreErrored) {
|
||||
if(!error)
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle errors in accept handlers and self accepted module load
|
||||
if(error) {
|
||||
|
|
|
@ -27,6 +27,6 @@ HarmonyAcceptDependency.Template.prototype.apply = function(dep, source, outputO
|
|||
source.insert(dep.range[0], "function(__WEBPACK_OUTDATED_DEPENDENCIES__) { " + content + "(");
|
||||
source.insert(dep.range[1], ")(__WEBPACK_OUTDATED_DEPENDENCIES__); }");
|
||||
} else {
|
||||
source.insert(dep.range[1] - 1, ", function() { " + content + "}");
|
||||
source.insert(dep.range[1] - 0.5, ", function() { " + content + "}");
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
import i from "./i";
|
||||
|
||||
if(module.hot) {
|
||||
module.hot.accept("./i");
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export default 1;
|
||||
---
|
||||
export default 2;
|
||||
throw new Error("Error while loading module h");
|
|
@ -2,15 +2,19 @@ import a from "./a";
|
|||
import b from "./b";
|
||||
import d from "./d";
|
||||
import f from "./f";
|
||||
import h from "./h";
|
||||
import j from "./j";
|
||||
|
||||
it("should fire the correct events", function(done) {
|
||||
var events = [];
|
||||
var options = {
|
||||
ignoreUnaccepted: true,
|
||||
ignoreDeclined: true,
|
||||
ignoreErrored: true,
|
||||
onDeclined: function(data) { events.push(data); },
|
||||
onUnaccepted: function(data) { events.push(data); },
|
||||
onAccepted: function(data) { events.push(data); }
|
||||
onAccepted: function(data) { events.push(data); },
|
||||
onErrored: function(data) { events.push(data); }
|
||||
};
|
||||
|
||||
function waitForUpdate(fn) {
|
||||
|
@ -22,31 +26,51 @@ it("should fire the correct events", function(done) {
|
|||
}
|
||||
|
||||
waitForUpdate(function() {
|
||||
events.sort(function(a, b) {
|
||||
if(a.type > b.type) return 1;
|
||||
if(a.type < b.type) return -1;
|
||||
return 0;
|
||||
}).should.be.eql([
|
||||
events.should.be.eql([
|
||||
{
|
||||
type: "unaccepted",
|
||||
moduleId: "./index.js",
|
||||
chain: [ "./a.js", "./index.js" ],
|
||||
},
|
||||
{
|
||||
type: "accepted",
|
||||
moduleId: "./c.js",
|
||||
outdatedDependencies: { "./b.js": [ "./c.js" ] },
|
||||
outdatedModules: [ "./c.js" ],
|
||||
type: "accepted"
|
||||
},
|
||||
{
|
||||
chain: [ "./g.js", "./f.js" ],
|
||||
type: "self-declined",
|
||||
moduleId: "./d.js",
|
||||
chain: [ "./e.js", "./d.js" ],
|
||||
},
|
||||
{
|
||||
type: "declined",
|
||||
moduleId: "./g.js",
|
||||
parentId: "./f.js",
|
||||
type: "declined"
|
||||
chain: [ "./g.js", "./f.js" ],
|
||||
},
|
||||
{
|
||||
chain: [ "./e.js", "./d.js" ],
|
||||
moduleId: "./d.js",
|
||||
type: "self-declined"
|
||||
type: "accepted",
|
||||
moduleId: "./i.js",
|
||||
outdatedDependencies: { "./h.js": [ "./i.js" ] },
|
||||
outdatedModules: [ "./i.js" ],
|
||||
},
|
||||
{
|
||||
chain: [ "./a.js", "./index.js" ],
|
||||
moduleId: "./index.js",
|
||||
type: "unaccepted"
|
||||
type: "accepted",
|
||||
moduleId: "./j.js",
|
||||
outdatedDependencies: {},
|
||||
outdatedModules: [ "./j.js" ],
|
||||
},
|
||||
{
|
||||
type: "accept-errored",
|
||||
moduleId: "./h.js",
|
||||
dependencyId: "./i.js",
|
||||
error: new Error("Error while loading module h")
|
||||
},
|
||||
{
|
||||
type: "self-accept-errored",
|
||||
moduleId: "./j.js",
|
||||
error: new Error("Error while loading module j")
|
||||
},
|
||||
]);
|
||||
done();
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
export default 1;
|
||||
module.hot.accept();
|
||||
---
|
||||
export default 2;
|
||||
throw new Error("Error while loading module j");
|
Loading…
Reference in New Issue