[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 | /* globals __resourceQuery */
|
---|
| 6 | if (module.hot) {
|
---|
| 7 | var log = require("./log");
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * @param {boolean=} fromUpdate true when called from update
|
---|
| 11 | */
|
---|
| 12 | var checkForUpdate = function checkForUpdate(fromUpdate) {
|
---|
| 13 | module.hot
|
---|
| 14 | .check()
|
---|
| 15 | .then(function (updatedModules) {
|
---|
| 16 | if (!updatedModules) {
|
---|
| 17 | if (fromUpdate) log("info", "[HMR] Update applied.");
|
---|
| 18 | else log("warning", "[HMR] Cannot find update.");
|
---|
| 19 | return;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | return module.hot
|
---|
| 23 | .apply({
|
---|
| 24 | ignoreUnaccepted: true,
|
---|
| 25 | onUnaccepted: function (data) {
|
---|
| 26 | log(
|
---|
| 27 | "warning",
|
---|
| 28 | "Ignored an update to unaccepted module " +
|
---|
| 29 | data.chain.join(" -> ")
|
---|
| 30 | );
|
---|
| 31 | }
|
---|
| 32 | })
|
---|
| 33 | .then(function (renewedModules) {
|
---|
| 34 | require("./log-apply-result")(updatedModules, renewedModules);
|
---|
| 35 |
|
---|
| 36 | checkForUpdate(true);
|
---|
| 37 | return null;
|
---|
| 38 | });
|
---|
| 39 | })
|
---|
| 40 | .catch(function (err) {
|
---|
| 41 | var status = module.hot.status();
|
---|
| 42 | if (["abort", "fail"].indexOf(status) >= 0) {
|
---|
| 43 | log("warning", "[HMR] Cannot apply update.");
|
---|
| 44 | log("warning", "[HMR] " + log.formatError(err));
|
---|
| 45 | log("warning", "[HMR] You need to restart the application!");
|
---|
| 46 | } else {
|
---|
| 47 | log("warning", "[HMR] Update failed: " + (err.stack || err.message));
|
---|
| 48 | }
|
---|
| 49 | });
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | process.on(__resourceQuery.slice(1) || "SIGUSR2", function () {
|
---|
| 53 | if (module.hot.status() !== "idle") {
|
---|
| 54 | log(
|
---|
| 55 | "warning",
|
---|
| 56 | "[HMR] Got signal but currently in " + module.hot.status() + " state."
|
---|
| 57 | );
|
---|
| 58 | log("warning", "[HMR] Need to be in idle state to start hot update.");
|
---|
| 59 | return;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | checkForUpdate();
|
---|
| 63 | });
|
---|
| 64 | } else {
|
---|
| 65 | throw new Error("[HMR] Hot Module Replacement is disabled.");
|
---|
| 66 | }
|
---|