"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _fs = _interopRequireDefault(require("fs"));

var _path = _interopRequireDefault(require("path"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

let coverageScript = _fs.default.readFileSync(_path.default.resolve(__dirname, '..', 'templates', 'CoverageScriptTemplate.js')).toString();

class ScriptInstrumentPlugin {
  apply(compiler) {
    compiler.hooks.emit.tapAsync('ScriptInstrumentPlugin', (compilation, callback) => {
      compilation.chunks.forEach(chunk => {
        chunk.files.forEach(filename => {
          if (filename === 'vendor.js') {
            compilation.assets[filename].children.forEach(child => {
              if (child._value) {
                child._value = coverageScript + child._value;
              }
            });
          }
        });
      });
      callback();
    });
  }

}

exports.default = ScriptInstrumentPlugin;