2015-03-12 06:48:00 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2024-07-31 12:23:44 +08:00
|
|
|
/* globals __resourceQuery */
|
2018-02-25 09:00:20 +08:00
|
|
|
if (module.hot) {
|
2017-05-31 17:00:41 +08:00
|
|
|
var log = require("./log");
|
2023-05-15 23:49:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {boolean=} fromUpdate true when called from update
|
|
|
|
*/
|
2016-10-29 21:57:58 +08:00
|
|
|
var checkForUpdate = function checkForUpdate(fromUpdate) {
|
2018-02-25 09:00:20 +08:00
|
|
|
module.hot
|
|
|
|
.check()
|
2020-03-29 06:10:15 +08:00
|
|
|
.then(function (updatedModules) {
|
2021-08-05 22:03:13 +08:00
|
|
|
if (!updatedModules) {
|
2018-02-25 09:00:20 +08:00
|
|
|
if (fromUpdate) log("info", "[HMR] Update applied.");
|
|
|
|
else log("warning", "[HMR] Cannot find update.");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-12 06:48:00 +08:00
|
|
|
|
2018-02-25 09:00:20 +08:00
|
|
|
return module.hot
|
|
|
|
.apply({
|
|
|
|
ignoreUnaccepted: true,
|
2020-03-29 06:10:15 +08:00
|
|
|
onUnaccepted: function (data) {
|
2018-02-25 09:00:20 +08:00
|
|
|
log(
|
|
|
|
"warning",
|
|
|
|
"Ignored an update to unaccepted module " +
|
|
|
|
data.chain.join(" -> ")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
2020-03-29 06:10:15 +08:00
|
|
|
.then(function (renewedModules) {
|
2018-02-25 09:00:20 +08:00
|
|
|
require("./log-apply-result")(updatedModules, renewedModules);
|
2015-05-22 04:58:22 +08:00
|
|
|
|
2018-02-25 09:00:20 +08:00
|
|
|
checkForUpdate(true);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
})
|
2020-03-29 06:10:15 +08:00
|
|
|
.catch(function (err) {
|
2018-02-25 09:00:20 +08:00
|
|
|
var status = module.hot.status();
|
|
|
|
if (["abort", "fail"].indexOf(status) >= 0) {
|
|
|
|
log("warning", "[HMR] Cannot apply update.");
|
2019-06-12 21:28:45 +08:00
|
|
|
log("warning", "[HMR] " + log.formatError(err));
|
2018-02-25 09:00:20 +08:00
|
|
|
log("warning", "[HMR] You need to restart the application!");
|
|
|
|
} else {
|
2018-07-10 04:20:45 +08:00
|
|
|
log("warning", "[HMR] Update failed: " + (err.stack || err.message));
|
2018-02-25 09:00:20 +08:00
|
|
|
}
|
2015-03-12 06:48:00 +08:00
|
|
|
});
|
2017-01-11 17:51:58 +08:00
|
|
|
};
|
2015-03-12 06:48:00 +08:00
|
|
|
|
2022-03-14 05:54:18 +08:00
|
|
|
process.on(__resourceQuery.slice(1) || "SIGUSR2", function () {
|
2018-02-25 09:00:20 +08:00
|
|
|
if (module.hot.status() !== "idle") {
|
|
|
|
log(
|
|
|
|
"warning",
|
|
|
|
"[HMR] Got signal but currently in " + module.hot.status() + " state."
|
|
|
|
);
|
2017-05-31 17:00:41 +08:00
|
|
|
log("warning", "[HMR] Need to be in idle state to start hot update.");
|
2015-03-12 06:48:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkForUpdate();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
|
|
|
}
|