<commit_before>import { exec } from 'child_process'
import { EnvironmentPlugin } from 'webpack'
import ForkTsPlugin from 'fork-ts-checker-webpack-plugin'
import CopyPlugin from 'copy-webpack-plugin'
import HtmlPlugin from 'html-webpack-plugin'
import HtmlIncAssetsPlugin from 'html-webpack-include-assets-plugin'
import HardSourcePlugin from 'hard-source-webpack-plugin'
import StylelintPlugin from 'stylelint-webpack-plugin'
import BuildNotifPlugin from 'webpack-build-notifier'
import CssExtractPlugin from 'mini-css-extract-plugin'
import SentryPlugin from '@sentry/webpack-plugin'
import ZipPlugin from 'zip-webpack-plugin'
import PostCompilePlugin from 'post-compile-webpack-plugin'
// Disabling this for now as it adds 2-4 seconds to inc. build time - look into finding out why
// import WebExtReloadPlugin from 'webpack-chrome-extension-reloader'

import initEnv from './env'
import * as staticFiles from './static-files'
import { output } from './config'

/**
 * @param {boolean} tslint Denotes whether or not to enable linting on this thread as well as type checking.
 */
const initTsPlugin = tslint =>
    new ForkTsPlugin({
        checkSyntacticErrors: true,
        async: false,
        tslint,
        // Hacky workaround for now as this plugin tries to lint imported TS node_modules for some reason
        // CI linting will still pick these up
        ignoreLints: ['class-name', 'no-shadowed-variable', 'comment-format'],
    })

export default function ({
    webExtReloadPort = 9090,
    mode = 'development',
    template,
    notifsEnabled = false,
    isCI = false,
    shouldPackage = false,
    packagePath = '../dist',
    extPackageName = 'extension.zip',
    sourcePackageName = 'source-code.zip',
}) {
    const plugins = [
        new EnvironmentPlugin(initEnv({ mode })),
        new CopyPlugin(staticFiles.copyPatterns),
        new HtmlPlugin({
            title: 'Popup',
            chunks: ['popup'],
            filename: 'popup.html',
            template,
        }),
        new HtmlPlugin({
            title: 'Settings',
            chunks: ['options'],
            filename: 'options.html',
            template,
        }),
        new HtmlIncAssetsPlugin({
            append: false,
            assets: staticFiles.htmlAssets,
        }),
        new CssExtractPlugin({
            filename: '[name].css',
        }),
    ]

    if (mode === 'development') {
        plugins.push(
            new HardSourcePlugin(),
            // new WebExtReloadPlugin({
            //     port: webExtReloadPort,
            // }),
        )
    } else if (mode === 'production') {
        plugins.push(
            new SentryPlugin({
                release: process.env.npm_package_version,
                include: output.path,
                dryRun: shouldPackage,
            }),
        )
    }

    // CI build doesn't need to use linting plugins
    if (isCI) {
        return [...plugins, initTsPlugin(false)]
    }

    if (notifsEnabled) {
        plugins.push(
            new BuildNotifPlugin({
                title: 'Memex Build',
            }),
        )
    }

    if (shouldPackage) {<commit_msg>Fix bug with sentry `dryRun` flag in prod build<commit_after>import { exec } from 'child_process'
import { EnvironmentPlugin } from 'webpack'
import ForkTsPlugin from 'fork-ts-checker-webpack-plugin'
import CopyPlugin from 'copy-webpack-plugin'
import HtmlPlugin from 'html-webpack-plugin'
import HtmlIncAssetsPlugin from 'html-webpack-include-assets-plugin'
import HardSourcePlugin from 'hard-source-webpack-plugin'
import StylelintPlugin from 'stylelint-webpack-plugin'
import BuildNotifPlugin from 'webpack-build-notifier'
import CssExtractPlugin from 'mini-css-extract-plugin'
import SentryPlugin from '@sentry/webpack-plugin'
import ZipPlugin from 'zip-webpack-plugin'
import PostCompilePlugin from 'post-compile-webpack-plugin'
// Disabling this for now as it adds 2-4 seconds to inc. build time - look into finding out why
// import WebExtReloadPlugin from 'webpack-chrome-extension-reloader'

import initEnv from './env'
import * as staticFiles from './static-files'
import { output } from './config'

/**
 * @param {boolean} tslint Denotes whether or not to enable linting on this thread as well as type checking.
 */
const initTsPlugin = tslint =>
    new ForkTsPlugin({
        checkSyntacticErrors: true,
        async: false,
        tslint,
        // Hacky workaround for now as this plugin tries to lint imported TS node_modules for some reason
        // CI linting will still pick these up
        ignoreLints: ['class-name', 'no-shadowed-variable', 'comment-format'],
    })

export default function({
    webExtReloadPort = 9090,
    mode = 'development',
    template,
    notifsEnabled = false,
    isCI = false,
    shouldPackage = false,
    packagePath = '../dist',
    extPackageName = 'extension.zip',
    sourcePackageName = 'source-code.zip',
}) {
    const plugins = [
        new EnvironmentPlugin(initEnv({ mode })),
        new CopyPlugin(staticFiles.copyPatterns),
        new HtmlPlugin({
            title: 'Popup',
            chunks: ['popup'],
            filename: 'popup.html',
            template,
        }),
        new HtmlPlugin({
            title: 'Settings',
            chunks: ['options'],
            filename: 'options.html',
            template,
        }),
        new HtmlIncAssetsPlugin({
            append: false,
            assets: staticFiles.htmlAssets,
        }),
        new CssExtractPlugin({
            filename: '[name].css',
        }),
    ]

    if (mode === 'development') {
        plugins.push(
            new HardSourcePlugin(),
            // new WebExtReloadPlugin({
            //     port: webExtReloadPort,
            // }),
        )
    } else if (mode === 'production') {
        plugins.push(
            new SentryPlugin({
                release: process.env.npm_package_version,
                include: output.path,
                dryRun: !shouldPackage,
            }),
        )
    }

    // CI build doesn't need to use linting plugins
    if (isCI) {
        return [...plugins, initTsPlugin(false)]
    }

    if (notifsEnabled) {
        plugins.push(
            new BuildNotifPlugin({
                title: 'Memex Build',
            }),
        )
    }

    if (shouldPackage) {
{'fraction_non_alphanumeric': 0.10625197347647616, 'fraction_numerical': 0.001894537417113988, 'mean_word_length': 2.278985507246377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '59960', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1721, 'n_words': 494}