SystemParity.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const pluginCompat = require('./util/plugin-compat');
  2. const logMessages = require('./util/log-messages');
  3. const { ParityRoot } = require('./util/parity');
  4. class ParitySystem {
  5. apply(compiler) {
  6. pluginCompat.register(compiler, '_hardSourceParityCache', 'sync', [
  7. 'parityRoot',
  8. ]);
  9. const compilerHooks = pluginCompat.hooks(compiler);
  10. function runParityOrReset(_compiler) {
  11. const parityRoot = new ParityRoot();
  12. compilerHooks._hardSourceParityCache.call(parityRoot);
  13. if (!parityRoot.verify()) {
  14. logMessages.cacheNoParity(compiler, { parityRoot });
  15. // Reset the cache, some part of it is incomplete and using it will lead
  16. // to errors.
  17. compilerHooks._hardSourceResetCache.call();
  18. }
  19. return Promise.resolve();
  20. }
  21. compilerHooks.watchRun.tapPromise(
  22. 'HardSource - index - parityOrReset',
  23. runParityOrReset,
  24. );
  25. compilerHooks.run.tapPromise(
  26. 'HardSource - index - parityOrReset',
  27. runParityOrReset,
  28. );
  29. }
  30. }
  31. module.exports = ParitySystem;