wallet-core/node_modules/webpack/hot/signal.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-05-03 15:35:00 +02:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
/*globals __resourceQuery */
if(module.hot) {
2017-08-14 05:01:11 +02:00
var log = require("./log");
2017-05-03 15:35:00 +02:00
var checkForUpdate = function checkForUpdate(fromUpdate) {
module.hot.check().then(function(updatedModules) {
if(!updatedModules) {
if(fromUpdate)
2017-08-14 05:01:11 +02:00
log("info", "[HMR] Update applied.");
2017-05-03 15:35:00 +02:00
else
2017-08-14 05:01:11 +02:00
log("warning", "[HMR] Cannot find update.");
2017-05-03 15:35:00 +02:00
return;
}
return module.hot.apply({
ignoreUnaccepted: true,
onUnaccepted: function(data) {
2017-08-14 05:01:11 +02:00
log("warning", "Ignored an update to unaccepted module " + data.chain.join(" -> "));
2017-05-03 15:35:00 +02:00
},
}).then(function(renewedModules) {
require("./log-apply-result")(updatedModules, renewedModules);
checkForUpdate(true);
});
}).catch(function(err) {
var status = module.hot.status();
if(["abort", "fail"].indexOf(status) >= 0) {
2017-08-14 05:01:11 +02:00
log("warning", "[HMR] Cannot apply update.");
log("warning", "[HMR] " + err.stack || err.message);
log("warning", "[HMR] You need to restart the application!");
2017-05-03 15:35:00 +02:00
} else {
2017-08-14 05:01:11 +02:00
log("warning", "[HMR] Update failed: " + err.stack || err.message);
2017-05-03 15:35:00 +02:00
}
});
};
process.on(__resourceQuery.substr(1) || "SIGUSR2", function() {
if(module.hot.status() !== "idle") {
2017-08-14 05:01:11 +02:00
log("warning", "[HMR] Got signal but currently in " + module.hot.status() + " state.");
log("warning", "[HMR] Need to be in idle state to start hot update.");
2017-05-03 15:35:00 +02:00
return;
}
checkForUpdate();
});
} else {
throw new Error("[HMR] Hot Module Replacement is disabled.");
}