Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Commit

Permalink
feat: auto restart dev container when hmr fails
Browse files Browse the repository at this point in the history
  • Loading branch information
enten committed May 26, 2019
1 parent b590970 commit a05dca5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions hot/poll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
Version 3e03edc on Jul 9, 2018
*/
/*globals __resourceQuery */
if (module.hot) {
var hotPollInterval = +__resourceQuery.substr(1) || 10 * 60 * 1000;
var log = require("webpack/hot/log");

var checkForUpdate = function checkForUpdate(fromUpdate) {
if (module.hot.status() === "idle") {
module.hot
.check(true)
.then(function(updatedModules) {
if (!updatedModules) {
if (fromUpdate) log("info", "[HMR] Update applied.");
return;
}
require("webpack/hot/log-apply-result")(updatedModules, updatedModules);
checkForUpdate(true);
})
.catch(function(err) {
var status = module.hot.status();
if (["abort", "fail"].indexOf(status) >= 0) {
log("warning", "[HMR] Cannot apply update.");
log("warning", "[HMR] " + (err.stack || err.message));
log("warning", "[HMR] You need to restart the application!");
} else {
log(
"warning",
"[HMR] Update failed: " + (err.stack || err.message)
);
}
// <udk patch>
if (process.send) {
log("warning", "[HMR] udk auto restart the application...");
process.send({ action: 'run' });
}
// </udk patch>
});
}
};
setInterval(checkForUpdate, hotPollInterval);
} else {
throw new Error("[HMR] Hot Module Replacement is disabled.");
}
2 changes: 1 addition & 1 deletion lib/devContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export class DevContainerRuntime extends ContainerRuntime {
if (!config.autoRestart) {
ensureConfigHasPlugin(nodeConfigs, HMRPlugin, [ hmr.pluginNode ]);

ensureConfigHasEntry(nodeConfigs, 'webpack/hot/poll', hmr.hotPollInterval, {
ensureConfigHasEntry(nodeConfigs, 'udk/hot/poll', hmr.hotPollInterval, {
entriesFilter: hmr.entriesNode,
topModuleEntries: config.topModuleEntries,
});
Expand Down

0 comments on commit a05dca5

Please sign in to comment.