<commit_before>var runGitCommand = require('./helpers/run-git-command')

module.exports = function buildFile (compiler, gitWorkTree, command, replacePattern, asset) {
  var data = ''

  compiler.plugin('compilation', function (compilation) {
    compilation.plugin('optimize-tree', function (chunks, modules, callback) {
      runGitCommand(gitWorkTree, command, function (err, res) {
        if (err) { return callback(err) }
        data = res

        callback()
      })
    })

    compilation.mainTemplate.plugin('asset-path', function (path) {
      return path.replace(replacePattern, data)
    })
  })

  compiler.plugin('emit', function (compilation, callback) {
    compilation.assets[asset] = {
      source: function () {
        return data
      },
      size: function () {
        return data.length
      }
    }

    callback()
  })
}<commit_msg>Update build-file to Webpack 4 to use .hooks instead of .plugin<commit_after>var runGitCommand = require('./helpers/run-git-command')

module.exports = function buildFile (compiler, gitWorkTree, command, replacePattern, asset) {
  var data = ''

  compiler.hooks.compilation.tap('compilation', (compilation) => {
    compilation.hooks.optimizeTree.tapAsync('optimize-tree', (chunks, modules, callback) => {
      runGitCommand(gitWorkTree, command, function (err, res) {
        if (err) { return callback(err) }
        data = res

        callback()
      })
    })

    compilation.mainTemplate.hooks.assetPath.tap('asset-path', (path) => {
      return path.replace(replacePattern, data)
    })
  })

  compiler.hooks.emit.tapAsync('emit', (compilation, callback) => {
    compilation.assets[asset] = {
      source: function () {
        return data
      },
      size: function () {
        return data.length
      }
    }

    callback()
  })
}
{'fraction_non_alphanumeric': 0.13586358635863585, 'fraction_numerical': 0.00055005500550055, 'mean_word_length': 2.90343347639485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1308219', 'n_tokens_mistral': 537, 'n_tokens_neox': 529, 'n_words': 112}