import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  ErrorViewer,
  createRendererToString,
  isCliError,
  require_react
} from "./chunk-NBSLOOJ5.js";
import {
  __toESM,
  init_esm_shims
} from "./chunk-4EFJZ3GQ.js";

// src/vite/logger.tsx
init_esm_shims();
var import_react = __toESM(require_react(), 1);
import { createLogger as createViteLogger } from "vite";
function isInfoMessageFiltered(msg) {
  return [/Port \d{1,5} is in use, trying another one/].some(
    (x) => x.test(msg)
  );
}
function createLogger({
  timestamp
} = {}) {
  const renderer = createRendererToString({ stripAnsi: false });
  const originalLogger = createViteLogger("info", {
    allowClearScreen: false,
    prefix: ""
  });
  const defaultOptions = { timestamp };
  const logMessage = (level, msg, options) => {
    const logOptions = { ...options, ...defaultOptions };
    if (typeof msg === "string") {
      if (!isInfoMessageFiltered(msg)) {
        return originalLogger[level](msg, logOptions);
      }
      return null;
    }
    return setTimeout(
      () => originalLogger[level](renderer.render(msg), logOptions)
    );
  };
  return {
    ...originalLogger,
    info: (msg, options) => logMessage("info", msg, options),
    error: (msg, options) => {
      if (msg instanceof Error) {
        return logMessage("error", /* @__PURE__ */ import_react.default.createElement(ErrorViewer, { error: msg }));
      }
      if (isCliError(options?.error)) {
        return logMessage("error", /* @__PURE__ */ import_react.default.createElement(ErrorViewer, { error: options.error }));
      }
      return logMessage("error", msg, options);
    },
    warn: (msg, options) => logMessage("warn", msg, options),
    warnOnce: (msg, options) => logMessage("warnOnce", msg, options)
  };
}

export {
  createLogger
};
//# sourceMappingURL=chunk-4UDB266J.js.map