{"ast":null,"code":"/**\n * Copyright (c) 2015-present, Facebook, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict'; // This alternative WebpackDevServer combines the functionality of:\n// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js\n// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js\n// It only supports their simplest configuration (hot updates on same server).\n// It makes some opinionated choices on top, like adding a syntax error overlay\n// that looks similar to our console output. The error overlay is inspired by:\n// https://github.com/glenjamin/webpack-hot-middleware\n\nvar SockJS = require('sockjs-client');\n\nvar stripAnsi = require('strip-ansi');\n\nvar url = require('url');\n\nvar launchEditorEndpoint = require('./launchEditorEndpoint');\n\nvar formatWebpackMessages = require('./formatWebpackMessages');\n\nvar ErrorOverlay = require('react-error-overlay');\n\nErrorOverlay.setEditorHandler(function editorHandler(errorLocation) {\n  // Keep this sync with errorOverlayMiddleware.js\n  fetch(launchEditorEndpoint + '?fileName=' + window.encodeURIComponent(errorLocation.fileName) + '&lineNumber=' + window.encodeURIComponent(errorLocation.lineNumber || 1) + '&colNumber=' + window.encodeURIComponent(errorLocation.colNumber || 1));\n}); // We need to keep track of if there has been a runtime error.\n// Essentially, we cannot guarantee application state was not corrupted by the\n// runtime error. To prevent confusing behavior, we forcibly reload the entire\n// application. This is handled below when we are notified of a compile (code\n// change).\n// See https://github.com/facebook/create-react-app/issues/3096\n\nvar hadRuntimeError = false;\nErrorOverlay.startReportingRuntimeErrors({\n  onError: function () {\n    hadRuntimeError = true;\n  },\n  filename: '/static/js/bundle.js'\n});\n\nif (module.hot && typeof module.hot.dispose === 'function') {\n  module.hot.dispose(function () {\n    // TODO: why do we need this?\n    ErrorOverlay.stopReportingRuntimeErrors();\n  });\n} // Connect to WebpackDevServer via a socket.\n\n\nvar connection = new SockJS(url.format({\n  protocol: window.location.protocol,\n  hostname: window.location.hostname,\n  port: window.location.port,\n  // Hardcoded in WebpackDevServer\n  pathname: '/sockjs-node'\n})); // Unlike WebpackDevServer client, we won't try to reconnect\n// to avoid spamming the console. Disconnect usually happens\n// when developer stops the server.\n\nconnection.onclose = function () {\n  if (typeof console !== 'undefined' && typeof console.info === 'function') {\n    console.info('The development server has disconnected.\\nRefresh the page if necessary.');\n  }\n}; // Remember some state related to hot module replacement.\n\n\nvar isFirstCompilation = true;\nvar mostRecentCompilationHash = null;\nvar hasCompileErrors = false;\n\nfunction clearOutdatedErrors() {\n  // Clean up outdated compile errors, if any.\n  if (typeof console !== 'undefined' && typeof console.clear === 'function') {\n    if (hasCompileErrors) {\n      console.clear();\n    }\n  }\n} // Successful compilation.\n\n\nfunction handleSuccess() {\n  clearOutdatedErrors();\n  var isHotUpdate = !isFirstCompilation;\n  isFirstCompilation = false;\n  hasCompileErrors = false; // Attempt to apply hot updates or reload.\n\n  if (isHotUpdate) {\n    tryApplyUpdates(function onHotUpdateSuccess() {\n      // Only dismiss it when we're sure it's a hot update.\n      // Otherwise it would flicker right before the reload.\n      tryDismissErrorOverlay();\n    });\n  }\n} // Compilation with warnings (e.g. ESLint).\n\n\nfunction handleWarnings(warnings) {\n  clearOutdatedErrors();\n  var isHotUpdate = !isFirstCompilation;\n  isFirstCompilation = false;\n  hasCompileErrors = false;\n\n  function printWarnings() {\n    // Print warnings to the console.\n    var formatted = formatWebpackMessages({\n      warnings: warnings,\n      errors: []\n    });\n\n    if (typeof console !== 'undefined' && typeof console.warn === 'function') {\n      for (var i = 0; i < formatted.warnings.length; i++) {\n        if (i === 5) {\n          console.warn('There were more warnings in other files.\\n' + 'You can find a complete log in the terminal.');\n          break;\n        }\n\n        console.warn(stripAnsi(formatted.warnings[i]));\n      }\n    }\n  }\n\n  printWarnings(); // Attempt to apply hot updates or reload.\n\n  if (isHotUpdate) {\n    tryApplyUpdates(function onSuccessfulHotUpdate() {\n      // Only dismiss it when we're sure it's a hot update.\n      // Otherwise it would flicker right before the reload.\n      tryDismissErrorOverlay();\n    });\n  }\n} // Compilation with errors (e.g. syntax error or missing modules).\n\n\nfunction handleErrors(errors) {\n  clearOutdatedErrors();\n  isFirstCompilation = false;\n  hasCompileErrors = true; // \"Massage\" webpack messages.\n\n  var formatted = formatWebpackMessages({\n    errors: errors,\n    warnings: []\n  }); // Only show the first error.\n\n  ErrorOverlay.reportBuildError(formatted.errors[0]); // Also log them to the console.\n\n  if (typeof console !== 'undefined' && typeof console.error === 'function') {\n    for (var i = 0; i < formatted.errors.length; i++) {\n      console.error(stripAnsi(formatted.errors[i]));\n    }\n  } // Do not attempt to reload now.\n  // We will reload on next success instead.\n\n}\n\nfunction tryDismissErrorOverlay() {\n  if (!hasCompileErrors) {\n    ErrorOverlay.dismissBuildError();\n  }\n} // There is a newer version of the code available.\n\n\nfunction handleAvailableHash(hash) {\n  // Update last known compilation hash.\n  mostRecentCompilationHash = hash;\n} // Handle messages from the server.\n\n\nconnection.onmessage = function (e) {\n  var message = JSON.parse(e.data);\n\n  switch (message.type) {\n    case 'hash':\n      handleAvailableHash(message.data);\n      break;\n\n    case 'still-ok':\n    case 'ok':\n      handleSuccess();\n      break;\n\n    case 'content-changed':\n      // Triggered when a file from `contentBase` changed.\n      window.location.reload();\n      break;\n\n    case 'warnings':\n      handleWarnings(message.data);\n      break;\n\n    case 'errors':\n      handleErrors(message.data);\n      break;\n\n    default: // Do nothing.\n\n  }\n}; // Is there a newer version of this code available?\n\n\nfunction isUpdateAvailable() {\n  /* globals __webpack_hash__ */\n  // __webpack_hash__ is the hash of the current compilation.\n  // It's a global variable injected by Webpack.\n  return mostRecentCompilationHash !== __webpack_hash__;\n} // Webpack disallows updates in other states.\n\n\nfunction canApplyUpdates() {\n  return module.hot.status() === 'idle';\n} // Attempt to update code on the fly, fall back to a hard reload.\n\n\nfunction tryApplyUpdates(onHotUpdateSuccess) {\n  if (!module.hot) {\n    // HotModuleReplacementPlugin is not in Webpack configuration.\n    window.location.reload();\n    return;\n  }\n\n  if (!isUpdateAvailable() || !canApplyUpdates()) {\n    return;\n  }\n\n  function handleApplyUpdates(err, updatedModules) {\n    if (err || !updatedModules || hadRuntimeError) {\n      window.location.reload();\n      return;\n    }\n\n    if (typeof onHotUpdateSuccess === 'function') {\n      // Maybe we want to do something.\n      onHotUpdateSuccess();\n    }\n\n    if (isUpdateAvailable()) {\n      // While we were updating, there was a new update! Do it again.\n      tryApplyUpdates();\n    }\n  } // https://webpack.github.io/docs/hot-module-replacement.html#check\n\n\n  var result = module.hot.check(\n  /* autoApply */\n  true, handleApplyUpdates); // // Webpack 2 returns a Promise instead of invoking a callback\n\n  if (result && result.then) {\n    result.then(function (updatedModules) {\n      handleApplyUpdates(null, updatedModules);\n    }, function (err) {\n      handleApplyUpdates(err, null);\n    });\n  }\n}","map":null,"metadata":{},"sourceType":"script"}