{"version":3,"file":"index.cjs","sources":["../../../../packages/php-wasm/logger/src/lib/handlers/log-event.ts","../../../../packages/php-wasm/logger/src/lib/handlers/log-to-console.ts","../../../../packages/php-wasm/logger/src/lib/handlers/log-to-memory.ts","../../../../packages/php-wasm/logger/src/lib/collectors/collect-php-logs.ts","../../../../packages/php-wasm/logger/src/lib/logger.ts","../../../../packages/php-wasm/logger/src/lib/collectors/collect-window-errors.ts","../../../../packages/php-wasm/logger/src/lib/collectors/collect-service-worker-metrics.ts"],"sourcesContent":["import type { LogHandler } from '../log-handlers';\nimport { type Log, logger } from '../logger';\n\nexport const logEventType = 'playground-log';\n\nexport const logEvent: LogHandler = (log: Log, ...args: any[]): void => {\n\tlogger.dispatchEvent(\n\t\tnew CustomEvent(logEventType, {\n\t\t\tdetail: {\n\t\t\t\tlog,\n\t\t\t\targs,\n\t\t\t},\n\t\t})\n\t);\n};\n","import type { LogHandler } from '../log-handlers';\nimport { type Log, LogSeverity, prepareLogMessage } from '../logger';\n\n/**\n * Log message to the console.\n */\nexport const logToConsole: LogHandler = (log: Log, ...args: any[]): void => {\n\tif (typeof log.message === 'string') {\n\t\t// Some errors have a read-only message property where direct\n\t\t// assignment will throw an error. The assignment is merely for\n\t\t// formatting, so let's assign with Reflect.set and avoid the error.\n\t\tReflect.set(log, 'message', prepareLogMessage(log.message));\n\t} else if (log.message.message && typeof log.message.message === 'string') {\n\t\t// Some errors have a read-only message property where direct\n\t\t// assignment will throw an error. The assignment is merely for\n\t\t// formatting, so let's assign with Reflect.set and avoid the error.\n\t\tReflect.set(\n\t\t\tlog.message,\n\t\t\t'message',\n\t\t\tprepareLogMessage(log.message.message)\n\t\t);\n\t}\n\t/* eslint-disable no-console */\n\tswitch (log.severity) {\n\t\tcase LogSeverity.Debug:\n\t\t\tconsole.debug(log.message, ...args);\n\t\t\tbreak;\n\t\tcase LogSeverity.Info:\n\t\t\tconsole.info(log.message, ...args);\n\t\t\tbreak;\n\t\tcase LogSeverity.Warn:\n\t\t\tconsole.warn(log.message, ...args);\n\t\t\tbreak;\n\t\tcase LogSeverity.Error:\n\t\t\tconsole.error(log.message, ...args);\n\t\t\tbreak;\n\t\tcase LogSeverity.Fatal:\n\t\t\tconsole.error(log.message, ...args);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tconsole.log(log.message, ...args);\n\t}\n\t/* eslint-enable no-console */\n};\n","import type { LogHandler } from '../log-handlers';\nimport { formatLogEntry, type Log, LogPrefix } from '../logger';\n\nconst prepareLogMessage = (logMessage: object): string => {\n\tif (logMessage instanceof Error) {\n\t\treturn [logMessage.message, logMessage.stack].join('\\n');\n\t}\n\treturn JSON.stringify(logMessage, null, 2);\n};\n\nexport const logs: string[] = [];\n\nconst addToLogArray = (message: string): void => {\n\tlogs.push(message);\n};\n\n/**\n * Log to memory\n */\nexport const logToMemory: LogHandler = (log: Log): void => {\n\tif (log.raw === true) {\n\t\taddToLogArray(log.message);\n\t} else {\n\t\tconst message = formatLogEntry(\n\t\t\ttypeof log.message === 'object'\n\t\t\t\t? prepareLogMessage(log.message)\n\t\t\t\t: log.message,\n\t\t\tlog.severity,\n\t\t\tlog.prefix ?? LogPrefix.JS\n\t\t);\n\t\taddToLogArray(message);\n\t}\n};\n\nexport const clearMemoryLogs = (): void => {\n\tlogs.length = 0;\n};\n","import type { UniversalPHP, PHPRequestErrorEvent } from '../types';\nimport { type Logger, LogPrefix, LogSeverity } from '../logger';\n\nexport const errorLogPath = '/wordpress/wp-content/debug.log';\n\n/**\n * Read the WordPress debug.log file and return its content.\n *\n * @param UniversalPHP playground instance\n * @returns string The content of the debug.log file\n */\nconst getRequestPhpErrorLog = async (playground: UniversalPHP) => {\n\tif (!(await playground.fileExists(errorLogPath))) {\n\t\treturn '';\n\t}\n\treturn await playground.readFileAsText(errorLogPath);\n};\n\n/**\n * Collect PHP logs from the error_log file and log them.\n * @param UniversalPHP playground instance\n * @param loggerInstance The logger instance\n */\nexport const collectPhpLogs = (\n\tloggerInstance: Logger,\n\tplayground: UniversalPHP\n) => {\n\tlet lastPHPLog = '';\n\tplayground.addEventListener('request.end', async () => {\n\t\tconst log = await getRequestPhpErrorLog(playground);\n\t\t// Imports can replace debug.log with a shorter or unrelated file. Track\n\t\t// each Playground separately and only skip a prefix we actually read.\n\t\tconst currentLog = log.startsWith(lastPHPLog)\n\t\t\t? log.substring(lastPHPLog.length)\n\t\t\t: log;\n\t\tlastPHPLog = log;\n\t\tif (currentLog) {\n\t\t\tloggerInstance.logMessage({\n\t\t\t\tmessage: currentLog,\n\t\t\t\tseverity: LogSeverity.Log,\n\t\t\t\traw: true,\n\t\t\t});\n\t\t}\n\t});\n\tplayground.addEventListener('request.error', (event) => {\n\t\tevent = event as PHPRequestErrorEvent;\n\t\tif (event.error) {\n\t\t\tloggerInstance.logMessage({\n\t\t\t\tmessage: `${event.error.message} ${event.error.stack}`,\n\t\t\t\tseverity: LogSeverity.Fatal,\n\t\t\t\tprefix:\n\t\t\t\t\tevent.source === 'request' ? LogPrefix.PHP : LogPrefix.WASM,\n\t\t\t});\n\t\t\tloggerInstance.dispatchEvent(\n\t\t\t\tnew CustomEvent(loggerInstance.fatalErrorEvent, {\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\tlogs: loggerInstance.getLogs(),\n\t\t\t\t\t\tsource: event.source,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t});\n};\n","import { logEvent } from './handlers/log-event';\nimport {\n\tlogToMemory,\n\tlogToConsole,\n\tlogs,\n\ttype LogHandler,\n} from './log-handlers';\n\nexport { logEventType } from './handlers/log-event';\n\nexport { errorLogPath } from './collectors/collect-php-logs';\n\nexport type Log = {\n\tmessage: any;\n\tseverity: LogSeverity;\n\tprefix?: LogPrefix;\n\traw?: boolean;\n};\n\n/**\n * Log severity levels.\n */\nexport const LogSeverity = {\n\tFatal: { name: 'fatal', level: 0 },\n\tError: { name: 'error', level: 1 },\n\tWarn: { name: 'warn', level: 2 },\n\tLog: { name: 'log', level: 3 },\n\tInfo: { name: 'info', level: 4 },\n\tDebug: { name: 'debug', level: 5 },\n} as const;\n\nexport type LogSeverity = (typeof LogSeverity)[keyof typeof LogSeverity];\n\n/**\n * Log prefix.\n */\nexport const LogPrefix = {\n\tWASM: 'Wasm Crash',\n\tPHP: 'PHP',\n\tJS: 'JavaScript',\n} as const;\n\nexport type LogPrefix = (typeof LogPrefix)[keyof typeof LogPrefix];\n\n/**\n * A logger for Playground.\n */\nexport class Logger extends EventTarget {\n\tpublic readonly fatalErrorEvent = 'playground-fatal-error';\n\tprivate readonly handlers: LogHandler[];\n\tprivate severity: LogSeverity = LogSeverity.Info;\n\n\t// constructor\n\tconstructor(\n\t\t// Log handlers\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n\t\thandlers: LogHandler[] = []\n\t) {\n\t\tsuper();\n\t\tthis.handlers = handlers;\n\t}\n\n\t/**\n\t * Get all logs.\n\t * @returns string[]\n\t */\n\tpublic getLogs(): string[] {\n\t\tif (!this.handlers.includes(logToMemory)) {\n\t\t\tthis\n\t\t\t\t.error(`Logs aren't stored because the logToMemory handler isn't registered.\n\t\t\t\tIf you're using a custom logger instance, make sure to register logToMemory handler.\n\t\t\t`);\n\t\t\treturn [];\n\t\t}\n\t\treturn [...logs];\n\t}\n\n\t/**\n\t * Log message with severity.\n\t *\n\t * @param log Log\n\t * @param args any\n\t */\n\tpublic logMessage(\n\t\tlog: Omit<Log, 'severity'> & { severity?: LogSeverity },\n\t\t...args: any[]\n\t): void {\n\t\tconst logWithSeverity: Log = {\n\t\t\t...log,\n\t\t\tseverity: log.severity ?? LogSeverity.Log,\n\t\t};\n\t\tfor (const handler of this.handlers) {\n\t\t\tif (logWithSeverity.severity.level <= this.severity.level) {\n\t\t\t\thandler(logWithSeverity, ...args);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Filter message based on severity\n\t * @param severity LogSeverity\n\t */\n\tpublic setSeverityFilterLevel(severity: LogSeverity): void {\n\t\tthis.severity = severity;\n\t}\n\n\t/**\n\t * Log message\n\t *\n\t * @param message any\n\t * @param args any\n\t */\n\tpublic log(message: any, ...args: any[]): void {\n\t\tthis.logMessage(\n\t\t\t{\n\t\t\t\tmessage,\n\t\t\t\tseverity: LogSeverity.Log,\n\t\t\t\tprefix: LogPrefix.JS,\n\t\t\t\traw: false,\n\t\t\t},\n\t\t\t...args\n\t\t);\n\t}\n\n\t/**\n\t * Log debug message\n\t *\n\t * @param message any\n\t * @param args any\n\t */\n\tpublic debug(message: any, ...args: any[]): void {\n\t\tthis.logMessage(\n\t\t\t{\n\t\t\t\tmessage,\n\t\t\t\tseverity: LogSeverity.Debug,\n\t\t\t\tprefix: LogPrefix.JS,\n\t\t\t\traw: false,\n\t\t\t},\n\t\t\t...args\n\t\t);\n\t}\n\n\t/**\n\t * Log info message\n\t *\n\t * @param message any\n\t * @param args any\n\t */\n\tpublic info(message: any, ...args: any[]): void {\n\t\tthis.logMessage(\n\t\t\t{\n\t\t\t\tmessage,\n\t\t\t\tseverity: LogSeverity.Info,\n\t\t\t\tprefix: LogPrefix.JS,\n\t\t\t\traw: false,\n\t\t\t},\n\t\t\t...args\n\t\t);\n\t}\n\n\t/**\n\t * Log warning message\n\t *\n\t * @param message any\n\t * @param args any\n\t */\n\tpublic warn(message: any, ...args: any[]): void {\n\t\tthis.logMessage(\n\t\t\t{\n\t\t\t\tmessage,\n\t\t\t\tseverity: LogSeverity.Warn,\n\t\t\t\tprefix: LogPrefix.JS,\n\t\t\t\traw: false,\n\t\t\t},\n\t\t\t...args\n\t\t);\n\t}\n\n\t/**\n\t * Log error message\n\t *\n\t * @param message any\n\t * @param args any\n\t */\n\tpublic error(message: any, ...args: any[]): void {\n\t\tthis.logMessage(\n\t\t\t{\n\t\t\t\tmessage,\n\t\t\t\tseverity: LogSeverity.Error,\n\t\t\t\tprefix: LogPrefix.JS,\n\t\t\t\traw: false,\n\t\t\t},\n\t\t\t...args\n\t\t);\n\t}\n}\n\nconst getDefaultHandlers = () => {\n\ttry {\n\t\tif (process.env['NODE_ENV'] === 'test') {\n\t\t\treturn [logToMemory, logEvent];\n\t\t}\n\t} catch {\n\t\t// Process.env is not available in the browser\n\t}\n\treturn [logToMemory, logToConsole, logEvent];\n};\n\n/**\n * The logger instance.\n */\nexport const logger: Logger = new Logger(getDefaultHandlers());\n\nexport const prepareLogMessage = (message: string) => {\n\treturn message.replace(/\\t/g, '');\n};\n\nexport const formatLogEntry = (\n\tmessage: string,\n\tseverity: LogSeverity,\n\tprefix: string\n): string => {\n\tconst date = new Date();\n\tconst formattedDate = new Intl.DateTimeFormat('en-GB', {\n\t\tyear: 'numeric',\n\t\tmonth: 'short',\n\t\tday: '2-digit',\n\t\ttimeZone: 'UTC',\n\t})\n\t\t.format(date)\n\t\t.replace(/ /g, '-');\n\n\tconst formattedTime = new Intl.DateTimeFormat('en-GB', {\n\t\thour: '2-digit',\n\t\tminute: '2-digit',\n\t\tsecond: '2-digit',\n\t\thour12: false,\n\t\ttimeZone: 'UTC',\n\t\ttimeZoneName: 'short',\n\t}).format(date);\n\tconst now = formattedDate + ' ' + formattedTime;\n\tmessage = prepareLogMessage(message);\n\treturn `[${now}] ${prefix} ${severity.name}: ${message}`;\n};\n\n/**\n * Add a listener for the Playground crashes.\n * These crashes include Playground errors like Asyncify errors.\n * The callback function will receive an Event object with logs in the detail\n * property.\n *\n * @param loggerInstance The logger instance\n * @param callback The callback function\n */\nexport const addCrashListener = (\n\tloggerInstance: Logger,\n\tcallback: EventListenerOrEventListenerObject\n) => {\n\tloggerInstance.addEventListener(loggerInstance.fatalErrorEvent, callback);\n};\n","import { type Logger, LogSeverity } from '../logger';\n\n/**\n * Log Windows errors.\n *\n * @param loggerInstance The logger instance\n * @param ErrorEvent event\n */\nconst logWindowErrorEvent = (loggerInstance: Logger, event: ErrorEvent) => {\n\tloggerInstance.logMessage({\n\t\tmessage: `${event.message} in ${event.filename} on line ${event.lineno}:${event.colno}`,\n\t\tseverity: LogSeverity.Error,\n\t});\n};\n\n/**\n * Log promise rejections.\n *\n * @param loggerInstance The logger instance\n * @param PromiseRejectionEvent event\n */\nconst logPromiseRejection = (\n\tloggerInstance: Logger,\n\tevent: PromiseRejectionEvent\n) => {\n\t// No reason was provided, so we can't log anything.\n\tif (!event?.reason) {\n\t\treturn;\n\t}\n\tconst message = event?.reason.stack ?? event.reason;\n\tloggerInstance.logMessage({\n\t\tmessage,\n\t\tseverity: LogSeverity.Error,\n\t});\n};\n\n/**\n * The number of open Playground tabs.\n */\nlet numberOfOpenPlaygroundTabs = 0;\n\n/**\n * Register a listener for service worker messages and log the data.\n * The service worker will send the number of open Playground tabs.\n *\n * @param loggerInstance The logger instance\n */\nconst addServiceWorkerMessageListener = (loggerInstance: Logger) => {\n\tnavigator.serviceWorker.addEventListener('message', (event) => {\n\t\tif (event.data?.numberOfOpenPlaygroundTabs === undefined) {\n\t\t\treturn;\n\t\t}\n\t\t// Each tab sends an activate event on load. Prevent sending the same\n\t\t// metrics multiple times if a tab is reloaded.\n\t\tif (\n\t\t\tnumberOfOpenPlaygroundTabs ===\n\t\t\tevent.data?.numberOfOpenPlaygroundTabs\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tnumberOfOpenPlaygroundTabs = event.data?.numberOfOpenPlaygroundTabs;\n\t\tloggerInstance.debug(\n\t\t\t`Number of open Playground tabs is: ${numberOfOpenPlaygroundTabs}`\n\t\t);\n\t});\n};\n\n// If the window events are already connected.\nlet windowConnected = false;\n\n/**\n * Collect errors from JavaScript window events like error and log them.\n * @param loggerInstance The logger instance\n */\nexport const collectWindowErrors = (loggerInstance: Logger) => {\n\t// Ensure that the window events are connected only once.\n\tif (windowConnected) {\n\t\treturn;\n\t}\n\taddServiceWorkerMessageListener(loggerInstance);\n\tif (typeof window === 'undefined') {\n\t\treturn;\n\t}\n\n\twindow.addEventListener('error', (event) =>\n\t\tlogWindowErrorEvent(loggerInstance, event as ErrorEvent)\n\t);\n\twindow.addEventListener('unhandledrejection', (event) =>\n\t\tlogPromiseRejection(loggerInstance, event as PromiseRejectionEvent)\n\t);\n\twindow.addEventListener('rejectionhandled', (event) =>\n\t\tlogPromiseRejection(loggerInstance, event as PromiseRejectionEvent)\n\t);\n\twindowConnected = true;\n};\n","/// <reference lib=\"WebWorker\" />\n\n/**\n * **Call this inside a service worker.**\n * These errors include Playground errors like Asyncify errors. PHP errors\n * won't trigger this event.\n *\n * Reports service worker metrics.\n * Allows the logger to request metrics from the service worker by sending a\n * message. The service worker will respond with the number of open Playground\n * tabs.\n *\n * @param worker The service worker\n */\nexport const reportServiceWorkerMetrics = (\n\tworker: ServiceWorkerGlobalScope\n) => {\n\tworker.addEventListener('activate', () => {\n\t\tworker.clients.matchAll().then((clients) => {\n\t\t\tconst metrics = {\n\t\t\t\tnumberOfOpenPlaygroundTabs: clients.filter(\n\t\t\t\t\t// Only count top-level frames to get the number of tabs.\n\t\t\t\t\t(c) => c.frameType === 'top-level'\n\t\t\t\t).length,\n\t\t\t};\n\t\t\tfor (const client of clients) {\n\t\t\t\tclient.postMessage(metrics);\n\t\t\t}\n\t\t});\n\t});\n};\n"],"names":["logEventType","logEvent","log","args","logger","logToConsole","prepareLogMessage","LogSeverity","logMessage","logs","addToLogArray","message","logToMemory","formatLogEntry","LogPrefix","clearMemoryLogs","errorLogPath","getRequestPhpErrorLog","playground","collectPhpLogs","loggerInstance","lastPHPLog","currentLog","event","Logger","handlers","logWithSeverity","handler","severity","getDefaultHandlers","prefix","date","formattedDate","formattedTime","now","addCrashListener","callback","logWindowErrorEvent","logPromiseRejection","numberOfOpenPlaygroundTabs","addServiceWorkerMessageListener","_a","_b","_c","windowConnected","collectWindowErrors","reportServiceWorkerMetrics","worker","clients","metrics","c","client"],"mappings":"gFAGO,MAAMA,EAAe,iBAEfC,EAAuB,CAACC,KAAaC,IAAsB,CACvEC,EAAO,cACN,IAAI,YAAYJ,EAAc,CAC7B,OAAQ,CACP,IAAAE,EACA,KAAAC,CAAA,CACD,CACA,CAAA,CAEH,ECRaE,EAA2B,CAACH,KA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