This commit is contained in:
Kismet Hasanaj
2026-05-02 20:07:02 +02:00
parent ce8672e283
commit 34dc9aec52
9428 changed files with 1733330 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
export declare function formatConsoleArgs(args: unknown[]): string;
export declare function parseConsoleArgs(args: unknown[]): {
environmentName: string | null;
error: Error | null;
};
+177
View File
@@ -0,0 +1,177 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
formatConsoleArgs: null,
parseConsoleArgs: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
formatConsoleArgs: function() {
return formatConsoleArgs;
},
parseConsoleArgs: function() {
return parseConsoleArgs;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _iserror = /*#__PURE__*/ _interop_require_default._(require("../../lib/is-error"));
function formatObject(arg, depth) {
switch(typeof arg){
case 'object':
if (arg === null) {
return 'null';
} else if (Array.isArray(arg)) {
let result = '[';
if (depth < 1) {
for(let i = 0; i < arg.length; i++){
if (result !== '[') {
result += ',';
}
if (Object.prototype.hasOwnProperty.call(arg, i)) {
result += formatObject(arg[i], depth + 1);
}
}
} else {
result += arg.length > 0 ? '...' : '';
}
result += ']';
return result;
} else if (arg instanceof Error) {
return arg + '';
} else {
const keys = Object.keys(arg);
let result = '{';
if (depth < 1) {
for(let i = 0; i < keys.length; i++){
const key = keys[i];
const desc = Object.getOwnPropertyDescriptor(arg, 'key');
if (desc && !desc.get && !desc.set) {
const jsonKey = JSON.stringify(key);
if (jsonKey !== '"' + key + '"') {
result += jsonKey + ': ';
} else {
result += key + ': ';
}
result += formatObject(desc.value, depth + 1);
}
}
} else {
result += keys.length > 0 ? '...' : '';
}
result += '}';
return result;
}
case 'string':
return JSON.stringify(arg);
case 'number':
case 'bigint':
case 'boolean':
case 'symbol':
case 'undefined':
case 'function':
default:
return String(arg);
}
}
function formatConsoleArgs(args) {
let message;
let idx;
if (typeof args[0] === 'string') {
message = args[0];
idx = 1;
} else {
message = '';
idx = 0;
}
let result = '';
let startQuote = false;
for(let i = 0; i < message.length; ++i){
const char = message[i];
if (char !== '%' || i === message.length - 1 || idx >= args.length) {
result += char;
continue;
}
const code = message[++i];
switch(code){
case 'c':
{
// TODO: We should colorize with HTML instead of turning into a string.
// Ignore for now.
result = startQuote ? `${result}]` : `[${result}`;
startQuote = !startQuote;
idx++;
break;
}
case 'O':
case 'o':
{
result += formatObject(args[idx++], 0);
break;
}
case 'd':
case 'i':
{
result += parseInt(args[idx++], 10);
break;
}
case 'f':
{
result += parseFloat(args[idx++]);
break;
}
case 's':
{
result += String(args[idx++]);
break;
}
default:
result += '%' + code;
}
}
for(; idx < args.length; idx++){
result += (idx > 0 ? ' ' : '') + formatObject(args[idx], 0);
}
return result;
}
function parseConsoleArgs(args) {
// See
// https://github.com/facebook/react/blob/65a56d0e99261481c721334a3ec4561d173594cd/packages/react-devtools-shared/src/backend/flight/renderer.js#L88-L93
//
// Logs replayed from the server look like this:
// [
// "%c%s%c%o\n\n%s\n\n%s\n",
// "background: #e6e6e6; ...",
// " Server ", // can also be e.g. " Prerender "
// "",
// Error,
// "The above error occurred in the <Page> component.",
// ...
// ]
if (args.length > 3 && typeof args[0] === 'string' && args[0].startsWith('%c%s%c') && typeof args[1] === 'string' && typeof args[2] === 'string' && typeof args[3] === 'string') {
const environmentName = args[2];
const maybeError = args[4];
return {
environmentName: environmentName.trim(),
error: (0, _iserror.default)(maybeError) ? maybeError : null
};
}
return {
environmentName: null,
error: null
};
}
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=console.js.map
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
export declare function isJavaScriptURLString(url: string): boolean;
+32
View File
@@ -0,0 +1,32 @@
// Adapted from React's sanitizeURL function found here: https://github.com/facebook/react/blob/b565373afd0cc1988497e1107106e851e8cfb261/packages/react-dom-bindings/src/shared/sanitizeURL.js
// A javascript: URL can contain leading C0 control or \u0020 SPACE,
// and any newline or tab are filtered out as if they're not part of the URL.
// https://url.spec.whatwg.org/#url-parsing
// Tab or newline are defined as \r\n\t:
// https://infra.spec.whatwg.org/#ascii-tab-or-newline
// A C0 control is a code point in the range \u0000 NULL to \u001F
// INFORMATION SEPARATOR ONE, inclusive:
// https://infra.spec.whatwg.org/#c0-control-or-space
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "isJavaScriptURLString", {
enumerable: true,
get: function() {
return isJavaScriptURLString;
}
});
const isJavaScriptProtocol = // eslint-disable-next-line no-control-regex
/^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;
function isJavaScriptURLString(url) {
return isJavaScriptProtocol.test('' + url);
}
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=javascript-url.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/client/lib/javascript-url.ts"],"sourcesContent":["// Adapted from React's sanitizeURL function found here: https://github.com/facebook/react/blob/b565373afd0cc1988497e1107106e851e8cfb261/packages/react-dom-bindings/src/shared/sanitizeURL.js\n\n// A javascript: URL can contain leading C0 control or \\u0020 SPACE,\n// and any newline or tab are filtered out as if they're not part of the URL.\n// https://url.spec.whatwg.org/#url-parsing\n// Tab or newline are defined as \\r\\n\\t:\n// https://infra.spec.whatwg.org/#ascii-tab-or-newline\n// A C0 control is a code point in the range \\u0000 NULL to \\u001F\n// INFORMATION SEPARATOR ONE, inclusive:\n// https://infra.spec.whatwg.org/#c0-control-or-space\n\nconst isJavaScriptProtocol =\n // eslint-disable-next-line no-control-regex\n /^[\\u0000-\\u001F ]*j[\\r\\n\\t]*a[\\r\\n\\t]*v[\\r\\n\\t]*a[\\r\\n\\t]*s[\\r\\n\\t]*c[\\r\\n\\t]*r[\\r\\n\\t]*i[\\r\\n\\t]*p[\\r\\n\\t]*t[\\r\\n\\t]*:/i\n\nexport function isJavaScriptURLString(url: string): boolean {\n return isJavaScriptProtocol.test('' + (url as unknown as string))\n}\n"],"names":["isJavaScriptURLString","isJavaScriptProtocol","url","test"],"mappings":"AAAA,8LAA8L;AAE9L,oEAAoE;AACpE,6EAA6E;AAC7E,2CAA2C;AAC3C,wCAAwC;AACxC,sDAAsD;AACtD,kEAAkE;AAClE,wCAAwC;AACxC,qDAAqD;;;;;+BAMrCA;;;eAAAA;;;AAJhB,MAAMC,uBACJ,4CAA4C;AAC5C;AAEK,SAASD,sBAAsBE,GAAW;IAC/C,OAAOD,qBAAqBE,IAAI,CAAC,KAAMD;AACzC","ignoreList":[0]}
+2
View File
@@ -0,0 +1,2 @@
/** Resolve a promise that times out after given amount of milliseconds. */
export declare function resolvePromiseWithTimeout<T>(p: Promise<T>, err: Error, devPromise: Promise<void> | undefined): Promise<T>;
+53
View File
@@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "resolvePromiseWithTimeout", {
enumerable: true,
get: function() {
return resolvePromiseWithTimeout;
}
});
const _requestidlecallback = require("../request-idle-callback");
// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive
// considers as "Good" time-to-interactive. We must assume something went
// wrong beyond this point, and then fall-back to a full page transition to
// show the user something of value.
const MS_MAX_IDLE_DELAY = 3800;
function resolvePromiseWithTimeout(p, err, devPromise) {
return new Promise((resolve, reject)=>{
let cancelled = false;
p.then((r)=>{
// Resolved, cancel the timeout
cancelled = true;
resolve(r);
}).catch(reject);
// We wrap these checks separately for better dead-code elimination in
// production bundles.
if (process.env.NODE_ENV === 'development') {
;
(devPromise || Promise.resolve()).then(()=>{
(0, _requestidlecallback.requestIdleCallback)(()=>setTimeout(()=>{
if (!cancelled) {
reject(err);
}
}, MS_MAX_IDLE_DELAY));
});
}
if (process.env.NODE_ENV !== 'development') {
(0, _requestidlecallback.requestIdleCallback)(()=>setTimeout(()=>{
if (!cancelled) {
reject(err);
}
}, MS_MAX_IDLE_DELAY));
}
});
}
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=promise.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/client/lib/promise.ts"],"sourcesContent":["import { requestIdleCallback } from '../request-idle-callback'\n\n// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive\n// considers as \"Good\" time-to-interactive. We must assume something went\n// wrong beyond this point, and then fall-back to a full page transition to\n// show the user something of value.\nconst MS_MAX_IDLE_DELAY = 3800\n\n/** Resolve a promise that times out after given amount of milliseconds. */\nexport function resolvePromiseWithTimeout<T>(\n p: Promise<T>,\n err: Error,\n devPromise: Promise<void> | undefined\n): Promise<T> {\n return new Promise((resolve, reject) => {\n let cancelled = false\n\n p.then((r) => {\n // Resolved, cancel the timeout\n cancelled = true\n resolve(r)\n }).catch(reject)\n\n // We wrap these checks separately for better dead-code elimination in\n // production bundles.\n if (process.env.NODE_ENV === 'development') {\n ;(devPromise || Promise.resolve()).then(() => {\n requestIdleCallback(() =>\n setTimeout(() => {\n if (!cancelled) {\n reject(err)\n }\n }, MS_MAX_IDLE_DELAY)\n )\n })\n }\n\n if (process.env.NODE_ENV !== 'development') {\n requestIdleCallback(() =>\n setTimeout(() => {\n if (!cancelled) {\n reject(err)\n }\n }, MS_MAX_IDLE_DELAY)\n )\n }\n })\n}\n"],"names":["resolvePromiseWithTimeout","MS_MAX_IDLE_DELAY","p","err","devPromise","Promise","resolve","reject","cancelled","then","r","catch","process","env","NODE_ENV","requestIdleCallback","setTimeout"],"mappings":";;;;+BASgBA;;;eAAAA;;;qCAToB;AAEpC,uEAAuE;AACvE,yEAAyE;AACzE,2EAA2E;AAC3E,oCAAoC;AACpC,MAAMC,oBAAoB;AAGnB,SAASD,0BACdE,CAAa,EACbC,GAAU,EACVC,UAAqC;IAErC,OAAO,IAAIC,QAAQ,CAACC,SAASC;QAC3B,IAAIC,YAAY;QAEhBN,EAAEO,IAAI,CAAC,CAACC;YACN,+BAA+B;YAC/BF,YAAY;YACZF,QAAQI;QACV,GAAGC,KAAK,CAACJ;QAET,sEAAsE;QACtE,sBAAsB;QACtB,IAAIK,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;;YACxCV,CAAAA,cAAcC,QAAQC,OAAO,EAAC,EAAGG,IAAI,CAAC;gBACtCM,IAAAA,wCAAmB,EAAC,IAClBC,WAAW;wBACT,IAAI,CAACR,WAAW;4BACdD,OAAOJ;wBACT;oBACF,GAAGF;YAEP;QACF;QAEA,IAAIW,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;YAC1CC,IAAAA,wCAAmB,EAAC,IAClBC,WAAW;oBACT,IAAI,CAACR,WAAW;wBACdD,OAAOJ;oBACT;gBACF,GAAGF;QAEP;IACF;AACF","ignoreList":[0]}