<commit_before>const webpack = require('webpack');
const AppConfigLoader = require('./app-config-loader');
const AppModulesFileWriter = require('./writer/app-modules-file-writer');
const CleanupStatsPlugin = require('./plugin/stats/cleanup-stats-plugin');
const ConfigsFileWriter = require('./writer/configs-file-writer');
const EntryPointFileWriter = require('./writer/scss-entry-point-file-writer');
const LayoutModulesConfigLoader = require('./modules-config/layout-modules-config-loader');
const LayoutStyleLoader = require('./style/layout-style-loader');
const MapModulesPlugin = require('./plugin/map/map-modules-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HappyPack = require('happypack');
const ModulesConfigLoader = require('./modules-config/modules-config-loader');
const DynamicImportsFileWriter = require('./writer/dynamic-imports-file-writer');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const prepareModulesShim = require('./prepare-modules-shim');
const StyleLoader = require('./style/style-loader');
const ThemeConfigFactory = require('./theme-config-factory');
const path = require('path');
const postcssConfig = path.join(__dirname, '../postcss.config.js');
const prepareModulesMap = require('./plugin/map/prepare-modules-map');
const resolve = require('enhanced-resolve');
const webpackMerge = require('webpack-merge');
const babelConfig = require('./../babel.config.js');

class ConfigBuilder {
    constructor() {
        this._publicPath = 'public/';
        this._adminTheme = 'admin.oro';
        this._enableLayoutThemes = false;
        this._defaultLayoutThemes = null;
    }

    /**
     * Set Symfony public directory path related to application root folder
     * @param {string} publicPath
     * @returns {ConfigBuilder}
     */
    setPublicPath(publicPath) {
        this._publicPath = publicPath;
        return this;
    }

    /**
     * Set Symfony cache directory path related to application root folder
     * @param {string} cachePath
     * @returns {ConfigBuilder}
     */
    setCachePath(cachePath) {
        this._cachePath = cachePath;
        return this;
    }

    /**
     * Set active admin (management console) theme. Out of the box there are 2 themes ("admin.oro" and "admin.demo")
     *
     * @param {string} adminTheme
     * @returns {ConfigBuilder}
     */
    setAdminTheme(adminTheme) {
        const themeNameParts = adminTheme.split(".");
        if (themeNameParts[0] !== 'admin' || themeNameParts.length !== 2) {
            throw new Error('Admin theme name should be in a format "admin.{themeName}", for example "admin.oro"');
        }

        this._adminTheme = adminTheme;
        return this;
    }

    /**
     * Enable build of Layout themes.
     */
    enableLayoutThemes(themes) {
        if (themes) {
            this._defaultLayoutThemes = themes;
        }
        this._enableLayoutThemes = true;
        return this;
    }

    /**
     * Returns callback that loads webpack configs based on environment and command arguments variables
     * @returns {Function}
     */
    getWebpackConfig() {
        return (env = {}, args = {}) => {
            this._initialize(args, env);

            let selectedTheme = env.theme;
            this._validateThemeName(selectedTheme);

            let themes = [];
            // Admin themes
            if (selectedTheme === undefined) {
                // themes.push(this._adminTheme.split(".")[1]);
                themes.push(this._adminTheme);
            } else if (this._adminThemes.indexOf(selectedTheme) !== -1) {
                // themes.push(selectedTheme.split(".")[1]);
                themes.push(selectedTheme);
            }

            // Layout Themes
            if (this._enableLayoutThemes) {
                if (selectedTheme === undefined) {
                    // build all layout themes
                    let layoutThemes = {};
                    if (this._defaultLayoutThemes) {
                        themes = [...themes, ...this._defaultLayoutThemes];
                    } else {
                        themes = [...themes, ...Object.keys(this._layoutModulesConfigLoader.themes)];
                    }
                } else if (this._layoutThemes.indexOf(selectedTheme) !== -1) {
                    // build single layout theme
                    themes.push(selectedTheme);
                }
            }

            const resolvedPublicPath = path.resolve(this._publicPath);

            const stats = env.stats || {
                hash: false,
                version: false,
                children: false,
                entrypoints: false,
                performance: this._isProduction,
                chunks: false,
                modules: false,
                source: false,
                publicPath: false,
                builtAt: false,
                warnings: false
            };
            let webpackConfig = {
                watchOptions: {
                    aggregateTimeout: 200,
                    ignored: [
                        /[\/\\]node_modules[\/\\].*\.js$/,
                        /[\/\\]bundles[\/\\](npmassets|bowerassets|components)[\/\\].*\.js$/
                    ]
                },
                stats: stats,
                output: {
                    filename: '[name].js',
                    // Due of using third party libraries 'chunkFilename' should consist of only from [name]
                    chunkFilename: 'chunk/[name].js?version=[chunkhash:8]',
                },
                devtool: !env.skipSourcemap && 'inline-cheap-module-source-map',
                mode: 'development',
                optimization: {
                    namedModules: true,
                    splitChunks: {
                        cacheGroups: {
                            commons: {
                                name: 'commons',
                                minSize: 30,
                                minChunks: 2,
                                priority: 10,
                                reuseExistingChunk: true
                            },
                            vendors: {
                                test: /[\/\\]node_modules[\/\\]/,
                                name: 'vendors',
                                priority: -10
                            },
                            tinymce: {
                                test: /tinymce/,
                                name: 'tinymce.min',<commit_msg>BAP-17728: Fix various typos (#25786)<commit_after>const webpack = require('webpack');
const AppConfigLoader = require('./app-config-loader');
const AppModulesFileWriter = require('./writer/app-modules-file-writer');
const CleanupStatsPlugin = require('./plugin/stats/cleanup-stats-plugin');
const ConfigsFileWriter = require('./writer/configs-file-writer');
const EntryPointFileWriter = require('./writer/scss-entry-point-file-writer');
const LayoutModulesConfigLoader = require('./modules-config/layout-modules-config-loader');
const LayoutStyleLoader = require('./style/layout-style-loader');
const MapModulesPlugin = require('./plugin/map/map-modules-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HappyPack = require('happypack');
const ModulesConfigLoader = require('./modules-config/modules-config-loader');
const DynamicImportsFileWriter = require('./writer/dynamic-imports-file-writer');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const prepareModulesShim = require('./prepare-modules-shim');
const StyleLoader = require('./style/style-loader');
const ThemeConfigFactory = require('./theme-config-factory');
const path = require('path');
const postcssConfig = path.join(__dirname, '../postcss.config.js');
const prepareModulesMap = require('./plugin/map/prepare-modules-map');
const resolve = require('enhanced-resolve');
const webpackMerge = require('webpack-merge');
const babelConfig = require('./../babel.config.js');

class ConfigBuilder {
    constructor() {
        this._publicPath = 'public/';
        this._adminTheme = 'admin.oro';
        this._enableLayoutThemes = false;
        this._defaultLayoutThemes = null;
    }

    /**
     * Set Symfony public directory path related to application root folder
     * @param {string} publicPath
     * @returns {ConfigBuilder}
     */
    setPublicPath(publicPath) {
        this._publicPath = publicPath;
        return this;
    }

    /**
     * Set Symfony cache directory path related to application root folder
     * @param {string} cachePath
     * @returns {ConfigBuilder}
     */
    setCachePath(cachePath) {
        this._cachePath = cachePath;
        return this;
    }

    /**
     * Set active admin (management console) theme. Out of the box there are 2 themes ("admin.oro" and "admin.demo")
     *
     * @param {string} adminTheme
     * @returns {ConfigBuilder}
     */
    setAdminTheme(adminTheme) {
        const themeNameParts = adminTheme.split(".");
        if (themeNameParts[0] !== 'admin' || themeNameParts.length !== 2) {
            throw new Error('Admin theme name should be in a format "admin.{themeName}", for example "admin.oro"');
        }

        this._adminTheme = adminTheme;
        return this;
    }

    /**
     * Enable build of Layout themes.
     */
    enableLayoutThemes(themes) {
        if (themes) {
            this._defaultLayoutThemes = themes;
        }
        this._enableLayoutThemes = true;
        return this;
    }

    /**
     * Returns callback that loads webpack configs based on environment and command arguments variables
     * @returns {Function}
     */
    getWebpackConfig() {
        return (env = {}, args = {}) => {
            this._initialize(args, env);

            let selectedTheme = env.theme;
            this._validateThemeName(selectedTheme);

            let themes = [];
            // Admin themes
            if (selectedTheme === undefined) {
                // themes.push(this._adminTheme.split(".")[1]);
                themes.push(this._adminTheme);
            } else if (this._adminThemes.indexOf(selectedTheme) !== -1) {
                // themes.push(selectedTheme.split(".")[1]);
                themes.push(selectedTheme);
            }

            // Layout Themes
            if (this._enableLayoutThemes) {
                if (selectedTheme === undefined) {
                    // build all layout themes
                    let layoutThemes = {};
                    if (this._defaultLayoutThemes) {
                        themes = [...themes, ...this._defaultLayoutThemes];
                    } else {
                        themes = [...themes, ...Object.keys(this._layoutModulesConfigLoader.themes)];
                    }
                } else if (this._layoutThemes.indexOf(selectedTheme) !== -1) {
                    // build single layout theme
                    themes.push(selectedTheme);
                }
            }

            const resolvedPublicPath = path.resolve(this._publicPath);

            const stats = env.stats || {
                hash: false,
                version: false,
                children: false,
                entrypoints: false,
                performance: this._isProduction,
                chunks: false,
                modules: false,
                source: false,
                publicPath: false,
                builtAt: false,
                warnings: false
            };
            let webpackConfig = {
                watchOptions: {
                    aggregateTimeout: 200,
                    ignored: [
                        /[\/\\]node_modules[\/\\].*\.js$/,
                        /[\/\\]bundles[\/\\](npmassets|bowerassets|components)[\/\\].*\.js$/
                    ]
                },
                stats: stats,
                output: {
                    filename: '[name].js',
                    // Because we use third party libraries 'chunkFilename' should include only [name]
                    chunkFilename: 'chunk/[name].js?version=[chunkhash:8]',
                },
                devtool: !env.skipSourcemap && 'inline-cheap-module-source-map',
                mode: 'development',
                optimization: {
                    namedModules: true,
                    splitChunks: {
                        cacheGroups: {
                            commons: {
                                name: 'commons',
                                minSize: 30,
                                minChunks: 2,
                                priority: 10,
                                reuseExistingChunk: true
                            },
                            vendors: {
                                test: /[\/\\]node_modules[\/\\]/,
                                name: 'vendors',
                                priority: -10
                            },
                            tinymce: {
                                test: /tinymce/,
                                name: 'tinymce.min',
{'fraction_non_alphanumeric': 0.11908758010375343, 'fraction_numerical': 0.003509307293256027, 'mean_word_length': 1.5948139350752177, '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': '1882291', 'n_tokens_mistral': 3311, 'n_tokens_neox': 3130, 'n_words': 689}