log-apply-result.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. /**
  6. * @param {(string | number)[]} updatedModules updated modules
  7. * @param {(string | number)[] | null} renewedModules renewed modules
  8. */
  9. module.exports = function (updatedModules, renewedModules) {
  10. var unacceptedModules = updatedModules.filter(function (moduleId) {
  11. return renewedModules && renewedModules.indexOf(moduleId) < 0;
  12. });
  13. var log = require("./log");
  14. if (unacceptedModules.length > 0) {
  15. log(
  16. "warning",
  17. "[HMR] The following modules couldn't be hot updated: (They would need a full reload!)"
  18. );
  19. unacceptedModules.forEach(function (moduleId) {
  20. log("warning", "[HMR] - " + moduleId);
  21. });
  22. }
  23. if (!renewedModules || renewedModules.length === 0) {
  24. log("info", "[HMR] Nothing hot updated.");
  25. } else {
  26. log("info", "[HMR] Updated modules:");
  27. renewedModules.forEach(function (moduleId) {
  28. if (typeof moduleId === "string" && moduleId.indexOf("!") !== -1) {
  29. var parts = moduleId.split("!");
  30. log.groupCollapsed("info", "[HMR] - " + parts.pop());
  31. log("info", "[HMR] - " + moduleId);
  32. log.groupEnd("info");
  33. } else {
  34. log("info", "[HMR] - " + moduleId);
  35. }
  36. });
  37. var numberIds = renewedModules.every(function (moduleId) {
  38. return typeof moduleId === "number";
  39. });
  40. if (numberIds)
  41. log(
  42. "info",
  43. '[HMR] Consider using the optimization.moduleIds: "named" for module names.'
  44. );
  45. }
  46. };