create project
This commit is contained in:
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.d.ts
generated
vendored
Normal file
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function formatWebpackMessages(json: any, verbose?: boolean): any
|
||||
119
kitabcitab/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js
generated
vendored
Normal file
119
kitabcitab/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
"use strict";
|
||||
var _extends = require("@swc/helpers/lib/_extends.js").default;
|
||||
var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default;
|
||||
var _stripAnsi = _interop_require_default(require("next/dist/compiled/strip-ansi"));
|
||||
// This file is based on https://github.com/facebook/create-react-app/blob/7b1a32be6ec9f99a6c9a3c66813f3ac09c4736b9/packages/react-dev-utils/formatWebpackMessages.js
|
||||
// It's been edited to remove chalk and CRA-specific logic
|
||||
const friendlySyntaxErrorLabel = 'Syntax error:';
|
||||
const WEBPACK_BREAKING_CHANGE_POLYFILLS = '\n\nBREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.';
|
||||
function isLikelyASyntaxError(message) {
|
||||
return (0, _stripAnsi).default(message).indexOf(friendlySyntaxErrorLabel) !== -1;
|
||||
}
|
||||
let hadMissingSassError = false;
|
||||
// Cleans up webpack error messages.
|
||||
function formatMessage(message, verbose, importTraceNote) {
|
||||
// TODO: Replace this once webpack 5 is stable
|
||||
if (typeof message === 'object' && message.message) {
|
||||
const filteredModuleTrace = message.moduleTrace && message.moduleTrace.filter((trace)=>!/next-(middleware|client-pages|edge-function)-loader\.js/.test(trace.originName));
|
||||
let body = message.message;
|
||||
const breakingChangeIndex = body.indexOf(WEBPACK_BREAKING_CHANGE_POLYFILLS);
|
||||
if (breakingChangeIndex >= 0) {
|
||||
body = body.slice(0, breakingChangeIndex);
|
||||
}
|
||||
message = (message.moduleName ? (0, _stripAnsi).default(message.moduleName) + '\n' : '') + (message.file ? (0, _stripAnsi).default(message.file) + '\n' : '') + body + (message.details && verbose ? '\n' + message.details : '') + (filteredModuleTrace && filteredModuleTrace.length && verbose ? (importTraceNote || '\n\nImport trace for requested module:') + filteredModuleTrace.map((trace)=>`\n${trace.moduleName}`).join('') : '') + (message.stack && verbose ? '\n' + message.stack : '');
|
||||
}
|
||||
let lines = message.split('\n');
|
||||
// Strip Webpack-added headers off errors/warnings
|
||||
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
||||
lines = lines.filter((line)=>!/Module [A-z ]+\(from/.test(line));
|
||||
// Transform parsing error into syntax error
|
||||
// TODO: move this to our ESLint formatter?
|
||||
lines = lines.map((line)=>{
|
||||
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
|
||||
if (!parsingError) {
|
||||
return line;
|
||||
}
|
||||
const [, errorLine, errorColumn, errorMessage] = parsingError;
|
||||
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
||||
});
|
||||
message = lines.join('\n');
|
||||
// Smoosh syntax errors (commonly found in CSS)
|
||||
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`);
|
||||
// Clean up export errors
|
||||
message = message.replace(/^.*export '(.+?)' was not found in '(.+?)'.*$/gm, `Attempted import error: '$1' is not exported from '$2'.`);
|
||||
message = message.replace(/^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, `Attempted import error: '$2' does not contain a default export (imported as '$1').`);
|
||||
message = message.replace(/^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm, `Attempted import error: '$1' is not exported from '$3' (imported as '$2').`);
|
||||
lines = message.split('\n');
|
||||
// Remove leading newline
|
||||
if (lines.length > 2 && lines[1].trim() === '') {
|
||||
lines.splice(1, 1);
|
||||
}
|
||||
// Cleans up verbose "module not found" messages for files and packages.
|
||||
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
||||
lines = [
|
||||
lines[0],
|
||||
lines[1].replace('Error: ', '').replace('Module not found: Cannot find file:', 'Cannot find file:'),
|
||||
...lines.slice(2),
|
||||
];
|
||||
}
|
||||
// Add helpful message for users trying to use Sass for the first time
|
||||
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
||||
// ./file.module.scss (<<loader info>>) => ./file.module.scss
|
||||
const firstLine = lines[0].split('!');
|
||||
lines[0] = firstLine[firstLine.length - 1];
|
||||
lines[1] = "To use Next.js' built-in Sass support, you first need to install `sass`.\n";
|
||||
lines[1] += 'Run `npm i sass` or `yarn add sass` inside your workspace.\n';
|
||||
lines[1] += '\nLearn more: https://nextjs.org/docs/messages/install-sass';
|
||||
// dispose of unhelpful stack trace
|
||||
lines = lines.slice(0, 2);
|
||||
hadMissingSassError = true;
|
||||
} else if (hadMissingSassError && message.match(/(sass-loader|resolve-url-loader: CSS error)/)) {
|
||||
// dispose of unhelpful stack trace following missing sass module
|
||||
lines = [];
|
||||
}
|
||||
if (!verbose) {
|
||||
message = lines.join('\n');
|
||||
// Internal stacks are generally useless so we strip them... with the
|
||||
// exception of stacks containing `webpack:` because they're normally
|
||||
// from user code generated by Webpack. For more information see
|
||||
// https://github.com/facebook/create-react-app/pull/1050
|
||||
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, '') // at ... ...:x:y
|
||||
;
|
||||
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, '') // at <anonymous>
|
||||
;
|
||||
lines = message.split('\n');
|
||||
}
|
||||
// Remove duplicated newlines
|
||||
lines = lines.filter((line, index, arr)=>index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim());
|
||||
// Reassemble the message
|
||||
message = lines.join('\n');
|
||||
return message.trim();
|
||||
}
|
||||
function formatWebpackMessages(json, verbose) {
|
||||
const formattedErrors = json.errors.map(function(message) {
|
||||
const isUnknownNextFontError = message.message.includes('An error occured in `@next/font`.');
|
||||
return formatMessage(message, isUnknownNextFontError || verbose);
|
||||
});
|
||||
const formattedWarnings = json.warnings.map(function(message) {
|
||||
return formatMessage(message, verbose);
|
||||
});
|
||||
const result = _extends({}, json, {
|
||||
errors: formattedErrors,
|
||||
warnings: formattedWarnings
|
||||
});
|
||||
if (!verbose && result.errors.some(isLikelyASyntaxError)) {
|
||||
// If there are any syntax errors, show just them.
|
||||
result.errors = result.errors.filter(isLikelyASyntaxError);
|
||||
result.warnings = [];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
module.exports = formatWebpackMessages;
|
||||
|
||||
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||||
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||||
Object.assign(exports.default, exports);
|
||||
module.exports = exports.default;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=format-webpack-messages.js.map
|
||||
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js.map
generated
vendored
Normal file
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/format-webpack-messages.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
308
kitabcitab/node_modules/next/dist/client/dev/error-overlay/hot-dev-client.js
generated
vendored
Normal file
308
kitabcitab/node_modules/next/dist/client/dev/error-overlay/hot-dev-client.js
generated
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = connect;
|
||||
var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default;
|
||||
var _client = require("next/dist/compiled/@next/react-dev-overlay/dist/client");
|
||||
var _stripAnsi = _interop_require_default(require("next/dist/compiled/strip-ansi"));
|
||||
var _websocket = require("./websocket");
|
||||
var _formatWebpackMessages = _interop_require_default(require("./format-webpack-messages"));
|
||||
function connect() {
|
||||
(0, _client).register();
|
||||
(0, _websocket).addMessageListener((event)=>{
|
||||
if (event.data.indexOf('action') === -1) return;
|
||||
try {
|
||||
processMessage(event);
|
||||
} catch (ex) {
|
||||
console.warn('Invalid HMR message: ' + event.data + '\n', ex);
|
||||
}
|
||||
});
|
||||
return {
|
||||
subscribeToHmrEvent (handler) {
|
||||
customHmrEventHandler = handler;
|
||||
},
|
||||
onUnrecoverableError () {
|
||||
hadRuntimeError = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
// This alternative WebpackDevServer combines the functionality of:
|
||||
// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js
|
||||
// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js
|
||||
// It only supports their simplest configuration (hot updates on same server).
|
||||
// It makes some opinionated choices on top, like adding a syntax error overlay
|
||||
// that looks similar to our console output. The error overlay is inspired by:
|
||||
// https://github.com/glenjamin/webpack-hot-middleware
|
||||
window.__nextDevClientId = Math.round(Math.random() * 100 + Date.now());
|
||||
let hadRuntimeError = false;
|
||||
let customHmrEventHandler;
|
||||
// Remember some state related to hot module replacement.
|
||||
var isFirstCompilation = true;
|
||||
var mostRecentCompilationHash = null;
|
||||
var hasCompileErrors = false;
|
||||
function clearOutdatedErrors() {
|
||||
// Clean up outdated compile errors, if any.
|
||||
if (typeof console !== 'undefined' && typeof console.clear === 'function') {
|
||||
if (hasCompileErrors) {
|
||||
console.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Successful compilation.
|
||||
function handleSuccess() {
|
||||
clearOutdatedErrors();
|
||||
const isHotUpdate = !isFirstCompilation || window.__NEXT_DATA__.page !== '/_error' && isUpdateAvailable();
|
||||
isFirstCompilation = false;
|
||||
hasCompileErrors = false;
|
||||
// Attempt to apply hot updates or reload.
|
||||
if (isHotUpdate) {
|
||||
tryApplyUpdates(onBeforeFastRefresh, onFastRefresh);
|
||||
}
|
||||
}
|
||||
// Compilation with warnings (e.g. ESLint).
|
||||
function handleWarnings(warnings) {
|
||||
clearOutdatedErrors();
|
||||
const isHotUpdate = !isFirstCompilation;
|
||||
isFirstCompilation = false;
|
||||
hasCompileErrors = false;
|
||||
function printWarnings() {
|
||||
// Print warnings to the console.
|
||||
const formatted = (0, _formatWebpackMessages).default({
|
||||
warnings: warnings,
|
||||
errors: []
|
||||
});
|
||||
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
|
||||
var ref;
|
||||
for(let i = 0; i < ((ref = formatted.warnings) == null ? void 0 : ref.length); i++){
|
||||
if (i === 5) {
|
||||
console.warn('There were more warnings in other files.\n' + 'You can find a complete log in the terminal.');
|
||||
break;
|
||||
}
|
||||
console.warn((0, _stripAnsi).default(formatted.warnings[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
printWarnings();
|
||||
// Attempt to apply hot updates or reload.
|
||||
if (isHotUpdate) {
|
||||
tryApplyUpdates(onBeforeFastRefresh, onFastRefresh);
|
||||
}
|
||||
}
|
||||
// Compilation with errors (e.g. syntax error or missing modules).
|
||||
function handleErrors(errors) {
|
||||
clearOutdatedErrors();
|
||||
isFirstCompilation = false;
|
||||
hasCompileErrors = true;
|
||||
// "Massage" webpack messages.
|
||||
var formatted = (0, _formatWebpackMessages).default({
|
||||
errors: errors,
|
||||
warnings: []
|
||||
});
|
||||
// Only show the first error.
|
||||
(0, _client).onBuildError(formatted.errors[0]);
|
||||
// Also log them to the console.
|
||||
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
||||
for(var i = 0; i < formatted.errors.length; i++){
|
||||
console.error((0, _stripAnsi).default(formatted.errors[i]));
|
||||
}
|
||||
}
|
||||
// Do not attempt to reload now.
|
||||
// We will reload on next success instead.
|
||||
if (process.env.__NEXT_TEST_MODE) {
|
||||
if (self.__NEXT_HMR_CB) {
|
||||
self.__NEXT_HMR_CB(formatted.errors[0]);
|
||||
self.__NEXT_HMR_CB = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
let startLatency = undefined;
|
||||
function onBeforeFastRefresh(hasUpdates) {
|
||||
if (hasUpdates) {
|
||||
// Only trigger a pending state if we have updates to apply
|
||||
// (cf. onFastRefresh)
|
||||
(0, _client).onBeforeRefresh();
|
||||
}
|
||||
}
|
||||
function onFastRefresh(hasUpdates) {
|
||||
(0, _client).onBuildOk();
|
||||
if (hasUpdates) {
|
||||
// Only complete a pending state if we applied updates
|
||||
// (cf. onBeforeFastRefresh)
|
||||
(0, _client).onRefresh();
|
||||
}
|
||||
if (startLatency) {
|
||||
const endLatency = Date.now();
|
||||
const latency = endLatency - startLatency;
|
||||
console.log(`[Fast Refresh] done in ${latency}ms`);
|
||||
(0, _websocket).sendMessage(JSON.stringify({
|
||||
event: 'client-hmr-latency',
|
||||
id: window.__nextDevClientId,
|
||||
startTime: startLatency,
|
||||
endTime: endLatency
|
||||
}));
|
||||
if (self.__NEXT_HMR_LATENCY_CB) {
|
||||
self.__NEXT_HMR_LATENCY_CB(latency);
|
||||
}
|
||||
}
|
||||
}
|
||||
// There is a newer version of the code available.
|
||||
function handleAvailableHash(hash) {
|
||||
// Update last known compilation hash.
|
||||
mostRecentCompilationHash = hash;
|
||||
}
|
||||
// Handle messages from the server.
|
||||
function processMessage(e) {
|
||||
const obj = JSON.parse(e.data);
|
||||
switch(obj.action){
|
||||
case 'building':
|
||||
{
|
||||
startLatency = Date.now();
|
||||
console.log('[Fast Refresh] rebuilding');
|
||||
break;
|
||||
}
|
||||
case 'built':
|
||||
case 'sync':
|
||||
{
|
||||
if (obj.hash) {
|
||||
handleAvailableHash(obj.hash);
|
||||
}
|
||||
const { errors , warnings } = obj;
|
||||
const hasErrors = Boolean(errors && errors.length);
|
||||
if (hasErrors) {
|
||||
(0, _websocket).sendMessage(JSON.stringify({
|
||||
event: 'client-error',
|
||||
errorCount: errors.length,
|
||||
clientId: window.__nextDevClientId
|
||||
}));
|
||||
return handleErrors(errors);
|
||||
}
|
||||
const hasWarnings = Boolean(warnings && warnings.length);
|
||||
if (hasWarnings) {
|
||||
(0, _websocket).sendMessage(JSON.stringify({
|
||||
event: 'client-warning',
|
||||
warningCount: warnings.length,
|
||||
clientId: window.__nextDevClientId
|
||||
}));
|
||||
return handleWarnings(warnings);
|
||||
}
|
||||
(0, _websocket).sendMessage(JSON.stringify({
|
||||
event: 'client-success',
|
||||
clientId: window.__nextDevClientId
|
||||
}));
|
||||
return handleSuccess();
|
||||
}
|
||||
case 'serverComponentChanges':
|
||||
{
|
||||
// Server component changes don't apply to `pages`.
|
||||
return;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (customHmrEventHandler) {
|
||||
customHmrEventHandler(obj);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Is there a newer version of this code available?
|
||||
function isUpdateAvailable() {
|
||||
/* globals __webpack_hash__ */ // __webpack_hash__ is the hash of the current compilation.
|
||||
// It's a global variable injected by Webpack.
|
||||
return mostRecentCompilationHash !== __webpack_hash__;
|
||||
}
|
||||
// Webpack disallows updates in other states.
|
||||
function canApplyUpdates() {
|
||||
return module.hot.status() === 'idle';
|
||||
}
|
||||
function afterApplyUpdates(fn) {
|
||||
if (canApplyUpdates()) {
|
||||
fn();
|
||||
} else {
|
||||
function handler(status) {
|
||||
if (status === 'idle') {
|
||||
module.hot.removeStatusHandler(handler);
|
||||
fn();
|
||||
}
|
||||
}
|
||||
module.hot.addStatusHandler(handler);
|
||||
}
|
||||
}
|
||||
// Attempt to update code on the fly, fall back to a hard reload.
|
||||
function tryApplyUpdates(onBeforeHotUpdate, onHotUpdateSuccess) {
|
||||
if (!module.hot) {
|
||||
// HotModuleReplacementPlugin is not in Webpack configuration.
|
||||
console.error('HotModuleReplacementPlugin is not in Webpack configuration.');
|
||||
// window.location.reload();
|
||||
return;
|
||||
}
|
||||
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
||||
(0, _client).onBuildOk();
|
||||
return;
|
||||
}
|
||||
function handleApplyUpdates(err, updatedModules) {
|
||||
if (err || hadRuntimeError || !updatedModules) {
|
||||
if (err) {
|
||||
console.warn('[Fast Refresh] performing full reload\n\n' + "Fast Refresh will perform a full reload when you edit a file that's imported by modules outside of the React rendering tree.\n" + 'You might have a file which exports a React component but also exports a value that is imported by a non-React component file.\n' + 'Consider migrating the non-React component export to a separate file and importing it into both files.\n\n' + 'It is also possible the parent component of the component you edited is a class component, which disables Fast Refresh.\n' + 'Fast Refresh requires at least one parent function component in your React tree.');
|
||||
} else if (hadRuntimeError) {
|
||||
console.warn('[Fast Refresh] performing full reload because your application had an unrecoverable error');
|
||||
}
|
||||
performFullReload(err);
|
||||
return;
|
||||
}
|
||||
const hasUpdates = Boolean(updatedModules.length);
|
||||
if (typeof onHotUpdateSuccess === 'function') {
|
||||
// Maybe we want to do something.
|
||||
onHotUpdateSuccess(hasUpdates);
|
||||
}
|
||||
if (isUpdateAvailable()) {
|
||||
// While we were updating, there was a new update! Do it again.
|
||||
// However, this time, don't trigger a pending refresh state.
|
||||
tryApplyUpdates(hasUpdates ? undefined : onBeforeHotUpdate, hasUpdates ? _client.onBuildOk : onHotUpdateSuccess);
|
||||
} else {
|
||||
(0, _client).onBuildOk();
|
||||
if (process.env.__NEXT_TEST_MODE) {
|
||||
afterApplyUpdates(()=>{
|
||||
if (self.__NEXT_HMR_CB) {
|
||||
self.__NEXT_HMR_CB();
|
||||
self.__NEXT_HMR_CB = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// https://webpack.js.org/api/hot-module-replacement/#check
|
||||
module.hot.check(/* autoApply */ false).then((updatedModules)=>{
|
||||
if (!updatedModules) {
|
||||
return null;
|
||||
}
|
||||
if (typeof onBeforeHotUpdate === 'function') {
|
||||
const hasUpdates = Boolean(updatedModules.length);
|
||||
onBeforeHotUpdate(hasUpdates);
|
||||
}
|
||||
return module.hot.apply();
|
||||
}).then((updatedModules)=>{
|
||||
handleApplyUpdates(null, updatedModules);
|
||||
}, (err)=>{
|
||||
handleApplyUpdates(err, null);
|
||||
});
|
||||
}
|
||||
function performFullReload(err) {
|
||||
const stackTrace = err && (err.stack && err.stack.split('\n').slice(0, 5).join('\n') || err.message || err + '');
|
||||
(0, _websocket).sendMessage(JSON.stringify({
|
||||
event: 'client-full-reload',
|
||||
stackTrace,
|
||||
hadRuntimeError: !!hadRuntimeError
|
||||
}));
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||||
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||||
Object.assign(exports.default, exports);
|
||||
module.exports = exports.default;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=hot-dev-client.js.map
|
||||
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/hot-dev-client.js.map
generated
vendored
Normal file
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/hot-dev-client.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
8
kitabcitab/node_modules/next/dist/client/dev/error-overlay/websocket.d.ts
generated
vendored
Normal file
8
kitabcitab/node_modules/next/dist/client/dev/error-overlay/websocket.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export declare function addMessageListener(cb: (event: any) => void): void;
|
||||
export declare function sendMessage(data: any): void;
|
||||
export declare function connectHMR(options: {
|
||||
path: string;
|
||||
assetPrefix: string;
|
||||
timeout: number;
|
||||
log?: boolean;
|
||||
}): void;
|
||||
74
kitabcitab/node_modules/next/dist/client/dev/error-overlay/websocket.js
generated
vendored
Normal file
74
kitabcitab/node_modules/next/dist/client/dev/error-overlay/websocket.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.addMessageListener = addMessageListener;
|
||||
exports.sendMessage = sendMessage;
|
||||
exports.connectHMR = connectHMR;
|
||||
let source;
|
||||
const eventCallbacks = [];
|
||||
let lastActivity = Date.now();
|
||||
function getSocketProtocol(assetPrefix) {
|
||||
let protocol = location.protocol;
|
||||
try {
|
||||
// assetPrefix is a url
|
||||
protocol = new URL(assetPrefix).protocol;
|
||||
} catch (_) {}
|
||||
return protocol === 'http:' ? 'ws' : 'wss';
|
||||
}
|
||||
function addMessageListener(cb) {
|
||||
eventCallbacks.push(cb);
|
||||
}
|
||||
function sendMessage(data) {
|
||||
if (!source || source.readyState !== source.OPEN) return;
|
||||
return source.send(data);
|
||||
}
|
||||
function connectHMR(options) {
|
||||
if (!options.timeout) {
|
||||
options.timeout = 5 * 1000;
|
||||
}
|
||||
function init() {
|
||||
if (source) source.close();
|
||||
function handleOnline() {
|
||||
if (options.log) console.log('[HMR] connected');
|
||||
lastActivity = Date.now();
|
||||
}
|
||||
function handleMessage(event) {
|
||||
lastActivity = Date.now();
|
||||
eventCallbacks.forEach((cb)=>{
|
||||
cb(event);
|
||||
});
|
||||
}
|
||||
let timer;
|
||||
function handleDisconnect() {
|
||||
clearInterval(timer);
|
||||
source.close();
|
||||
setTimeout(init, options.timeout);
|
||||
}
|
||||
timer = setInterval(function() {
|
||||
if (Date.now() - lastActivity > options.timeout) {
|
||||
handleDisconnect();
|
||||
}
|
||||
}, options.timeout / 2);
|
||||
const { hostname , port } = location;
|
||||
const protocol = getSocketProtocol(options.assetPrefix || '');
|
||||
const assetPrefix = options.assetPrefix.replace(/^\/+/, '');
|
||||
let url = `${protocol}://${hostname}:${port}${assetPrefix ? `/${assetPrefix}` : ''}`;
|
||||
if (assetPrefix.startsWith('http')) {
|
||||
url = `${protocol}://${assetPrefix.split('://')[1]}`;
|
||||
}
|
||||
source = new window.WebSocket(`${url}${options.path}`);
|
||||
source.onopen = handleOnline;
|
||||
source.onerror = handleDisconnect;
|
||||
source.onmessage = handleMessage;
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||||
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||||
Object.assign(exports.default, exports);
|
||||
module.exports = exports.default;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=websocket.js.map
|
||||
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/websocket.js.map
generated
vendored
Normal file
1
kitabcitab/node_modules/next/dist/client/dev/error-overlay/websocket.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../client/dev/error-overlay/websocket.ts"],"names":["addMessageListener","sendMessage","connectHMR","source","eventCallbacks","lastActivity","Date","now","getSocketProtocol","assetPrefix","protocol","location","URL","_","cb","push","data","readyState","OPEN","send","options","timeout","init","close","handleOnline","log","console","handleMessage","event","forEach","timer","handleDisconnect","clearInterval","setTimeout","setInterval","hostname","port","replace","url","startsWith","split","window","WebSocket","path","onopen","onerror","onmessage"],"mappings":"AAAA;;;;QAegBA,kBAAkB,GAAlBA,kBAAkB;QAIlBC,WAAW,GAAXA,WAAW;QAKXC,UAAU,GAAVA,UAAU;AAxB1B,IAAIC,MAAM,AAAW;AACrB,MAAMC,cAAc,GAA6B,EAAE;AACnD,IAAIC,YAAY,GAAGC,IAAI,CAACC,GAAG,EAAE;AAE7B,SAASC,iBAAiB,CAACC,WAAmB,EAAU;IACtD,IAAIC,QAAQ,GAAGC,QAAQ,CAACD,QAAQ;IAEhC,IAAI;QACF,uBAAuB;QACvBA,QAAQ,GAAG,IAAIE,GAAG,CAACH,WAAW,CAAC,CAACC,QAAQ;KACzC,CAAC,OAAOG,CAAC,EAAE,EAAE;IAEd,OAAOH,QAAQ,KAAK,OAAO,GAAG,IAAI,GAAG,KAAK,CAAA;CAC3C;AAEM,SAASV,kBAAkB,CAACc,EAAwB,EAAE;IAC3DV,cAAc,CAACW,IAAI,CAACD,EAAE,CAAC;CACxB;AAEM,SAASb,WAAW,CAACe,IAAS,EAAE;IACrC,IAAI,CAACb,MAAM,IAAIA,MAAM,CAACc,UAAU,KAAKd,MAAM,CAACe,IAAI,EAAE,OAAM;IACxD,OAAOf,MAAM,CA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