import fs from "node:fs";
import { performance } from "perf_hooks";
import { attachContentServerListeners } from "../../content/index.js";
import { telemetry } from "../../events/index.js";
import { info, warn } from "../logger/core.js";
import * as msg from "../messages.js";
import { startContainer } from "./container.js";
import { createContainerWithAutomaticRestart } from "./restart.js";
async function dev(inlineConfig) {
  var _a, _b;
  const devStart = performance.now();
  await telemetry.record([]);
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
  const logging = restart.container.logging;
  const devServerAddressInfo = await startContainer(restart.container);
  info(
    logging,
    null,
    msg.serverStart({
      startupTime: performance.now() - devStart,
      resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
      host: restart.container.settings.config.server.host,
      base: restart.container.settings.config.base
    })
  );
  const currentVersion = "2.10.2";
  if (currentVersion.includes("-")) {
    warn(logging, null, msg.prerelease({ currentVersion }));
  }
  if (((_b = (_a = restart.container.viteServer.config.server) == null ? void 0 : _a.fs) == null ? void 0 : _b.strict) === false) {
    warn(logging, null, msg.fsStrictWarning());
  }
  await attachContentServerListeners(restart.container);
  return {
    address: devServerAddressInfo,
    get watcher() {
      return restart.container.viteServer.watcher;
    },
    handle(req, res) {
      return restart.container.handle(req, res);
    },
    async stop() {
      await restart.container.close();
    }
  };
}
export {
  dev as default
};
