log-messages.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. const cachePrefix = require('.').cachePrefix;
  2. const LoggerFactory = require('../loggerFactory');
  3. exports.moduleFreezeError = (compilation, module, e) => {
  4. const loggerSerial = LoggerFactory.getLogger(compilation).from('serial');
  5. const compilerName = compilation.compiler.name;
  6. const compilerContext = compilation.compiler.options.context;
  7. const identifierPrefix = cachePrefix(compilation);
  8. const moduleIdentifier = module.identifier();
  9. const shortener = new (require('webpack/lib/RequestShortener'))(
  10. compilerContext,
  11. );
  12. const moduleReadable = module.readableIdentifier(shortener);
  13. loggerSerial.error(
  14. {
  15. id: 'serialization--error-freezing-module',
  16. identifierPrefix,
  17. compilerName,
  18. moduleIdentifier,
  19. moduleReadable,
  20. error: e,
  21. errorMessage: e.message,
  22. errorStack: e.stack,
  23. },
  24. `Unable to freeze module "${moduleReadable}${
  25. compilerName ? `" in compilation "${compilerName}` : ''
  26. }". An error occured serializing it into a string: ${e.message}`,
  27. );
  28. };
  29. exports.cacheNoParity = (compiler, { parityRoot }) => {
  30. const loggerSerial = new LoggerFactory(compiler).create().from('serial');
  31. loggerSerial.error(
  32. {
  33. id: 'serialzation--cache-incomplete',
  34. parityRoot,
  35. },
  36. [
  37. `Previous cache did not complete parity check. ${parityRoot.reason}`,
  38. 'Resetting cache.',
  39. ].join('\n'),
  40. );
  41. };
  42. exports.serialBadCache = (compiler, error) => {
  43. const loggerSerial = new LoggerFactory(compiler).create().from('serial');
  44. loggerSerial.error(
  45. {
  46. id: 'serialzation--bad-cache',
  47. },
  48. ['Cache is corrupted.', error.stack || error.message || error].join('\n'),
  49. );
  50. };
  51. const logCore = compiler => new LoggerFactory(compiler).create().from('core');
  52. exports.configHashSetButNotUsed = (compiler, { cacheDirectory }) => {
  53. const loggerCore = logCore(compiler);
  54. loggerCore.error(
  55. {
  56. id: 'confighash--directory-no-confighash',
  57. cacheDirectory: cacheDirectory,
  58. },
  59. 'HardSourceWebpackPlugin cannot use [confighash] in cacheDirectory ' +
  60. 'without configHash option being set and returning a non-falsy value.',
  61. );
  62. };
  63. exports.configHashFirstBuild = (compiler, { cacheDirPath, configHash }) => {
  64. const loggerCore = logCore(compiler);
  65. loggerCore.log(
  66. {
  67. id: 'confighash--new',
  68. cacheDirPath,
  69. configHash,
  70. },
  71. `HardSourceWebpackPlugin is writing to a new confighash path for the first time: ${cacheDirPath}`,
  72. );
  73. };
  74. exports.configHashBuildWith = (compiler, { cacheDirPath, configHash }) => {
  75. const loggerCore = logCore(compiler);
  76. loggerCore.log(
  77. {
  78. id: 'confighash--reused',
  79. cacheDirPath,
  80. configHash,
  81. },
  82. `HardSourceWebpackPlugin is reading from and writing to a confighash path: ${cacheDirPath}`,
  83. );
  84. };
  85. exports.deleteOldCaches = (compiler, { newTotalSize, oldTotalSize }) => {
  86. const loggerCore = logCore(compiler);
  87. const sizeMB = Math.ceil(newTotalSize / 1024 / 1024);
  88. const deletedSizeMB = Math.ceil(oldTotalSize / 1024 / 1024);
  89. loggerCore.log(
  90. {
  91. id: 'caches--delete-old',
  92. size: newTotalSize,
  93. sizeMB,
  94. deletedSize: oldTotalSize,
  95. deletedSizeMB,
  96. },
  97. `HardSourceWebpackPlugin is using ${sizeMB} MB of disk space after deleting ${deletedSizeMB} MB.`,
  98. );
  99. };
  100. exports.keepCaches = (compiler, { totalSize }) => {
  101. const loggerCore = logCore(compiler);
  102. const sizeMB = Math.ceil(totalSize / 1024 / 1024);
  103. loggerCore.log(
  104. {
  105. id: 'caches--keep',
  106. size: totalSize,
  107. sizeMB,
  108. },
  109. `HardSourceWebpackPlugin is using ${sizeMB} MB of disk space.`,
  110. );
  111. };
  112. exports.environmentInputs = (compiler, { inputs }) => {
  113. const loggerCore = logCore(compiler);
  114. loggerCore.log(
  115. {
  116. id: 'environment--inputs',
  117. inputs,
  118. },
  119. `Tracking environment changes with ${inputs.join(', ')}.`,
  120. );
  121. };
  122. exports.configHashChanged = compiler => {
  123. const loggerCore = logCore(compiler);
  124. loggerCore.warn(
  125. {
  126. id: 'environment--config-changed',
  127. },
  128. 'Environment has changed (configuration was changed).\n' +
  129. 'HardSourceWebpackPlugin will reset the cache and store a fresh one.',
  130. );
  131. };
  132. exports.environmentHashChanged = compiler => {
  133. const loggerCore = logCore(compiler);
  134. loggerCore.warn(
  135. {
  136. id: 'environment--changed',
  137. },
  138. 'Environment has changed (node_modules was updated).\n' +
  139. 'HardSourceWebpackPlugin will reset the cache and store a fresh one.',
  140. );
  141. };
  142. exports.hardSourceVersionChanged = compiler => {
  143. const loggerCore = logCore(compiler);
  144. loggerCore.warn(
  145. {
  146. id: 'environment--hardsource-changed',
  147. },
  148. 'Installed HardSource version does not match the saved ' +
  149. 'cache.\nHardSourceWebpackPlugin will reset the cache and store ' +
  150. 'a fresh one.',
  151. );
  152. };
  153. exports.childCompilerWithoutCache = compilation => {
  154. var loggerUtil = LoggerFactory.getLogger(compilation).from('util');
  155. loggerUtil.error(
  156. {
  157. id: 'childcompiler--no-cache',
  158. compilerName: compilation.compiler.name,
  159. },
  160. [
  161. `A child compiler (${compilation.compiler.name}) does not`,
  162. "have a memory cache. Enable a memory cache with webpack's",
  163. '`cache` configuration option. HardSourceWebpackPlugin will be',
  164. 'disabled for this child compiler until then.',
  165. ].join('\n'),
  166. );
  167. };
  168. exports.childCompilerUnnamedCache = compilation => {
  169. var loggerUtil = LoggerFactory.getLogger(compilation).from('util');
  170. loggerUtil.error(
  171. {
  172. id: 'childcompiler--unnamed-cache',
  173. compilerName: compilation.compiler.name,
  174. },
  175. [
  176. `A child compiler (${compilation.compiler.name}) has a`,
  177. 'memory cache but its cache name is unknown.',
  178. 'HardSourceWebpackPlugin will be disabled for this child',
  179. 'compiler.',
  180. ].join('\n'),
  181. );
  182. };
  183. const logParallel = compiler =>
  184. new LoggerFactory(compiler).create().from('parallel');
  185. exports.parallelStartWorkers = (compiler, options) => {
  186. const loggerParallel = logParallel(compiler);
  187. loggerParallel.log(
  188. {
  189. id: 'parallel--start-workers',
  190. numWorkers: options.numWorkers,
  191. },
  192. [`Start ${options.numWorkers} module workers.`].join('\n'),
  193. );
  194. };
  195. exports.parallelConfigMismatch = (compiler, options) => {
  196. const loggerParallel = logParallel(compiler);
  197. loggerParallel.error(
  198. {
  199. id: 'parallel--config-mismatch',
  200. ourHash: options.ourHash,
  201. theirHash: options.theirHash,
  202. },
  203. [
  204. `Child process's configuration does not match parent `,
  205. `configuration. Unable to parallelize webpack.`,
  206. ].join('\n'),
  207. );
  208. };
  209. exports.parallelErrorSendingJob = (compiler, error) => {
  210. const loggerParallel = logParallel(compiler);
  211. loggerParallel.error(
  212. {
  213. id: 'parallel--error-sending-job',
  214. error,
  215. },
  216. `Failed to send parallel module work. ${error.stack}`,
  217. );
  218. };
  219. exports.parallelRequireWebpack4 = compiler => {
  220. const loggerParallel = logParallel(compiler);
  221. loggerParallel.error(
  222. {
  223. id: 'parallel--webpack-4',
  224. },
  225. `Parallel Module Plugin requires webpack 4.`,
  226. );
  227. };