Spaces:
Running
Running
File size: 6,035 Bytes
979bf48 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
DecodeError: null,
MiddlewareNotFoundError: null,
MissingStaticPage: null,
NormalizeError: null,
PageNotFoundError: null,
SP: null,
ST: null,
WEB_VITALS: null,
execOnce: null,
getDisplayName: null,
getLocationOrigin: null,
getURL: null,
isAbsoluteUrl: null,
isResSent: null,
loadGetInitialProps: null,
normalizeRepeatedSlashes: null,
stringifyError: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
DecodeError: function() {
return DecodeError;
},
MiddlewareNotFoundError: function() {
return MiddlewareNotFoundError;
},
MissingStaticPage: function() {
return MissingStaticPage;
},
NormalizeError: function() {
return NormalizeError;
},
PageNotFoundError: function() {
return PageNotFoundError;
},
SP: function() {
return SP;
},
ST: function() {
return ST;
},
WEB_VITALS: function() {
return WEB_VITALS;
},
execOnce: function() {
return execOnce;
},
getDisplayName: function() {
return getDisplayName;
},
getLocationOrigin: function() {
return getLocationOrigin;
},
getURL: function() {
return getURL;
},
isAbsoluteUrl: function() {
return isAbsoluteUrl;
},
isResSent: function() {
return isResSent;
},
loadGetInitialProps: function() {
return loadGetInitialProps;
},
normalizeRepeatedSlashes: function() {
return normalizeRepeatedSlashes;
},
stringifyError: function() {
return stringifyError;
}
});
const WEB_VITALS = [
'CLS',
'FCP',
'FID',
'INP',
'LCP',
'TTFB'
];
function execOnce(fn) {
let used = false;
let result;
return (...args)=>{
if (!used) {
used = true;
result = fn(...args);
}
return result;
};
}
// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
const ABSOLUTE_URL_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/;
const isAbsoluteUrl = (url)=>ABSOLUTE_URL_REGEX.test(url);
function getLocationOrigin() {
const { protocol, hostname, port } = window.location;
return `${protocol}//${hostname}${port ? ':' + port : ''}`;
}
function getURL() {
const { href } = window.location;
const origin = getLocationOrigin();
return href.substring(origin.length);
}
function getDisplayName(Component) {
return typeof Component === 'string' ? Component : Component.displayName || Component.name || 'Unknown';
}
function isResSent(res) {
return res.finished || res.headersSent;
}
function normalizeRepeatedSlashes(url) {
const urlParts = url.split('?');
const urlNoQuery = urlParts[0];
return urlNoQuery// first we replace any non-encoded backslashes with forward
// then normalize repeated forward slashes
.replace(/\\/g, '/').replace(/\/\/+/g, '/') + (urlParts[1] ? `?${urlParts.slice(1).join('?')}` : '');
}
async function loadGetInitialProps(App, ctx) {
if (process.env.NODE_ENV !== 'production') {
if (App.prototype?.getInitialProps) {
const message = `"${getDisplayName(App)}.getInitialProps()" is defined as an instance method - visit https://nextjs.org/docs/messages/get-initial-props-as-an-instance-method for more information.`;
throw Object.defineProperty(new Error(message), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
}
}
// when called from _app `ctx` is nested in `ctx`
const res = ctx.res || ctx.ctx && ctx.ctx.res;
if (!App.getInitialProps) {
if (ctx.ctx && ctx.Component) {
// @ts-ignore pageProps default
return {
pageProps: await loadGetInitialProps(ctx.Component, ctx.ctx)
};
}
return {};
}
const props = await App.getInitialProps(ctx);
if (res && isResSent(res)) {
return props;
}
if (!props) {
const message = `"${getDisplayName(App)}.getInitialProps()" should resolve to an object. But found "${props}" instead.`;
throw Object.defineProperty(new Error(message), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
}
if (process.env.NODE_ENV !== 'production') {
if (Object.keys(props).length === 0 && !ctx.ctx) {
console.warn(`${getDisplayName(App)} returned an empty object from \`getInitialProps\`. This de-optimizes and prevents automatic static optimization. https://nextjs.org/docs/messages/empty-object-getInitialProps`);
}
}
return props;
}
const SP = typeof performance !== 'undefined';
const ST = SP && [
'mark',
'measure',
'getEntriesByName'
].every((method)=>typeof performance[method] === 'function');
class DecodeError extends Error {
}
class NormalizeError extends Error {
}
class PageNotFoundError extends Error {
constructor(page){
super();
this.code = 'ENOENT';
this.name = 'PageNotFoundError';
this.message = `Cannot find module for page: ${page}`;
}
}
class MissingStaticPage extends Error {
constructor(page, message){
super();
this.message = `Failed to load static file for page: ${page} ${message}`;
}
}
class MiddlewareNotFoundError extends Error {
constructor(){
super();
this.code = 'ENOENT';
this.message = `Cannot find the middleware module`;
}
}
function stringifyError(error) {
return JSON.stringify({
message: error.message,
stack: error.stack
});
}
//# sourceMappingURL=utils.js.map |