<commit_before>'use strict';

/* eslint func-names: off */
require('./polyfills');

const fs = require('fs');
const http = require('http');
const path = require('path');
const url = require('url');
const chokidar = require('chokidar');
const compress = require('compression');
const del = require('del');
const express = require('express');
const httpProxyMiddleware = require('http-proxy-middleware');
const ip = require('ip');
const killable = require('killable');
const serveIndex = require('serve-index');
const historyApiFallback = require('connect-history-api-fallback');
const selfsigned = require('selfsigned');
const sockjs = require('sockjs');
const spdy = require('spdy');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const OptionsValidationError = require('./OptionsValidationError');
const optionsSchema = require('./optionsSchema.json');

const clientStats = { errorDetails: false };
const log = console.log; // eslint-disable-line no-console

function Server(compiler, options) {
  // Default options
  if (!options) options = {};

  const validationErrors = webpack.validateSchema(optionsSchema, options);
  if (validationErrors.length) {
    throw new OptionsValidationError(validationErrors);
  }

  if (options.lazy && !options.filename) {
    throw new Error("'filename' option must be set in lazy mode.");
  }

  this.hot = options.hot || options.hotOnly;
  this.headers = options.headers;
  this.clientLogLevel = options.clientLogLevel;
  this.clientOverlay = options.overlay;
  this.progress = options.progress;
  this.disableHostCheck = !!options.disableHostCheck;
  this.publicHost = options.public;
  this.allowedHosts = options.allowedHosts;
  this.sockets = [];
  this.contentBaseWatchers = [];
  this.watchOptions = options.watchOptions || {};

  // Listening for events
  const invalidPlugin = () => {
    this.sockWrite(this.sockets, 'invalid');
  };
  if (this.progress) {
    const progressPlugin = new webpack.ProgressPlugin((percent, msg, addInfo) => {
      percent = Math.floor(percent * 100);
      if (percent === 100) msg = 'Compilation completed';
      if (addInfo) msg = `${msg} (${addInfo})`;
      this.sockWrite(this.sockets, 'progress-update', { percent, msg });
    });
    compiler.apply(progressPlugin);
  }
  compiler.plugin('compile', invalidPlugin);
  compiler.plugin('invalid', invalidPlugin);
  compiler.plugin('done', (stats) => {
    this._sendStats(this.sockets, stats.toJson(clientStats));
    this._stats = stats;
  });

  // Init express server
  const app = this.app = new express(); // eslint-disable-line

  app.all('*', (req, res, next) => { // eslint-disable-line
    if (this.checkHost(req.headers)) { return next(); }<commit_msg>Use non-deprecated webpack 4 API's<commit_after>'use strict';

/* eslint func-names: off */
require('./polyfills');

const fs = require('fs');
const http = require('http');
const path = require('path');
const url = require('url');
const chokidar = require('chokidar');
const compress = require('compression');
const del = require('del');
const express = require('express');
const httpProxyMiddleware = require('http-proxy-middleware');
const ip = require('ip');
const killable = require('killable');
const serveIndex = require('serve-index');
const historyApiFallback = require('connect-history-api-fallback');
const selfsigned = require('selfsigned');
const sockjs = require('sockjs');
const spdy = require('spdy');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const OptionsValidationError = require('./OptionsValidationError');
const optionsSchema = require('./optionsSchema.json');

const clientStats = { errorDetails: false };
const log = console.log; // eslint-disable-line no-console

function Server(compiler, options) {
  // Default options
  if (!options) options = {};

  const validationErrors = webpack.validateSchema(optionsSchema, options);
  if (validationErrors.length) {
    throw new OptionsValidationError(validationErrors);
  }

  if (options.lazy && !options.filename) {
    throw new Error("'filename' option must be set in lazy mode.");
  }

  this.hot = options.hot || options.hotOnly;
  this.headers = options.headers;
  this.clientLogLevel = options.clientLogLevel;
  this.clientOverlay = options.overlay;
  this.progress = options.progress;
  this.disableHostCheck = !!options.disableHostCheck;
  this.publicHost = options.public;
  this.allowedHosts = options.allowedHosts;
  this.sockets = [];
  this.contentBaseWatchers = [];
  this.watchOptions = options.watchOptions || {};

  // Listening for events
  const invalidPlugin = () => {
    this.sockWrite(this.sockets, 'invalid');
  };
  if (this.progress) {
    const progressPlugin = new webpack.ProgressPlugin((percent, msg, addInfo) => {
      percent = Math.floor(percent * 100);
      if (percent === 100) msg = 'Compilation completed';
      if (addInfo) msg = `${msg} (${addInfo})`;
      this.sockWrite(this.sockets, 'progress-update', { percent, msg });
    });
    compiler.apply(progressPlugin);
  }
  compiler.hooks.compile.tap('webpack-dev-server', invalidPlugin);
  compiler.hooks.invalid.tap('webpack-dev-server', invalidPlugin);
  compiler.hooks.done.tap('webpack-dev-server', (stats) => {
    this._sendStats(this.sockets, stats.toJson(clientStats));
    this._stats = stats;
  });

  // Init express server
  const app = this.app = new express(); // eslint-disable-line

  app.all('*', (req, res, next) => { // eslint-disable-line
    if (this.checkHost(req.headers)) { return next(); }
{'fraction_non_alphanumeric': 0.15453407261670543, 'fraction_numerical': 0.0023251654444643175, 'mean_word_length': 4.648484848484848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6834793', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1610, 'n_words': 380}