<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

'use strict';

const mix = require('laravel-mix');
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const SentryPlugin = require('webpack-sentry-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

// .js doesn't support globbing by itself, so we need to glob
// and spread the values in.
const glob = require('glob');
let min = '';
let reactMin = 'development';
if (mix.inProduction()) {
  min = '.min';
  reactMin = 'production.min';
}

const reactComponentSet = function(name) {
    return [[`resources/assets/coffee/react/${name}.coffee`], `js/react/${name}.js`];
};

const paymentSandbox = !(process.env.PAYMENT_SANDBOX === '0'
                         || process.env.PAYMENT_SANDBOX === 'false'
                         || !process.env.PAYMENT_SANDBOX);

// relative from root?
const nodeRoot = 'node_modules';

const vendor = [
  path.join(nodeRoot, 'clipboard-polyfill/build/clipboard-polyfill.js'),
  path.join(nodeRoot, `url-polyfill/url-polyfill${min}.js`),
  path.join(nodeRoot, 'turbolinks/dist/turbolinks.js'),
  path.join(nodeRoot, `jquery/dist/jquery${min}.js`),
  path.join(nodeRoot, 'jquery-ujs/src/rails.js'),
  path.join(nodeRoot, `qtip2/dist/jquery.qtip${min}.js`),
  path.join(nodeRoot, 'jquery.scrollto/jquery.scrollTo.js'),
  path.join(nodeRoot, 'jquery-ui/ui/data.js'),
  path.join(nodeRoot, 'jquery-ui/ui/scroll-parent.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widget.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widgets/mouse.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widgets/slider.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widgets/sortable.js'),
  path.join(nodeRoot, 'jquery-ui/ui/keycode.js'),
  path.join(nodeRoot, 'timeago/jquery.timeago.js'),
  path.join(nodeRoot, 'blueimp-file-upload/js/jquery.fileupload.js'),
  path.join(nodeRoot, 'bootstrap/dist/js/bootstrap.js'),
  path.join(nodeRoot, 'lodash/lodash.js'),
  path.join(nodeRoot, 'layzr.js/dist/layzr.js'),
  path.join(nodeRoot, `react/umd/react.${reactMin}.js`),
  path.join(nodeRoot, 'react-dom-factories/index.js'),
  path.join(nodeRoot, `react-dom/umd/react-dom.${reactMin}.js`),
  path.join(nodeRoot, `prop-types/prop-types${min}.js`),
  path.join(nodeRoot, 'photoswipe/dist/photoswipe.js'),
  path.join(nodeRoot, 'photoswipe/dist/photoswipe-ui-default.js'),
  path.join(nodeRoot, `d3/dist/d3${min}.js`),
  path.join(nodeRoot, 'moment/moment.js'),
  path.join(nodeRoot, 'js-cookie/src/js.cookie.js'),
  path.join(nodeRoot, `imagesloaded/imagesloaded.pkgd${min}.js`),
];

vendor.forEach(function(script) {
  if (!fs.existsSync(script)) {
    throw new Error(`${script} doesn't exist`);
  }
});

let webpackConfig = {
  externals: {
    'd3': 'd3',
    'lodash': '_',
    'moment': 'moment',
    'prop-types': 'PropTypes',
    'react': 'React',
    'react-dom': 'ReactDOM',
    'react-dom-factories': 'ReactDOMFactories',
  },
  module: {
    rules: [
      {
        enforce: 'pre',
        exclude: /(node_modules)/,
        loader: 'import-glob-loader',
        test: /\.(js|coffee)$/,
      },
      {
        // loader for preexisting global coffeescript
        exclude: [
          path.resolve(__dirname, 'resources/assets/coffee/react'),
        ],
        include: [
          path.resolve(__dirname, 'resources/assets/coffee'),
        ],
        test: /\.coffee$/,
        use: ['imports-loader?this=>window', 'coffee-loader'],
      },
      {
        // loader for import-based coffeescript
        include: [
          path.resolve(__dirname, 'resources/assets/coffee/react'),
          path.resolve(__dirname, 'resources/assets/lib'),
        ],
        test: /\.coffee$/,
        use: ['coffee-loader'],
      },
    ],
  },
  optimization: {
    runtimeChunk: {
      name: '/js/commons',
    },
    splitChunks: {
      cacheGroups: {
        commons: {
          chunks: 'initial',
          minChunks: 2,
          name: '/js/commons',
        },
      },
    },
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env.DOCS_URL': JSON.stringify(process.env.DOCS_URL || 'https://docs.ppy.sh'),
      'process.env.PAYMENT_SANDBOX': JSON.stringify(paymentSandbox),
      'process.env.SHOPIFY_DOMAIN': JSON.stringify(process.env.SHOPIFY_DOMAIN),
      'process.env.SHOPIFY_STOREFRONT_TOKEN': JSON.stringify(process.env.SHOPIFY_STOREFRONT_TOKEN),
    }),
  ],
  resolve: {
    alias: {
      'ziggy': path.resolve(__dirname, 'resources/assets/js/ziggy.js'),
      'ziggy-route': path.resolve(__dirname, 'vendor/tightenco/ziggy/dist/js/route.js'),
      '@fonts': path.resolve(__dirname, 'resources/assets/fonts'),
    },
    extensions: ['*', '.js', '.coffee', '.ts'],
    modules: [
      path.resolve(__dirname, 'resources/assets/coffee'),
      path.resolve(__dirname, 'resources/assets/lib'),
      path.resolve(__dirname, 'resources/assets/coffee/react/_components'),
      path.resolve(__dirname, 'node_modules'),
    ],
    plugins: [new TsconfigPathsPlugin()],
  },
};<commit_msg>Lint fix<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

'use strict';

const mix = require('laravel-mix');
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const SentryPlugin = require('webpack-sentry-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

// .js doesn't support globbing by itself, so we need to glob
// and spread the values in.
const glob = require('glob');
let min = '';
let reactMin = 'development';
if (mix.inProduction()) {
  min = '.min';
  reactMin = 'production.min';
}

const reactComponentSet = function(name) {
    return [[`resources/assets/coffee/react/${name}.coffee`], `js/react/${name}.js`];
};

const paymentSandbox = !(process.env.PAYMENT_SANDBOX === '0'
                         || process.env.PAYMENT_SANDBOX === 'false'
                         || !process.env.PAYMENT_SANDBOX);

// relative from root?
const nodeRoot = 'node_modules';

const vendor = [
  path.join(nodeRoot, 'clipboard-polyfill/build/clipboard-polyfill.js'),
  path.join(nodeRoot, `url-polyfill/url-polyfill${min}.js`),
  path.join(nodeRoot, 'turbolinks/dist/turbolinks.js'),
  path.join(nodeRoot, `jquery/dist/jquery${min}.js`),
  path.join(nodeRoot, 'jquery-ujs/src/rails.js'),
  path.join(nodeRoot, `qtip2/dist/jquery.qtip${min}.js`),
  path.join(nodeRoot, 'jquery.scrollto/jquery.scrollTo.js'),
  path.join(nodeRoot, 'jquery-ui/ui/data.js'),
  path.join(nodeRoot, 'jquery-ui/ui/scroll-parent.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widget.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widgets/mouse.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widgets/slider.js'),
  path.join(nodeRoot, 'jquery-ui/ui/widgets/sortable.js'),
  path.join(nodeRoot, 'jquery-ui/ui/keycode.js'),
  path.join(nodeRoot, 'timeago/jquery.timeago.js'),
  path.join(nodeRoot, 'blueimp-file-upload/js/jquery.fileupload.js'),
  path.join(nodeRoot, 'bootstrap/dist/js/bootstrap.js'),
  path.join(nodeRoot, 'lodash/lodash.js'),
  path.join(nodeRoot, 'layzr.js/dist/layzr.js'),
  path.join(nodeRoot, `react/umd/react.${reactMin}.js`),
  path.join(nodeRoot, 'react-dom-factories/index.js'),
  path.join(nodeRoot, `react-dom/umd/react-dom.${reactMin}.js`),
  path.join(nodeRoot, `prop-types/prop-types${min}.js`),
  path.join(nodeRoot, 'photoswipe/dist/photoswipe.js'),
  path.join(nodeRoot, 'photoswipe/dist/photoswipe-ui-default.js'),
  path.join(nodeRoot, `d3/dist/d3${min}.js`),
  path.join(nodeRoot, 'moment/moment.js'),
  path.join(nodeRoot, 'js-cookie/src/js.cookie.js'),
  path.join(nodeRoot, `imagesloaded/imagesloaded.pkgd${min}.js`),
];

vendor.forEach(function(script) {
  if (!fs.existsSync(script)) {
    throw new Error(`${script} doesn't exist`);
  }
});

let webpackConfig = {
  externals: {
    'd3': 'd3',
    'lodash': '_',
    'moment': 'moment',
    'prop-types': 'PropTypes',
    'react': 'React',
    'react-dom': 'ReactDOM',
    'react-dom-factories': 'ReactDOMFactories',
  },
  module: {
    rules: [
      {
        enforce: 'pre',
        exclude: /(node_modules)/,
        loader: 'import-glob-loader',
        test: /\.(js|coffee)$/,
      },
      {
        // loader for preexisting global coffeescript
        exclude: [
          path.resolve(__dirname, 'resources/assets/coffee/react'),
        ],
        include: [
          path.resolve(__dirname, 'resources/assets/coffee'),
        ],
        test: /\.coffee$/,
        use: ['imports-loader?this=>window', 'coffee-loader'],
      },
      {
        // loader for import-based coffeescript
        include: [
          path.resolve(__dirname, 'resources/assets/coffee/react'),
          path.resolve(__dirname, 'resources/assets/lib'),
        ],
        test: /\.coffee$/,
        use: ['coffee-loader'],
      },
    ],
  },
  optimization: {
    runtimeChunk: {
      name: '/js/commons',
    },
    splitChunks: {
      cacheGroups: {
        commons: {
          chunks: 'initial',
          minChunks: 2,
          name: '/js/commons',
        },
      },
    },
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env.DOCS_URL': JSON.stringify(process.env.DOCS_URL || 'https://docs.ppy.sh'),
      'process.env.PAYMENT_SANDBOX': JSON.stringify(paymentSandbox),
      'process.env.SHOPIFY_DOMAIN': JSON.stringify(process.env.SHOPIFY_DOMAIN),
      'process.env.SHOPIFY_STOREFRONT_TOKEN': JSON.stringify(process.env.SHOPIFY_STOREFRONT_TOKEN),
    }),
  ],
  resolve: {
    alias: {
      '@fonts': path.resolve(__dirname, 'resources/assets/fonts'),
      'ziggy': path.resolve(__dirname, 'resources/assets/js/ziggy.js'),
      'ziggy-route': path.resolve(__dirname, 'vendor/tightenco/ziggy/dist/js/route.js'),
    },
    extensions: ['*', '.js', '.coffee', '.ts'],
    modules: [
      path.resolve(__dirname, 'resources/assets/coffee'),
      path.resolve(__dirname, 'resources/assets/lib'),
      path.resolve(__dirname, 'resources/assets/coffee/react/_components'),
      path.resolve(__dirname, 'node_modules'),
    ],
    plugins: [new TsconfigPathsPlugin()],
  },
};
{'fraction_non_alphanumeric': 0.18183561906588663, 'fraction_numerical': 0.0017262875227774049, 'mean_word_length': 3.291358024691358, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2588489', 'n_tokens_mistral': 3669, 'n_tokens_neox': 3588, 'n_words': 551}