<commit_before>const purify = require('purify-css');
const ConcatSource = require('webpack-sources').ConcatSource;
const parse = require('./parse');
const search = require('./search');

module.exports = function PurifyPlugin(options) {
  return {
    apply(compiler) {
      compiler.plugin('this-compilation', (compilation) => {
        const paths = parse.paths(options.paths);
        const extensions = options.extensions || compiler.options.resolve.extensions;

        compilation.plugin('additional-assets', (cb) => {
          [].concat(...compilation.chunks.map(
            ({ name, modules }) => purifyCSS(
              (paths[name] || paths).concat(
                search.files(modules, extensions, file => file.resource)
              ),
              search.assets(compilation.assets, /\.css$/i).filter(
                asset => asset.name.indexOf(name) >= 0
              ),
              options.purifyOptions
            )
          )).forEach(({ name, source }) => {
            compilation.assets[name] = source;
          });

          cb();
        });
      });
    }
  };
};

const purifyCSS = (files, assets, purifyOptions) => (
  assets.map(({ name, asset }) => (
    {
      name,
      source: new ConcatSource(purify(files, asset.source(), purifyOptions))
    }
  ))
);<commit_msg>chore - Write the logic in a more compact form<commit_after>const purify = require('purify-css');
const ConcatSource = require('webpack-sources').ConcatSource;
const parse = require('./parse');
const search = require('./search');

module.exports = function PurifyPlugin(options) {
  return {
    apply(compiler) {
      compiler.plugin('this-compilation', (compilation) => {
        const paths = parse.paths(options.paths);
        const extensions = options.extensions || compiler.options.resolve.extensions;

        compilation.plugin('additional-assets', (cb) => {
          [].concat(...compilation.chunks.map(
            ({ name: chunkName, modules }) => (
              search.assets(compilation.assets, /\.css$/i).filter(
                asset => asset.name.indexOf(chunkName) >= 0
              ).forEach(({ name, asset }) => {
                compilation.assets[name] = new ConcatSource(
                  purify(
                    (paths[chunkName] || paths).concat(
                      search.files(modules, extensions, file => file.resource)
                    ),
                    asset.source(),
                    options.purifyOptions
                  )
                );
              })
            )
          ));

          cb();
        });
      });
    }
  };
};
{'fraction_non_alphanumeric': 0.14942528735632185, 'fraction_numerical': 0.0007662835249042146, 'mean_word_length': 1.923852183650616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5470369', 'n_tokens_mistral': 698, 'n_tokens_neox': 676, 'n_words': 125}