<commit_before>import fs from 'fs'
import Purgecss from 'purgecss'
import { ConcatSource } from 'webpack-sources'
import * as parse from './parse'
import * as search from './search'

export default class PurgecssPlugin {
    constructor(options) {
        this.options = options
    }

    apply(compiler) {
        compiler.plugin('this-compilation', compilation => {
            const entryPaths = parse.entryPaths(this.options.paths)

            parse.flatten(entryPaths).forEach(p => {
                if (!fs.existsSync(p))
                    throw new Error(`Path ${p} does not exist.`)
            })

            compilation.plugin('additional-assets', cb => {
                // Go through chunks and purge as configured
                compilation.chunks.forEach(
                    ({ name: chunkName, files, modules }) => {
                        const assetsToPurge = search
                            .assets(compilation.assets, ['.css'])
                            .filter(asset => files.indexOf(asset.name) >= 0)

                        assetsToPurge.forEach(({ name, asset }) => {
                            const filesToSearch = parse
                                .entries(entryPaths, chunkName)
                                .concat(
                                    search.files(
                                        modules,
                                        this.options.moduleExtensions || [],
                                        file => file.resource
                                    )
                                )
                                .filter(v => !v.endsWith('.css'))

                            // Compile through Purgecss and attach to output.
                            // This loses sourcemaps should there be any!
                            const purgecss = new Purgecss({
                                content: filesToSearch,
                                css: [asset.source()],
                                stdin: true
                            })
                            compilation.assets[name] = new ConcatSource(
                                purgecss.purge()[0].css
                            )
                        })
                    }
                )

                cb()
            })
        })
    }
}<commit_msg>change deprecated property, add purgecss options<commit_after>import fs from 'fs'
import Purgecss from 'purgecss'
import { ConcatSource } from 'webpack-sources'
import * as parse from './parse'
import * as search from './search'

export default class PurgecssPlugin {
  constructor(options) {
    this.options = options
  }

  apply(compiler) {
    compiler.plugin('this-compilation', compilation => {
      const entryPaths = parse.entryPaths(this.options.paths)

      parse.flatten(entryPaths).forEach(p => {
        if (!fs.existsSync(p)) throw new Error(`Path ${p} does not exist.`)
      })

      compilation.plugin('additional-assets', cb => {
        // Go through chunks and purge as configured
        compilation.chunks.forEach(chunk => {
          const { name: chunkName, files } = chunk
          const modules = chunk.mapModules(mod => mod)
          const assetsToPurge = search
            .assets(compilation.assets, ['.css'])
            .filter(asset => files.indexOf(asset.name) >= 0)

          assetsToPurge.forEach(({ name, asset }) => {
            const filesToSearch = parse
              .entries(entryPaths, chunkName)
              .concat(
                search.files(
                  modules,
                  this.options.moduleExtensions || [],
                  file => file.resource
                )
              )
              .filter(v => !v.endsWith('.css'))

            // Compile through Purgecss and attach to output.
            // This loses sourcemaps should there be any!
            const purgecss = new Purgecss({
              ...this.options,
              content: filesToSearch,
              css: [asset.source()],
              stdin: true
            })
            compilation.assets[name] = new ConcatSource(purgecss.purge()[0].css)
          })
        })

        cb()
      })
    })
  }
}
{'fraction_non_alphanumeric': 0.1006679389312977, 'fraction_numerical': 0.0009541984732824427, 'mean_word_length': 1.2220455749867514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3008611', 'n_tokens_mistral': 1006, 'n_tokens_neox': 957, 'n_words': 234}