noEmitOnErrorsPlugin.js 698 B

12345678910111213141516171819202122232425262728293031323334
  1. const {
  2. addOrUpdateConfigObject,
  3. findAndRemovePluginByName
  4. } = require("../../utils/ast-utils");
  5. /**
  6. *
  7. * Transform for NoEmitOnErrorsPlugin. If found, removes the
  8. * plugin and sets optimizations.noEmitOnErrors to true
  9. *
  10. * @param {Object} j - jscodeshift top-level import
  11. * @param {Node} ast - jscodeshift ast to transform
  12. * @returns {Node} ast - jscodeshift ast
  13. */
  14. module.exports = function(j, ast) {
  15. // Remove old plugin
  16. const root = findAndRemovePluginByName(
  17. j,
  18. ast,
  19. "webpack.NoEmitOnErrorsPlugin"
  20. );
  21. // Add new optimizations option
  22. root &&
  23. addOrUpdateConfigObject(
  24. j,
  25. root,
  26. "optimizations",
  27. "noEmitOnErrors",
  28. j.booleanLiteral(true)
  29. );
  30. return ast;
  31. };